Risolto problema blocco
This commit is contained in:
@@ -28,7 +28,8 @@ const orderSchema = new Schema({
|
|||||||
idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }],
|
idScontisticas: [{ type: Schema.Types.ObjectId, ref: 'Scontistica' }],
|
||||||
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
idProvider: { type: Schema.Types.ObjectId, ref: 'Provider' },
|
||||||
price: {
|
price: {
|
||||||
type: Number
|
type: Number,
|
||||||
|
default: 0,
|
||||||
},
|
},
|
||||||
after_price: {
|
after_price: {
|
||||||
type: String
|
type: String
|
||||||
@@ -40,7 +41,12 @@ const orderSchema = new Schema({
|
|||||||
type: String
|
type: String
|
||||||
},
|
},
|
||||||
quantity: {
|
quantity: {
|
||||||
type: Number
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
TotalPriceProduct: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
},
|
},
|
||||||
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo StockQty)
|
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo StockQty)
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|||||||
@@ -544,7 +544,7 @@ module.exports.getmsgorderTelegram = async function (ordersCart) {
|
|||||||
msg += '<br><br>Lista Prodotti:';
|
msg += '<br><br>Lista Prodotti:';
|
||||||
for (const ord of ordersCart.items) {
|
for (const ord of ordersCart.items) {
|
||||||
msg += '<br>';
|
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>';
|
msg += '<br>';
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ class Cart {
|
|||||||
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
||||||
if (!!myitem) {
|
if (!!myitem) {
|
||||||
myitem.order.quantity++;
|
myitem.order.quantity++;
|
||||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
|
||||||
this.updatetotals();
|
this.updatetotals();
|
||||||
|
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||||
return myitem.order.quantity;
|
return myitem.order.quantity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,8 @@ class Cart {
|
|||||||
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
|
||||||
if (!!myitem && myitem.order.quantity > 0) {
|
if (!!myitem && myitem.order.quantity > 0) {
|
||||||
myitem.order.quantity--;
|
myitem.order.quantity--;
|
||||||
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
|
||||||
this.updatetotals();
|
this.updatetotals();
|
||||||
|
await Order.findOneAndUpdate({ _id: myitem.order._id }, { $set: myitem.order }, { new: false });
|
||||||
return myitem.order.quantity;
|
return myitem.order.quantity;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -94,15 +94,17 @@ class Cart {
|
|||||||
this.totalQty = 0;
|
this.totalQty = 0;
|
||||||
this.totalPrice = 0;
|
this.totalPrice = 0;
|
||||||
for (const rec in this.items) {
|
for (const rec in this.items) {
|
||||||
|
let mypricecalc = 0;
|
||||||
|
|
||||||
let order = this.items[rec].order;
|
let order = this.items[rec].order;
|
||||||
if (!order) {
|
if (!order) {
|
||||||
order = this.items[rec];
|
order = this.items[rec];
|
||||||
}
|
}
|
||||||
|
order.TotalPriceProduct = 0;
|
||||||
this.totalQty += order.quantity;
|
this.totalQty += order.quantity;
|
||||||
|
|
||||||
// Calcolo Sconto
|
// Calcolo Sconto
|
||||||
let sconti_da_applicare = [];
|
let sconti_da_applicare = [];
|
||||||
let mypricecalc = 0;
|
|
||||||
if (order.scontisticas) {
|
if (order.scontisticas) {
|
||||||
|
|
||||||
let qtadascontare = order.quantity
|
let qtadascontare = order.quantity
|
||||||
@@ -131,10 +133,7 @@ class Cart {
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
mypricecalc = order.price * order.quantity;
|
|
||||||
|
|
||||||
if (sconti_da_applicare.length > 0) {
|
if (sconti_da_applicare.length > 0) {
|
||||||
mypricecalc = 0
|
|
||||||
for (const sconto of sconti_da_applicare) {
|
for (const sconto of sconti_da_applicare) {
|
||||||
if (sconto.perc_sconto > 0) {
|
if (sconto.perc_sconto > 0) {
|
||||||
mypricecalc += (sconto.qtadascontare * order.price) * (1 - (sconto.perc_sconto / 100))
|
mypricecalc += (sconto.qtadascontare * order.price) * (1 - (sconto.perc_sconto / 100))
|
||||||
@@ -150,7 +149,8 @@ class Cart {
|
|||||||
} else {
|
} else {
|
||||||
mypricecalc = order.price * order.quantity;
|
mypricecalc = order.price * order.quantity;
|
||||||
}
|
}
|
||||||
this.totalPrice += mypricecalc;
|
order.TotalPriceProduct += mypricecalc;
|
||||||
|
this.totalPrice += order.TotalPriceProduct;
|
||||||
}
|
}
|
||||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user