Просмотр исходного кода

Mostly fixed dashboard strand. Most popular card unfixed, need to come back to it later.

Lee Morgan 5 лет назад
Родитель
Сommit
23f9221fb3

+ 75 - 60
views/dashboardPage/bundle.js

@@ -98,14 +98,18 @@ class Ingredient{
 module.exports = Ingredient;
 },{}],2:[function(require,module,exports){
 class MerchantIngredient{
-    constructor(ingredient, quantity){
+    constructor(ingredient, quantity, isBase = false){
         if(quantity < 0){
             banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
             return false;
         }
+        if(isBase){
+            this._quantity = quantity;
+        }else{
+            this._quantity = this.convertToBase(quantity);
+        }
 
         this._ingredient = ingredient;
-        this._quantity = this.convertToBase(quantity);
     }
 
     get ingredient(){
@@ -113,25 +117,29 @@ class MerchantIngredient{
     }
 
     get quantity(){
+        if(this._ingredient.specialUnit === "bottle"){
+            return this._quantity / this._ingredient.unitSize;
+        }
+
         switch(this._ingredient.unit){
             case "g":return this._quantity; 
-            case "kg": return this._quantity * 1000;
-            case "oz": return this._quantity * 28.3495;
-            case "lb": return this._quantity * 453.5924;
-            case "ml": return this._quantity / 1000;
+            case "kg": return this._quantity / 1000;
+            case "oz": return this._quantity / 28.3495;
+            case "lb": return this._quantity / 453.5924;
+            case "ml": return this._quantity * 1000;
             case "l": return this._quantity;
-            case "tsp": return this._quantity / 202.8842;
-            case "tbsp": return this._quantity / 67.6278;
-            case "ozfl": return this._quantity / 33.8141;
-            case "cup": return this._quantity / 4.1667;
-            case "pt": return this._quantity / 2.1134;
-            case "qt": return this._quantity / 1.0567;
-            case "gal": return this._quantity * 3.7854;
-            case "mm": return this._quantity / 1000;
-            case "cm": return this._quantity / 100;
+            case "tsp": return this._quantity * 202.8842;
+            case "tbsp": return this._quantity * 67.6278;
+            case "ozfl": return this._quantity * 33.8141;
+            case "cup": return this._quantity * 4.1667;
+            case "pt": return this._quantity * 2.1134;
+            case "qt": return this._quantity * 1.0567;
+            case "gal": return this._quantity / 3.7854;
+            case "mm": return this._quantity * 1000;
+            case "cm": return this._quantity * 100;
             case "m": return this._quantity;
-            case "in": return this._quantity / 39.3701;
-            case "ft": return this._quantity / 3.2808;
+            case "in": return this._quantity * 39.3701;
+            case "ft": return this._quantity * 3.2808;
             default: return this._quantity;
         }
     }
@@ -200,7 +208,8 @@ class Merchant{
 
             const merchantIngredient = new MerchantIngredient(
                 ingredient,
-                oldMerchant.inventory[i].quantity
+                oldMerchant.inventory[i].quantity,
+                true
             );
 
             this._ingredients.push(merchantIngredient);
@@ -283,8 +292,6 @@ class Merchant{
 
         this._modules.home.isPopulated = false;
         this._modules.ingredients.isPopulated = false;
-        this._modules.ingredients.display();
-        controller.closeSidebar();
     }
 
     updateIngredient(ingredient, quantity){
@@ -297,8 +304,6 @@ class Merchant{
 
         this._modules.home.isPopulated = false;
         this._modules.ingredients.isPopulated = false;
-        this._modules.ingredients.display()
-        controller.closeSidebar();
     }
 
     get recipes(){
@@ -310,8 +315,6 @@ class Merchant{
 
         this._modules.transactions.isPopulated = false;
         this._modules.recipeBook.isPopulated = false;
-        this._modules.recipeBook.display();
-        controller.closeSidebar();
     }
 
     removeRecipe(recipe){
@@ -324,8 +327,6 @@ class Merchant{
 
         this._modules.transactions.isPopulated = false;
         this._modules.recipeBook.isPopulated = false;
-        this._modules.recipeBook.display();
-        controller.closeSidebar();
     }
 
     getTransactions(from = 0, to = new Date()){
@@ -373,8 +374,6 @@ class Merchant{
         this._modules.ingredients.isPopulated = false;
         this._modules.transactions.isPopulated = false;
         this._modules.analytics.newData = true;
-        this._modeules.transactions.display();
-        controller.closeSidebar();
     }
 
     removeTransaction(transaction){
@@ -411,8 +410,6 @@ class Merchant{
         this._modules.ingredients.isPopulated = false;
         this._modules.transactions.isPopulated = false;
         this._modules.analytics.newData = true;
-        this._modules.transactions.display();
-        controller.closeSidebar();
     }
 
     get orders(){
@@ -435,8 +432,6 @@ class Merchant{
 
         this._modules.ingredients.isPopulated = false;
         this._modules.orders.isPopulated = false;
-        this._modules.orders.display();
-        controller.closeSidebar();
     }
 
     removeOrder(order){
@@ -457,8 +452,6 @@ class Merchant{
 
         this._modules.ingredients.isPopulated = false;
         this._modules.orders.isPopulated = false;
-        this._modules.orders.display();
-        controller.closeSidebar();
     }
 
     get units(){
@@ -469,7 +462,6 @@ class Merchant{
         if(from === 0){
             from = this._transactions[0].date;
         }
-
         const {start, end} = this.getTransactionIndices(from, to);
 
         let total = 0;
@@ -493,7 +485,7 @@ class Merchant{
     Return:
         [{
             ingredient: Ingredient object,
-            quantity: quantity of ingredient sold
+            quantity: quantity of ingredient sold in default unit
         }]
     */
     getIngredientsSold(from = 0, to = new Date()){
@@ -512,7 +504,6 @@ class Merchant{
                     if(ingredientList[k].ingredient === recipes[i].recipe.ingredients[j].ingredient){
                         exists = true;
                         ingredientList[k].quantity += recipes[i].quantity * recipes[i].recipe.ingredients[j].quantity;
-                        
                     }
                 }
 
@@ -541,7 +532,7 @@ class Merchant{
                 for(let k = 0; k < this._transactions[i].recipes[j].recipe.ingredients.length; k++){
                     if(this._transactions[i].recipes[j].recipe.ingredients[k].ingredient === ingredient.ingredient){
                         total += this._transactions[i].recipes[j].recipe.ingredients[k].quantity;
-                        
+                        break;
                     }
                 }
             }
@@ -575,7 +566,7 @@ class Merchant{
                     if(recipeList[k].recipe === this._transactions[i].recipes[j].recipe){
                         exists = true;
                         recipeList[k].quantity += this._transactions[i].recipes[j].quantity;
-                        
+                        break;
                     }
                 }
 
@@ -608,7 +599,7 @@ class Merchant{
                     ingredientsByCategory[j].ingredients.push(this.ingredients[i]);
 
                     categoryExists = true;
-                    
+                    break;
                 }
             }
 
@@ -634,7 +625,7 @@ class Merchant{
                     ingredientsByUnit[j].ingredients.push(this.ingredients[i]);
 
                     unitExists = true;
-                    
+                    break;
                 }
             }
 
@@ -663,6 +654,7 @@ class Merchant{
             for(let j = 0; j < this._recipes[i].ingredients.length; j++){
                 if(this._recipes[i].ingredients[j].ingredient === ingredient){
                     recipes.push(this._recipes[i]);
+                    break;
                 }
             }
         }
@@ -671,21 +663,29 @@ class Merchant{
     }
 
     getTransactionIndices(from, to){
-        for(let i = 0; i < this._transactions.length; i++){
+        let start, end;
+        to.setDate(to.getDate() + 1);
+
+        for(let i = this._transactions.length - 1; i >= 0; i--){
             if(this._transactions[i].date >= from){
-                from = i;
-                
+                start = i;
+                break;
             }
         }
         
-        for(let i = this._transactions.length - 1; i >= 0; i--){
-            if(this._transactions[i].date <= to){
-                to = i;
-                
+        for(let i = 0; i < this._transactions.length; i++){
+            if(this._transactions[i].date < to){
+                end = i;
+                break;
             }
         }
 
-        return {from: from, to: to};
+        if(start === undefined){
+            return false;
+        }
+
+        //these are switched due to the order of the transactions in the merchant
+        return {start: end, end: start};
     }
 
     isSanitaryString(str){
@@ -718,6 +718,10 @@ class OrderIngredient{
     }
 
     get quantity(){
+        if(this._ingredient.specialUnit === "bottle"){
+            return this._quantity / this._ingredient.unitSize;
+        }
+
         switch(unit){
             case "g":return this._quantity;
             case "kg": return this._quantity * 1000;
@@ -859,7 +863,11 @@ class RecipeIngredient{
     }
 
     get quantity(){
-        switch(unit){
+        if(this._ingredient.specialUnit === "bottle"){
+            return this._quantity / this._ingredient.unitSize;
+        }
+
+        switch(this._ingredient.unit){
             case "g":return this._quantity;
             case "kg": return this._quantity * 1000;
             case "oz": return this._quantity * 28.3495;
@@ -992,7 +1000,6 @@ class Recipe{
 
         this._parent.modules.recipeBook.isPopulated = false;
         this._parent.modules.analytics.isPopulated = false;
-        this._parent.modules.recipeBook.display();
     }
 
     removeIngredient(ingredient){
@@ -1062,12 +1069,18 @@ class Transaction{
         this._recipes = [];
 
         for(let i = 0; i < recipes.length; i++){
-            const transactionRecipe = new TransactionRecipe(
-                recipes[i].recipe,
-                recipes[i].quantity
-            )
+            for(let j = 0; j < parent.recipes.length; j++){
+                if(recipes[i].recipe === parent.recipes[j].id){
+                    const transactionRecipe = new TransactionRecipe(
+                        parent.recipes[j],
+                        recipes[i].quantity
+                    )
+        
+                    this._recipes.push(transactionRecipe);
 
-            this._recipes.push(transactionRecipe);
+                    break;
+                }
+            }
         }
     }
 
@@ -1710,7 +1723,7 @@ let home = {
         const revenueThisMonth = merchant.getRevenue(firstOfMonth);
         const revenueLastMonthToDay = merchant.getRevenue(firstOfLastMonth, lastMonthToDay);
 
-        document.getElementById("revenue").innerText = `$${revenueThisMonth.toLocaleString("en")}`;
+        document.getElementById("revenue").innerText = `$${revenueThisMonth.toFixed(2)}`;
 
         let revenueChange = ((revenueThisMonth - revenueLastMonthToDay) / revenueLastMonthToDay) * 100;
         
@@ -1805,10 +1818,10 @@ let home = {
                 input.changed = true;
             };
             if(ingredient.ingredient.specialUnit === "bottle"){
-                input.value = (ingredient.quantity / ingredient.ingredient.unitSize).toFixed(2);
+                input.value = ingredient.quantity.toFixed(2);
                 ingredientCheck.children[2].innerText = "BOTTLES";
             }else{
-                input.value = ingredient.ingredient.convert(ingredient.quantity).toFixed(2);
+                input.value = ingredient.quantity.toFixed(2);
                 ingredientCheck.children[2].innerText = ingredient.ingredient.unit.toUpperCase();
             }
 
@@ -1849,7 +1862,7 @@ let home = {
             let count = (ingredientList.length < 5) ? ingredientList.length - 1 : 4;
             for(let i = count; i >= 0; i--){
                 const ingredientName = ingredientList[i].ingredient.name;
-                const ingredientQuantity = ingredientList[i].ingredient.convert(ingredientList[i].quantity);
+                const ingredientQuantity = ingredientList[i].quantity;
                 const unitName = ingredientList[i].ingredient.unit;
 
                 quantities.push(ingredientList[i].quantity);
@@ -1895,6 +1908,8 @@ let home = {
         }
     },
 
+    //Need to change the updating of ingredients
+    //should update the ingredient directly, then send that.  Maybe...
     submitInventoryCheck: function(){
         let lis = document.querySelectorAll("#inventoryCheckCard li");
 

+ 49 - 49
views/dashboardPage/js/Merchant.js

@@ -1,12 +1,16 @@
 class MerchantIngredient{
-    constructor(ingredient, quantity){
+    constructor(ingredient, quantity, isBase = false){
         if(quantity < 0){
             banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
             return false;
         }
+        if(isBase){
+            this._quantity = quantity;
+        }else{
+            this._quantity = this.convertToBase(quantity);
+        }
 
         this._ingredient = ingredient;
-        this._quantity = this.convertToBase(quantity);
     }
 
     get ingredient(){
@@ -14,25 +18,29 @@ class MerchantIngredient{
     }
 
     get quantity(){
+        if(this._ingredient.specialUnit === "bottle"){
+            return this._quantity / this._ingredient.unitSize;
+        }
+
         switch(this._ingredient.unit){
             case "g":return this._quantity; 
-            case "kg": return this._quantity * 1000;
-            case "oz": return this._quantity * 28.3495;
-            case "lb": return this._quantity * 453.5924;
-            case "ml": return this._quantity / 1000;
+            case "kg": return this._quantity / 1000;
+            case "oz": return this._quantity / 28.3495;
+            case "lb": return this._quantity / 453.5924;
+            case "ml": return this._quantity * 1000;
             case "l": return this._quantity;
-            case "tsp": return this._quantity / 202.8842;
-            case "tbsp": return this._quantity / 67.6278;
-            case "ozfl": return this._quantity / 33.8141;
-            case "cup": return this._quantity / 4.1667;
-            case "pt": return this._quantity / 2.1134;
-            case "qt": return this._quantity / 1.0567;
-            case "gal": return this._quantity * 3.7854;
-            case "mm": return this._quantity / 1000;
-            case "cm": return this._quantity / 100;
+            case "tsp": return this._quantity * 202.8842;
+            case "tbsp": return this._quantity * 67.6278;
+            case "ozfl": return this._quantity * 33.8141;
+            case "cup": return this._quantity * 4.1667;
+            case "pt": return this._quantity * 2.1134;
+            case "qt": return this._quantity * 1.0567;
+            case "gal": return this._quantity / 3.7854;
+            case "mm": return this._quantity * 1000;
+            case "cm": return this._quantity * 100;
             case "m": return this._quantity;
-            case "in": return this._quantity / 39.3701;
-            case "ft": return this._quantity / 3.2808;
+            case "in": return this._quantity * 39.3701;
+            case "ft": return this._quantity * 3.2808;
             default: return this._quantity;
         }
     }
@@ -101,7 +109,8 @@ class Merchant{
 
             const merchantIngredient = new MerchantIngredient(
                 ingredient,
-                oldMerchant.inventory[i].quantity
+                oldMerchant.inventory[i].quantity,
+                true
             );
 
             this._ingredients.push(merchantIngredient);
@@ -184,8 +193,6 @@ class Merchant{
 
         this._modules.home.isPopulated = false;
         this._modules.ingredients.isPopulated = false;
-        this._modules.ingredients.display();
-        controller.closeSidebar();
     }
 
     updateIngredient(ingredient, quantity){
@@ -198,8 +205,6 @@ class Merchant{
 
         this._modules.home.isPopulated = false;
         this._modules.ingredients.isPopulated = false;
-        this._modules.ingredients.display()
-        controller.closeSidebar();
     }
 
     get recipes(){
@@ -211,8 +216,6 @@ class Merchant{
 
         this._modules.transactions.isPopulated = false;
         this._modules.recipeBook.isPopulated = false;
-        this._modules.recipeBook.display();
-        controller.closeSidebar();
     }
 
     removeRecipe(recipe){
@@ -225,8 +228,6 @@ class Merchant{
 
         this._modules.transactions.isPopulated = false;
         this._modules.recipeBook.isPopulated = false;
-        this._modules.recipeBook.display();
-        controller.closeSidebar();
     }
 
     getTransactions(from = 0, to = new Date()){
@@ -274,8 +275,6 @@ class Merchant{
         this._modules.ingredients.isPopulated = false;
         this._modules.transactions.isPopulated = false;
         this._modules.analytics.newData = true;
-        this._modeules.transactions.display();
-        controller.closeSidebar();
     }
 
     removeTransaction(transaction){
@@ -312,8 +311,6 @@ class Merchant{
         this._modules.ingredients.isPopulated = false;
         this._modules.transactions.isPopulated = false;
         this._modules.analytics.newData = true;
-        this._modules.transactions.display();
-        controller.closeSidebar();
     }
 
     get orders(){
@@ -336,8 +333,6 @@ class Merchant{
 
         this._modules.ingredients.isPopulated = false;
         this._modules.orders.isPopulated = false;
-        this._modules.orders.display();
-        controller.closeSidebar();
     }
 
     removeOrder(order){
@@ -358,8 +353,6 @@ class Merchant{
 
         this._modules.ingredients.isPopulated = false;
         this._modules.orders.isPopulated = false;
-        this._modules.orders.display();
-        controller.closeSidebar();
     }
 
     get units(){
@@ -370,7 +363,6 @@ class Merchant{
         if(from === 0){
             from = this._transactions[0].date;
         }
-
         const {start, end} = this.getTransactionIndices(from, to);
 
         let total = 0;
@@ -394,7 +386,7 @@ class Merchant{
     Return:
         [{
             ingredient: Ingredient object,
-            quantity: quantity of ingredient sold
+            quantity: quantity of ingredient sold in default unit
         }]
     */
     getIngredientsSold(from = 0, to = new Date()){
@@ -413,7 +405,6 @@ class Merchant{
                     if(ingredientList[k].ingredient === recipes[i].recipe.ingredients[j].ingredient){
                         exists = true;
                         ingredientList[k].quantity += recipes[i].quantity * recipes[i].recipe.ingredients[j].quantity;
-                        
                     }
                 }
 
@@ -442,7 +433,7 @@ class Merchant{
                 for(let k = 0; k < this._transactions[i].recipes[j].recipe.ingredients.length; k++){
                     if(this._transactions[i].recipes[j].recipe.ingredients[k].ingredient === ingredient.ingredient){
                         total += this._transactions[i].recipes[j].recipe.ingredients[k].quantity;
-                        
+                        break;
                     }
                 }
             }
@@ -476,7 +467,7 @@ class Merchant{
                     if(recipeList[k].recipe === this._transactions[i].recipes[j].recipe){
                         exists = true;
                         recipeList[k].quantity += this._transactions[i].recipes[j].quantity;
-                        
+                        break;
                     }
                 }
 
@@ -509,7 +500,7 @@ class Merchant{
                     ingredientsByCategory[j].ingredients.push(this.ingredients[i]);
 
                     categoryExists = true;
-                    
+                    break;
                 }
             }
 
@@ -535,7 +526,7 @@ class Merchant{
                     ingredientsByUnit[j].ingredients.push(this.ingredients[i]);
 
                     unitExists = true;
-                    
+                    break;
                 }
             }
 
@@ -564,6 +555,7 @@ class Merchant{
             for(let j = 0; j < this._recipes[i].ingredients.length; j++){
                 if(this._recipes[i].ingredients[j].ingredient === ingredient){
                     recipes.push(this._recipes[i]);
+                    break;
                 }
             }
         }
@@ -572,21 +564,29 @@ class Merchant{
     }
 
     getTransactionIndices(from, to){
-        for(let i = 0; i < this._transactions.length; i++){
+        let start, end;
+        to.setDate(to.getDate() + 1);
+
+        for(let i = this._transactions.length - 1; i >= 0; i--){
             if(this._transactions[i].date >= from){
-                from = i;
-                
+                start = i;
+                break;
             }
         }
         
-        for(let i = this._transactions.length - 1; i >= 0; i--){
-            if(this._transactions[i].date <= to){
-                to = i;
-                
+        for(let i = 0; i < this._transactions.length; i++){
+            if(this._transactions[i].date < to){
+                end = i;
+                break;
             }
         }
 
-        return {from: from, to: to};
+        if(start === undefined){
+            return false;
+        }
+
+        //these are switched due to the order of the transactions in the merchant
+        return {start: end, end: start};
     }
 
     isSanitaryString(str){

+ 4 - 0
views/dashboardPage/js/Order.js

@@ -13,6 +13,10 @@ class OrderIngredient{
     }
 
     get quantity(){
+        if(this._ingredient.specialUnit === "bottle"){
+            return this._quantity / this._ingredient.unitSize;
+        }
+
         switch(unit){
             case "g":return this._quantity;
             case "kg": return this._quantity * 1000;

+ 5 - 2
views/dashboardPage/js/Recipe.js

@@ -13,7 +13,11 @@ class RecipeIngredient{
     }
 
     get quantity(){
-        switch(unit){
+        if(this._ingredient.specialUnit === "bottle"){
+            return this._quantity / this._ingredient.unitSize;
+        }
+
+        switch(this._ingredient.unit){
             case "g":return this._quantity;
             case "kg": return this._quantity * 1000;
             case "oz": return this._quantity * 28.3495;
@@ -146,7 +150,6 @@ class Recipe{
 
         this._parent.modules.recipeBook.isPopulated = false;
         this._parent.modules.analytics.isPopulated = false;
-        this._parent.modules.recipeBook.display();
     }
 
     removeIngredient(ingredient){

+ 11 - 5
views/dashboardPage/js/Transaction.js

@@ -34,12 +34,18 @@ class Transaction{
         this._recipes = [];
 
         for(let i = 0; i < recipes.length; i++){
-            const transactionRecipe = new TransactionRecipe(
-                recipes[i].recipe,
-                recipes[i].quantity
-            )
+            for(let j = 0; j < parent.recipes.length; j++){
+                if(recipes[i].recipe === parent.recipes[j].id){
+                    const transactionRecipe = new TransactionRecipe(
+                        parent.recipes[j],
+                        recipes[i].quantity
+                    )
+        
+                    this._recipes.push(transactionRecipe);
 
-            this._recipes.push(transactionRecipe);
+                    break;
+                }
+            }
         }
     }
 

+ 6 - 4
views/dashboardPage/js/home.js

@@ -21,7 +21,7 @@ let home = {
         const revenueThisMonth = merchant.getRevenue(firstOfMonth);
         const revenueLastMonthToDay = merchant.getRevenue(firstOfLastMonth, lastMonthToDay);
 
-        document.getElementById("revenue").innerText = `$${revenueThisMonth.toLocaleString("en")}`;
+        document.getElementById("revenue").innerText = `$${revenueThisMonth.toFixed(2)}`;
 
         let revenueChange = ((revenueThisMonth - revenueLastMonthToDay) / revenueLastMonthToDay) * 100;
         
@@ -116,10 +116,10 @@ let home = {
                 input.changed = true;
             };
             if(ingredient.ingredient.specialUnit === "bottle"){
-                input.value = (ingredient.quantity / ingredient.ingredient.unitSize).toFixed(2);
+                input.value = ingredient.quantity.toFixed(2);
                 ingredientCheck.children[2].innerText = "BOTTLES";
             }else{
-                input.value = ingredient.ingredient.convert(ingredient.quantity).toFixed(2);
+                input.value = ingredient.quantity.toFixed(2);
                 ingredientCheck.children[2].innerText = ingredient.ingredient.unit.toUpperCase();
             }
 
@@ -160,7 +160,7 @@ let home = {
             let count = (ingredientList.length < 5) ? ingredientList.length - 1 : 4;
             for(let i = count; i >= 0; i--){
                 const ingredientName = ingredientList[i].ingredient.name;
-                const ingredientQuantity = ingredientList[i].ingredient.convert(ingredientList[i].quantity);
+                const ingredientQuantity = ingredientList[i].quantity;
                 const unitName = ingredientList[i].ingredient.unit;
 
                 quantities.push(ingredientList[i].quantity);
@@ -206,6 +206,8 @@ let home = {
         }
     },
 
+    //Need to change the updating of ingredients
+    //should update the ingredient directly, then send that.  Maybe...
     submitInventoryCheck: function(){
         let lis = document.querySelectorAll("#inventoryCheckCard li");