Parcourir la source

Merge branch 'development'

Lee Morgan il y a 5 ans
Parent
commit
f71b3095a8
2 fichiers modifiés avec 25 ajouts et 6 suppressions
  1. 3 0
      controllers/ingredientData.js
  2. 22 6
      controllers/orderData.js

+ 3 - 0
controllers/ingredientData.js

@@ -197,6 +197,9 @@ module.exports = {
             }
 
             if(array[i][locations.bottle] === true){
+                let quantity = array[i][locations.quantity] * array[i][locations.bottleSize];
+                merchantItem.quantity = helper.convertQuantityToBaseUnit(quantity, array[i][locations.unit]);
+                
                 ingredient.unitType = "volume";
                 ingredient.specialUnit = "bottle";
                 ingredient.unitSize = helper.convertQuantityToBaseUnit(array[i][locations.bottleSize], array[i][locations.unit]);

+ 22 - 6
controllers/orderData.js

@@ -6,6 +6,7 @@ const helper = require("./helper.js");
 const ObjectId = require("mongoose").Types.ObjectId;
 const xlsx = require("xlsx");
 const fs = require("fs");
+const { base } = require("../models/merchant.js");
 
 module.exports = {
     /*
@@ -229,12 +230,26 @@ module.exports = {
                     let exists = false;
                     for(let j = 0; j < merchant.inventory.length; j++){
                         if(merchant.inventory[j].ingredient.name.toLowerCase() === array[i][locations.ingredients].toLowerCase()){
-                            const baseQuantity = helper.convertQuantityToBaseUnit(array[i][locations.quantity], merchant.inventory[j].defaultUnit);
-                            currentOrder.ingredients.push({
-                                ingredient: merchant.inventory[j].ingredient._id,
-                                quantity: baseQuantity,
-                                pricePerUnit: helper.convertPrice(array[i][locations.price] * 100, merchant.inventory[j].defaultUnit)
-                            });
+                            let baseQuantity = 0;
+                            if(merchant.inventory[j].ingredient.specialUnit === "bottle"){
+                                baseQuantity = array[i][locations.quantity] * merchant.inventory[j].ingredient.unitSize * 1000;
+                                console.log(array[i][locations.price]);
+                                console.log((array[i][locations.price] * 100));
+                                console.log(merchant.inventory[j].ingredient.unitSize);
+                                console.log((array[i][locations.price] * 100) / merchant.inventory[j].ingredient.unitSize);
+                                currentOrder.ingredients.push({
+                                    ingredient: merchant.inventory[j].ingredient._id,
+                                    quantity: baseQuantity,
+                                    pricePerUnit: (array[i][locations.price] * 100) / merchant.inventory[j].ingredient.unitSize / 1000
+                                });
+                            }else{
+                                baseQuantity = helper.convertQuantityToBaseUnit(array[i][locations.quantity], merchant.inventory[j].defaultUnit);
+                                currentOrder.ingredients.push({
+                                    ingredient: merchant.inventory[j].ingredient._id,
+                                    quantity: baseQuantity,
+                                    pricePerUnit: helper.convertPrice(array[i][locations.price] * 100, merchant.inventory[j].defaultUnit)
+                                });
+                            }
 
                             merchant.inventory[j].quantity += baseQuantity;
 
@@ -254,6 +269,7 @@ module.exports = {
                 return res.json(response[0]);
             })
             .catch((err)=>{
+                console.log(err);
                 if(typeof(err) === "string"){
                     return res.json(err);
                 }