- Uscita PRIMA VERSIONE PiuCheBuono.app

This commit is contained in:
Surya Paolo
2023-12-30 21:33:59 +01:00
parent ade9c149c5
commit b6204c7612
15 changed files with 330 additions and 121 deletions

View File

@@ -37,8 +37,12 @@ html
p!= mioheader p!= mioheader
else else
p Ciao #{username}, p Ciao #{username},
if (orders.items[0].order.quantitypreordered > 0)
- var miomakeorder = mystorehouse.email_html_GAS_makeorder
else
- var miomakeorder = mystorehouse.email_html_makeorder
- var miomakeorder = mystorehouse.email_html_makeorder
if (miomakeorder) if (miomakeorder)
p!= miomakeorder p!= miomakeorder
else else
@@ -46,67 +50,67 @@ html
p Il pagamento, se non diversamente comunicato, potrai farlo direttamente in sede. p Il pagamento, se non diversamente comunicato, potrai farlo direttamente in sede.
tr tr
td(class="whitespace", height="10") td(class="whitespace", height="10")
p   p  
- var totalPrice = orders.totalPrice - var totalPrice = orders.totalPrice
- var note = orders.note - var note = orders.note
- var index = 0 - var index = 0
each rec in orders.items each rec in orders.items
- var descr = rec.order.product.productInfo.name - var descr = rec.order.product.productInfo.name
- var img = rec.order.product.productInfo.img - var img = rec.order.product.productInfo.img
- var price = rec.order.price - var price = rec.order.price
- var after_price = rec.order.after_price - var after_price = rec.order.after_price
- var TotalPriceProduct = rec.order.TotalPriceProduct - var TotalPriceProduct = rec.order.TotalPriceProduct
if (rec.order.gasordine) if (rec.order.gasordine)
- var gasordine = rec.order.gasordine.name - var gasordine = rec.order.gasordine.name
else else
- var gasordine = '' - var gasordine = ''
- var qty = rec.order.quantity - var qty = rec.order.quantity
- var qtypreordered = rec.order.quantitypreordered - var qtypreordered = rec.order.quantitypreordered
- index = index + 1 - index = index + 1
table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center") table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
tr tr
td(class="column", valign="center" width="40") td(class="column", valign="center" width="40")
p.boldhigh #{index}. p.boldhigh #{index}.
td(class="column sectionArticleImage", valign="top" width="150") td(class="column sectionArticleImage", valign="top" width="150")
table(cellpadding="0", cellspacing="0", summary="", border="0") table(cellpadding="0", cellspacing="0", summary="", border="0")
tr tr
td td
img(src=baseimg + img, alt="", width="150" height="150") img(src=baseimg + img, alt="", width="150" height="150")
td(class="column", valign="top") td(class="column", valign="top")
table(cellpadding="0", cellspacing="0", summary="", border="0") table(cellpadding="0", cellspacing="0", summary="", border="0")
if (qtypreordered > 0) if (qtypreordered > 0)
tr tr
td(class="sectionContent", valign="top") td(class="sectionContent", valign="top")
p Gas Ordine: #{gasordine} p Gas Ordine: #{gasordine}
p   p  
tr tr
td(class="sectionContentTitle boldhigh", valign="top") td(class="sectionContentTitle boldhigh", valign="top")
p #{descr} p #{descr}
tr tr
td(class="sectionContent", valign="top") td(class="sectionContent", valign="top")
p Prezzo: #{price} € #{after_price} p Prezzo: #{price} € #{after_price}
if (qty > 0) if (qty > 0)
td(class="sectionContent", valign="top") td(class="sectionContent", valign="top")
p Quantità: #{qty} p Quantità: #{qty}
if (qtypreordered > 0) if (qtypreordered > 0)
td(class="sectionContent", valign="top") td(class="sectionContent", valign="top")
p Quantità Prenotata: #{qtypreordered} p Quantità Prenotata: #{qtypreordered}
tr tr
td(class="sectionContent", valign="top") td(class="sectionContent", valign="top")
p Totale: #{TotalPriceProduct} € p Totale: #{TotalPriceProduct} €
if (note) if (note)
p Note Aggiuntive: #{note} p Note Aggiuntive: #{note}
p.sectionContentTitle.boldhigh.sectionTotal Totale Ordine: #{totalPrice} € p.sectionContentTitle.boldhigh.sectionTotal Totale Ordine: #{totalPrice} €
tr tr
td(class="whitespace", height="10") td(class="whitespace", height="10")

View File

@@ -40,14 +40,17 @@ html
else else
p Ciao #{name}, p Ciao #{name},
- var miordconfirmed = mystorehouse.email_html_order_confirmed
if (orders.items[0].order.quantitypreordered > 0)
- var miordconfirmed = mystorehouse.email_html_GAS_order_confirmed
else
- var miordconfirmed = mystorehouse.email_html_order_confirmed
if (miordconfirmed) if (miordconfirmed)
p!= miordconfirmed p!= miordconfirmed
else else
p Puoi pertanto venire a ritirarli direttamente in sede, negli orari che ti sono stati indicati. p Puoi pertanto venire a ritirarli direttamente in sede, negli orari che ti sono stati indicati.
tr
td(class="whitespace", height="10")
p   p  
- var totalPrice = orders.totalPrice - var totalPrice = orders.totalPrice

View File

@@ -28,9 +28,35 @@ html
tr tr
td(class="emailContainer", valign="top") td(class="emailContainer", valign="top")
p Ciao #{name},
if (orders.items && orders.items.length > 0)
- var mystorehouse = orders.items[0].order.storehouse
else
- var mystorehouse = null
- var mioheader = mystorehouse.email_html_header
if (mioheader)
p!= mioheader
else
p Ciao #{username},
p L'ordine n. #{ordernumber} è stato Consegnato correttamente ! p L'ordine n. #{ordernumber} è stato Consegnato correttamente !
p Grazie Mille per aver contribuito a far crescere la Comunità
if (orders.items[0].order.quantitypreordered > 0)
- var miomakeorder = mystorehouse.email_html_GAS_order_consegnato
else
- var miomakeorder = mystorehouse.email_html_order_consegnato
if (miomakeorder)
p!= miomakeorder
tr
td
- var miofooter = mystorehouse.email_html_footer
if (miofooter)
p!= miofooter
else
p Grazie Mille
table.footer(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center") table.footer(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
tr tr

View File

@@ -105,3 +105,30 @@ Dom 17/12 ORE 16:19: USER [admin]: il mio profilo
Dom 17/12 ORE 16:19: USER [admin]: prova Dom 17/12 ORE 16:19: USER [admin]: prova
Dom 17/12 ORE 16:19: USER [admin]: link da condividere Dom 17/12 ORE 16:19: USER [admin]: link da condividere
Sab 30/12 ORE 20:06: USER [admin]: gruppo di acquisto per le arance:
produttore:
🍊sicilia frutta express (catania)
la piccola azienda a conduzione familiare di giovanni si trova in provincia di catania (sicilia), i frutti vengono prodotti rispettando i principi della biodinamica infatti non viene utilizzato nulla di chimico (niente irrorazioni) e la concimazione avviene tramite concimi naturali (letame).
⚠️ offerta sconto valida solo fino al 3 gennaio 2024, raggiungendo 100 kg totali di ordini di arance:
i prezzi sono compresi di spese di spedizione e di gestione.
🍊 arance tarocco spremuta: 1,20 € / kg
🥑 avocado: 7,80 € / kg
🍋 limoni: 2,40 € / kg
👉🏻 entra sul gruppo telegram piu che buono
per le prenotazioni potete registratevi sul nuovo sito:
👉🏻 piu che buono - gas e bottega (piuchebuono.app)
come funziona:
- registratevi su piuchebuono.app, verificate la email.
- accedete e poi cliccate su "gruppo di acquisto".
- cliccate sul carrello verde 🛒 per aggiungere i kg che desiderate.
- per finire: cliccare su "procedi all'ordine" e confermate.

View File

@@ -54,18 +54,11 @@ const orderSchema = new Schema({
type: Number, type: Number,
default: 0, 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, type: Boolean,
default: false, default: false,
}, },
date_evaso: { date_confermato: {
type: Date
},
consegnato: {
type: Boolean,
default: false,
},
date_consegnato: {
type: Date type: Date
}, },
pagato: { pagato: {
@@ -75,13 +68,6 @@ const orderSchema = new Schema({
date_pagato: { date_pagato: {
type: Date type: Date
}, },
spedito: {
type: Boolean,
default: false,
},
date_spedito: {
type: Date
},
consegnato: { consegnato: {
type: Boolean, type: Boolean,
default: false, default: false,
@@ -89,6 +75,13 @@ const orderSchema = new Schema({
date_consegnato: { date_consegnato: {
type: Date type: Date
}, },
spedito: {
type: Boolean,
default: false,
},
date_spedito: {
type: Date
},
ricevuto: { ricevuto: {
type: Boolean, type: Boolean,
default: false, default: false,
@@ -572,7 +565,7 @@ module.exports.getTotalOrderById = async function (id) {
$subtract: ["$product.stockQty", "$product.QuantitaOrdinateInAttesa"], $subtract: ["$product.stockQty", "$product.QuantitaOrdinateInAttesa"],
}, },
'product.bookableAvailableQty': { 'product.bookableAvailableQty': {
$subtract: ["$product.bookableQty", "$product.QuantitaPrenotateInAttesa"], $subtract: ["$product.maxbookableGASQty", "$product.QuantitaPrenotateInAttesa"],
} }
} }
}, },

View File

@@ -39,11 +39,11 @@ const OrdersCartSchema = new Schema({
type: Number, type: Number,
Default: 0, 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, type: Boolean,
default: false, default: false,
}, },
date_evaso: { date_confermato: {
type: Date type: Date
}, },
pagato: { 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 = { let objtoset = {
evaso: value, confermato: value,
date_evaso: new Date(), date_confermato: new Date(),
}; };
return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart); return await OrdersCart.setFieldInOrdersById(objtoset, myOrderCart);
@@ -469,7 +469,7 @@ module.exports.createOrdersCart = async function (newOrdersCart) {
return await newOrdersCart.save() return await newOrdersCart.save()
} }
module.exports.updateStockQtaDalMagazzino = async function (idorderscart) { module.exports.updateStockQtaDalMagazzinoOrdineConfermato = async function (idorderscart) {
try { try {
@@ -479,19 +479,21 @@ module.exports.updateStockQtaDalMagazzino = async function (idorderscart) {
for (const idkey in myorderscart.items) { for (const idkey in myorderscart.items) {
let order = myorderscart.items[idkey].order; let order = myorderscart.items[idkey].order;
if (!order.evaso) { if (!order.confermato) { // Se ancora non è stato confermato:
let update = { let update = {
$inc: { $inc: {
stockQty: -order.quantity, stockQty: -order.quantity,
stockBloccatiQty: order.quantity stockBloccatiQty: order.quantity,
bookedQtyConfirmed: order.quantity,
} }
}; };
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false }); await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
update = { update = {
$inc: { $inc: {
bookableQty: -order.quantitypreordered, maxbookableGASQty: -order.quantitypreordered,
bookableBloccatiQty: order.quantitypreordered bookableGASBloccatiQty: order.quantitypreordered,
bookedGASQtyOrdered: order.quantitypreordered,
} }
}; };
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false }); 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 { try {
@@ -523,7 +558,7 @@ module.exports.updateStockBloccatiQtaDalMagazzino = async function (idorderscart
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false }); await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false });
update = { update = {
$inc: { $inc: {
bookableBloccatiQty: -order.quantitypreordered bookableGASBloccatiQty: -order.quantitypreordered
} }
}; };
await Product.findOneAndUpdate({ _id: order.idProduct }, update, { new: false }); 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) { module.exports.updateCmd = async function (ordersCart, status, value) {
@@ -547,26 +643,40 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
if (!!myOrderCart) { if (!!myOrderCart) {
const id = myOrderCart._id; 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 // Aggiorna anche il Magazzino, togliendo le quantità in Stock e aggiungendole su quelle bloccate
if (value) { 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) { } else if (status === shared_consts.OrderStatus.PAYED) {
ris = await OrdersCart.setPagatoById(value, myOrderCart); ris = await OrdersCart.setPagatoById(value, myOrderCart);
} else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato } else if (status === shared_consts.OrderStatus.DELIVERED) { // Consegnato
if (value) { if (value) {
await OrdersCart.updateStockBloccatiQtaDalMagazzino(id); await OrdersCart.updateStockBloccatiQtaDalMagazzinoOrdineConsegnato(id);
} }
ris = await OrdersCart.setConsegnatoById(value, myOrderCart); ris = await OrdersCart.setConsegnatoById(value, myOrderCart);
} else if (status === shared_consts.OrderStatus.SHIPPED) { } else if (status === shared_consts.OrderStatus.SHIPPED) {
ris = await OrdersCart.setSpeditoById(value, myOrderCart); ris = await OrdersCart.setSpeditoById(value, myOrderCart);
} else if (status === shared_consts.OrderStatus.RECEIVED) { } else if (status === shared_consts.OrderStatus.RECEIVED) {
ris = await OrdersCart.setRicevutoById(value, myOrderCart); 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) { } else if (status === shared_consts.OrderStatus.DELETE_REALLY) {
await OrdersCart.updateStockQtaPerCancellazioneOrdine(id)
ris = await OrdersCart.deleteReally(value, myOrderCart); ris = await OrdersCart.deleteReally(value, myOrderCart);
} }
@@ -574,7 +684,6 @@ module.exports.updateCmd = async function (ordersCart, status, value) {
await OrdersCart.setFieldInOrdersById({ status }, myOrderCart); await OrdersCart.setFieldInOrdersById({ status }, myOrderCart);
myOrderCart = await OrdersCart.getOrdersCartById(ordersCart._id) myOrderCart = await OrdersCart.getOrdersCartById(ordersCart._id)
} }
// myOrderCart = await OrdersCart.findOne({ _id: idorderscart }); // myOrderCart = await OrdersCart.findOne({ _id: idorderscart });

View File

@@ -71,26 +71,42 @@ const productSchema = new Schema({
default: 1, default: 1,
required: true, required: true,
}, },
maxBookableQty: { // quantità massima Pre-ordinabile (singolarmente) maxBookableSinglePersQty: { // quantità massima Pre-ordinabile (singolarmente)
type: Number, type: Number,
default: 0, default: 0,
}, },
stockQty: { // in magazzino stockQty: { // in magazzino
type: Number, type: Number,
default: 0, default: 0,
}, },
bookableQty: { // Quantità prenotabili stockBloccatiQty: { // Prenotati Bloccati
type: Number, type: Number,
default: 0, default: 0,
}, },
stockBloccatiQty: { // Prenotati bookedQtyConfirmed: { // Quantità Prenotate Confermate Totali
type: Number, type: Number,
default: 0, default: 0,
}, },
bookableBloccatiQty: { // Quantità Prenotati e prenotabili
// GAS:
qtyToReachForGas: { // Quantità minima da raggiungere per fare l'ordine GAS
type: Number, type: Number,
default: 0, 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 quantityLow: { //Soglia disponibilità bassa
type: Number, type: Number,
default: 0, default: 0,
@@ -114,6 +130,9 @@ const productSchema = new Schema({
dateAvailableFrom: { dateAvailableFrom: {
type: Date type: Date
}, },
note: {
type: String,
},
producer_name: { producer_name: {
type: String, type: String,
}, },
@@ -421,7 +440,7 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
$subtract: ["$stockQty", "$QuantitaOrdinateInAttesa"], $subtract: ["$stockQty", "$QuantitaOrdinateInAttesa"],
}, },
bookableAvailableQty: { bookableAvailableQty: {
$subtract: ["$bookableQty", "$QuantitaPrenotateInAttesa"], $subtract: ["$maxbookableGASQty", "$QuantitaPrenotateInAttesa"],
} }
} }
}, },
@@ -503,16 +522,16 @@ module.exports.createIndexes((err) => {
if (err) throw 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(); const arrprod = await Product.find({ idapp }).lean();
for (const prod of arrprod) { 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; let setta = false;
@@ -524,9 +543,13 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod, isnuo
if (isnuovo) { if (isnuovo) {
objtoset = { objtoset = {
idapp, idapp,
minBuyQty: 1, // minBuyQty: 1,
minStepQty: 1, // minStepQty: 1,
maxBookableQty: 0, 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) { if (prod.provider_name) {
// Cerca il produttore // Cerca il produttore
let recprovider = await Provider.findOne({ idapp, name: prod.provider_name }).lean(); let recprovider = await Provider.findOne({ idapp, name: prod.provider_name }).lean();

View File

@@ -50,7 +50,8 @@ const productInfoSchema = new Schema({
type: Boolean type: Boolean
}, },
unit: { unit: {
type: Number type: Number,
default: 0,
}, },
icon: { icon: {
type: String, type: String,

View File

@@ -189,10 +189,10 @@ reactionSchema.statics.updateReactionsCounts = async function () {
risupdate = await mytable.updateOne({ _id: rec._id }, { risupdate = await mytable.updateOne({ _id: rec._id }, {
$set: { $set: {
numseen: ris.myreact.numseen | 0, numseen: ris.myreact.numseen ?? 0,
numfav: ris.myreact.numfav | 0, numfav: ris.myreact.numfav ?? 0,
numbook: ris.myreact.numbook | 0, numbook: ris.myreact.numbook ?? 0,
numattend: ris.myreact.numattend | 0, numattend: ris.myreact.numattend ?? 0,
} }
}) })
} }

View File

@@ -60,6 +60,18 @@ const storehouseSchema = new Schema({
type: String, type: String,
default: '', 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); var Storehouse = module.exports = mongoose.model('Storehouse', storehouseSchema);

View File

@@ -73,7 +73,7 @@ class Cart {
let step = stepmin; let step = stepmin;
if (this.isAvailableByOrder(myitem.order)) { if (this.isAvailableByOrder(myitem.order)) {
if (myitem.order.quantity === 0) if (myitem.order.quantity === 0)
step = myitem.order.product.minBuyQty | stepmin step = myitem.order.product.minBuyQty ?? stepmin
else if (myitem.order.quantity >= 10) else if (myitem.order.quantity >= 10)
step = stepmin < 2 ? 2 : stepmin step = stepmin < 2 ? 2 : stepmin
else if (myitem.order.quantity >= 20) else if (myitem.order.quantity >= 20)
@@ -82,7 +82,7 @@ class Cart {
myitem.order.quantity += step; myitem.order.quantity += step;
} else { } else {
if (myitem.order.quantitypreordered === 0) if (myitem.order.quantitypreordered === 0)
step = myitem.order.product.minBuyQty | stepmin step = myitem.order.product.minBuyQty ?? stepmin
else if (myitem.order.quantitypreordered >= 10) else if (myitem.order.quantitypreordered >= 10)
step = stepmin < 2 ? 2 : stepmin step = stepmin < 2 ? 2 : stepmin
else if (myitem.order.quantitypreordered >= 20) else if (myitem.order.quantitypreordered >= 20)

View File

@@ -74,13 +74,15 @@ router.post('/import', authenticate, async (req, res) => {
if (product.cat_name) { if (product.cat_name) {
arrcat = product.cat_name.trim().split(','); arrcat = product.cat_name.trim().split(',');
for (const mycat of arrcat) { for (const mycat of arrcat) {
let mycatstr = mycat.trim();
// Cerca la Categoria // Cerca la Categoria
let reccateg = await CatProd.findOne({ idapp, name: mycat }).lean(); let reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
if (!reccateg) { if (!reccateg) {
// Non esiste questo produttore, quindi lo creo ! // Non esiste questo produttore, quindi lo creo !
reccateg = new CatProd({ idapp, name: mycat }); reccateg = new CatProd({ idapp, name: mycatstr });
ris = await reccateg.save(); ris = await reccateg.save();
reccateg = await CatProd.findOne({ idapp, name: mycat }).lean(); reccateg = await CatProd.findOne({ idapp, name: mycatstr }).lean();
} }
if (reccateg) { if (reccateg) {
@@ -125,9 +127,10 @@ router.post('/import', authenticate, async (req, res) => {
if (!options.aggiornaStockQty && esisteindb) { if (!options.aggiornaStockQty && esisteindb) {
delete product.stockQty; delete product.stockQty;
delete product.bookableQty; delete product.maxbookableGASQty;
} }
// AGGIORNA PRODUCT
let risrec = await Product.findOneAndUpdate({ idProductInfo: product.idProductInfo }, { $set: product }, { new: true, upsert: true }); let risrec = await Product.findOneAndUpdate({ idProductInfo: product.idProductInfo }, { $set: product }, { new: true, upsert: true });
let recnew = await Product.findOne({ idProductInfo: product.idProductInfo }).lean(); let recnew = await Product.findOne({ idProductInfo: product.idProductInfo }).lean();
@@ -150,7 +153,7 @@ router.post('/import', authenticate, async (req, res) => {
errors++; errors++;
} }
await Product.singlerecconvert_AfterImport(idapp, recnew, isnuovo); await Product.singlerecconvert_AfterImport_AndSave(idapp, recnew, isnuovo);
} else { } else {
console.error('Error ProductInfo: ', product.code); console.error('Error ProductInfo: ', product.code);
errors++; errors++;
@@ -162,7 +165,7 @@ router.post('/import', authenticate, async (req, res) => {
/*return await Product.insertMany(dataObjects, { ordered: false }) /*return await Product.insertMany(dataObjects, { ordered: false })
.then((ris) => { .then((ris) => {
Product.convertAfterImport(idapp, dataObjects).then((ris) => { Product.convertAfterImportALLPROD(idapp, dataObjects).then((ris) => {
return res.status(200).send(true); return res.status(200).send(true);
}); });
@@ -170,7 +173,7 @@ router.post('/import', authenticate, async (req, res) => {
}) })
.catch((errors) => { .catch((errors) => {
console.error(errors); console.error(errors);
Product.convertAfterImport(idapp).then((ris) => { Product.convertAfterImportALLPROD(idapp).then((ris) => {
return res.status(200).send(true); return res.status(200).send(true);
}); });
});*/ });*/

View File

@@ -290,7 +290,7 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 }); return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
else { else {
await Order.updateStatusOrders(mycart.items, status); await Order.updateStatusOrders(mycart.items, status);
const myris = ris; const myris = ris;
// Cancella il Cart appena salvato in OrdersCart // Cancella il Cart appena salvato in OrdersCart
@@ -302,6 +302,8 @@ router.post('/:userId/createorderscart', authenticate, async function (req, res,
.then((orders) => { .then((orders) => {
if (!!orders) { if (!!orders) {
OrdersCart.updateCmd(orders[0], status, true);
// Invia la email dell'Ordine // Invia la email dell'Ordine
sendemail.sendEmail_OrderProduct(user.lang, idapp, orders[0], user) sendemail.sendEmail_OrderProduct(user.lang, idapp, orders[0], user)
.then(async (ris) => { .then(async (ris) => {
@@ -384,7 +386,7 @@ router.post('/:userId/ordercartstatus', authenticate, async function (req, res,
} }
if (ordertype !== '') { if (ordertype !== '') {
sendemail.sendEmail_Order(user.lang, idapp, orderCart, user, ordertype) sendemail.sendEmail_Order(user.lang, idapp, orderCart, user, ordertype, status)
.then((ris) => { .then((ris) => {
}) })

View File

@@ -36,6 +36,7 @@ const { authenticate, authenticate_noerror } = require('../middleware/authentica
const Cart = require('../models/cart'); const Cart = require('../models/cart');
const CartClass = require('../modules/Cart'); const CartClass = require('../modules/Cart');
const Product = require('../models/product'); const Product = require('../models/product');
const CatProd = require('../models/catprod');
const ProductInfo = require('../models/productInfo'); const ProductInfo = require('../models/productInfo');
const Order = require('../models/order'); const Order = require('../models/order');
const OrdersCart = require('../models/orderscart'); const OrdersCart = require('../models/orderscart');
@@ -1311,6 +1312,10 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
await Product.collection.drop(); await Product.collection.drop();
ris = await ProductInfo.collection.drop(); ris = await ProductInfo.collection.drop();
} else if (mydata.dbop === 'dropCatProd') {
await CatProd.collection.drop();
} else if (mydata.dbop === 'dropAllOrders') { } else if (mydata.dbop === 'dropAllOrders') {
try { try {