Aggiornamento modifiche preOrdini

This commit is contained in:
Surya Paolo
2023-12-20 21:52:17 +01:00
parent 56b5bac5f0
commit 0e1fc359a0
11 changed files with 290 additions and 61 deletions

View File

@@ -22,6 +22,7 @@ const OrdersCartSchema = new Schema({
numord_pers: { type: Number },
userId: { type: Schema.Types.ObjectId, ref: 'User' },
totalQty: { type: Number, default: 0 },
totalQtyPreordered: { type: Number, default: 0 },
totalPrice: { type: Number, default: 0 },
department: {
type: String, ref: 'Department'
@@ -250,10 +251,10 @@ module.exports.getOrdersCartByQuery = async function (query) {
return myorderscart;
}
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder, filterStatus) {
try {
let query = { idapp, status: { $gte: shared_consts.OrderStatus.CHECKOUT_SENT }, deleted: false }
let query = { idapp, deleted: false }
let myorderscart = null;
if (numorder > 0) {
query.numorder = numorder;
@@ -263,10 +264,14 @@ module.exports.getOrdersCartByUserId = async function (uid, idapp, numorder) {
query.userId = uid;
}
if (filterStatus) {
query.status = { $gte: shared_consts.OrderStatus.CHECKOUT_SENT };
}
myorderscart = await OrdersCart.getOrdersCartByQuery(query);
if (myorderscart)
console.log('*** Num myorderscart ', myorderscart.length);
// if (myorderscart)
// console.log('*** Num myorderscart ', myorderscart.length);
/*transform: function(doc, populated) {
@@ -301,6 +306,7 @@ module.exports.updateOrdersCartById = function (id, newOrdersCart, callback) {
$set: {
items: newOrdersCart.items,
totalQty: newOrdersCart.totalQty,
totalQtyPreordered: newOrdersCart.totalQtyPreordered,
totalPrice: newOrdersCart.totalPrice,
userId: userId,
status: newOrdersCart.status,
@@ -433,12 +439,18 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
let order = myorderscart.items[idkey].order;
if (!order.evaso) {
const update = {
let update = {
$inc: {
stockQty: -order.quantity
}
};
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
update = {
$inc: {
bookableQty: -order.quantitypreordered
}
};
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
}
}
@@ -544,12 +556,17 @@ 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 : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
let qtystr = ''
if (ord.order.quantity > 0)
qtystr += 'Ordinate: ' + ord.order.quantity
if (ord.order.quantitypreordered > 0)
qtystr += 'Prenotate: ' + ord.order.quantitypreordered
msg += '✅ [' + qtystr + '] ' + ord.order.product.name + ' (' + ord.order.price + ' € ' + (ord.order.after_price ? ord.order.after_price : '') + ' Tot=' + ord.order.TotalPriceProduct + '€ )';
}
msg += '<br>';
msg += '<br>Totale Prodotti: ' + ordersCart.totalQty;
msg += '<br>Totale Prodotti: ' + ordersCart.totalQty + ordersCart.totalQtyPreordered;
msg += '<br>Totale Ordine: ' + ordersCart.totalPrice + ' € 💰';