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

Frontend non-pos transactions updating

Lee Morgan пре 6 година
родитељ
комит
a61fbc5abe
2 измењених фајлова са 11 додато и 2 уклоњено
  1. 1 1
      controllers/home.js
  2. 10 1
      views/inventoryPage/enterTransactions.js

+ 1 - 1
controllers/home.js

@@ -576,7 +576,7 @@ module.exports = {
 
                 merchant.save()
                     .then((merchant)=>{
-                        res.json();
+                        res.json(merchant.inventory);
                     })
                     .catch((err)=>{
                         console.log(err);

+ 10 - 1
views/inventoryPage/enterTransactions.js

@@ -57,8 +57,17 @@ let enterTransactionsObj = {
 
         axios.post("/transactions/create", recipesSold)
             .then(()=>{
-                banner.createNotification("Your sales have been logged");
+                for(let soldRecipe of recipesSold){
+                    let merchRecipe = merchant.recipes.find(r => r._id === soldRecipe.id);
+                    for(let recipeIngredient of merchRecipe.ingredients){
+                        let merchInvIngredient = merchant.inventory.find(i => i.ingredient._id === recipeIngredient.ingredient);
+                        merchInvIngredient.quantity -= recipeIngredient.quantity * soldRecipe.quantity;
+                    }
+                }
+
+                inventoryObj.isPopulated = false;
                 inventoryObj.display();
+                banner.createNotification("Your sales have been logged");
             })
             .catch((err)=>{
                 banner.createError("Something went wrong and your sales could not be logged");