Quellcode durchsuchen

Fix bugs in merchant transaction sorting/handling.
May need to go back and fix some other things that use merchant.getTransactionIndices.

Lee Morgan vor 5 Jahren
Ursprung
Commit
78701090a3

+ 22 - 6
views/dashboardPage/bundle.js

@@ -600,7 +600,7 @@ class Merchant{
         }]
     */
     getIngredientsSold(from = 0, to = new Date()){
-        if(from = 0){
+        if(from === 0){
             from = this._ingredients[0].date;
         }
         
@@ -615,6 +615,7 @@ class Merchant{
                     if(ingredientList[k].ingredient === recipes[i].recipe.ingredients[j].ingredient){
                         exists = true;
                         ingredientList[k].quantity += recipes[i].quantity * recipes[i].recipe.ingredients[j].quantity;
+                        break;
                     }
                 }
 
@@ -671,7 +672,7 @@ class Merchant{
         }]
     */
     getRecipesSold(from = 0, to = new Date()){
-        if(from = 0){
+        if(from === 0){
             from = this._transactions[0].date;
         }
 
@@ -783,7 +784,9 @@ class Merchant{
 
     getTransactionIndices(from, to){
         let start, end;
-        to.setDate(to.getDate() + 1);
+        console.log(from);
+        console.log(to);
+        
 
         for(let i = this._transactions.length - 1; i >= 0; i--){
             if(this._transactions[i].date >= from){
@@ -803,10 +806,10 @@ class Merchant{
             return false;
         }
 
-        //these are switched due to the order of the transactions in the merchant
-        return {start: end, end: start};
+        return {start: start, end: end};
     }
 
+
     isSanitaryString(str){
         let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
 
@@ -2643,7 +2646,20 @@ module.exports = newTransaction;
 },{}],14:[function(require,module,exports){
 let orderCalculator = {
     display: function(){
-        console.log("something");
+        let calculations = this.getDailyAverages();
+
+        // console.log(calculations);
+
+    },
+
+    getDailyAverages: function(){
+        let now = new Date();
+        let yesterday = new Date();
+        yesterday.setHours(0, 0, 0, 0);
+        let past = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
+
+        let ingredients = merchant.getIngredientsSold(past, yesterday);
+        console.log(ingredients);
     }
 }
 

+ 8 - 5
views/dashboardPage/js/classes/Merchant.js

@@ -473,7 +473,7 @@ class Merchant{
         }]
     */
     getIngredientsSold(from = 0, to = new Date()){
-        if(from = 0){
+        if(from === 0){
             from = this._ingredients[0].date;
         }
         
@@ -488,6 +488,7 @@ class Merchant{
                     if(ingredientList[k].ingredient === recipes[i].recipe.ingredients[j].ingredient){
                         exists = true;
                         ingredientList[k].quantity += recipes[i].quantity * recipes[i].recipe.ingredients[j].quantity;
+                        break;
                     }
                 }
 
@@ -544,7 +545,7 @@ class Merchant{
         }]
     */
     getRecipesSold(from = 0, to = new Date()){
-        if(from = 0){
+        if(from === 0){
             from = this._transactions[0].date;
         }
 
@@ -656,7 +657,9 @@ class Merchant{
 
     getTransactionIndices(from, to){
         let start, end;
-        to.setDate(to.getDate() + 1);
+        console.log(from);
+        console.log(to);
+        
 
         for(let i = this._transactions.length - 1; i >= 0; i--){
             if(this._transactions[i].date >= from){
@@ -676,10 +679,10 @@ class Merchant{
             return false;
         }
 
-        //these are switched due to the order of the transactions in the merchant
-        return {start: end, end: start};
+        return {start: start, end: end};
     }
 
+
     isSanitaryString(str){
         let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
 

+ 14 - 1
views/dashboardPage/js/sidebars/orderCalculator.js

@@ -1,6 +1,19 @@
 let orderCalculator = {
     display: function(){
-        console.log("something");
+        let calculations = this.getDailyAverages();
+
+        // console.log(calculations);
+
+    },
+
+    getDailyAverages: function(){
+        let now = new Date();
+        let yesterday = new Date();
+        yesterday.setHours(0, 0, 0, 0);
+        let past = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 30);
+
+        let ingredients = merchant.getIngredientsSold(past, yesterday);
+        console.log(ingredients);
     }
 }