Selaa lähdekoodia

Fix data page after removal of nonpostransaction

Lee Morgan 6 vuotta sitten
vanhempi
sitoutus
3b49183f63
4 muutettua tiedostoa jossa 17 lisäystä ja 73 poistoa
  1. 0 1
      controllers/otherData.js
  2. 5 15
      controllers/renderer.js
  3. 0 26
      models/nonPosTransaction.js
  4. 12 31
      views/dataPage/home.js

+ 0 - 1
controllers/otherData.js

@@ -1,7 +1,6 @@
 const bcrypt = require("bcryptjs");
 const axios = require("axios");
 
-const NonPosTransaction = require("../models/nonPosTransaction");
 const Merchant = require("../models/merchant");
 const Purchase = require("../models/purchase");
 

+ 5 - 15
controllers/renderer.js

@@ -4,7 +4,6 @@ const Merchant = require("../models/merchant");
 const Ingredient = require("../models/ingredient");
 const Transaction = require("../models/transaction");
 const Purchase = require("../models/purchase");
-const NonPosTransaction = require("../models/nonPosTransaction");
 
 module.exports = {
     //GET - Shows the public landing page
@@ -243,20 +242,11 @@ module.exports = {
                     let firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
                     let lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
 
-                    if(merchant.pos === "clover"){
-                        Transaction.find({merchant: req.session.user, date: {$gte: firstDay, $lt: lastDay}})
-                            .then((transactions)=>{
-                                resolve({merchant: merchant, transactions: transactions});
-                            })
-                            .catch((err)=>{});
-                    }else{
-                        NonPosTransaction.find({merchant: req.session.user, date: {$gte: firstDay, $lt: lastDay}})
-                        
-                            .then((transactions)=>{
-                                resolve({merchant: merchant, transactions: transactions});
-                            })
-                            .catch((err)=>{});
-                    }
+                    Transaction.find({merchant: req.session.user, date: {$gte: firstDay, $lt: lastDay}})
+                        .then((transactions)=>{
+                            resolve({merchant: merchant, transactions: transactions});
+                        })
+                        .catch((err)=>{});
                 })
                 .catch((err)=>{});
         });

+ 0 - 26
models/nonPosTransaction.js

@@ -1,26 +0,0 @@
-const mongoose = require("mongoose");
-
-let NonPosTransactionSchema = new mongoose.Schema({
-    date: {
-        type: Date,
-        required: [true, "Must provide a date and time"]
-    },
-    merchant: {
-        type: mongoose.Schema.Types.ObjectId,
-        ref: "Merchant",
-        required: [true, "Log must contain a reference to a merchant"]
-    },
-    recipes: [{
-        recipe: {
-            type: mongoose.Schema.Types.ObjectId,
-            ref: "Recipe"
-        },
-        quantity: {
-            type: Number,
-            required: [true, "Must provide the number sold for each recipe"],
-            min: [0, "Must be a positive number"]
-        }
-    }]
-});
-
-module.exports = mongoose.model("NonPOSTransaction", NonPosTransactionSchema);

+ 12 - 31
views/dataPage/home.js

@@ -50,7 +50,18 @@ window.homeObj = {
         }
         
         //Populate number of recipes sold
-        this.populateRecipesObject(recipes);
+        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;
+                    }
+                }
+            }
+        }
 
         //Populate amount of ingredients sold
         for(let recipe of recipes){
@@ -135,35 +146,5 @@ window.homeObj = {
         //Populate totals
         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;
-                        }
-                    }
-                }
-            }
-        }
     }
 }