- 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:
@@ -916,20 +916,14 @@ function fixURL(url) {
|
||||
return url.replace(/https:\//g, 'https://');
|
||||
}
|
||||
|
||||
async function completaSettaggioProduct_AndProductInfo(
|
||||
arrcampi_productInfo,
|
||||
arrcampi_product,
|
||||
rec,
|
||||
product,
|
||||
productInfo
|
||||
) {
|
||||
async function completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product) {
|
||||
try {
|
||||
if (shared_consts.CAMPI_PRODUCTINFO_CONVERT.includes('weight_and_unit')) {
|
||||
if (rec.hasOwnProperty('weight_and_unit')) {
|
||||
const ris1 = tools.getWeightAndUnitByText(rec['weight_and_unit']);
|
||||
if (ris1) {
|
||||
productInfo.weight = ris1.weight;
|
||||
productInfo.unit = ris1.unit;
|
||||
product.productInfo.weight = ris1.weight;
|
||||
product.productInfo.unit = ris1.unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -938,20 +932,20 @@ async function completaSettaggioProduct_AndProductInfo(
|
||||
if (rec.hasOwnProperty('weight_and_unit_lordo')) {
|
||||
const ris2 = tools.getWeightAndUnitByText(rec['weight_and_unit_lordo']);
|
||||
if (ris2) {
|
||||
productInfo.weight_lordo = ris2.weight;
|
||||
productInfo.unit_lordo = ris2.unit;
|
||||
product.productInfo.weight_lordo = ris2.weight;
|
||||
product.productInfo.unit_lordo = ris2.unit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if (rec.hasOwnProperty(campo)) {
|
||||
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) {
|
||||
productInfo.imagefile = product.code + '.jpg';
|
||||
if (!rec.hasOwnProperty('img') && product.productInfo.code) {
|
||||
product.productInfo.imagefile = product.productInfo.code + '.jpg';
|
||||
} else {
|
||||
if (rec.hasOwnProperty('img')) {
|
||||
if (rec['img']) {
|
||||
productInfo.imagefile = rec['img'];
|
||||
product.productInfo.imagefile = rec['img'];
|
||||
} else {
|
||||
productInfo.imagefile = '';
|
||||
product.productInfo.imagefile = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rec.hasOwnProperty('productTypes')) {
|
||||
productInfo.productTypes = productInfo.productTypes;
|
||||
// product.productInfo.productTypes = product.productInfo.productTypes;
|
||||
} else {
|
||||
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
|
||||
product.productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
|
||||
}
|
||||
|
||||
return { product, productInfo };
|
||||
return { product };
|
||||
} catch (e) {
|
||||
console.error('Err', e);
|
||||
}
|
||||
|
||||
return { product, productInfo };
|
||||
return { product };
|
||||
}
|
||||
|
||||
function getValoriAndIndice(dati, arrinclude) {
|
||||
@@ -1023,13 +1017,11 @@ function getValoriAndIndice_Product(dati) {
|
||||
async function extractArrayDataFromCSV(idapp, rec) {
|
||||
try {
|
||||
// la prima riga contiene il nome della proprietà:
|
||||
let productInfo = {
|
||||
idapp: idapp,
|
||||
idCatProds: [],
|
||||
idSubCatProds: [],
|
||||
};
|
||||
|
||||
let product = {
|
||||
productInfo: {
|
||||
idCatProds: [],
|
||||
idSubCatProds: [],
|
||||
},
|
||||
idapp,
|
||||
};
|
||||
|
||||
@@ -1041,7 +1033,7 @@ async function extractArrayDataFromCSV(idapp, rec) {
|
||||
const mykey = Object.keys(rec).find((key) => key.toLowerCase() === campoobj.name.toLowerCase());
|
||||
if (mykey) {
|
||||
let myval = tools.ripulisciCampo(rec[mykey]);
|
||||
productInfo[campoobj.name] =
|
||||
product.productInfo[campoobj.name] =
|
||||
myval === 'TRUE' || myval.toUpperCase() === 'SI'
|
||||
? true
|
||||
: myval === 'FALSE' || myval.toUpperCase() === 'NO'
|
||||
@@ -1054,13 +1046,16 @@ async function extractArrayDataFromCSV(idapp, rec) {
|
||||
if (rec.hasOwnProperty(campoobj)) product[campoobj] = rec[campoobj];
|
||||
}
|
||||
|
||||
const ris = await completaSettaggioProduct_AndProductInfo(
|
||||
arrcampi_productInfo,
|
||||
arrcampi_product,
|
||||
rec,
|
||||
product,
|
||||
productInfo
|
||||
);
|
||||
for (const campoconvertiti of shared_consts.CONVERTI_CAMPO) {
|
||||
if (rec.hasOwnProperty(campoconvertiti.convertito)) {
|
||||
product[campoconvertiti.originale] = rec[campoconvertiti.convertito];
|
||||
}
|
||||
}
|
||||
|
||||
// Se trovi questi campi, li converti
|
||||
|
||||
|
||||
const ris = await completaSettaggioProduct_AndProductInfo(arrcampi_productInfo, arrcampi_product, rec, product);
|
||||
|
||||
/*
|
||||
// code: product.code,
|
||||
@@ -1209,50 +1204,50 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
|
||||
let numprod = dataObjects.length;
|
||||
|
||||
for (const product of dataObjects) {
|
||||
for (const productImported of dataObjects) {
|
||||
let isnuovo = false;
|
||||
let setta = false;
|
||||
|
||||
let importa = true;
|
||||
|
||||
if (!product.code) importa = false;
|
||||
if (!productImported.code) importa = false;
|
||||
|
||||
if (importa) {
|
||||
let productInfo = {
|
||||
idapp: product.idapp,
|
||||
code: product.code,
|
||||
idapp: productImported.idapp,
|
||||
code: productImported.code,
|
||||
};
|
||||
|
||||
const myproduct = await Product.findOne({ 'productInfo.code': productInfo.code });
|
||||
|
||||
// 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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
productInfo.name = getvalueByJsonText(product.titolo);
|
||||
productInfo.name = getvalueByJsonText(productImported.titolo);
|
||||
}
|
||||
|
||||
const pagine = getvalueByJsonText(product.pagine);
|
||||
const pagine = getvalueByJsonText(productImported.pagine);
|
||||
|
||||
let recisbn = {};
|
||||
|
||||
const trovato = await ImportaIsbn.findOne({ isbn: product.code }).lean();
|
||||
const trovato = await ImportaIsbn.findOne({ isbn: productImported.code }).lean();
|
||||
if (trovato) {
|
||||
// togli a recisbn l'_id
|
||||
delete trovato._id;
|
||||
@@ -1271,7 +1266,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
|
||||
try {
|
||||
let risisbn = await ImportaIsbn.findOneAndUpdate(
|
||||
{ isbn: product.code },
|
||||
{ isbn: productImported.code },
|
||||
{ $set: recisbn },
|
||||
{ new: true, upsert: true, strict: false }
|
||||
);
|
||||
@@ -1393,20 +1388,18 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
{ $set: { productInfo: productInfo } },
|
||||
{ new: true, upsert: true }
|
||||
);
|
||||
|
||||
// .... ANDARE AVANTI DA QUI... .productInfo.... SISTEMARE!
|
||||
|
||||
|
||||
if (risrecInfo) {
|
||||
productImported.productInfo = risrecInfo._id;
|
||||
|
||||
recnewInfo = await Product.findOne({ code: product.code }).lean();
|
||||
recnewInfo = await Product.findOne({ code: product.productInfo.code }).lean();
|
||||
|
||||
if (risrecInfo._id) {
|
||||
// Record existed, so it was updated
|
||||
let arrfieldchange = tools.differentObjects(productInfo, recnewInfo);
|
||||
if (arrfieldchange && arrfieldchange.length > 0) {
|
||||
// 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 queryprod = { idProductInfo: productImported.idProductInfo };
|
||||
let queryprod = { _id: productImported._id };
|
||||
|
||||
if (recGas) {
|
||||
queryprod = { ...queryprod, idGasordine: recGas._id };
|
||||
@@ -1443,7 +1436,11 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
@@ -1453,7 +1450,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
let arrfieldchange = tools.differentObjects(productImported, recnew);
|
||||
if (arrfieldchange.length > 0) {
|
||||
updated++;
|
||||
console.log('Changed:', productImported.idProductInfo + ': ' + arrfieldchange);
|
||||
console.log('Changed:', productImported.productInfo.name + ': ' + arrfieldchange);
|
||||
}
|
||||
} else {
|
||||
// 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);
|
||||
} else {
|
||||
console.error('Error ProductInfo: ', productImported.code);
|
||||
console.error('Error product: ', productImported.code);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
@@ -1495,7 +1492,6 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
for (const rec of myarrshift) {
|
||||
let risprod = await extractArrayDataFromCSV(idapp, rec);
|
||||
let product = risprod.product;
|
||||
let productInfo = risprod.productInfo;
|
||||
|
||||
let isnuovo = false;
|
||||
let setta = false;
|
||||
@@ -1516,7 +1512,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (productInfo.productTypes.length === 1 && productInfo.productTypes[0] === undefined) {
|
||||
productInfo.productTypes = [shared_consts.PRODUCTTYPE.PRODUCT];
|
||||
if (product.productInfo.productTypes.length === 1 && product.productInfo.productTypes[0] === undefined) {
|
||||
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
|
||||
let risrecInfo = await Product.findOneAndUpdate(
|
||||
{ code: product.code },
|
||||
{ 'productInfo.code': product.productInfo.code },
|
||||
{ $set: product },
|
||||
{ new: true, upsert: true }
|
||||
);
|
||||
if (risrecInfo) {
|
||||
recnewInfo = await Product.findOne({ code: product.code }).lean();
|
||||
recnewInfo = await Product.findOne({ 'productInfo.code': product.productInfo.code }).lean();
|
||||
|
||||
if (risrecInfo._id) {
|
||||
// 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) {
|
||||
// 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 queryprod = { idProductInfo: product.idProductInfo };
|
||||
let queryprod = { 'productInfo.code': product.productInfo.code };
|
||||
|
||||
if (recGas) {
|
||||
queryprod = { ...queryprod, idGasordine: recGas._id };
|
||||
}
|
||||
//if (recGas) {
|
||||
// queryprod = { ...queryprod, idGasordine: recGas._id };
|
||||
//}
|
||||
|
||||
recProductExist = await Product.findOne(queryprod).lean();
|
||||
|
||||
@@ -1620,7 +1616,7 @@ router.post('/import', authenticate, async (req, res) => {
|
||||
let arrfieldchange = tools.differentObjects(product, recnew);
|
||||
if (arrfieldchange.length > 0) {
|
||||
updated++;
|
||||
console.log('Changed: ', product.idProductInfo + ': ' + arrfieldchange);
|
||||
console.log('Changed: ', product._id + ': ' + arrfieldchange);
|
||||
}
|
||||
} else {
|
||||
// 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);
|
||||
} else {
|
||||
console.error('Error ProductInfo: ', product.code);
|
||||
console.error('Error ProductInfo: ', product.productInfo.code);
|
||||
errors++;
|
||||
}
|
||||
|
||||
|
||||
@@ -506,7 +506,7 @@ router.post('/:userId/gestord', authenticate, async function (req, res, next) {
|
||||
$match: {
|
||||
idGasordine: {
|
||||
$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
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -2057,7 +2057,6 @@ async function load(req, res, version = '0') {
|
||||
? Product.findAllIdApp(idapp, undefined, undefined, req.user ? User.isManager(req.user.perm) : false)
|
||||
: Promise.resolve([]),*/
|
||||
products: Promise.resolve([]),
|
||||
productInfos: Promise.resolve([]),
|
||||
catprods: version >= 91 ? Product.getArrCatProds(idapp, shared_consts.PROD.BOTTEGA) : Promise.resolve([]),
|
||||
subcatprods: version >= 91 ? SubCatProd.findAllIdApp(idapp) : 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,
|
||||
gasordines: data.gasordines,
|
||||
products: data.products,
|
||||
productInfos: data.productInfos,
|
||||
catprods: data.catprods,
|
||||
subcatprods: data.subcatprods,
|
||||
catprods_gas: data.catprods_gas,
|
||||
|
||||
Reference in New Issue
Block a user