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

Bug fix, orders were not uploading the base unit for bottles.

Lee Morgan преди 4 години
родител
ревизия
613548492a
променени са 4 файла, в които са добавени 24 реда и са изтрити 16 реда
  1. 2 2
      controllers/admin.js
  2. 6 8
      views/dashboardPage/js/classes/Recipe.js
  3. 15 6
      views/dashboardPage/js/sidebars/newOrder.js
  4. 1 0
      views/dashboardPage/js/strands/home.js

+ 2 - 2
controllers/admin.js

@@ -77,8 +77,8 @@ module.exports = {
                         
                         if(ingredient.unit === "bottle"){
                             ingredient.altUnit = data[5];
-                            ingredient.convert.toBottle = helper.convertQuantityToBaseUnit(data[4], data[5]);
-                            merchIngredient.quantity = data[2] / ingredient.convert.toBottle;
+                            merchIngredient.quantity = helper.convertQuantityToBaseUnit(data[4], data[5]) * data[2];
+                            ingredient.convert.toBottle = data[2] / merchIngredient.quantity;
                         }
                         
                         newIngredients.push(ingredient);

+ 6 - 8
views/dashboardPage/js/classes/Recipe.js

@@ -120,16 +120,14 @@ class Recipe{
 
     //Returns the quantity of a single ingredient with the recipe.
     //Returns the quantity converted to the base unit of the ingredient
-    getIngredientTotal(id, isDisplay = false){
-        if(isDisplay === true){
-            for(let i = 0; i < this._ingredients.length; i++){
-                if(this._ingredients[i].ingredient.id === id){
-                    return (this._ingredientTotals[id] === undefined) ? 0 : controller.displayUnit(this._ingredientTotals[id], this._ingredients[i].ingredient.unit);
-                }
-                break;
+    getIngredientTotal(id){
+        for(let i = 0; i < this._ingredients.length; i++){
+            if(this._ingredients[i].ingredient.id === id){
+                return (this._ingredientTotals[id] === undefined) ? 0 : this._ingredientTotals[id] * controller.unitMultiplier(controller.toBase(this._ingredients[i].ingredient.unit), this._ingredients[i].ingredient.unit);
             }
         }
-        return (this._ingredientTotals[id] === undefined) ? 0 : this._ingredientTotals[id];
+
+        return 0;
     }
 
     addIngredient(ingredient, quantity, unit, baseUnitMultiplier){

+ 15 - 6
views/dashboardPage/js/sidebars/newOrder.js

@@ -66,12 +66,21 @@ let newOrder = {
         for(let i = 0; i < ingredients.length; i++){
             let quantity = ingredients[i].children[1].children[0].value;
             let price = ingredients[i].children[1].children[1].value;
+            let unit = (ingredients[i].ingredient.ingredient.unit === "bottle") ? ingredients[i].ingredient.ingredient.altUnit : ingredients[i].ingredient.ingredient.unit;
 
-            data.ingredients.push({
+            let newIngredient = {
                 ingredient: ingredients[i].ingredient.ingredient.id,
-                quantity: controller.baseUnit(quantity, ingredients[i].ingredient.ingredient.unit),
-                pricePerUnit: this.convertPrice(ingredients[i].ingredient.ingredient, price * 100)
-            });
+                quantity: controller.toBase(quantity, unit),
+                pricePerUnit: this.convertPrice(controller.getBaseUnit(unit), price * 100)
+            };
+
+            if(ingredients[i].ingredient.ingredient.unit === "bottle"){
+                newIngredient.quantity = quantity / ingredients[i].ingredient.ingredient.convert.toBottle;
+                newIngredient.pricePerUnit = this.convertPrice(controller.getBaseUnit(unit), price * ingredients[i].ingredient.ingredient.convert.toBottle * 100);
+            }
+            console.log(newIngredient);
+
+            data.ingredients.push(newIngredient);
         }
 
         let loader = document.getElementById("loaderContainer");
@@ -108,8 +117,8 @@ let newOrder = {
             });
     },
 
-    convertPrice: function(ingredient, price){
-        switch(ingredient.unit){
+    convertPrice: function(unit, price){
+        switch(unit){
             case "g": return price;
             case "kg": return price / 1000; 
             case "oz": return price / 28.3495; 

+ 1 - 0
views/dashboardPage/js/strands/home.js

@@ -50,6 +50,7 @@ let home = {
         let ingredients = [];
         let from = new Date();
         from.setDate(from.getDate() - 30);
+        from.setHours(0, 0, 0, 0);
 
         for(let i = 0; i < merchant.inventory.length; i++){
             let unitCost = merchant.inventory[i].ingredient.getUnitCost();