Lee Morgan преди 5 години
родител
ревизия
b42407de2c
променени са 3 файла, в които са добавени 10 реда и са изтрити 7 реда
  1. 1 1
      views/dashboardPage/js/classes/Merchant.js
  2. 7 6
      views/dashboardPage/js/classes/Recipe.js
  3. 2 0
      views/dashboardPage/js/classes/Transaction.js

+ 1 - 1
views/dashboardPage/js/classes/Merchant.js

@@ -62,7 +62,7 @@ class MerchantIngredient{
         const {start, end} = this._parent.getTransactionIndices(from, to);
 
         for(let i = start; i < end; i++){
-            total += this._parent.transactions[i].getIngredientQuantity(this._ingredient);
+            total += this._parent.transactions[i].getIngredientQuantityBase(this._ingredient);
         }
 
         return total;

+ 7 - 6
views/dashboardPage/js/classes/Recipe.js

@@ -125,7 +125,7 @@ class Recipe{
     }
 
     getIngredientTotalBase(id){
-        return (this._ingredientTotalsBase[i] === undefined) ? 0 : this._ingredientTotals[id];
+        return (this._ingredientTotalsBase[id] === undefined) ? 0 : this._ingredientTotalsBase[id];
     }
 
     addIngredient(ingredient, quantity, unit, baseUnitMultiplier){
@@ -143,9 +143,10 @@ class Recipe{
     calculateIngredientTotals(){
         this._ingredientTotals = {};
         
-        let traverseIngredient = (ingredient, multiplier)=>{
+        let traverseIngredient = (recipeIngredient, multiplier)=>{
+            let ingredient = recipeIngredient._ingredient;
             for(let i = 0; i < ingredient.subIngredients.length; i++){
-                traverseIngredient(ingredient.subIngredients[i].ingredient, multiplier * ingredient.subIngredients[i].quantity);                
+                traverseIngredient(ingredient.subIngredients[i].ingredient, multiplier * ingredient.subIngredients[i].quantity);
             }
 
             if(this._ingredientTotals[ingredient.id] === undefined){
@@ -155,14 +156,14 @@ class Recipe{
             }
 
             if(this._ingredientTotalsBase[ingredient.id] === undefined){
-                this._ingredientTotalsBase[ingredient.id] = multiplier * this._baseUnitMultiplier;
+                this._ingredientTotalsBase[ingredient.id] = multiplier * recipeIngredient._baseUnitMultiplier;
             }else{
-                this._ingredientTotalsBase[ingredient.id] += multiplier * this._baseUnitMultiplier;
+                this._ingredientTotalsBase[ingredient.id] += multiplier * recipeIngredient._baseUnitMultiplier;
             }
         }
 
         for(let i = 0; i < this._ingredients.length; i++){
-            traverseIngredient(this._ingredients[i]._ingredient, this._ingredients[i].quantity);
+            traverseIngredient(this._ingredients[i], this._ingredients[i].quantity);
         }
     }
 }

+ 2 - 0
views/dashboardPage/js/classes/Transaction.js

@@ -55,7 +55,9 @@ class Transaction{
     getIngredientQuantityBase(ingredient){
         let total = 0;
         for(let i = 0; i < this._recipes.length; i++){
+            console.log(total);
             total += this._recipes[i].recipe.getIngredientTotalBase(ingredient.id) * this._recipes[i].quantity;
+            console.log(total);
         }
 
         return total;