- Sistemato link pdf che ogni volta che si aggiorna prendeva il PDF dalla cache...
- Raccolta Cataloghi, procedura che li AUTO genera in automatico.
This commit is contained in:
@@ -6,7 +6,7 @@ const { ObjectId } = require('mongodb');
|
||||
const Gasordine = require('../models/gasordine');
|
||||
|
||||
const Order = require('../models/order');
|
||||
const OrderClass = require('../modules/orderclass');
|
||||
const OrderClass = require('../modules/OrderClass');
|
||||
|
||||
const Scontistica = require('../models/scontistica');
|
||||
|
||||
|
||||
@@ -88,6 +88,22 @@ class CronMod {
|
||||
await genPdf.launch();
|
||||
|
||||
return await genPdf.generatePdfFromIdCatalog(mydata.options);
|
||||
} else if (mydata.dbop === 'GeneraPdfRaccolta') {
|
||||
|
||||
const genPdf = new GenPdf(idapp);
|
||||
|
||||
await genPdf.launch();
|
||||
|
||||
return await genPdf.generatePdfFromIdRaccolta(mydata.options);
|
||||
} else if (mydata.dbop === 'onlinePdfRaccolta') {
|
||||
|
||||
const genPdf = new GenPdf(idapp);
|
||||
|
||||
await genPdf.launch();
|
||||
|
||||
mydata.options.idapp = idapp;
|
||||
|
||||
return await genPdf.onlinePdfFromIdRaccolta(mydata.options);
|
||||
} else if (mydata.dbop === 'ReplaceAllCircuits') {
|
||||
// ++ Replace All Circuitname with 'Circuito RIS %s'
|
||||
await Circuit.replaceAllCircuitNames(idapp);
|
||||
|
||||
@@ -15,6 +15,7 @@ const tools = require('../tools/general');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { compress } = require('compress-pdf');
|
||||
const { RaccoltaCataloghi } = require('../models/raccoltacataloghi');
|
||||
|
||||
class GenPdf {
|
||||
constructor(idapp) {
|
||||
@@ -210,7 +211,6 @@ class GenPdf {
|
||||
|
||||
// Assicurati che la directory output esista
|
||||
const outputDir = path.dirname(outputFile);
|
||||
const fs = require('fs').promises;
|
||||
try {
|
||||
await fs.mkdir(outputDir, { recursive: true });
|
||||
} catch (error) {
|
||||
@@ -387,6 +387,49 @@ class GenPdf {
|
||||
return '';
|
||||
}
|
||||
|
||||
async generatePdfFromIdRaccolta(options) {
|
||||
try {
|
||||
if (!options) {
|
||||
console.error('Opzioni non passate !');
|
||||
return null;
|
||||
}
|
||||
const raccolta = await RaccoltaCataloghi.findById(options.idRaccolta);
|
||||
if (raccolta) {
|
||||
for (const catalogo of raccolta.lista_cataloghi) {
|
||||
await this.generatePdfFromIdCatalog({
|
||||
...options,
|
||||
idCatalog: catalogo._id,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
}
|
||||
async onlinePdfFromIdRaccolta(options) {
|
||||
try {
|
||||
if (!options) {
|
||||
console.error('Opzioni non passate !');
|
||||
return null;
|
||||
}
|
||||
const raccolta = await RaccoltaCataloghi.findById(options.idRaccolta);
|
||||
if (raccolta) {
|
||||
for (const catalogo of raccolta.lista_cataloghi) {
|
||||
await this.onlinePdfFromIdCatalog({
|
||||
...options,
|
||||
id_catalog: catalogo._id,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('err', e);
|
||||
}
|
||||
}
|
||||
|
||||
async onlinePdfFromIdCatalog(options) {
|
||||
const risout = await GenPdf.onlinePdf(options);
|
||||
}
|
||||
|
||||
async generatePdfFromIdCatalog(options) {
|
||||
try {
|
||||
if (!options) {
|
||||
@@ -435,13 +478,36 @@ class GenPdf {
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
const ris = {
|
||||
fileout: filenamerelative,
|
||||
fileout_compressed: filenamerelative_compressed,
|
||||
filesize: await tools.getSizeFile(fullnamepath),
|
||||
filesize_compressed: await tools.getSizeFile(fullnamepath_compr),
|
||||
error: '',
|
||||
};
|
||||
|
||||
if (catalog) {
|
||||
if (stampa) {
|
||||
catalog.pdf_generato_stampa = ris.fileout;
|
||||
catalog.pdf_generato_stampa_compressed = ris.fileout_compressed;
|
||||
|
||||
catalog.pdf_generato_stampa_size = ris.filesize;
|
||||
catalog.pdf_generato_stampa_compr_size = ris.filesize_compressed;
|
||||
|
||||
catalog.data_generato_stampa = tools.getDateNow();
|
||||
} else {
|
||||
catalog.pdf_generato_compressed = ris.fileout_compressed;
|
||||
catalog.pdf_generato = ris.fileout;
|
||||
|
||||
catalog.pdf_generato_size = ris.filesize;
|
||||
catalog.pdf_generato_compr_size = ris.filesize_compressed;
|
||||
|
||||
catalog.data_generato = tools.getDateNow();
|
||||
}
|
||||
await catalog.save();
|
||||
}
|
||||
|
||||
return ris;
|
||||
} catch (error) {
|
||||
console.error('Errore durante la generazione del PDF dal catalogo ID:', error);
|
||||
return {
|
||||
@@ -481,6 +547,81 @@ class GenPdf {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static async onlinePdf(options) {
|
||||
const idapp = options.idapp;
|
||||
const id_catalog = options.id_catalog;
|
||||
const id_raccolta = options.id_raccolta;
|
||||
const stampa = options.stampa;
|
||||
const compresso = options.compresso;
|
||||
let mydir = '';
|
||||
let risout = {};
|
||||
|
||||
try {
|
||||
let myrec = null;
|
||||
|
||||
// Aggiorna il PDF OnLine, copiando il file da Generato a OnLine
|
||||
if (id_catalog) {
|
||||
myrec = await Catalog.findOne({ _id: id_catalog });
|
||||
} else if (id_raccolta) {
|
||||
myrec = await RaccoltaCataloghi.findOne({ _id: id_raccolta });
|
||||
}
|
||||
|
||||
if (myrec) {
|
||||
mydir = tools.getdirByIdApp(idapp) + '/';
|
||||
// const baseurl = this.getHostByIdApp(idapp);
|
||||
|
||||
if (stampa) {
|
||||
myrec.pdf_online_stampa = myrec.pdf_generato_stampa?.replace('_generato', '');
|
||||
} else {
|
||||
myrec.pdf_online = myrec.pdf_generato?.replace('_generato', '');
|
||||
}
|
||||
|
||||
const myfile = stampa ? myrec.pdf_generato_stampa : myrec.pdf_generato;
|
||||
|
||||
|
||||
if (myfile && (await tools.isFileExistsAsync(mydir + myfile))) {
|
||||
// Aggiorna il PDF OnLine, copiando il file da Generato a OnLine
|
||||
let fileOrigin = mydir + (stampa ? myrec.pdf_generato_stampa : myrec.pdf_generato);
|
||||
|
||||
if (compresso) {
|
||||
let fileInCompressed = tools.removeFileExtension(fileOrigin) + `_compressed.pdf`;
|
||||
// Se esiste allora prende questo COmpresso !
|
||||
if (await tools.isFileExistsAsync(fileInCompressed)) {
|
||||
fileOrigin = fileInCompressed;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
const fileDest = mydir + (stampa ? myrec.pdf_online_stampa : myrec.pdf_online);
|
||||
const fileDestNoDir = stampa ? myrec.pdf_online_stampa : myrec.pdf_online;
|
||||
// copia il file
|
||||
await fs.copyFile(fileOrigin, fileDest);
|
||||
|
||||
if (stampa) {
|
||||
myrec.pdf_online_stampa_size = await tools.getSizeFile(fileDest);
|
||||
} else {
|
||||
myrec.pdf_online_size = await tools.getSizeFile(fileDest);
|
||||
}
|
||||
|
||||
if (stampa) {
|
||||
myrec.data_online_stampa = myrec.data_generato_stampa;
|
||||
} else {
|
||||
myrec.data_online = myrec.data_generato;
|
||||
}
|
||||
|
||||
// Aggiorna il record
|
||||
await myrec.save();
|
||||
}
|
||||
|
||||
risout = { record: myrec._doc };
|
||||
}
|
||||
|
||||
return risout;
|
||||
} catch (e) {
|
||||
console.error('Err Online-pdf', e.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GenPdf;
|
||||
|
||||
@@ -436,7 +436,6 @@ class Macro {
|
||||
console.log('numrec', numrec);
|
||||
}
|
||||
|
||||
|
||||
let rimuoviTabellePerIniziare = false;
|
||||
|
||||
let count = 0;
|
||||
@@ -467,16 +466,16 @@ class Macro {
|
||||
.filter(([isbn, products]) => products.length > 1)
|
||||
.map(([isbn]) => isbn);
|
||||
|
||||
recproducts = recproducts.filter(product => isbnConMultipliRecord.includes(product.Ean13));
|
||||
recproducts = recproducts.filter((product) => isbnConMultipliRecord.includes(product.Ean13));
|
||||
|
||||
console.log(`Trovati ${isbnConMultipliRecord.length} record con ISBN duplicati: ${isbnConMultipliRecord.join(', ')}`);
|
||||
|
||||
console.log(
|
||||
`Trovati ${isbnConMultipliRecord.length} record con ISBN duplicati: ${isbnConMultipliRecord.join(', ')}`
|
||||
);
|
||||
}
|
||||
|
||||
for (const recproduct of recproducts) {
|
||||
await this.elaboraProdotto(recproduct, opt);
|
||||
|
||||
|
||||
const sku = recproduct.IdArticolo;
|
||||
|
||||
if (sku) {
|
||||
@@ -859,44 +858,52 @@ class Macro {
|
||||
* Gestisce le categorie e sottocategorie del prodotto.
|
||||
*/
|
||||
async gestisciCategorie(productInfo, product) {
|
||||
if (product.DescrArgomento) {
|
||||
productInfo.idCatProds = [];
|
||||
const reccateg = await CatProd.findOne({ idapp: this.idapp, name: product.DescrArgomento });
|
||||
let nuovaCategoria = null;
|
||||
if (!reccateg) {
|
||||
nuovaCategoria = new CatProd({ idapp: this.idapp, name: product.DescrArgomento });
|
||||
await nuovaCategoria.save();
|
||||
}
|
||||
|
||||
if (!reccateg.idArgomento) {
|
||||
// Se non c'è l'argomento, allora lo cerco nel DB
|
||||
const recarg = await T_Web_Argomenti.findOne({ Descrizione: product.DescrArgomento }).lean();
|
||||
reccateg.idArgomento = recarg.IdArgomento;
|
||||
await reccateg.save();
|
||||
}
|
||||
|
||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||
if (myriscat) productInfo.idCatProds.push(myriscat);
|
||||
} else {
|
||||
if (product.categories) {
|
||||
// const arrcat = product.categories.trim().split(',');
|
||||
const arrcat = product.categories.trim().split(',');
|
||||
try {
|
||||
if (product.DescrArgomento) {
|
||||
productInfo.idCatProds = [];
|
||||
const reccateg = await CatProd.findOne({ idapp: this.idapp, name: product.DescrArgomento });
|
||||
let nuovaCategoria = null;
|
||||
if (!reccateg) {
|
||||
nuovaCategoria = new CatProd({ idapp: this.idapp, name: product.DescrArgomento });
|
||||
await nuovaCategoria.save();
|
||||
}
|
||||
|
||||
for (const mycat of arrcat) {
|
||||
const mycatstr = mycat.trim();
|
||||
const reccateg = await CatProd.findOne({ idapp: this.idapp, name: mycatstr }).lean();
|
||||
|
||||
let nuovaCategoria = null;
|
||||
if (!reccateg) {
|
||||
nuovaCategoria = new CatProd({ idapp: this.idapp, name: mycatstr });
|
||||
await nuovaCategoria.save();
|
||||
|
||||
if (!reccateg?.idArgomento && product.DescrArgomento) {
|
||||
// Se non c'è l'argomento, allora lo cerco nel DB
|
||||
const recarg = await T_Web_Argomenti.findOne({ Descrizione: product.DescrArgomento }).lean();
|
||||
if (recarg) {
|
||||
reccateg.idArgomento = recarg.IdArgomento;
|
||||
await reccateg.save();
|
||||
}
|
||||
}
|
||||
|
||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||
if (myriscat) productInfo.idCatProds.push(myriscat);
|
||||
|
||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||
if (myriscat) productInfo.idCatProds.push(myriscat);
|
||||
} else {
|
||||
if (product.categories) {
|
||||
// const arrcat = product.categories.trim().split(',');
|
||||
const arrcat = product.categories.trim().split(',');
|
||||
productInfo.idCatProds = [];
|
||||
|
||||
for (const mycat of arrcat) {
|
||||
const mycatstr = mycat.trim();
|
||||
const reccateg = await CatProd.findOne({ idapp: this.idapp, name: mycatstr }).lean();
|
||||
|
||||
let nuovaCategoria = null;
|
||||
if (!reccateg) {
|
||||
nuovaCategoria = new CatProd({ idapp: this.idapp, name: mycatstr });
|
||||
await nuovaCategoria.save();
|
||||
}
|
||||
|
||||
const myriscat = reccateg?._id || (nuovaCategoria ? nuovaCategoria._id : null);
|
||||
if (myriscat) productInfo.idCatProds.push(myriscat);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Errore gestisciCategorie:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user