possibilità di modificare un ordine, e anche i totali

This commit is contained in:
Surya Paolo
2024-01-15 22:19:26 +01:00
parent 79ca364e84
commit 3183825137
7 changed files with 121 additions and 49 deletions

View File

@@ -54,6 +54,10 @@ const orderSchema = new Schema({
type: Number,
default: 0,
},
TotalPriceProductCalc: {
type: Number,
default: 0,
},
confermato: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockQty)
type: Boolean,
default: false,
@@ -288,9 +292,11 @@ module.exports.updateOrderByParams = async function (idOrder, paramstoupdate) {
let myorder = await Order.findOne({ _id: idOrder }).lean();
this.updateTotals(myorder);
if (paramstoupdate && !paramstoupdate.hasOwnProperty('TotalPriceProduct')) {
this.updateTotals(myorder);
await Order.findOneAndUpdate({ _id: idOrder }, { $set: myorder });
await Order.findOneAndUpdate({ _id: idOrder }, { $set: myorder });
}
return myorder;
}
@@ -304,6 +310,7 @@ module.exports.updateTotals = function (order) {
let mypricecalc = 0;
order.TotalPriceProduct = 0;
order.TotalPriceProductCalc = 0;
order.modify_at = new Date();
// Calcolo Sconto
@@ -352,6 +359,8 @@ module.exports.updateTotals = function (order) {
} else {
mypricecalc = (order.price * order.quantity) + (order.price * order.quantitypreordered);
}
order.TotalPriceProductCalc += mypricecalc;
order.TotalPriceProduct += mypricecalc;
return order;