瀏覽代碼

Fix bugs from recipe and ingredient strands.
Update unit cost for accuracy.

Lee Morgan 5 年之前
父節點
當前提交
a6685e9315

+ 2 - 2
views/dashboardPage/js/classes/Ingredient.js

@@ -163,7 +163,7 @@ class Ingredient{
         return [];
     }
 
-    getUnitCost(isDisplay = false){
+    getUnitCost(){
         let totalCost = 0;
         let quantity = 0;
 
@@ -172,7 +172,7 @@ class Ingredient{
                 let ingredient = this._parent.orders[i].ingredients[j];
 
                 if(ingredient.ingredient === this){
-                    totalCost += ingredient.quantity * (isDisplay === true) ?  ingredient.pricePerUnit : ingredient.pricePerBaseUnit;
+                    totalCost += ingredient.pricePerUnit * ingredient.quantity;
                     quantity += ingredient.quantity;
                     break;
                 }

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

@@ -146,7 +146,6 @@ class Merchant{
                 recipes[i].hidden
             );
 
-            newRecipe.calculateIngredientTotals();
             this._recipes.push(newRecipe);
         }
 

+ 4 - 5
views/dashboardPage/js/classes/Recipe.js

@@ -155,21 +155,20 @@ class Recipe{
     calculateIngredientTotals(){
         this._ingredientTotals = {};
 
-        let traverseIngredient = (recipeIngredient, multiplier)=>{
-            let ingredient = recipeIngredient._ingredient;
+        let traverseIngredient = (ingredient, multiplier)=>{
             for(let i = 0; i < ingredient.subIngredients.length; i++){
                 traverseIngredient(ingredient.subIngredients[i].ingredient, multiplier * ingredient.subIngredients[i].quantity);
             }
 
-            if(this._ingredientstotals[ingredient.id] === undefined){
-                this.ingredienttotals[ingredient.id] = multiplier;
+            if(this._ingredientTotals[ingredient.id] === undefined){
+                this._ingredientTotals[ingredient.id] = multiplier;
             }else{
                 this._ingredientTotals[ingredient.id] += multiplier;
             }
         }
 
         for(let i = 0; i < this._ingredients.length; i++){
-            traverseIngredient(this._ingredients[i], this._ingredients[i].getQuantityAsBase());
+            traverseIngredient(this._ingredients[i]._ingredient, this._ingredients[i].getQuantityAsBase());
         }
     }
 }

+ 6 - 2
views/dashboardPage/js/dashboard.js

@@ -22,7 +22,6 @@ const transactionFilter = require("./sidebars/transactionFilter.js");
 const modalScript = require("./modal.js");
 
 const Merchant = require("./classes/Merchant.js");
-
 window.merchant = new Merchant(
     data.merchant.name,
     data.merchant.pos,
@@ -518,6 +517,7 @@ window.state = {
         recipeBook.isPopulated = false;
     }
 }
+
 let from = new Date();
 from.setDate(from.getDate() - 7);
 from.setHours(0, 0, 0, 0);
@@ -536,4 +536,8 @@ document.getElementById("feedbackButton").onclick = ()=>{controller.openModal("f
 
 document.getElementById("menuLocationName").innerText = merchant.name;
 
-controller.openStrand("home");
+controller.openStrand("home");
+
+for(let i = 0; i < merchant.recipes.length; i++){
+    merchant.recipes[i].calculateIngredientTotals();
+}

+ 2 - 2
views/dashboardPage/js/strands/home.js

@@ -52,12 +52,12 @@ let home = {
         from.setDate(from.getDate() - 30);
 
         for(let i = 0; i < merchant.inventory.length; i++){
-            let unitCost = merchant.inventory[i].ingredient.getUnitCost(false);
+            let unitCost = merchant.inventory[i].ingredient.getUnitCost();
             let totalCost = unitCost * merchant.inventory[i].getSoldQuantity(from, new Date());
             
             ingredients.push({
                 inventoryItem: merchant.inventory[i],
-                unitCost: merchant.inventory[i].ingredient.getUnitCost(true),
+                unitCost: merchant.inventory[i].ingredient.getUnitCost(),
                 totalCost: totalCost / 100
             });
         }