- Uscita PRIMA VERSIONE PiuCheBuono.app
This commit is contained in:
@@ -39,11 +39,11 @@ const OrdersCartSchema = new Schema({
|
||||
type: Number,
|
||||
Default: 0,
|
||||
},
|
||||
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockBloccatiQty)
|
||||
confermato: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockBloccatiQty)
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_evaso: {
|
||||
date_confermato: {
|
||||
type: Date
|
||||
},
|
||||
pagato: {
|
||||
@@ -439,11 +439,11 @@ module.exports.setConsegnatoById = async function (value, myOrderCart) {
|
||||
|
||||
}
|
||||
|
||||
module.exports.setEvasoById = async function (value, myOrderCart) {
|
||||
module.exports.setConfermatoById = async function (value, myOrderCart) {
|
||||
|
||||
let objtoset = {
|
||||
evaso: value,
|
||||
date_evaso: new Date(),
|
||||
confermato: value,
|
||||
date_confermato: new Date(),
|
||||
};
|
||||
|
||||
return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart);
|
||||
@@ -469,7 +469,7 @@ module.exports.createOrdersCart = async function (newOrdersCart) {
|
||||
return await newOrdersCart.save()
|
||||
}
|
||||
|
||||
module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
||||
module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -479,19 +479,21 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
||||
for (const idkey in myorderscart.items) {
|
||||
let order = myorderscart.items[idkey].order;
|
||||
|
||||
if (!order.evaso) {
|
||||
if (!order.confermato) { // Se ancora non è stato confermato:
|
||||
let update = {
|
||||
$inc: {
|
||||
stockQty: -order.quantity,
|
||||
stockBloccatiQty: order.quantity
|
||||
stockBloccatiQty: order.quantity,
|
||||
bookedQtyConfirmed: order.quantity,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
|
||||
update = {
|
||||
$inc: {
|
||||
bookableQty: -order.quantitypreordered,
|
||||
bookableBloccatiQty: order.quantitypreordered
|
||||
maxbookableGASQty: -order.quantitypreordered,
|
||||
bookableGASBloccatiQty: order.quantitypreordered,
|
||||
bookedGASQtyOrdered: order.quantitypreordered,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
@@ -504,7 +506,40 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
|
||||
}
|
||||
|
||||
}
|
||||
module.exports.updateStockBloccatiQtaDalMagazzino = async function (idorderscart) {
|
||||
module.exports.updateMagazzinoOrdineInLavorazione = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
|
||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||
|
||||
if (myorderscart) {
|
||||
for (const idkey in myorderscart.items) {
|
||||
let order = myorderscart.items[idkey].order;
|
||||
|
||||
if (!order.confermato) { // Se ancora non è stato confermato:
|
||||
let update = {
|
||||
$inc: {
|
||||
bookedQtyConfirmed: order.quantity,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
|
||||
update = {
|
||||
$inc: {
|
||||
bookedGASQtyOrdered: order.quantitypreordered,
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
}
|
||||
module.exports.updateStockBloccatiQtaDalMagazzinoOrdineConsegnato = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -523,7 +558,7 @@ module.exports.updateStockBloccatiQtaDalMagazzino = async function (idorderscart
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
update = {
|
||||
$inc: {
|
||||
bookableBloccatiQty: -order.quantitypreordered
|
||||
bookableGASBloccatiQty: -order.quantitypreordered
|
||||
}
|
||||
};
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
@@ -537,6 +572,67 @@ module.exports.updateStockBloccatiQtaDalMagazzino = async function (idorderscart
|
||||
|
||||
}
|
||||
|
||||
module.exports.updateStockQtaPerCancellazioneOrdine = async function (idorderscart) {
|
||||
|
||||
try {
|
||||
|
||||
const myorderscart = await OrdersCart.findOne({ _id: idorderscart }).populate('items.order').lean();
|
||||
|
||||
if (myorderscart) {
|
||||
for (const idkey in myorderscart.items) {
|
||||
let order = myorderscart.items[idkey].order;
|
||||
let update = {};
|
||||
|
||||
let fieldstoUpdate = {};
|
||||
|
||||
if (order.consegnato) {
|
||||
// Se l'ordine era stato già Consegnato, allora non fare niente !
|
||||
return false;
|
||||
} else {
|
||||
|
||||
if (order.confermato) { // Se l'ordine era stato confermato, allora rimetti le Qta in Magazzino
|
||||
fieldstoUpdate = {
|
||||
...fieldstoUpdate,
|
||||
stockQty: order.quantity,
|
||||
stockBloccatiQty: -order.quantity,
|
||||
bookedQtyConfirmed: -order.quantity,
|
||||
}
|
||||
}
|
||||
|
||||
update = {
|
||||
$inc: fieldstoUpdate,
|
||||
};
|
||||
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
// --------------
|
||||
|
||||
fieldstoUpdate = {};
|
||||
|
||||
if (order.confermato) { // Se l'ordine era stato confermato, allora rimetti le Qta in Magazzino
|
||||
fieldstoUpdate = {
|
||||
...fieldstoUpdate,
|
||||
maxbookableGASQty: order.quantitypreordered,
|
||||
bookableGASBloccatiQty: -order.quantitypreordered,
|
||||
bookedGASQtyOrdered: -order.quantitypreordered,
|
||||
}
|
||||
}
|
||||
|
||||
update = {
|
||||
$inc: fieldstoUpdate,
|
||||
};
|
||||
|
||||
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.updateCmd = async function (ordersCart, status, value) {
|
||||
|
||||
|
||||
@@ -547,26 +643,40 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
|
||||
if (!!myOrderCart) {
|
||||
|
||||
const id = myOrderCart._id;
|
||||
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
||||
if (status === shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
|
||||
if (value) {
|
||||
await OrdersCart.updateMagazzinoOrdineInLavorazione(id);
|
||||
}
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
||||
|
||||
// Aggiorna anche il Magazzino, togliendo le quantità in Stock e aggiungendole su quelle bloccate
|
||||
if (value) {
|
||||
await OrdersCart.updateStockQtaDalMagazzino(id);
|
||||
await OrdersCart.updateStockQtaDalMagazzinoOrdineConfermato(id);
|
||||
}
|
||||
ris = await OrdersCart.setEvasoById(value, myOrderCart);
|
||||
ris = await OrdersCart.setConfermatoById(value, myOrderCart);
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.PAYED) {
|
||||
|
||||
ris = await OrdersCart.setPagatoById(value, myOrderCart);
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato
|
||||
if (value) {
|
||||
await OrdersCart.updateStockBloccatiQtaDalMagazzino(id);
|
||||
await OrdersCart.updateStockBloccatiQtaDalMagazzinoOrdineConsegnato(id);
|
||||
}
|
||||
ris = await OrdersCart.setConsegnatoById(value, myOrderCart);
|
||||
} else if (status === shared_consts.OrderStatus.SHIPPED) {
|
||||
|
||||
ris = await OrdersCart.setSpeditoById(value, myOrderCart);
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.RECEIVED) {
|
||||
ris = await OrdersCart.setRicevutoById(value, myOrderCart);
|
||||
} else if (status === shared_consts.OrderStatus.CANCELED) {
|
||||
await OrdersCart.updateStockQtaPerCancellazioneOrdine(id)
|
||||
|
||||
} else if (status === shared_consts.OrderStatus.DELETE_REALLY) {
|
||||
await OrdersCart.updateStockQtaPerCancellazioneOrdine(id)
|
||||
ris = await OrdersCart.deleteReally(value, myOrderCart);
|
||||
}
|
||||
|
||||
@@ -574,7 +684,6 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
|
||||
|
||||
await OrdersCart.setFieldInOrdersById({ status }, myOrderCart);
|
||||
|
||||
|
||||
myOrderCart = await OrdersCart.getOrdersCartById(ordersCart._id)
|
||||
}
|
||||
// myOrderCart = await OrdersCart.findOne({ _id: idorderscart });
|
||||
|
||||
Reference in New Issue
Block a user