From cc4201f2b5ea8a930aad5b39df0757ea2bf5812b Mon Sep 17 00:00:00 2001 From: TLRZ Seyfferth Date: Thu, 25 Jan 2018 11:29:48 +0100 Subject: [PATCH] changed behaviour --- backend.php | 32 ++++++++++++++++++++++++++++++++ data/articles.json | 26 ++++++++++++++++++++++++++ data/inventur_2018-01-25.csv | 27 +++++++++++++++++++++++++++ index.html | 23 ++++++++++++----------- js/app.js | 18 ++++++++++-------- js/model/article.js | 8 ++++++++ 6 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 data/inventur_2018-01-25.csv 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 @@
{{ a.name }} -
+
+
+ + +
@@ -74,9 +78,6 @@ Artikel löschen
-
- -
@@ -109,7 +110,7 @@
-
+
@@ -126,12 +127,12 @@
-
- +
+
-
+
@@ -152,10 +153,10 @@ add
  • - save + reset
  • - add + export
  • diff --git a/js/app.js b/js/app.js index 3de080d..37af647 100644 --- a/js/app.js +++ b/js/app.js @@ -9,13 +9,6 @@ Vue.filter('number', function(number, precision = 2){ var app = new Vue({ el: "#app", data : { - dimensions: [ - 'l', - 'Stk.', - 'Gl.', - 'Fl.', - 'T.', - ], articles : [], inventory : { ug : [], @@ -70,13 +63,22 @@ var app = new Vue({ ia = new InventoryArticle(); ia.article = a; this.inventory.ug.push(ia); - this.bon.push({count: 0, name: a.name, price: a.portion.price}); + this.bon.push({count: 0, name: a.name, short: a.short, price: a.portion.price}); }); }).then( x => { M.updateTextFields(); this.ready = true; }); }, + resetInventur: function() { + + }, + exportInventur: function() { + this.$http.post('./backend?controller=Inventur&action=export', JSON.stringify(this.inventory.ug)) + .then(response => { + M.toast({html: response.body}); + }) + }, resetBon: function(article) { this.bon.forEach(function (item){ item.count = 0; diff --git a/js/model/article.js b/js/model/article.js index b9494b5..eacf25d 100644 --- a/js/model/article.js +++ b/js/model/article.js @@ -1,5 +1,6 @@ function Article() { this.name = ""; + this.short = ""; this.dimension = ""; this.content = { size : 0, @@ -19,6 +20,12 @@ Article.prototype = { set Name(value) { this.name = value; }, + get Short() { + return this.short; + }, + set Short(value) { + this.short = value; + }, get ContentSize() { return this.content.size; }, @@ -61,6 +68,7 @@ Article.thaw = function (json) { var article = new Article(); article.id = json.id; article.Name = json.name; + article.Short = json.short; article.Dimension = json.dimension; article.ContentSize = json.content.size; article.PortionPrice = json.portion.price;