possibilità di modificare un ordine, e anche i totali
This commit is contained in:
@@ -31,6 +31,7 @@ const OrdersCartSchema = new Schema({
|
||||
totalQty: { type: Number, default: 0 },
|
||||
totalQtyPreordered: { type: Number, default: 0 },
|
||||
totalPrice: { type: Number, default: 0 },
|
||||
totalPriceCalc: { type: Number, default: 0 },
|
||||
department: {
|
||||
type: String, ref: 'Department'
|
||||
},
|
||||
@@ -72,11 +73,11 @@ const OrdersCartSchema = new Schema({
|
||||
date_consegnato: {
|
||||
type: Date
|
||||
},
|
||||
consegnato: {
|
||||
preparato: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_consegnato: {
|
||||
date_preparato: {
|
||||
type: Date
|
||||
},
|
||||
ricevuto: {
|
||||
@@ -109,6 +110,16 @@ const OrdersCartSchema = new Schema({
|
||||
|
||||
var OrdersCart = module.exports = mongoose.model('OrdersCart', OrdersCartSchema);
|
||||
|
||||
function fixupdated(myrec) {
|
||||
return myrec;
|
||||
/*if (myrec) {
|
||||
if (myrec.totalPriceCalc === undefined) {
|
||||
myrec.totalPriceCalc = myrec.totalPrice;
|
||||
}
|
||||
}
|
||||
return myrec;*/
|
||||
}
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp, userId) {
|
||||
const myfind = { idapp, userId, deleted: false };
|
||||
|
||||
@@ -186,7 +197,9 @@ module.exports.getOrdersCartById = async function (id) {
|
||||
let query = { _id: ObjectID(id) };
|
||||
|
||||
const arrris = await OrdersCart.getOrdersCartByQuery(query);
|
||||
return arrris && arrris.length > 0 ? arrris[0] : null;
|
||||
let myrec = arrris && arrris.length > 0 ? arrris[0] : null;
|
||||
myrec = fixupdated(myrec);
|
||||
return myrec;
|
||||
|
||||
}
|
||||
|
||||
@@ -279,6 +292,7 @@ module.exports.getOrdersCartByQuery = async function (query) {
|
||||
return order;
|
||||
});
|
||||
|
||||
myorderscart = fixupdated(myorderscart);
|
||||
|
||||
return myorderscart;
|
||||
}
|
||||
@@ -302,7 +316,6 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder, fil
|
||||
|
||||
myorderscart = await OrdersCart.getOrdersCartByQuery(query);
|
||||
|
||||
|
||||
/*transform: function(doc, populated) {
|
||||
// Rinomina 'idProduct' a 'product' nei risultati della popolazione
|
||||
populated.product = populated.idProduct;
|
||||
@@ -337,6 +350,7 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
|
||||
totalQty: newOrdersCart.totalQty,
|
||||
totalQtyPreordered: newOrdersCart.totalQtyPreordered,
|
||||
totalPrice: newOrdersCart.totalPrice,
|
||||
totalPriceCalc: newOrdersCart.totalPriceCalc ? newOrdersCart.totalPriceCalc : newOrdersCart.totalPrice,
|
||||
userId: userId,
|
||||
status: newOrdersCart.status,
|
||||
numorder: newOrdersCart.numorder,
|
||||
@@ -413,6 +427,17 @@ module.exports.setConsegnatoById = async function (value, myOrderCart) {
|
||||
|
||||
}
|
||||
|
||||
module.exports.setPreparatoById = async function (value, myOrderCart) {
|
||||
|
||||
let objtoset = {
|
||||
preparato: value,
|
||||
date_preparato: new Date(),
|
||||
};
|
||||
|
||||
return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart);
|
||||
|
||||
}
|
||||
|
||||
module.exports.setSpeditoById = async function (value, myOrderCart) {
|
||||
|
||||
let objtoset = {
|
||||
@@ -731,6 +756,8 @@ module.exports.updateCmd = async function (ordersCart, status, value, req, optio
|
||||
}
|
||||
}
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.PREPARED) {
|
||||
ris = await OrdersCart.setPreparatoById(value, myOrderCart);
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato
|
||||
if (value) {
|
||||
@@ -743,6 +770,8 @@ module.exports.updateCmd = async function (ordersCart, status, value, req, optio
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.RECEIVED) {
|
||||
ris = await OrdersCart.setRicevutoById(value, myOrderCart);
|
||||
} else if (status === shared_consts.OrderStatus.PREPARED) {
|
||||
ris = await OrdersCart.setPreparatoById(value, myOrderCart);
|
||||
} else if (status === shared_consts.OrderStatus.CANCELED) {
|
||||
await OrdersCart.updateStockQtaPerCancellazioneOrdine(id)
|
||||
|
||||
@@ -807,7 +836,7 @@ module.exports.updateOrdersCartByParams = async function (idOrdersCart, paramsto
|
||||
|
||||
const ris = await OrdersCart.findOneAndUpdate({ _id: idOrdersCart }, { $set: paramstoupdate });
|
||||
|
||||
let myorderscart = await Order.findOne({ _id: idOrder });
|
||||
let myorderscart = await OrdersCart.getOrdersCartById(idOrdersCart);
|
||||
|
||||
return myorderscart;
|
||||
}
|
||||
@@ -821,12 +850,13 @@ module.exports.updateOrdersCartTotals = async function (idOrdersCart, update) {
|
||||
|
||||
let newOrdersCart = CartClass.constructByCart(orderscart);
|
||||
|
||||
await newOrdersCart.updatetotals();
|
||||
await newOrdersCart.updatecarttotals(false);
|
||||
|
||||
if (update) {
|
||||
await OrdersCart.findOneAndUpdate({ _id: idOrdersCart }, {
|
||||
$set: {
|
||||
totalPrice: newOrdersCart.totalPrice,
|
||||
totalPriceCalc: newOrdersCart.totalPriceCalc,
|
||||
totalQty: newOrdersCart.totalQty,
|
||||
note: newOrdersCart.note,
|
||||
modify_at: new Date(),
|
||||
|
||||
Reference in New Issue
Block a user