Преглед на файлове

Update data site to calculate for non-pos users

Lee Morgan преди 6 години
родител
ревизия
ccebbfb123
променени са 3 файла, в които са добавени 47 реда и са изтрити 23 реда
  1. 9 3
      controllers/otherData.js
  2. 36 18
      views/dataPage/home.js
  3. 2 2
      views/inventoryPage/enterTransactions.js

+ 9 - 3
controllers/otherData.js

@@ -16,14 +16,20 @@ module.exports = {
             res.session.error = "Must be logged in to do that";
             return res.redirect("/");
         }
-        
+
         let transaction = new NonPosTransaction({
             date: Date.now(),
-            author: "None",
             merchant: req.session.user,
-            recipes: req.body
+            recipes: []
         });
 
+        for(let recipe of req.body){
+            transaction.recipes.push({
+                recipe: recipe.id,
+                quantity: recipe.quantity
+            });
+        }
+
         //Calculate all ingredients used, store to list
         Merchant.findOne({_id: req.session.user})
             .populate("recipes")

+ 36 - 18
views/dataPage/home.js

@@ -1,4 +1,7 @@
 window.homeObj = {
+    recipeTotal: 0,
+    revenueTotal: 0,
+
     display: function(){
         clearScreen();
         document.querySelector("#homeStrand").style.display = "flex";
@@ -47,22 +50,7 @@ window.homeObj = {
         }
         
         //Populate number of recipes sold
-        let revenueTotal = 0;
-        let recipeTotal = 0;
-        for(let transaction of data.transactions){
-            for(let transactionRecipe of transaction.recipes){
-                for(let recipeCounter of recipes){
-                    console.log("recipecounter");
-                    if(transactionRecipe === recipeCounter.id){
-                        console.log(transactionRecipe);
-                        recipeCounter.quantity++;
-                        recipeTotal++;
-                        revenueTotal += (recipeCounter.price * recipeCounter.quantity);
-                        break;
-                    }
-                }
-            }
-        }
+        this.populateRecipesObject(recipes);
 
         //Populate amount of ingredients sold
         for(let recipe of recipes){
@@ -145,7 +133,37 @@ window.homeObj = {
         }
 
         //Populate totals
-        document.querySelector("#revenueTotal").innerText = `$${revenueTotal.toFixed(2)}`;
-        document.querySelector("#soldTotal").innerText = recipeTotal;
+        document.querySelector("#revenueTotal").innerText = `$${this.revenueTotal.toFixed(2)}`;
+        document.querySelector("#soldTotal").innerText = this.recipeTotal;
+    },
+
+    populateRecipesObject: function(recipes){
+        if(data.merchant.pos === "clover"){
+            for(let transaction of data.transactions){
+                for(let transactionRecipe of transaction.recipes){
+                    for(let recipeCounter of recipes){
+                        if(transactionRecipe === recipeCounter.id){
+                            recipeCounter.quantity++;
+                            this.recipeTotal++;
+                            this.revenueTotal += recipeCounter.price;
+                            break;
+                        }
+                    }
+                }
+            }
+        }else{
+            for(let transaction of data.transactions){
+                for(let recipe of transaction.recipes){
+                    for(let newRecipe of recipes){
+                        if(recipe.recipe === newRecipe.id){
+                            newRecipe.quantity += recipe.quantity;
+                            this.recipeTotal += recipe.quantity;
+                            this.revenueTotal += (newRecipe.price * recipe.quantity);
+                            break;
+                        }
+                    }
+                }
+            }
+        }
     }
 }

+ 2 - 2
views/inventoryPage/enterTransactions.js

@@ -49,14 +49,14 @@ window.enterTransactionsObj = {
                     id: row._id,
                     quantity: quantity
                 }
-
+                console.log(recipe.id);
                 recipes.push(recipe);
             }else if(quantity < 0){
                 banner.createError("Cannot have negative quantities");
                 break;
             }
         }
-
+        console.log(recipes);
         axios.post("/transactions/create", recipes)
             .then((response)=>{
                 if(typeof(response.data) === "string"){