Преглед изворни кода

Fix problem with sub-ingredients not being calculated.

Lee Morgan пре 4 година
родитељ
комит
be0a24bf07
2 измењених фајлова са 12 додато и 18 уклоњено
  1. 11 17
      views/dashboardPage/js/classes/Recipe.js
  2. 1 1
      views/dashboardPage/js/classes/Transaction.js

+ 11 - 17
views/dashboardPage/js/classes/Recipe.js

@@ -73,24 +73,18 @@ class Recipe{
     //Returns the quantity of a single ingredient with the recipe.
     //Returns the quantity converted to the base unit of the ingredient
     getIngredientTotal(id){
-        for(let i = 0; i < this.ingredients.length; i++){
-            if(this.ingredients[i].ingredient.id === id){
-                if(this.ingredientTotals[id] === undefined) break;
-                let ingredientTotal = this.ingredientTotals[id];
-                let toIngredientBase = 0;
-
-                switch(controller.getBaseUnit(this.ingredients[i].unit)){
-                    case "g": toIngredientBase = this.ingredients[i].ingredient.convert.toMass; break;
-                    case "l": toIngredientBase = this.ingredients[i].ingredient.convert.toVolume; break;
-                    case "m": toIngredientBase = this.ingredients[i].ingredient.convert.toLength; break;
-                }
-
-                return ingredientTotal / toIngredientBase;
-                // return (this.ingredientTotals[id] === undefined) ? 0 : this.ingredientTotals[id] * controller.unitMultiplier(controller.toBase(this.ingredients[i].ingredient.unit), this.ingredients[i].ingredient.unit);
-            }
-        }
+        if(this.ingredientTotals[id] === undefined) return 0;
 
-        return 0;
+        let ingredient = merchant.getIngredient(id).ingredient;
+        let ingredientTotal = this.ingredientTotals[id];
+        let toIngredientBase = 0;
+
+        switch(controller.getBaseUnit(controller.getBaseUnit(ingredient.unit))){
+            case "g": toIngredientBase = ingredient.convert.toMass; break;
+            case "l": toIngredientBase = ingredient.convert.toVolume; break;
+            case "m": toIngredientBase = ingredient.convert.toLength; break;
+        }
+        return ingredientTotal / toIngredientBase;
     }
 
     addIngredient(ingredient, quantity, unit, baseUnitMultiplier){

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

@@ -23,7 +23,7 @@ class Transaction{
     /*
     Gets the quantity for a given ingredient
     */
-    getIngredientQuantity(ingredient, isDisplay = false){
+    getIngredientQuantity(ingredient){
         let total = 0;
 
         for(let i = 0; i < this.recipes.length; i++){