Risolto problema blocco

This commit is contained in:
Surya Paolo
2023-12-18 08:02:28 +01:00
parent 50d610b1b1
commit 139d7ea33c
3 changed files with 16 additions and 10 deletions

View File

@@ -28,7 +28,8 @@ const orderSchema = new Schema({
idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }],
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
price: {
type: Number
type: Number,
default: 0,
},
after_price: {
type: String
@@ -40,7 +41,12 @@ const orderSchema = new Schema({
type: String
},
quantity: {
type: Number
type: Number,
default: 0,
},
TotalPriceProduct: {
type: Number,
default: 0,
},
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo StockQty)
type: Boolean,

View File

@@ -544,7 +544,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
msg += '<br><br>Lista Prodotti:';
for (const ord of ordersCart.items) {
msg += '<br>';
msg += '✅ [' + ord.order.quantity + '] ' + ord.order.product.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ')';
msg += '✅ [' + ord.order.quantity + '] ' + ord.order.product.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
}
msg += '<br>';

View File

@@ -38,8 +38,8 @@ class Cart {
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
if (!!myitem) {
myitem.order.quantity++;
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
this.updatetotals();
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
return myitem.order.quantity;
}
}
@@ -49,8 +49,8 @@ class Cart {
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
if (!!myitem && myitem.order.quantity > 0) {
myitem.order.quantity--;
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
this.updatetotals();
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
return myitem.order.quantity;
}
} catch (e) {
@@ -94,15 +94,17 @@ class Cart {
this.totalQty = 0;
this.totalPrice = 0;
for (const rec in this.items) {
let mypricecalc = 0;
let order = this.items[rec].order;
if (!order) {
order = this.items[rec];
}
order.TotalPriceProduct = 0;
this.totalQty += order.quantity;
// Calcolo Sconto
let sconti_da_applicare = [];
let mypricecalc = 0;
if (order.scontisticas) {
let qtadascontare = order.quantity
@@ -131,10 +133,7 @@ class Cart {
}
}*/
mypricecalc = order.price * order.quantity;
if (sconti_da_applicare.length > 0) {
mypricecalc = 0
for (const sconto of sconti_da_applicare) {
if (sconto.perc_sconto > 0) {
mypricecalc += (sconto.qtadascontare * order.price) * (1 - (sconto.perc_sconto / 100))
@@ -150,7 +149,8 @@ class Cart {
} else {
mypricecalc = order.price * order.quantity;
}
this.totalPrice += mypricecalc;
order.TotalPriceProduct += mypricecalc;
this.totalPrice += order.TotalPriceProduct;
}
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
} catch (e) {