- Uscita PRIMA VERSIONE PiuCheBuono.app
This commit is contained in:
@@ -54,18 +54,11 @@ const orderSchema = new Schema({
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
evaso: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockQty)
|
||||
confermato: { // e quindi è stato tolto dal magazzino (aggiornando il campo stockQty)
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_evaso: {
|
||||
type: Date
|
||||
},
|
||||
consegnato: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_consegnato: {
|
||||
date_confermato: {
|
||||
type: Date
|
||||
},
|
||||
pagato: {
|
||||
@@ -75,13 +68,6 @@ const orderSchema = new Schema({
|
||||
date_pagato: {
|
||||
type: Date
|
||||
},
|
||||
spedito: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_spedito: {
|
||||
type: Date
|
||||
},
|
||||
consegnato: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -89,6 +75,13 @@ const orderSchema = new Schema({
|
||||
date_consegnato: {
|
||||
type: Date
|
||||
},
|
||||
spedito: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
date_spedito: {
|
||||
type: Date
|
||||
},
|
||||
ricevuto: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
@@ -572,7 +565,7 @@ module.exports.getTotalOrderById = async function (id) {
|
||||
$subtract: ["$product.stockQty", "$product.QuantitaOrdinateInAttesa"],
|
||||
},
|
||||
'product.bookableAvailableQty': {
|
||||
$subtract: ["$product.bookableQty", "$product.QuantitaPrenotateInAttesa"],
|
||||
$subtract: ["$product.maxbookableGASQty", "$product.QuantitaPrenotateInAttesa"],
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -71,26 +71,42 @@ const productSchema = new Schema({
|
||||
default: 1,
|
||||
required: true,
|
||||
},
|
||||
maxBookableQty: { // quantità massima Pre-ordinabile (singolarmente)
|
||||
maxBookableSinglePersQty: { // quantità massima Pre-ordinabile (singolarmente)
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
|
||||
stockQty: { // in magazzino
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookableQty: { // Quantità prenotabili
|
||||
stockBloccatiQty: { // Prenotati Bloccati
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
stockBloccatiQty: { // Prenotati
|
||||
bookedQtyConfirmed: { // Quantità Prenotate Confermate Totali
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookableBloccatiQty: { // Quantità Prenotati e prenotabili
|
||||
|
||||
// GAS:
|
||||
qtyToReachForGas: { // Quantità minima da raggiungere per fare l'ordine GAS
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
maxbookableGASQty: { // Quantità massima (ancora disponibile) Ordine GAS prenotabile (Complessivamente tra tutti gli ordini)
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookedGASQtyOrdered: { // Quantità Ordine GAS Prenotate Confermate Totali
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
bookableGASBloccatiQty: { // Quantità Prenotate Bloccate GAS
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
|
||||
quantityLow: { //Soglia disponibilità bassa
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -114,6 +130,9 @@ const productSchema = new Schema({
|
||||
dateAvailableFrom: {
|
||||
type: Date
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
producer_name: {
|
||||
type: String,
|
||||
},
|
||||
@@ -421,7 +440,7 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
||||
$subtract: ["$stockQty", "$QuantitaOrdinateInAttesa"],
|
||||
},
|
||||
bookableAvailableQty: {
|
||||
$subtract: ["$bookableQty", "$QuantitaPrenotateInAttesa"],
|
||||
$subtract: ["$maxbookableGASQty", "$QuantitaPrenotateInAttesa"],
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -503,16 +522,16 @@ module.exports.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
|
||||
module.exports.convertAfterImport = async function (idapp, dataObjects) {
|
||||
module.exports.convertAfterImportALLPROD = async function (idapp, dataObjects) {
|
||||
|
||||
const arrprod = await Product.find({ idapp }).lean();
|
||||
for (const prod of arrprod) {
|
||||
await this.singlerecconvert_AfterImport(prod);
|
||||
await this.singlerecconvert_AfterImport_AndSave(prod);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuovo) {
|
||||
module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, prod, isnuovo) {
|
||||
|
||||
let setta = false;
|
||||
|
||||
@@ -524,9 +543,13 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
||||
if (isnuovo) {
|
||||
objtoset = {
|
||||
idapp,
|
||||
minBuyQty: 1,
|
||||
minStepQty: 1,
|
||||
maxBookableQty: 0,
|
||||
// minBuyQty: 1,
|
||||
// minStepQty: 1,
|
||||
maxBookableSinglePersQty: 0,
|
||||
bookedGASQtyOrdered: 0,
|
||||
bookableGASBloccatiQty: 0,
|
||||
// qtyToReachForGas: 0,
|
||||
// maxbookableGASQty: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,6 +591,7 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (prod.provider_name) {
|
||||
// Cerca il produttore
|
||||
let recprovider = await Provider.findOne({ idapp, name: prod.provider_name }).lean();
|
||||
|
||||
@@ -50,7 +50,8 @@ const productInfoSchema = new Schema({
|
||||
type: Boolean
|
||||
},
|
||||
unit: {
|
||||
type: Number
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
|
||||
@@ -189,10 +189,10 @@ reactionSchema.statics.updateReactionsCounts = async function () {
|
||||
|
||||
risupdate = await mytable.updateOne({ _id: rec._id }, {
|
||||
$set: {
|
||||
numseen: ris.myreact.numseen | 0,
|
||||
numfav: ris.myreact.numfav | 0,
|
||||
numbook: ris.myreact.numbook | 0,
|
||||
numattend: ris.myreact.numattend | 0,
|
||||
numseen: ris.myreact.numseen ?? 0,
|
||||
numfav: ris.myreact.numfav ?? 0,
|
||||
numbook: ris.myreact.numbook ?? 0,
|
||||
numattend: ris.myreact.numattend ?? 0,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -60,6 +60,18 @@ const storehouseSchema = new Schema({
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
email_html_GAS_makeorder: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
email_html_GAS_order_confirmed: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
email_html_GAS_order_consegnato: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
});
|
||||
|
||||
var Storehouse = module.exports = mongoose.model('Storehouse', storehouseSchema);
|
||||
|
||||
Reference in New Issue
Block a user