diff --git a/backend.php b/backend.php index 38ace29..9692c6a 100644 --- a/backend.php +++ b/backend.php @@ -20,3 +20,35 @@ if ($_GET['controller'] == "Article"){ echo "Artikel wurden gespeichert."; } } + +if ($_GET['controller'] == "Inventur"){ + if ($_GET['action'] == "export") { + $json = file_get_contents('php://input'); + $list = json_decode($json, true); + $fp = fopen('data/inventur_'.date('Y-m-d').'.csv', 'w'); + + fputcsv($fp,array_keys(flatten($list[0]))); + foreach ($list as $obj) { + $fields = flatten($obj); + //array_walk_recursive($obj, function($a)use (&$fields) { $fields[] = $a;}); + //print_r($fields); + fputcsv($fp,$fields); + } + echo "Inventur wurde gespeichert."; + fclose($fp); + } +} + + +function flatten($array, $prefix = '') { + $result = array(); + foreach($array as $key=>$value) { + if(is_array($value)) { + $result = $result + flatten($value, $prefix . $key . '_'); + } + else { + $result[$prefix . $key] = $value; + } + } + return $result; +} \ No newline at end of file diff --git a/data/articles.json b/data/articles.json index 93a2a8b..a02072b 100644 --- a/data/articles.json +++ b/data/articles.json @@ -1,5 +1,6 @@ [{ "name": "Edelpils", + "short": "Pils", "dimension": "l", "content": { "size": 0.33, @@ -12,6 +13,7 @@ } }, { "name": "Schwarzbier", + "short": "Sb", "dimension": "l", "content": { "size": 0.33, @@ -24,6 +26,7 @@ } }, { "name": "Schöfferhofer", + "short": "Schö", "dimension": "l", "content": { "size": 0.33, @@ -36,6 +39,7 @@ } }, { "name": "Bitburger af.", + "short": "0%", "dimension": "l", "content": { "size": 0.33, @@ -48,6 +52,7 @@ } }, { "name": "Weiswein", + "short": "WW", "dimension": "l", "content": { "size": 1, @@ -60,6 +65,7 @@ } }, { "name": "Rotwein", + "short": "RW", "dimension": "l", "content": { "size": 0.75, @@ -72,6 +78,7 @@ } }, { "name": "Secco", + "short": "Sekt", "dimension": "l", "content": { "size": 0.75, @@ -84,6 +91,7 @@ } }, { "name": "B-Saft", + "short": "BS", "dimension": "l", "content": { "size": 1, @@ -96,6 +104,7 @@ } }, { "name": "K-Saft", + "short": "KS", "dimension": "l", "content": { "size": 1, @@ -108,6 +117,7 @@ } }, { "name": "O-Saft", + "short": "OS", "dimension": "l", "content": { "size": 1, @@ -120,6 +130,7 @@ } }, { "name": "G-Saft", + "short": "GS", "dimension": "l", "content": { "size": 1, @@ -132,6 +143,7 @@ } }, { "name": "Vita Cola", + "short": "Co", "dimension": "l", "content": { "size": 1, @@ -144,6 +156,7 @@ } }, { "name": "Vita Orange", + "short": "Fa", "dimension": "l", "content": { "size": 1, @@ -156,6 +169,7 @@ } }, { "name": "Vita Zitrone", + "short": "Spr", "dimension": "l", "content": { "size": 1, @@ -168,6 +182,7 @@ } }, { "name": "Tonic", + "short": "To", "dimension": "l", "content": { "size": 0.25, @@ -180,6 +195,7 @@ } }, { "name": "Bitter Lemon", + "short": "BL", "dimension": "l", "content": { "size": 0.25, @@ -192,6 +208,7 @@ } }, { "name": "Ginger Ale", + "short": "GA", "dimension": "l", "content": { "size": 0.25, @@ -204,6 +221,7 @@ } }, { "name": "Apfelschorle", + "short": "AS", "dimension": "l", "content": { "size": 0.25, @@ -216,6 +234,7 @@ } }, { "name": "TWQ naturell", + "short": "W-", "dimension": "l", "content": { "size": 0.25, @@ -228,6 +247,7 @@ } }, { "name": "TWQ medium", + "short": "W", "dimension": "l", "content": { "size": 0.25, @@ -240,6 +260,7 @@ } }, { "name": "TWQ classic", + "short": "W+", "dimension": "l", "content": { "size": 0.25, @@ -252,6 +273,7 @@ } }, { "name": "Kaffee", + "short": "TK", "dimension": "Tasse", "content": { "size": 1, @@ -264,6 +286,7 @@ } }, { "name": "Latte Macchiato", + "short": "LM", "dimension": "Glas", "content": { "size": 1, @@ -276,6 +299,7 @@ } }, { "name": "dopp. Esp.", + "short": "dEsp", "dimension": "Tasse", "content": { "size": 1, @@ -288,6 +312,7 @@ } }, { "name": "Brezel", + "short": "Br", "dimension": "Stück", "content": { "size": 1, @@ -300,6 +325,7 @@ } }, { "name": "Schokoriegel", + "short": "Schoko", "dimension": "Stück", "content": { "size": 1, diff --git a/data/inventur_2018-01-25.csv b/data/inventur_2018-01-25.csv new file mode 100644 index 0000000..49720a5 --- /dev/null +++ b/data/inventur_2018-01-25.csv @@ -0,0 +1,27 @@ +article_name,article_short,article_dimension,article_content_size,article_content_price,article_portion_size,article_portion_price,article_portion_type,end,start,fetched,lost +Edelpils,Pils,l,0.33,0,0.33,3.5,Fl.,0,0,0,0 +Schwarzbier,Sb,l,0.33,0,0.33,3.5,Fl.,0,0,0,0 +Schöfferhofer,Schö,l,0.33,0,0.33,3.5,Fl.,0,0,0,0 +"Bitburger af.",0%,l,0.33,0,0.33,3.5,Fl.,0,0,0,0 +Weiswein,WW,l,1,0,0.2,6,Gl.,0,0,0,0 +Rotwein,RW,l,0.75,0,0.2,6.5,Gl.,0,0,0,0 +Secco,Sekt,l,0.75,0,0.1,6,Gl.,0,0,0,0 +B-Saft,BS,l,1,0,0.2,3.5,Gl.,0,0,0,0 +K-Saft,KS,l,1,0,0.2,3.5,Gl.,0,0,0,0 +O-Saft,OS,l,1,0,0.2,3.5,Gl.,0,0,0,0 +G-Saft,GS,l,1,0,0.2,3.5,Gl.,0,0,0,0 +"Vita Cola",Co,l,1,0,0.2,2.5,Gl.,0,0,0,0 +"Vita Orange",Fa,l,1,0,0.2,2.5,Gl.,0,0,0,0 +"Vita Zitrone",Spr,l,1,0,0.2,2.5,Gl.,0,0,0,0 +Tonic,To,l,0.25,0,0.25,3,Fl.,0,0,0,0 +"Bitter Lemon",BL,l,0.25,0,0.25,3,Fl.,0,0,0,0 +"Ginger Ale",GA,l,0.25,0,0.25,3,Fl.,0,0,0,0 +Apfelschorle,AS,l,0.25,0,0.25,3,Fl.,0,0,0,0 +"TWQ naturell",W-,l,0.25,0,0.25,2.5,Fl.,0,0,0,0 +"TWQ medium",W,l,0.25,0,0.25,2.5,Fl.,0,0,0,0 +"TWQ classic",W+,l,0.25,0,0.25,2.5,Fl.,0,0,0,0 +Kaffee,TK,Tasse,1,0,1,2.5,T,0,0,0,0 +"Latte Macchiato",LM,Glas,1,0,1,3.5,Gl.,0,0,0,0 +"dopp. Esp.",dEsp,Tasse,1,0,1,3.5,T,0,0,0,0 +Brezel,Br,Stück,1,0,1,2.5,Stk.,0,0,0,0 +Schokoriegel,Schoko,Stück,1,0,1,2,Stk.,0,0,0,0 diff --git a/index.html b/index.html index a864548..7c16ca0 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ - +
@@ -38,10 +38,14 @@