- Gestore Ordini GAS (aggiornato)

- Possibilità di modificare un record, click sulla matita rossa.
- corretto altre sistemazioni sui valori di minimo e massimo quantità.
This commit is contained in:
Surya Paolo
2025-10-03 16:28:53 +02:00
parent 6048cd526b
commit 4e37475d00
11 changed files with 138 additions and 142 deletions

View File

@@ -484,3 +484,8 @@ Dom 23/03 ORE 22:24: [<b>Circuito RIS Italia</b>]: Inviate Monete da surya1977 a
Saldi: Saldi:
surya1977: 88.20 RIS] surya1977: 88.20 RIS]
GruppoYurta: 6.00 RIS] GruppoYurta: 6.00 RIS]
Ven 03/10 ORE 15:03: [<b>Euro</b>]: Inviate Monete da paoloar77 a piuchebuono 6 € [causale: Pagato Ordine n.442]
Saldi:
paoloar77: -312.80 €]
piuchebuono: 10552.82 €]

View File

@@ -144,9 +144,11 @@ async function filterValidItems(mycart) {
mycart.newitems = []; mycart.newitems = [];
let haschanged = false; let haschanged = false;
for (let item of mycart.items) { for (let item of mycart.items) {
try {
if ( if (
item.order && item.order &&
item.order.hasOwnProperty('idapp') && item.order.hasOwnProperty('idapp') &&
item.order.product.productInfo &&
(item.order.quantity > 0 || item.order.quantitypreordered > 0) && (item.order.quantity > 0 || item.order.quantitypreordered > 0) &&
(await checkIfExistProduct(item.order.product.productInfo.code)) (await checkIfExistProduct(item.order.product.productInfo.code))
) { ) {
@@ -161,6 +163,9 @@ async function filterValidItems(mycart) {
haschanged = true; haschanged = true;
} }
} catch (e) {
console.log('err', e);
}
} }
mycart.items = [...mycart.newitems]; mycart.items = [...mycart.newitems];
mycart.newitems = []; mycart.newitems = [];

View File

@@ -329,7 +329,7 @@ module.exports.updateTotals = async function (order, codice_sconto) {
module.exports.getTotalOrderById = async function (id) { module.exports.getTotalOrderById = async function (id) {
const query = [ const query = [
{ $match: { _id: new ObjectId(id) } }, { $match: { _id: new mongoose.Types.ObjectId(id) } },
{ {
$lookup: { $lookup: {
from: 'products', from: 'products',

View File

@@ -204,7 +204,7 @@ module.exports.getRecCartByUserId = async function (uid, idapp, numorder) {
module.exports.getOrdersCartById = async function (id) { module.exports.getOrdersCartById = async function (id) {
let query = { _id: new ObjectId(id) }; let query = { _id: new mongoose.Types.ObjectId(id) };
const arrris = await OrdersCart.getOrdersCartByQuery(query); const arrris = await OrdersCart.getOrdersCartByQuery(query);
let myrec = arrris && arrris.length > 0 ? arrris[0] : null; let myrec = arrris && arrris.length > 0 ? arrris[0] : null;
@@ -274,13 +274,6 @@ module.exports.getOrdersCartByQuery = async function (query) {
order.items = order.items.map(item => { order.items = order.items.map(item => {
if (item.order) { if (item.order) {
try { try {
if (item.order.idProduct) {
item.order.idProduct.productInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo : { ...item.order.idProduct.idProductInfo };
item.order.idProduct.productInfo.unitstr = tools.getUnitsMeasure(item.order.idProduct.productInfo.unit, true);
// item.order.idProduct.idProductInfo = item.order.idProduct.productInfo ? item.order.idProduct.productInfo._id : '';
}
const myid = item.order._id;
// console.log('ID ORD', order.numorder, myid, order.user.name);
item.order.product = { ...item.order.idProduct }; item.order.product = { ...item.order.idProduct };
item.order.idProduct = item.order.product ? item.order.product._id : ''; item.order.idProduct = item.order.product ? item.order.product._id : '';
item.order.producer = item.order.idProducer; item.order.producer = item.order.idProducer;

View File

@@ -308,6 +308,7 @@ const productSchema = new Schema({
maxBookableSinglePersQty: { maxBookableSinglePersQty: {
// quantità massima Pre-ordinabile (singolarmente) // quantità massima Pre-ordinabile (singolarmente)
type: Number, type: Number,
default: 1,
}, },
stockQty: { stockQty: {
// in magazzino // in magazzino
@@ -318,6 +319,7 @@ const productSchema = new Schema({
stockBloccatiQty: { stockBloccatiQty: {
// Prenotati Bloccati // Prenotati Bloccati
type: Number, type: Number,
default: 0,
}, },
bookedQtyOrdered: { bookedQtyOrdered: {
// Quantità Prenotate ordinate (in Lavorazione) // Quantità Prenotate ordinate (in Lavorazione)
@@ -326,12 +328,14 @@ const productSchema = new Schema({
bookedQtyConfirmed: { bookedQtyConfirmed: {
// Quantità Prenotate Confermate Totali // Quantità Prenotate Confermate Totali
type: Number, type: Number,
default: 0,
}, },
// GAS: // GAS:
qtyToReachForGas: { qtyToReachForGas: {
// Quantità minima da raggiungere per fare l'ordine GAS // Quantità minima da raggiungere per fare l'ordine GAS
type: Number, type: Number,
default: 0,
}, },
maxbookableGASQty: { maxbookableGASQty: {
// Quantità massima (ancora disponibile) Ordine GAS prenotabile (Complessivamente tra tutti gli ordini) // Quantità massima (ancora disponibile) Ordine GAS prenotabile (Complessivamente tra tutti gli ordini)
@@ -341,10 +345,12 @@ const productSchema = new Schema({
bookedGASQtyOrdered: { bookedGASQtyOrdered: {
// Quantità Ordine GAS Prenotate Totali // Quantità Ordine GAS Prenotate Totali
type: Number, type: Number,
default: 0,
}, },
bookedGASQtyConfirmed: { bookedGASQtyConfirmed: {
// Quantità Ordine GAS Confermate Totali // Quantità Ordine GAS Confermate Totali
type: Number, type: Number,
default: 0,
}, },
bookableGASBloccatiQty: { bookableGASBloccatiQty: {
// Quantità Prenotate Bloccate GAS // Quantità Prenotate Bloccate GAS
@@ -354,6 +360,7 @@ const productSchema = new Schema({
quantityLow: { quantityLow: {
//Soglia disponibilità bassa //Soglia disponibilità bassa
type: Number, type: Number,
default: 0,
}, },
visibilityProductOutOfStock: { visibilityProductOutOfStock: {
// Visibilità prodotto "esaurito" // Visibilità prodotto "esaurito"
@@ -1173,7 +1180,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
} }
if (!tools.isObjectEmpty(objtoset)) { if (!tools.isObjectEmpty(objtoset)) {
ris = await Product.findOneAndUpdate({ _id: new ObjectId(prod._id) }, { $set: objtoset }); ris = await Product.findOneAndUpdate({ _id: prod._id }, { $set: objtoset });
const objDelete = { const objDelete = {
cat_name: 1, cat_name: 1,
@@ -1186,7 +1193,7 @@ module.exports.singlerecconvert_AfterImport_AndSave = async function (idapp, pro
gas_name: 1, gas_name: 1,
}; };
ris = await Product.updateOne({ _id: new ObjectId(prod._id) }, { $unset: objDelete }); ris = await Product.updateOne({ _id: prod._id }, { $unset: objDelete });
if (ris && ris.modifiedCount > 0) { if (ris && ris.modifiedCount > 0) {
console.log('Modificato: ', objtoset.name); console.log('Modificato: ', objtoset.name);

View File

@@ -146,8 +146,11 @@ class Cart {
} else { } else {
if (myorder.quantitypreordered === minqta) { if (myorder.quantitypreordered === minqta) {
step = minqta; step = minqta;
} else {
if (myorder.quantitypreordered - step < 0) {
step = myorder.quantitypreordered - step;
}
} }
step = myorder.quantity - stepΩ;
} }
return step; return step;
} catch (e) { } catch (e) {

View File

@@ -431,8 +431,8 @@ class AmazonBookScraper {
}*/ }*/
} }
if (product.idProductInfo) { if (product.productInfo) {
if (!tools.isDateValid(product.idProductInfo.date_pub)) { if (!tools.isDateValid(product.productInfo.date_pub)) {
datimancanti = true; datimancanti = true;
} }
} }
@@ -458,7 +458,7 @@ class AmazonBookScraper {
} }
includiNelControlloIlRecProduct(product) { includiNelControlloIlRecProduct(product) {
return product.idProductInfo && [1, 4, 34, 45, 46].includes(product.idProductInfo.idStatoProdotto); return product.productInfo && [1, 4, 34, 45, 46].includes(product.productInfo.idStatoProdotto);
} }
async scrapeMultiple(products, options) { async scrapeMultiple(products, options) {
@@ -474,7 +474,7 @@ class AmazonBookScraper {
if (this.includiNelControlloIlRecProduct(product)) { if (this.includiNelControlloIlRecProduct(product)) {
if (this.datiMancanti(product) || options.caricatutti) { if (this.datiMancanti(product) || options.caricatutti) {
// console.log(`${quanti} / ${products.length} - Scraping: ${product.idProductInfo.name}`); // console.log(`${quanti} / ${products.length} - Scraping: ${product.productInfo.name}`);
const data = await this.scrapeISBN(product, isbn, options); const data = await this.scrapeISBN(product, isbn, options);
if (data?.updated) { if (data?.updated) {
@@ -485,7 +485,7 @@ class AmazonBookScraper {
if (i % 1 === 0) { if (i % 1 === 0) {
const percentuale = ((i / products.length) * 100).toFixed(2); const percentuale = ((i / products.length) * 100).toFixed(2);
console.log( console.log(
`Scraping: ${product.isbn} - ${product.idProductInfo.name} - ${quanti} su ${i + 1} / ${ `Scraping: ${product.isbn} - ${product.productInfo.name} - ${quanti} su ${i + 1} / ${
products.length products.length
} - [${percentuale}%] - ${this.getRemainingTimeToTheEnd(dataorainizio, i, products.length)}` } - [${percentuale}%] - ${this.getRemainingTimeToTheEnd(dataorainizio, i, products.length)}`
); );
@@ -615,9 +615,8 @@ class AmazonBookScraper {
const headers = ['isbn', 'titolo', 'pagine', 'misure', 'edizione', 'date_pub' /*'sottotitolo'*/]; const headers = ['isbn', 'titolo', 'pagine', 'misure', 'edizione', 'date_pub' /*'sottotitolo'*/];
try { try {
// Trova i prodotti e popula 'idProductInfo' // Trova i prodotti
const products = await Product.find({ idapp, scraped_updated: true }) const products = await Product.find({ idapp, scraped_updated: true })
.populate({ path: 'idProductInfo', select: 'date_pub name sottotitolo' })
.lean(); .lean();
// Funzione per "appiattire" i dati // Funzione per "appiattire" i dati
@@ -634,10 +633,10 @@ class AmazonBookScraper {
flattened.ristampa = variation.ristampa || ''; flattened.ristampa = variation.ristampa || '';
} }
// Assicurati che 'idProductInfo' esista prima di usarlo // Assicurati che 'productInfo' esista prima di usarlo
flattened.date_pub = item.idProductInfo ? item.idProductInfo.date_pub : ''; flattened.date_pub = item.productInfo ? item.productInfo.date_pub : '';
flattened.titolo = item.idProductInfo ? item.idProductInfo.name : ''; flattened.titolo = item.productInfo ? item.productInfo.name : '';
// flattened.sottotitolo = item.idProductInfo ? item.idProductInfo.sottotitolo : ''; // flattened.sottotitolo = item.productInfo ? item.productInfo.sottotitolo : '';
return flattened; return flattened;
}); });

View File

@@ -916,20 +916,14 @@ function fixURL(url) {
return url.replace(/https:\//g, 'https://'); return url.replace(/https:\//g, 'https://');
} }
async function completaSettaggioProduct_AndProductInfo( async function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product) {
arrcampi_productInfo,
arrcampi_product,
rec,
product,
productInfo
) {
try { try {
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit')) { if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit')) {
if (rec.hasOwnProperty('weight_and_unit')) { if (rec.hasOwnProperty('weight_and_unit')) {
const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']); const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']);
if (ris1) { if (ris1) {
productInfo.weight = ris1.weight; product.productInfo.weight = ris1.weight;
productInfo.unit = ris1.unit; product.productInfo.unit = ris1.unit;
} }
} }
} }
@@ -938,20 +932,20 @@ async function completaSettaggioProduct_AndProductInfo(
if (rec.hasOwnProperty('weight_and_unit_lordo')) { if (rec.hasOwnProperty('weight_and_unit_lordo')) {
const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']); const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']);
if (ris2) { if (ris2) {
productInfo.weight_lordo = ris2.weight; product.productInfo.weight_lordo = ris2.weight;
productInfo.unit_lordo = ris2.unit; product.productInfo.unit_lordo = ris2.unit;
} }
} }
} }
if (rec.hasOwnProperty('link_scheda')) { if (rec.hasOwnProperty('link_scheda')) {
if (fixURL(rec['link_scheda'])) productInfo['link_scheda'] = fixURL(rec['link_scheda']); if (fixURL(rec['link_scheda'])) product.productInfo['link_scheda'] = fixURL(rec['link_scheda']);
} }
for (const campo of shared_consts.PRODUCTINFO.CAMPI_FIRST_UPPERCASE) { for (const campo of shared_consts.PRODUCTINFO.CAMPI_FIRST_UPPERCASE) {
if (rec.hasOwnProperty(campo)) { if (rec.hasOwnProperty(campo)) {
let mystr = tools.capitalize(rec[campo]).trim(); let mystr = tools.capitalize(rec[campo]).trim();
if (mystr) productInfo[campo] = mystr; if (mystr) product.productInfo[campo] = mystr;
} }
} }
@@ -962,30 +956,30 @@ async function completaSettaggioProduct_AndProductInfo(
} }
} }
if (!rec.hasOwnProperty('img') && product.code) { if (!rec.hasOwnProperty('img') && product.productInfo.code) {
productInfo.imagefile = product.code + '.jpg'; product.productInfo.imagefile = product.productInfo.code + '.jpg';
} else { } else {
if (rec.hasOwnProperty('img')) { if (rec.hasOwnProperty('img')) {
if (rec['img']) { if (rec['img']) {
productInfo.imagefile = rec['img']; product.productInfo.imagefile = rec['img'];
} else { } else {
productInfo.imagefile = ''; product.productInfo.imagefile = '';
} }
} }
} }
if (rec.hasOwnProperty('productTypes')) { if (rec.hasOwnProperty('productTypes')) {
productInfo.productTypes = productInfo.productTypes; // product.productInfo.productTypes = product.productInfo.productTypes;
} else { } else {
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT]; product.productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
} }
return { product, productInfo }; return { product };
} catch (e) { } catch (e) {
console.error('Err', e); console.error('Err', e);
} }
return { product, productInfo }; return { product };
} }
function getValoriAndIndice(dati, arrinclude) { function getValoriAndIndice(dati, arrinclude) {
@@ -1023,13 +1017,11 @@ function getValoriAndIndice_Product(dati) {
async function extractArrayDataFromCSV(idapp, rec) { async function extractArrayDataFromCSV(idapp, rec) {
try { try {
// la prima riga contiene il nome della proprietà: // la prima riga contiene il nome della proprietà:
let productInfo = { let product = {
idapp: idapp, productInfo: {
idCatProds: [], idCatProds: [],
idSubCatProds: [], idSubCatProds: [],
}; },
let product = {
idapp, idapp,
}; };
@@ -1041,7 +1033,7 @@ async function extractArrayDataFromCSV(idapp, rec) {
const mykey = Object.keys(rec).find((key) => key.toLowerCase() === campoobj.name.toLowerCase()); const mykey = Object.keys(rec).find((key) => key.toLowerCase() === campoobj.name.toLowerCase());
if (mykey) { if (mykey) {
let myval = tools.ripulisciCampo(rec[mykey]); let myval = tools.ripulisciCampo(rec[mykey]);
productInfo[campoobj.name] = product.productInfo[campoobj.name] =
myval === 'TRUE' || myval.toUpperCase() === 'SI' myval === 'TRUE' || myval.toUpperCase() === 'SI'
? true ? true
: myval === 'FALSE' || myval.toUpperCase() === 'NO' : myval === 'FALSE' || myval.toUpperCase() === 'NO'
@@ -1054,13 +1046,16 @@ async function extractArrayDataFromCSV(idapp, rec) {
if (rec.hasOwnProperty(campoobj)) product[campoobj] = rec[campoobj]; if (rec.hasOwnProperty(campoobj)) product[campoobj] = rec[campoobj];
} }
const ris = await completaSettaggioProduct_AndProductInfo( for (const campoconvertiti of shared_consts.CONVERTI_CAMPO) {
arrcampi_productInfo, if (rec.hasOwnProperty(campoconvertiti.convertito)) {
arrcampi_product, product[campoconvertiti.originale] = rec[campoconvertiti.convertito];
rec, }
product, }
productInfo
); // Se trovi questi campi, li converti
const ris = await completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product);
/* /*
// code: product.code, // code: product.code,
@@ -1209,50 +1204,50 @@ router.post('/import', authenticate, async (req, res) => {
let numprod = dataObjects.length; let numprod = dataObjects.length;
for (const product of dataObjects) { for (const productImported of dataObjects) {
let isnuovo = false; let isnuovo = false;
let setta = false; let setta = false;
let importa = true; let importa = true;
if (!product.code) importa = false; if (!productImported.code) importa = false;
if (importa) { if (importa) {
let productInfo = { let productInfo = {
idapp: product.idapp, idapp: productImported.idapp,
code: product.code, code: productImported.code,
}; };
const myproduct = await Product.findOne({ 'productInfo.code': productInfo.code }); const myproduct = await Product.findOne({ 'productInfo.code': productInfo.code });
// IMPOSTA I VALORI SOLO SE NON ESISTONO ! ALTRIMENTI LASCIA QUELLI GIA' IMPORTATI (O MODIFICATI) // IMPOSTA I VALORI SOLO SE NON ESISTONO ! ALTRIMENTI LASCIA QUELLI GIA' IMPORTATI (O MODIFICATI)
if (getvalueByJsonText(product.url)) { if (getvalueByJsonText(productImported.url)) {
if ((myproduct && !myproduct.productInfo.link_macro) || !myproduct.productInfo) if ((myproduct && !myproduct.productInfo.link_macro) || !myproduct.productInfo)
productInfo.link_macro = getvalueByJsonText(product.url); productInfo.link_macro = getvalueByJsonText(productImported.url);
} }
if (getvalueByJsonText(product.descrizione)) { if (getvalueByJsonText(productImported.descrizione)) {
if ((myproduct && !myproduct.productInfo.descrizione_breve_macro) || !myproduct.productInfo) if ((myproduct && !myproduct.productInfo.descrizione_breve_macro) || !myproduct.productInfo)
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione); productInfo.descrizione_breve_macro = getvalueByJsonText(productImported.descrizione);
} }
if (getvalueByJsonText(product.descrizione_completa)) { if (getvalueByJsonText(productImported.descrizione_completa)) {
if ((myproduct && !myproduct.productInfo.descrizione_completa_macro) || !myproduct.productInfo) if ((myproduct && !myproduct.productInfo.descrizione_completa_macro) || !myproduct.productInfo)
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa); productInfo.descrizione_completa_macro = getvalueByJsonText(productImported.descrizione_completa);
} }
if (getvalueByJsonText(product.sottotitolo)) { if (getvalueByJsonText(productImported.sottotitolo)) {
if ((myproduct && !myproduct.productInfo.sottotitolo) || !myproduct.productInfo) if ((myproduct && !myproduct.productInfo.sottotitolo) || !myproduct.productInfo)
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo); productInfo.sottotitolo = getvalueByJsonText(productImported.sottotitolo);
} }
if (getvalueByJsonText(product.titolo)) { if (getvalueByJsonText(productImported.titolo)) {
if ((myproduct && !myproduct.productInfo.name) || !myproduct.productInfo) if ((myproduct && !myproduct.productInfo.name) || !myproduct.productInfo)
productInfo.name = getvalueByJsonText(product.titolo); productInfo.name = getvalueByJsonText(productImported.titolo);
} }
const pagine = getvalueByJsonText(product.pagine); const pagine = getvalueByJsonText(productImported.pagine);
let recisbn = {}; let recisbn = {};
const trovato = await ImportaIsbn.findOne({ isbn: product.code }).lean(); const trovato = await ImportaIsbn.findOne({ isbn: productImported.code }).lean();
if (trovato) { if (trovato) {
// togli a recisbn l'_id // togli a recisbn l'_id
delete trovato._id; delete trovato._id;
@@ -1271,7 +1266,7 @@ router.post('/import', authenticate, async (req, res) => {
try { try {
let risisbn = await ImportaIsbn.findOneAndUpdate( let risisbn = await ImportaIsbn.findOneAndUpdate(
{ isbn: product.code }, { isbn: productImported.code },
{ $set: recisbn }, { $set: recisbn },
{ new: true, upsert: true, strict: false } { new: true, upsert: true, strict: false }
); );
@@ -1394,19 +1389,17 @@ router.post('/import', authenticate, async (req, res) => {
{ new: true, upsert: true } { new: true, upsert: true }
); );
// .... ANDARE AVANTI DA QUI... .productInfo.... SISTEMARE!
if (risrecInfo) { if (risrecInfo) {
productImported.productInfo = risrecInfo._id; productImported.productInfo = risrecInfo._id;
recnewInfo = await Product.findOne({ code: product.code }).lean(); recnewInfo = await Product.findOne({ code: product.productInfo.code }).lean();
if (risrecInfo._id) { if (risrecInfo._id) {
// Record existed, so it was updated // Record existed, so it was updated
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo); let arrfieldchange = tools.differentObjects(productInfo, recnewInfo);
if (arrfieldchange && arrfieldchange.length > 0) { if (arrfieldchange && arrfieldchange.length > 0) {
// updated++; // updated++;
console.log('Changed: ', recnewInfo.name + ': ' + arrfieldchange); console.log('Changed: ', recnewInfo.productInfo.name + ': ' + arrfieldchange);
} }
} }
@@ -1425,7 +1418,7 @@ router.post('/import', authenticate, async (req, res) => {
} }
let recProductExist = null; let recProductExist = null;
let queryprod = { idProductInfo: productImported.idProductInfo }; let queryprod = { _id: productImported._id };
if (recGas) { if (recGas) {
queryprod = { ...queryprod, idGasordine: recGas._id }; queryprod = { ...queryprod, idGasordine: recGas._id };
@@ -1443,7 +1436,11 @@ router.post('/import', authenticate, async (req, res) => {
} }
// AGGIORNA PRODUCT // AGGIORNA PRODUCT
let risrec = await Product.findOneAndUpdate(queryprod, { $set: productImported }, { new: true, upsert: true }); let risrec = await Product.findOneAndUpdate(
queryprod,
{ $set: productImported },
{ new: true, upsert: true }
);
let recnew = await Product.findOne(queryprod).lean(); let recnew = await Product.findOne(queryprod).lean();
@@ -1453,7 +1450,7 @@ router.post('/import', authenticate, async (req, res) => {
let arrfieldchange = tools.differentObjects(productImported, recnew); let arrfieldchange = tools.differentObjects(productImported, recnew);
if (arrfieldchange.length > 0) { if (arrfieldchange.length > 0) {
updated++; updated++;
console.log('Changed:', productImported.idProductInfo + ': ' + arrfieldchange); console.log('Changed:', productImported.productInfo.name + ': ' + arrfieldchange);
} }
} else { } else {
// Record didn't exist, so it was created // Record didn't exist, so it was created
@@ -1467,7 +1464,7 @@ router.post('/import', authenticate, async (req, res) => {
await Product.singlerecconvert_AfterImport_AndSave(idapp, recnew, isnuovo); await Product.singlerecconvert_AfterImport_AndSave(idapp, recnew, isnuovo);
} else { } else {
console.error('Error ProductInfo: ', productImported.code); console.error('Error product: ', productImported.code);
errors++; errors++;
} }
} }
@@ -1495,7 +1492,6 @@ router.post('/import', authenticate, async (req, res) => {
for (const rec of myarrshift) { for (const rec of myarrshift) {
let risprod = await extractArrayDataFromCSV(idapp, rec); let risprod = await extractArrayDataFromCSV(idapp, rec);
let product = risprod.product; let product = risprod.product;
let productInfo = risprod.productInfo;
let isnuovo = false; let isnuovo = false;
let setta = false; let setta = false;
@@ -1516,7 +1512,7 @@ router.post('/import', authenticate, async (req, res) => {
} }
if (reccateg) { if (reccateg) {
productInfo.idCatProds.push(reccateg._id); product.productInfo.idCatProds.push(reccateg._id);
} }
} }
} }
@@ -1537,7 +1533,7 @@ router.post('/import', authenticate, async (req, res) => {
} }
if (recsubcateg) { if (recsubcateg) {
productInfo.idSubCatProds.push(recsubcateg._id); product.productInfo.idSubCatProds.push(recsubcateg._id);
} }
} }
} }
@@ -1546,27 +1542,27 @@ router.post('/import', authenticate, async (req, res) => {
product.active = true; product.active = true;
} }
if (productInfo.productTypes.length === 1 && productInfo.productTypes[0] === undefined) { if (product.productInfo.productTypes.length === 1 && product.productInfo.productTypes[0] === undefined) {
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT]; product.productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
} }
let esisteindb = await Product.findOne({ code: productInfo.code }).lean(); let esisteindb = await Product.findOne({ 'productInfo.code': product.productInfo.code }).lean();
// Update Product // Update Product
let risrecInfo = await Product.findOneAndUpdate( let risrecInfo = await Product.findOneAndUpdate(
{ code: product.code }, { 'productInfo.code': product.productInfo.code },
{ $set: product }, { $set: product },
{ new: true, upsert: true } { new: true, upsert: true }
); );
if (risrecInfo) { if (risrecInfo) {
recnewInfo = await Product.findOne({ code: product.code }).lean(); recnewInfo = await Product.findOne({ 'productInfo.code': product.productInfo.code }).lean();
if (risrecInfo._id) { if (risrecInfo._id) {
// Record existed, so it was updated // Record existed, so it was updated
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo.productInfo); let arrfieldchange = tools.differentObjects(product.productInfo, recnewInfo.productInfo);
if (arrfieldchange && arrfieldchange.length > 0) { if (arrfieldchange && arrfieldchange.length > 0) {
// updated++; // updated++;
console.log('Changed: ', recnewInfo.name + ': ' + arrfieldchange); console.log('Changed: ', recnewInfo.productInfo.name + ': ' + arrfieldchange);
} }
} }
@@ -1592,11 +1588,11 @@ router.post('/import', authenticate, async (req, res) => {
} }
let recProductExist = null; let recProductExist = null;
let queryprod = { idProductInfo: product.idProductInfo }; let queryprod = { 'productInfo.code': product.productInfo.code };
if (recGas) { //if (recGas) {
queryprod = { ...queryprod, idGasordine: recGas._id }; // queryprod = { ...queryprod, idGasordine: recGas._id };
} //}
recProductExist = await Product.findOne(queryprod).lean(); recProductExist = await Product.findOne(queryprod).lean();
@@ -1620,7 +1616,7 @@ router.post('/import', authenticate, async (req, res) => {
let arrfieldchange = tools.differentObjects(product, recnew); let arrfieldchange = tools.differentObjects(product, recnew);
if (arrfieldchange.length > 0) { if (arrfieldchange.length > 0) {
updated++; updated++;
console.log('Changed: ', product.idProductInfo + ': ' + arrfieldchange); console.log('Changed: ', product._id + ': ' + arrfieldchange);
} }
} else { } else {
// Record didn't exist, so it was created // Record didn't exist, so it was created
@@ -1634,7 +1630,7 @@ router.post('/import', authenticate, async (req, res) => {
await Product.singlerecconvert_AfterImport_AndSave(idapp, recnew, isnuovo); await Product.singlerecconvert_AfterImport_AndSave(idapp, recnew, isnuovo);
} else { } else {
console.error('Error ProductInfo: ', product.code); console.error('Error ProductInfo: ', product.productInfo.code);
errors++; errors++;
} }

View File

@@ -506,7 +506,7 @@ router.post('/:userId/gestord', authenticate, async function (req, res, next) {
$match: { $match: {
idGasordine: { idGasordine: {
$type: 'objectId', // Checks if the field is of type ObjectId $type: 'objectId', // Checks if the field is of type ObjectId
$eq: new ObjectId(idGasordine), // Compares the value to a specific ObjectId $eq: new mongoose.Types.ObjectId(idGasordine), // Compares the value to a specific ObjectId
}, },
}, },
}; };

View File

@@ -2057,7 +2057,6 @@ async function load(req, res, version = '0') {
? Product.findAllIdApp(idapp, undefined, undefined, req.user ? User.isManager(req.user.perm) : false) ? Product.findAllIdApp(idapp, undefined, undefined, req.user ? User.isManager(req.user.perm) : false)
: Promise.resolve([]),*/ : Promise.resolve([]),*/
products: Promise.resolve([]), products: Promise.resolve([]),
productInfos: Promise.resolve([]),
catprods: version >= 91 ? Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA) : Promise.resolve([]), catprods: version >= 91 ? Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA) : Promise.resolve([]),
subcatprods: version >= 91 ? SubCatProd.findAllIdApp(idapp) : Promise.resolve([]), subcatprods: version >= 91 ? SubCatProd.findAllIdApp(idapp) : Promise.resolve([]),
catprods_gas: version >= 91 ? Product.getArrCatProds(idapp, shared_consts.PROD.GAS) : Promise.resolve([]), catprods_gas: version >= 91 ? Product.getArrCatProds(idapp, shared_consts.PROD.GAS) : Promise.resolve([]),
@@ -2172,7 +2171,6 @@ async function load(req, res, version = '0') {
scontisticas: data.scontisticas, scontisticas: data.scontisticas,
gasordines: data.gasordines, gasordines: data.gasordines,
products: data.products, products: data.products,
productInfos: data.productInfos,
catprods: data.catprods, catprods: data.catprods,
subcatprods: data.subcatprods, subcatprods: data.subcatprods,
catprods_gas: data.catprods_gas, catprods_gas: data.catprods_gas,

View File

@@ -197,37 +197,16 @@ module.exports = {
// Solo per NODEJS // Solo per NODEJS
TABLES_ENABLE_GETREC_BYID: [ TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods', 'attivitas'],
'mybachecas',
'myhosps',
'myskills',
'mygoods',
'attivitas',
],
TABLES_USER_INCLUDE_MY: ['mygroups', 'circuits'], TABLES_USER_INCLUDE_MY: ['mygroups', 'circuits'],
TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'attivitas'], TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'attivitas'],
//++Todo: per abilitare gli utenti ad inserire un Circuito aggiungere 'circuits' alla lista TABLES_PERM_NEWREC //++Todo: per abilitare gli utenti ad inserire un Circuito aggiungere 'circuits' alla lista TABLES_PERM_NEWREC
TABLES_PERM_NEWREC: [ TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups', 'myhosps', 'catalogs', 'raccoltacataloghis'],
'skills',
'goods',
'subskills',
'mygroups',
'myhosps',
'catalogs',
'raccoltacataloghis',
],
TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods', 'attivitas'], TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods', 'attivitas'],
TABLES_VISU_STAT_IN_HOME: [ TABLES_VISU_STAT_IN_HOME: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'mygroups', 'circuits'],
'myskills',
'mybachecas',
'myhosps',
'mygoods',
'mygroups',
'circuits',
],
TABLES_ADV_NOTIFICATION: ['myskills', 'myhosps', 'mygoods'], TABLES_ADV_NOTIFICATION: ['myskills', 'myhosps', 'mygoods'],
TABLES_ORDER_DATE_UPDATED: ['myskills', 'myhosps', 'mygoods'], TABLES_ORDER_DATE_UPDATED: ['myskills', 'myhosps', 'mygoods'],
@@ -1169,6 +1148,17 @@ module.exports = {
'sconto2', 'sconto2',
], ],
CONVERTI_CAMPO: [
{
originale: 'maxbookableGASQty',
convertito: 'prenotato',
},
{
originale: 'qtyToReachForGas',
convertito: 'quantita_da_raggiungere',
},
],
CAMPI_EURO: ['price', 'price_acquistato'], CAMPI_EURO: ['price', 'price_acquistato'],
MAX_QTA_PREORD: 5000, MAX_QTA_PREORD: 5000,