浏览代码

Add frontend code to immediately display changes in transactions from uploading spreadsheet.

Lee Morgan 5 年之前
父节点
当前提交
dd5be38596

二进制
uploads/245c49431e93d192f097804ebcf4de40


二进制
uploads/3b2843da45a9c40c9bc4d4f74a5b3104


+ 21 - 15
views/dashboardPage/bundle.js

@@ -127,14 +127,10 @@ module.exports = Ingredient;
 },{}],2:[function(require,module,exports){
 const Order = require("./Order.js");
 const Recipe = require("./Recipe.js");
+const Transaction = require("./Transaction.js");
 
 class MerchantIngredient{
     constructor(ingredient, quantity){
-        if(quantity < 0){
-            banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
-            return false;
-        }
-        
         this._quantity = quantity;
         this._ingredient = ingredient;
     }
@@ -415,6 +411,10 @@ class Merchant{
         this._modules.recipeBook.isPopulated = false;
     }
 
+    get transactions(){
+        return this._transactions;
+    }
+
     getTransactions(from = 0, to = new Date()){
         if(merchant._transactions.length <= 0){
             return [];
@@ -430,6 +430,13 @@ class Merchant{
     }
 
     addTransaction(transaction){
+        transaction = new Transaction(
+            transaction._id,
+            transaction.date,
+            transaction.recipes,
+            this
+        );
+
         this._transactions.push(transaction);
         this._transactions.sort((a, b)=>{
             if(a.date > b.date){
@@ -814,7 +821,7 @@ class Merchant{
 }
 
 module.exports = Merchant;
-},{"./Order.js":3,"./Recipe.js":4}],3:[function(require,module,exports){
+},{"./Order.js":3,"./Recipe.js":4,"./Transaction.js":5}],3:[function(require,module,exports){
 class OrderIngredient{
     constructor(ingredient, quantity, pricePerUnit){
         if(quantity < 0){
@@ -2524,14 +2531,7 @@ let newTransaction = {
                     if(typeof(response) === "string"){
                         banner.createError(response);
                     }else{
-                        const transaction = new Transaction(
-                            response._id,
-                            response.date,
-                            response.recipes,
-                            merchant
-                        );
-
-                        merchant.addTransaction(transaction);
+                        merchant.addTransaction(response);
 
                         controller.openStrand("transactions", merchant.getTransactions());
                         banner.createNotification("TRANSACTION CREATED");
@@ -2566,7 +2566,13 @@ let newTransaction = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    console.log(response);
+                    for(let i = 0; i < response.recipes.length; i++){
+                        response.recipes[i].recipe = response.recipes[i].recipe._id;
+                    }
+                    merchant.addTransaction(response);
+
+                    controller.openStrand("transactions", merchant.transactions);
+                    banner.createNotification("TRANSACTION SUCCESSFULLY CREATED.  INGREDIENTS UPDATED");
                 }
             })
             .catch((err)=>{

+ 12 - 5
views/dashboardPage/js/classes/Merchant.js

@@ -1,13 +1,9 @@
 const Order = require("./Order.js");
 const Recipe = require("./Recipe.js");
+const Transaction = require("./Transaction.js");
 
 class MerchantIngredient{
     constructor(ingredient, quantity){
-        if(quantity < 0){
-            banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
-            return false;
-        }
-        
         this._quantity = quantity;
         this._ingredient = ingredient;
     }
@@ -288,6 +284,10 @@ class Merchant{
         this._modules.recipeBook.isPopulated = false;
     }
 
+    get transactions(){
+        return this._transactions;
+    }
+
     getTransactions(from = 0, to = new Date()){
         if(merchant._transactions.length <= 0){
             return [];
@@ -303,6 +303,13 @@ class Merchant{
     }
 
     addTransaction(transaction){
+        transaction = new Transaction(
+            transaction._id,
+            transaction.date,
+            transaction.recipes,
+            this
+        );
+
         this._transactions.push(transaction);
         this._transactions.sort((a, b)=>{
             if(a.date > b.date){

+ 8 - 9
views/dashboardPage/js/sidebars/newTransaction.js

@@ -73,14 +73,7 @@ let newTransaction = {
                     if(typeof(response) === "string"){
                         banner.createError(response);
                     }else{
-                        const transaction = new Transaction(
-                            response._id,
-                            response.date,
-                            response.recipes,
-                            merchant
-                        );
-
-                        merchant.addTransaction(transaction);
+                        merchant.addTransaction(response);
 
                         controller.openStrand("transactions", merchant.getTransactions());
                         banner.createNotification("TRANSACTION CREATED");
@@ -115,7 +108,13 @@ let newTransaction = {
                 if(typeof(response) === "string"){
                     banner.createError(response);
                 }else{
-                    console.log(response);
+                    for(let i = 0; i < response.recipes.length; i++){
+                        response.recipes[i].recipe = response.recipes[i].recipe._id;
+                    }
+                    merchant.addTransaction(response);
+
+                    controller.openStrand("transactions", merchant.transactions);
+                    banner.createNotification("TRANSACTION SUCCESSFULLY CREATED.  INGREDIENTS UPDATED");
                 }
             })
             .catch((err)=>{