- Cataloghi: parte finale... prima bozza 9 dic
This commit is contained in:
@@ -63,6 +63,7 @@ const catalogo = new Schema(
|
|||||||
pdf: { type: Boolean },
|
pdf: { type: Boolean },
|
||||||
pdf_filename: { type: String },
|
pdf_filename: { type: String },
|
||||||
printable: { type: Boolean },
|
printable: { type: Boolean },
|
||||||
|
indebug: { type: Boolean },
|
||||||
|
|
||||||
first_page: IDimensioni,
|
first_page: IDimensioni,
|
||||||
last_page: IDimensioni,
|
last_page: IDimensioni,
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ const IAreaDiStampa = new Schema({
|
|||||||
orientation: String,
|
orientation: String,
|
||||||
compress: Boolean,
|
compress: Boolean,
|
||||||
scale: Number,
|
scale: Number,
|
||||||
|
scale_printable: Number,
|
||||||
scalecanvas: Number,
|
scalecanvas: Number,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -221,6 +221,7 @@ async function convertPDF_PdfLib(inputFile, outputFile, width, height, compressi
|
|||||||
console.log(`PDF convertito e salvato come '${outputFile}'`);
|
console.log(`PDF convertito e salvato come '${outputFile}'`);
|
||||||
|
|
||||||
const comprimi = false;
|
const comprimi = false;
|
||||||
|
const mostrainfo = true;
|
||||||
|
|
||||||
let fileout = outputFile;
|
let fileout = outputFile;
|
||||||
|
|
||||||
@@ -229,7 +230,9 @@ async function convertPDF_PdfLib(inputFile, outputFile, width, height, compressi
|
|||||||
|
|
||||||
await compressPdf(outputFile, compressed, compressione);
|
await compressPdf(outputFile, compressed, compressione);
|
||||||
|
|
||||||
|
if (mostrainfo)
|
||||||
extractPdfInfo(compressed);
|
extractPdfInfo(compressed);
|
||||||
|
|
||||||
fileout = compressed;
|
fileout = compressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,10 +265,6 @@ router.post('/convert-pdf', upload.single('pdf'), async (req, res) => {
|
|||||||
await fs.promises.mkdir(DIR_PDF_IN, { recursive: true });
|
await fs.promises.mkdir(DIR_PDF_IN, { recursive: true });
|
||||||
await fs.promises.mkdir(DIR_PDF_OUT, { recursive: true });
|
await fs.promises.mkdir(DIR_PDF_OUT, { recursive: true });
|
||||||
|
|
||||||
// console.log('File:', req.file);
|
|
||||||
// console.log('Width:', width);
|
|
||||||
// console.log('Height:', height);
|
|
||||||
|
|
||||||
// Converti il PDF
|
// Converti il PDF
|
||||||
// await convertPDF_GS(inputFile, outputFile, width, height);
|
// await convertPDF_GS(inputFile, outputFile, width, height);
|
||||||
const fileout = await convertPDF_PdfLib(inputFile, outputFile, width, height, compressione);
|
const fileout = await convertPDF_PdfLib(inputFile, outputFile, width, height, compressione);
|
||||||
@@ -713,18 +712,30 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
code: product.code,
|
code: product.code,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const myproductInfo = await ProductInfo.findOne({ code: productInfo.code });
|
||||||
|
|
||||||
|
// IMPOSTA I VALORI SOLO SE NON ESISTONO ! ALTRIMENTI LASCIA QUELLI GIA' IMPORTATI (O MODIFICATI)
|
||||||
|
|
||||||
if (getvalueByJsonText(product.url)) {
|
if (getvalueByJsonText(product.url)) {
|
||||||
|
if (!myproductInfo.link_macro)
|
||||||
productInfo.link_macro = getvalueByJsonText(product.url);
|
productInfo.link_macro = getvalueByJsonText(product.url);
|
||||||
}
|
}
|
||||||
if (getvalueByJsonText(product.descrizione)) {
|
if (getvalueByJsonText(product.descrizione)) {
|
||||||
|
if (!myproductInfo.descrizione_completa_macro)
|
||||||
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione);
|
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione);
|
||||||
}
|
}
|
||||||
if (getvalueByJsonText(product.descrizione_completa)) {
|
if (getvalueByJsonText(product.descrizione_completa)) {
|
||||||
|
if (!myproductInfo.descrizione_completa_macro)
|
||||||
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa)
|
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa)
|
||||||
}
|
}
|
||||||
if (getvalueByJsonText(product.sottotitolo)) {
|
if (getvalueByJsonText(product.sottotitolo)) {
|
||||||
|
if (!myproductInfo.sottotitolo)
|
||||||
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
|
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
|
||||||
}
|
}
|
||||||
|
if (getvalueByJsonText(product.titolo)) {
|
||||||
|
if (!myproductInfo.name)
|
||||||
|
productInfo.name = getvalueByJsonText(product.titolo);
|
||||||
|
}
|
||||||
|
|
||||||
const pagine = getvalueByJsonText(product.pagine);
|
const pagine = getvalueByJsonText(product.pagine);
|
||||||
|
|
||||||
@@ -770,12 +781,15 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
dataObjects = null;
|
dataObjects = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dataObjects && dataObjects[0]) {
|
if (dataObjects && dataObjects[0]) {
|
||||||
// Cancella la collection ImportaMacros
|
// Cancella la collection ImportaMacros
|
||||||
await ImportaIsbn.deleteMany({ idapp });
|
await ImportaIsbn.deleteMany({ idapp });
|
||||||
|
|
||||||
const numtot = dataObjects[0].length
|
const numtot = dataObjects[0].length
|
||||||
|
|
||||||
|
console.log('Numero di RECORD da Importare = ', numtot);
|
||||||
|
|
||||||
// Aggiungi i record su ImportaMacros
|
// Aggiungi i record su ImportaMacros
|
||||||
for (const recinv of dataObjects[0]) {
|
for (const recinv of dataObjects[0]) {
|
||||||
let recmacro = recinv;
|
let recmacro = recinv;
|
||||||
@@ -783,7 +797,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
recmacro.idapp = idapp;
|
recmacro.idapp = idapp;
|
||||||
|
|
||||||
//recmacro._id = recmacro.id;
|
//recmacro._id = recmacro.id;
|
||||||
recmacro.sku = recmacro.idArticolo;
|
recmacro.sku = recmacro.IdArticolo;
|
||||||
|
|
||||||
if (recmacro.DataPubblicazione) {
|
if (recmacro.DataPubblicazione) {
|
||||||
|
|
||||||
@@ -795,6 +809,7 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
|
||||||
if (risrec) {
|
if (risrec) {
|
||||||
imported++;
|
imported++;
|
||||||
|
if ((imported % 10) === 0)
|
||||||
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
|
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -810,12 +825,30 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
// Rileggi tutti i record di ImportaIsbn
|
// Rileggi tutti i record di ImportaIsbn
|
||||||
dataObjects = await ImportaIsbn.find({ idapp }).lean();
|
dataObjects = await ImportaIsbn.find({ idapp }).lean();
|
||||||
|
|
||||||
console.log('*** INIZIO IMPORT RANKING ... ');
|
let numprod = dataObjects.length;
|
||||||
|
|
||||||
|
console.log('*** INIZIO IMPORT RANKING ... NUMRECORD = ', numprod);
|
||||||
|
|
||||||
let indprod = 0;
|
let indprod = 0;
|
||||||
let newprod = 0;
|
let newprod = 0;
|
||||||
|
|
||||||
let numprod = dataObjects.length;
|
if (numprod) {
|
||||||
|
// Rimuove prima tutti i valori precedenti
|
||||||
|
let risupdate = await ProductInfo.updateMany({ idapp }, {
|
||||||
|
$set: {
|
||||||
|
totaleVenduti: 0,
|
||||||
|
venditeLastM: 0,
|
||||||
|
venditeLast6M: 0,
|
||||||
|
venditeLastY: 0,
|
||||||
|
venditeLast2Y: 0,
|
||||||
|
rank3M: 0,
|
||||||
|
rank6M: 0,
|
||||||
|
rank1Y: 0,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
imported = 0;
|
imported = 0;
|
||||||
|
|
||||||
@@ -843,14 +876,14 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
// id_wp: product._id,
|
// id_wp: product._id,
|
||||||
|
|
||||||
// name: product.title,
|
// name: product.title,
|
||||||
totaleVenduti: product.totaleaVenduti,
|
totaleVenduti: product.totaleVenduti || 0,
|
||||||
venditeLastM: product.venditeLastM,
|
venditeLastM: product.venditeLastM || 0,
|
||||||
venditeLast6M: product.venditeLast6M,
|
venditeLast6M: product.venditeLast6M || 0,
|
||||||
venditeLastY: product.venditeLastY,
|
venditeLastY: product.venditeLastY || 0,
|
||||||
venditeLast2Y: product.venditeLast2Y,
|
venditeLast2Y: product.venditeLast2Y || 0,
|
||||||
rank3M: product.rank3M,
|
rank3M: product.rank3M || 0,
|
||||||
rank6M: product.rank6M,
|
rank6M: product.rank6M || 0,
|
||||||
rank1Y: product.rank1Y,
|
rank1Y: product.rank1Y || 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (product.DataPubblicazione) {
|
if (product.DataPubblicazione) {
|
||||||
@@ -862,10 +895,12 @@ router.post('/import', authenticate, async (req, res) => {
|
|||||||
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
|
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update ProductInfo
|
// Update ProductInfo
|
||||||
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
|
||||||
if (risrecInfo) {
|
if (risrecInfo) {
|
||||||
imported++;
|
imported++;
|
||||||
|
if (imported % 10 === 0)
|
||||||
console.log('Importati... ', imported + '/' + numprod);
|
console.log('Importati... ', imported + '/' + numprod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -935,7 +935,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const mytable = globalTables.getTableByTableName(mydata.table);
|
const mytable = globalTables.getTableByTableName(mydata.table);
|
||||||
const fieldsvalue = mydata.fieldsvalue;
|
let fieldsvalue = mydata.fieldsvalue;
|
||||||
const unset = mydata.unset;
|
const unset = mydata.unset;
|
||||||
|
|
||||||
const { Account } = require('../models/account');
|
const { Account } = require('../models/account');
|
||||||
@@ -1032,6 +1032,21 @@ router.patch('/chval', authenticate, async (req, res) => {
|
|||||||
precRec = await mytable.findById(id);
|
precRec = await mytable.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (mydata.table === 'arrvariazioni') {
|
||||||
|
let chiave = null;
|
||||||
|
let valore = null;
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(fieldsvalue)) {
|
||||||
|
chiave = key;
|
||||||
|
valore = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chiave) {
|
||||||
|
// Costruiamo la stringa di assegnazione dinamica
|
||||||
|
fieldsvalue = { [`arrvariazioni.0.${chiave}`]: valore };
|
||||||
|
}
|
||||||
|
}
|
||||||
return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }, { new: true }).
|
return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }, { new: true }).
|
||||||
then(async (rec) => {
|
then(async (rec) => {
|
||||||
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
// tools.mylogshow(' REC TO MODIFY: ', rec);
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ module.exports = {
|
|||||||
mytable = Operator;
|
mytable = Operator;
|
||||||
else if (tablename === 'products')
|
else if (tablename === 'products')
|
||||||
mytable = Product;
|
mytable = Product;
|
||||||
|
else if (tablename === 'arrvariazioni')
|
||||||
|
mytable = Product;
|
||||||
else if (tablename === 'productinfos')
|
else if (tablename === 'productinfos')
|
||||||
mytable = ProductInfo;
|
mytable = ProductInfo;
|
||||||
else if (tablename === 'storehouses')
|
else if (tablename === 'storehouses')
|
||||||
|
|||||||
Reference in New Issue
Block a user