diff --git a/src/components/CCatalogoCard/CCatalogoCard.ts b/src/components/CCatalogoCard/CCatalogoCard.ts index 57e98494..9be563a4 100755 --- a/src/components/CCatalogoCard/CCatalogoCard.ts +++ b/src/components/CCatalogoCard/CCatalogoCard.ts @@ -299,7 +299,7 @@ export default defineComponent({ } - async function updateproduct(atload: boolean) { + async function updateproduct(atload: boolean, forza?: boolean) { let carica = true @@ -313,7 +313,7 @@ export default defineComponent({ if (carica) { myproduct.value = null; - updateproductmodif(null) + updateproductmodif(null, forza) } // products.updateQuantityAvailable(myproduct.value._id) @@ -331,13 +331,13 @@ export default defineComponent({ } - async function updateproductmodif(element: any) { + async function updateproductmodif(element: any, forza?: boolean) { console.log('CCATALOGOCARD: updateproductmodif') try { if (element?._id) { - myproduct.value = await products.getProductById(element?._id, true) + myproduct.value = await products.getProductById(element?._id, forza) } else { - myproduct.value = await products.getProductById(props.id, true) + myproduct.value = await products.getProductById(props.id, forza) } updateLabel() @@ -458,7 +458,7 @@ export default defineComponent({ async function load() { indvariazSel.value = -1 initproduct() - await updateproduct(true) + await updateproduct(true, true) labelDataArrivoMerce.value = '' labelDataRitiro.value = '' @@ -643,7 +643,7 @@ export default defineComponent({ return optcatalogo.value.areadistampa!.scale } - async function refreshDataFromGM() { + /*async function refreshDataFromGM() { if (myproduct.value) { loading.value = true updatefromgm.value = true @@ -659,8 +659,9 @@ export default defineComponent({ loading.value = false } - } - async function refreshAllDataBookFromGM(options: any) { + }*/ + + /*async function refreshAllDataBookFromGM(options: any) { if (myproduct.value) { loading.value = true updatefromgm.value = true @@ -669,14 +670,15 @@ export default defineComponent({ if (ris) { // field_updated_fromGM.value = t('dbgm.updateLocalDb_OK') - await updateproduct(false) + await updateproduct(false, false) tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK')) updatefromgm.value = false } loading.value = false } - } + }*/ + async function refreshSingleBookFromGM(options: any) { if (myproduct.value) { loading.value = true @@ -686,8 +688,13 @@ export default defineComponent({ if (ris) { // field_updated_fromGM.value = t('dbgm.updateLocalDb_OK') - await updateproduct(false) - tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK')) + if (ris.error) { + tools.showNegativeNotif($q, ris.error) + } else { + + await updateproduct(false, false) + tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK')) + } updatefromgm.value = false } loading.value = false @@ -777,8 +784,8 @@ export default defineComponent({ field_updated_fromGM, refreshFieldFromGM, updatetogm, - refreshDataFromGM, - refreshAllDataBookFromGM, + // refreshDataFromGM, + // refreshAllDataBookFromGM, refreshSingleBookFromGM, loading, } diff --git a/src/components/CCatalogoCard/CCatalogoCard.vue b/src/components/CCatalogoCard/CCatalogoCard.vue index 1a784fa7..00207fb4 100755 --- a/src/components/CCatalogoCard/CCatalogoCard.vue +++ b/src/components/CCatalogoCard/CCatalogoCard.vue @@ -138,7 +138,7 @@ - Carica da GM - + --> - - + + + {{ tools.getValueByFunzOrVal(scope.opt, optlab) }} diff --git a/src/components/CProductTable/CProductTable.ts b/src/components/CProductTable/CProductTable.ts index 9ce7aea2..50b9c22e 100755 --- a/src/components/CProductTable/CProductTable.ts +++ b/src/components/CProductTable/CProductTable.ts @@ -115,6 +115,7 @@ export default defineComponent({ { name: "catprods", label: "Argomento", field: "catprods", align: "left" }, { name: "idCollana", label: "Collana", field: "idCollana", align: "left" }, { name: "stato", label: "Stato", field: "stato", align: "left" }, + { name: "tipologia", label: "Tipologia", field: "tipologia", align: "left" }, { name: "date_pub", label: "Pubblicato", field: "date_pub", align: "left" }, { name: "ranking", label: "Class.", field: "ranking", align: "right" }, { name: "rank3M", label: "Class. 3M", field: "rank3M", align: "right" }, @@ -245,9 +246,6 @@ export default defineComponent({ } } - async function refreshDataFromGM() { - - } async function refreshFieldFromGM(field: string) { if (selProd.value) { loading.value = true @@ -312,7 +310,6 @@ export default defineComponent({ updateProduct, field_updated_fromGM, refreshFieldFromGM, - refreshDataFromGM, updatefromgm, visufromgm, loading, diff --git a/src/components/CProductTable/CProductTable.vue b/src/components/CProductTable/CProductTable.vue index 6d337c7a..65f88304 100755 --- a/src/components/CProductTable/CProductTable.vue +++ b/src/components/CProductTable/CProductTable.vue @@ -56,10 +56,11 @@ @@ -115,6 +116,12 @@ {{ products.getDescrStatiProdottoByIdStatoProdotto(element.productInfo.idStatoProdotto || '') }} + + {{ products.getDescrByIdTipologia(element.arrvariazioni[0].idTipologia || '') }} + + + {{ products.getDescrByIdTipoFormato(element.arrvariazioni[0].idTipoFormato || '') }} + {{ tools.getstrDate(element.productInfo?.date_pub) }} diff --git a/src/components/CSchedaProdotto/CSchedaProdotto.ts b/src/components/CSchedaProdotto/CSchedaProdotto.ts index 4cf8f50f..64894746 100755 --- a/src/components/CSchedaProdotto/CSchedaProdotto.ts +++ b/src/components/CSchedaProdotto/CSchedaProdotto.ts @@ -274,6 +274,18 @@ export default defineComponent({ type: costanti.FieldType.onlydate, dense: true, }, + { + editOn: false, + label: "Stato", + table: "productinfos", + id: myproduct.value.productInfo._id, + rec: myproduct.value.productInfo, + mykey: "idStatoProdotto", + debounce: "1000", + type: costanti.FieldType.select, + jointable: 't_web_statiprodottos', + dense: true, + }, { editOn: true, label: "Argomento", @@ -309,6 +321,30 @@ export default defineComponent({ type: costanti.FieldType.string, dense: true, }, + { + editOn: false, + label: "Tipologia", + table: "arrvariazioni", + id: myproduct.value._id, + rec: myproduct.value, + mykey: "idTipologia", + debounce: "1000", + type: costanti.FieldType.select, + jointable: 't_web_tipologies', + dense: true, + }, + { + editOn: false, + label: "Formato", + table: "arrvariazioni", + id: myproduct.value._id, + rec: myproduct.value, + mykey: "idTipoFormato", + debounce: "1000", + type: costanti.FieldType.select, + jointable: 't_web_tipiformatos', + dense: true, + }, { editOn: true, label: "Formato", @@ -412,11 +448,11 @@ export default defineComponent({ } async function updateproduct(load?: boolean) { - myproduct.value = await products.getProductById(myproduct.value._id, true) + myproduct.value = await products.getProductById(myproduct.value._id, load) } - async function refreshDataFromGM() { + /*async function refreshDataFromGM() { if (myproduct.value) { loading.value = true const ris = await globalStore.updateLocalDbFromGM_T_Web_Articoli(myproduct.value.productInfo.sku!, myproduct.value.isbn) @@ -429,9 +465,31 @@ export default defineComponent({ loading.value = false } + }*/ + + async function refreshSingleBookFromGM(options: any) { + if (myproduct.value) { + loading.value = true + await globalStore.updateAllBookFromGM_T_Web_Articoli({ sku: myproduct.value.productInfo.sku!, isbn: myproduct.value.productInfo.code, ...options }) + .then((ris) => { + if (ris) { + if (ris.error) { + tools.showNegativeNotif($q, ris.error) + } else { + + updateproduct(false) + // console.log('product AGGIORNATO:', myproduct.value) + tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK')) + } + loading.value = false + } + }) + } + } + onMounted(mounted) return { @@ -451,7 +509,8 @@ export default defineComponent({ field_updated_toGM, loading, updateRecordToGM, - refreshDataFromGM, + refreshSingleBookFromGM, + // refreshDataFromGM, } } }) diff --git a/src/components/CSchedaProdotto/CSchedaProdotto.vue b/src/components/CSchedaProdotto/CSchedaProdotto.vue index 01061f5d..92d779f7 100755 --- a/src/components/CSchedaProdotto/CSchedaProdotto.vue +++ b/src/components/CSchedaProdotto/CSchedaProdotto.vue @@ -77,8 +77,8 @@ class="q-ma-sm" color="accent" icon="fas fa-save" - label="Carica da GM" - @click="refreshDataFromGM" + label="Riaggiorna da GM" + @click="refreshSingleBookFromGM({usaDBGMLocale: false})" > diff --git a/src/components/CSearchProduct/CSearchProduct.ts b/src/components/CSearchProduct/CSearchProduct.ts index c6f6d68d..5affaa51 100755 --- a/src/components/CSearchProduct/CSearchProduct.ts +++ b/src/components/CSearchProduct/CSearchProduct.ts @@ -292,7 +292,12 @@ async function searchOnGM(mystr: string) { updateproductmodif(myproduct.value) // await updateproduct(false) - tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK')) + if (ris.error) { + tools.showNegativeNotif($q, ris.error) + } else { + tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK')) + } + // updatefromgm.value = false } diff --git a/src/model/Products.ts b/src/model/Products.ts index 68ef66b0..e2030d68 100755 --- a/src/model/Products.ts +++ b/src/model/Products.ts @@ -84,6 +84,8 @@ export interface IVariazione { misure?: string pagine?: number tipologia?: string + idTipologia?: number + idTipoFormato?: number edizione?: string preOrderDate?: Date addtocart_link?: string @@ -180,6 +182,8 @@ export interface IProductsState { authors: IAuthor[] publishers: IPublisher[] stati_prodotto?: T_Web_StatiProdotto[] + tipologie?: T_Web_Tipologie[] + tipoformato?: T_WEB_TipiFormato[] cart: ICart orders: IOrderCart[] catprods: ICatProd[] @@ -191,6 +195,7 @@ export interface IProductsState { userActive: IUserShort isPubblicatoById?: (idStatoProdotto: number) => boolean; + isProssimaUscitaById?: (idStatoProdotto: number) => boolean; } export interface IProducer { @@ -280,6 +285,20 @@ export interface T_Web_StatiProdotto { enabled?: boolean } +export interface T_Web_Tipologie { + IdTipologia: number + Descrizione: string + dataora?: Date, + enabled?: boolean +} + +export interface T_WEB_TipiFormato { + IdTipoFormato: number + Descrizione: string + dataora?: Date, + enabled?: boolean +} + export interface IStorehouse { _id?: any idapp?: string diff --git a/src/store/Modules/fieldsTable.ts b/src/store/Modules/fieldsTable.ts index 470fa4b7..25d1b60c 100755 --- a/src/store/Modules/fieldsTable.ts +++ b/src/store/Modules/fieldsTable.ts @@ -646,6 +646,24 @@ export const colTableCatProd = [ AddCol(DeleteRec), AddCol(DuplicateRec), ] +export const colTableStatiProdotto = [ + AddCol({ name: 'IdTipologia', label_trans: 'statoprod.IdTipologia' }), + AddCol({ name: 'Descrizione', label_trans: 'statoprod.Descrizione' }), + AddCol(DeleteRec), + AddCol(DuplicateRec), +] +export const colTableTipoFormato = [ + AddCol({ name: 'IdTipoFormato', label_trans: 'statoprod.IdTipologia' }), + AddCol({ name: 'Descrizione', label_trans: 'statoprod.Descrizione' }), + AddCol(DeleteRec), + AddCol(DuplicateRec), +] +export const colTableTipologie = [ + AddCol({ name: 'IdStatoProdotto', label_trans: 'statoprod.IdStatoProdotto' }), + AddCol({ name: 'Descrizione', label_trans: 'statoprod.Descrizione' }), + AddCol(DeleteRec), + AddCol(DuplicateRec), +] export const colTableCollane = [ AddCol({ name: 'idCollana', label_trans: 'collane.idCollana', fieldtype: costanti.FieldType.number }), AddCol({ name: 'title', label_trans: 'collane.title' }), @@ -4372,6 +4390,27 @@ export const fieldsTable = { colkey: '_id', collabel: 'name', }, + { + value: 't_web_statiprodottos', + label: 'Stati Prodotto', + columns: colTableStatiProdotto, + colkey: 'IdStatoProdotto', + collabel: 'Descrizione', + }, + { + value: 't_web_tipiformatos', + label: 'Tipo Formato', + columns: colTableTipoFormato, + colkey: 'IdTipoFormato', + collabel: 'Descrizione', + }, + { + value: 't_web_tipologies', + label: 'Tipologie', + columns: colTableTipologie, + colkey: 'IdStatoProdotto', + collabel: 'Descrizione', + }, { value: 'collanas', label: 'Collane', diff --git a/src/store/Products.ts b/src/store/Products.ts index aac707e6..2960d294 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -1,4 +1,4 @@ -import type { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort, IGasordine, IAuthor, ISubCatProd, IText, IOptCatalogo, ICatalog, ICatPrTotali, ISingleProductOrdered, ISchedaSingola, IMyScheda, IElementiScheda, T_Web_StatiProdotto } from 'model' +import type { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort, IGasordine, IAuthor, ISubCatProd, IText, IOptCatalogo, ICatalog, ICatPrTotali, ISingleProductOrdered, ISchedaSingola, IMyScheda, IElementiScheda, T_Web_StatiProdotto, T_Web_Tipologie, T_WEB_TipiFormato } from 'model' import { Api } from '@api' import { serv_constants } from '@src/store/Modules/serv_constants' @@ -130,6 +130,10 @@ export const useProducts = defineStore('Products', { }, isDisponibile: (state: IProductsState) => (product: IProduct): boolean => { + return product?.arrvariazioni?.[0]?.quantita > 1 + }, + + isDisponibilitaOk: (state: IProductsState) => (product: IProduct): boolean => { return product?.arrvariazioni?.[0]?.quantita > 100 }, @@ -146,11 +150,9 @@ export const useProducts = defineStore('Products', { isPubblicatoById: (state: IProductsState) => (idStatoProdotto: number): boolean => { switch (idStatoProdotto) { - case 1: - case 4: - case 34: - case 45: - case 46: + case 1: // In Commercio + case 45: // In Commercio + case 46: // 2023 in commercio case undefined: return true; default: @@ -158,16 +160,41 @@ export const useProducts = defineStore('Products', { } }, + isProssimaUscitaById: (state: IProductsState) => (idStatoProdotto: number): boolean => { + // 4 - Prossima uscita + // 34 - In Prevendita + return (idStatoProdotto === 4) || (idStatoProdotto === 34) + }, + isPubblicato: (state: IProductsState) => (productInfo: IProductInfo): boolean => { return state.isPubblicatoById(productInfo.idStatoProdotto) }, + isNonVendibile: (state: IProductsState) => (productInfo: IProductInfo): boolean => { + return !state.isPubblicatoById(productInfo.idStatoProdotto) && !state.isProssimaUscitaById(productInfo.idStatoProdotto) + }, + + isProssimaUscita: (state: IProductsState) => (productInfo: IProductInfo): boolean => { + return state.isProssimaUscitaById(productInfo.idStatoProdotto) + }, + getDescrStatiProdottoByIdStatoProdotto: (state: IProductsState) => (idStatoProdotto: number): string => { const ctrec = state.stati_prodotto.find((mystatus: T_Web_StatiProdotto) => mystatus.IdStatoProdotto === idStatoProdotto) return (ctrec) ? ctrec.Descrizione : '' }, + getDescrByIdTipologia: (state: IProductsState) => (idTipologia: number): string => { + const ctrec = state.tipologie.find((mystatus: T_Web_Tipologie) => mystatus.IdTipologia === idTipologia) + return (ctrec) ? ctrec.Descrizione : '' + }, + + getDescrByIdTipoFormato: (state: IProductsState) => (idTipoFormato: number): string => { + const ctrec = state.tipoformato.find((mystatus: T_WEB_TipiFormato) => mystatus.IdTipoFormato === idTipoFormato) + return (ctrec) ? ctrec.Descrizione : '' + }, + + getArrayidArgomentoByArridCatProds: (state: IProductsState) => (arridCatProds: string[]): string[] => { const myarr: string[] = [] for (const idCatProd of arridCatProds) { @@ -1426,114 +1453,158 @@ export const useProducts = defineStore('Products', { return testo.contenuto; } - const autori = this.getAutoriByArrayAuthors(myproduct.productInfo.authors) - const collana = tools.formatCollane(myproduct.productInfo.idCollana) + const replacements: { [key: string]: any } = {}; + + if (testo.contenuto.includes('{autore}')) { + replacements['{autore}'] = this.getAutoriByArrayAuthors(myproduct.productInfo.authors) || ''; + } + + if (testo.contenuto.includes('{collana}')) { + replacements['{collana}'] = tools.formatCollane(myproduct.productInfo.idCollana) || ''; + } const maxDescriptionLength = testo.maxlength ?? 100; - const description = myproduct.productInfo.short_descr || ''; - const long_descr = myproduct.productInfo.description || ''; - const date_pub = tools.getstrDateShort(myproduct.productInfo.date_pub) || ''; - const fatLast3M = myproduct.productInfo.fatLast3M! || 0; - const fatLast6M = myproduct.productInfo.fatLast6M! || 0; - const vLast3M = myproduct.productInfo.vLast3M! || 0; - const vLast6M = myproduct.productInfo.vLast6M! || 0; - const ranking_globale = myproduct.productInfo.rank3M! || 0; - const venduti = myproduct.productInfo.totVen! || 0; - const fatturati = myproduct.productInfo.totFat! || 0; - const linkvenduti = '' + venduti + '' - const linkfatturati = '' + fatturati + '' - const debugstr = this.getkeyValStr('Pub:', date_pub) + - this.getkeyValStr('fat6M', fatLast6M) + - // this.getkeyValStr('Rank3M', myproduct.productInfo.rank3M) + - this.getkeyValStr('Ven:', linkvenduti) + - this.getkeyValStr('v3M', vLast3M) + - this.getkeyValStr('v6M', vLast6M) + - this.getkeyValStr('Fatt:', linkfatturati) + - this.getkeyValStr('fat3M', fatLast3M) - - const truncatedDescription = description.length > maxDescriptionLength - ? description.substring(0, description.lastIndexOf(' ', maxDescriptionLength)) + '...' - : description; - - const truncatedlongDescription = long_descr.length > maxDescriptionLength - ? long_descr.substring(0, long_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' - : long_descr; - - let addtesto = false - - const long_descr_macro = myproduct.productInfo.descrizione_completa_macro || ''; - if (long_descr_macro.length > maxDescriptionLength) { - addtesto = true - } - const addstrcontinua = '👉🏻 continua a leggere' - - let descrizione_completa_macro = addtesto - ? long_descr_macro.substring(0, long_descr_macro.lastIndexOf(' ', maxDescriptionLength)) + '...' - : long_descr_macro; - - if (addtesto) { - descrizione_completa_macro += addstrcontinua + if (testo.contenuto.includes('{descrizione_da_fdv}')) { + const description = myproduct.productInfo.short_descr || ''; + replacements['{descrizione_da_fdv}'] = description.length > maxDescriptionLength + ? description.substring(0, description.lastIndexOf(' ', maxDescriptionLength)) + '...' + : description; } - const descr_trafiletto_catalogo = myproduct.productInfo.descr_trafiletto_catalogo || ''; - const short_descr = myproduct.productInfo.descrizione_breve_macro || ''; - const descrizione_breve_macro = short_descr.length > maxDescriptionLength - ? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' - : short_descr; + if (testo.contenuto.includes('{descrizione_estesa_fdv}')) { + const long_descr = myproduct.productInfo.description || ''; + replacements['{descrizione_estesa_fdv}'] = long_descr.length > maxDescriptionLength + ? long_descr.substring(0, long_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' + : long_descr; + } - const sottotitolo = myproduct.productInfo.sottotitolo || ''; - const link_macro = myproduct.productInfo.link_macro || ''; + if (testo.contenuto.includes('{descrizione_estesa}')) { + let addtesto = false; + const long_descr_macro = myproduct.productInfo.descrizione_completa_macro || ''; + if (long_descr_macro.length > maxDescriptionLength) { + addtesto = true; + } + const addstrcontinua = '👉🏻 continua a leggere'; + let descrizione_completa_macro = addtesto + ? long_descr_macro.substring(0, long_descr_macro.lastIndexOf(' ', maxDescriptionLength)) + '...' + : long_descr_macro; - const prezzo = tools.arrotonda2Dec(myproduct.arrvariazioni![0].price) || '' - const prezzo_scontato = tools.arrotonda2Dec(myproduct.arrvariazioni![0].sale_price) || '' - const categoria = this.getCatProdsStrByCatProds(myproduct.productInfo.catprods!) - const sottocategoria = myproduct.productInfo.subcatprods && myproduct.productInfo.subcatprods.length > 0 ? myproduct.productInfo.subcatprods[0].name! : '' - const descr_categoria = myproduct.productInfo.catprods && myproduct.productInfo.catprods.length > 0 ? this.getCatProdDescrStrByIdCatProd(myproduct.productInfo.catprods![0].name) : '' - const misure = myproduct.arrvariazioni![0].misure || '' - const formato = myproduct.arrvariazioni![0].formato || '' - const pagine = myproduct.arrvariazioni![0].pagine || '' - const qta = myproduct.arrvariazioni![0].quantita || '' - const isbn = myproduct.productInfo.code || '' - const image_link = myproduct.productInfo.image_link || '' - const imagefile = myproduct.productInfo.imagefile || '' - const stato = this.getDescrStatiProdottoByIdStatoProdotto(myproduct.productInfo.idStatoProdotto || '') + if (addtesto) { + descrizione_completa_macro += addstrcontinua; + } + replacements['{descrizione_estesa}'] = descrizione_completa_macro || ''; + } - const scale = optcatalogo.printable ? optcatalogo.areadistampa?.scale : 1 - // Crea una mappa di sostituzioni - const replacements = { - '{autore}': autori || '', - '{titolo}': myproduct.productInfo.name || '', - '{sottotitolo}': (sottotitolo) || '', - '{descrizione_da_fdv}': truncatedDescription || '', - '{descrizione_estesa_fdv}': truncatedlongDescription || '', - '{descrizione_estesa}': descrizione_completa_macro || '', - '{debug}': (debugstr) || '', - '{categoria}': (categoria) || '', - '{sottocategoria}': (sottocategoria) || '', - '{descr_categoria}': (descr_categoria) || '', - '{pagine}': (pagine) || '', - '{isbn}': (isbn) || '', - '{misure}': misure || '', - '{argomento}': categoria || '', - '{date_pub}': date_pub || '', - '{ranking_globale}': ranking_globale || '', - '{venduti}': venduti || '', - '{formato}': formato || '', - '{stato}': stato || '', - '{collana}': collana ? collana || '' : '', - '{prezzo}': prezzo || '', - '{scale}': scale || '', - '{prezzo_scontato}': prezzo_scontato || '', - '{descrizione_completa_macro}': descrizione_completa_macro || '', - '{descrizione_breve_macro}': descrizione_breve_macro || '', - '{descr_trafiletto_catalogo}': descr_trafiletto_catalogo || '', - '{link_macro}': link_macro || '', - '{qta}': qta || '', - '{image_link}': image_link || '', - '{imagefile}': imagefile || '', - }; + if (testo.contenuto.includes('{descrizione_breve_macro}')) { + const short_descr = myproduct.productInfo.descrizione_breve_macro || ''; + replacements['{descrizione_breve_macro}'] = short_descr.length > maxDescriptionLength + ? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' + : short_descr; + } + if (testo.contenuto.includes('{descr_trafiletto_catalogo}')) { + const short_descr = myproduct.productInfo.descr_trafiletto_catalogo || ''; + replacements['{descr_trafiletto_catalogo}'] = short_descr.length > maxDescriptionLength + ? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' + : short_descr; + } + + if (testo.contenuto.includes('{prezzo}') || testo.contenuto.includes('{prezzo_scontato}')) { + const prezzo = tools.arrotonda2Dec(myproduct.arrvariazioni![0].price) || ''; + const prezzo_scontato = tools.arrotonda2Dec(myproduct.arrvariazioni![0].sale_price) || ''; + replacements['{prezzo}'] = prezzo; + replacements['{prezzo_scontato}'] = prezzo_scontato; + } + + // Additional replacements based on the content + const keysToCheck = [ + '{titolo}', '{sottotitolo}', '{categoria}', '{sottocategoria}', '{descr_categoria}', + '{pagine}', '{isbn}', '{misure}', '{argomento}', '{date_pub}', '{ranking_globale}', + '{venduti}', '{formato}', '{tipologia}', '{stato}', '{scale}', '{descr_trafiletto_catalogo}', + '{link_macro}', '{qta}', '{image_link}', '{imagefile}', '{debug}' + ]; + + for (const key of keysToCheck) { + if (testo.contenuto.includes(key)) { + switch (key) { + case '{titolo}': + replacements[key] = myproduct.productInfo.name || ''; + break; + case '{sottotitolo}': + replacements[key] = myproduct.productInfo.sottotitolo || ''; + break; + case '{sottocategoria}': + replacements[key] = myproduct.productInfo.subcatprods && myproduct.productInfo.subcatprods.length > 0 ? myproduct.productInfo.subcatprods[0].name! : ''; + break; + case '{descr_categoria}': + replacements[key] = myproduct.productInfo.catprods && myproduct.productInfo.catprods.length > 0 ? this.getCatProdDescrStrByIdCatProd(myproduct.productInfo.catprods![0].name) : ''; + break; + case '{pagine}': + replacements[key] = myproduct.arrvariazioni![0].pagine || ''; + break; + case '{isbn}': + replacements[key] = myproduct.productInfo.code || ''; + break; + case '{misure}': + replacements[key] = myproduct.arrvariazioni![0].misure || ''; + break; + case '{argomento}': + replacements[key] = this.getCatProdsStrByCatProds(myproduct.productInfo.catprods!) || ''; + break; + case '{date_pub}': + replacements[key] = tools.getstrDateShort(myproduct.productInfo.date_pub) || ''; + break; + case '{ranking_globale}': + replacements[key] = myproduct.productInfo.rank3M! || '0'; + break; + case '{venduti}': + replacements[key] = myproduct.productInfo.totVen! || '0'; + break; + case '{formato}': + replacements[key] = this.getDescrByIdTipoFormato(myproduct.arrvariazioni[0].idTipoFormato || 0) + break; + case '{tipologia}': + replacements[key] = this.getDescrByIdTipologia(myproduct.arrvariazioni[0].idTipologia || 0); + break; + case '{stato}': + replacements[key] = this.getDescrStatiProdottoByIdStatoProdotto(myproduct.productInfo.idStatoProdotto || ''); + break; + case '{scale}': + replacements[key] = optcatalogo.printable ? optcatalogo.areadistampa?.scale : '1'; + break; + case '{link_macro}': + replacements[key] = myproduct.productInfo.link_macro || ''; + break; + case '{qta}': + replacements[key] = myproduct.arrvariazioni![0].quantita || ''; + break; + case '{image_link}': + replacements[key] = myproduct.productInfo.image_link || ''; + break; + case '{imagefile}': + replacements[key] = myproduct.productInfo.imagefile || ''; + break; + case '{debug}': + const date_pub = replacements['{date_pub}'] || ''; + const fatLast6M = myproduct.productInfo.fatLast6M! || 0; + const linkvenduti = `${replacements['{venduti}']}`; + const vLast3M = myproduct.productInfo.vLast3M! || 0; + const vLast6M = myproduct.productInfo.vLast6M! || 0; + const linkfatturati = `${myproduct.productInfo.totFat! || 0}`; + const fatLast3M = myproduct.productInfo.fatLast3M! || 0; + + replacements[key] = this.getkeyValStr('Pub:', date_pub) + + this.getkeyValStr('fat6M', fatLast6M) + + this.getkeyValStr('Ven:', linkvenduti) + + this.getkeyValStr('v3M', vLast3M) + + this.getkeyValStr('v6M', vLast6M) + + this.getkeyValStr('Fatt:', linkfatturati) + + this.getkeyValStr('fat3M', fatLast3M); + break; + } + } + } // Esegue le sostituzioni let result = testo.contenuto; @@ -1541,7 +1612,7 @@ export const useProducts = defineStore('Products', { result = result.replace(new RegExp(key, 'g'), value); } - return result.trim() + return result.trim(); }, getSubCatStrByProduct(myproductInfo: IProductInfo): string { diff --git a/src/store/globalStore.ts b/src/store/globalStore.ts index 2b80fdc1..9d0dd695 100644 --- a/src/store/globalStore.ts +++ b/src/store/globalStore.ts @@ -13,7 +13,10 @@ import type { StateConnection, ISchedaSingola, IOptQueryGM, - IOptCatalogo + IOptCatalogo, + IProduct, + IProductInfo, + IVariazione } from '@model'; import { ICity, IMySkill, @@ -442,6 +445,8 @@ export const useGlobalStore = defineStore('GlobalStore', { else if (table === 'authors') ris = Products.authors else if (table === 'publishers') ris = Products.publishers else if (table === 't_web_statiprodottos') ris = Products.stati_prodotto + else if (table === 't_web_tipologies') ris = Products.tipologie + else if (table === 't_web_tipiformatos') ris = Products.tipoformato else if (table === 'catais') ris = state.catAI else if (table === 'queryais') ris = state.queryAIList else if (table === 'sharewithus') ris = state.sharewithus @@ -1829,6 +1834,8 @@ export const useGlobalStore = defineStore('GlobalStore', { Products.collane = (res.data.collane) ? [...res.data.collane] : [] Products.subcatprods = (res.data.subcatprods) ? [...res.data.subcatprods] : [] Products.stati_prodotto = (res.data.stati_prodotto) ? [...res.data.stati_prodotto] : [] + Products.tipologie = (res.data.tipologie) ? [...res.data.tipologie] : [] + Products.tipoformato = (res.data.tipoformato) ? [...res.data.tipoformato] : [] Products.catprods_gas = (res.data.catprods_gas) ? [...res.data.catprods_gas] : [] Products.authors = (res.data.authors) ? [...res.data.authors] : [] Products.publishers = (res.data.publishers) ? [...res.data.publishers] : [] @@ -2676,15 +2683,41 @@ export const useGlobalStore = defineStore('GlobalStore', { } }, + async updateTablesInMemory(data: any) { + + const table = data.table + const id = data.idRecUpdated + + if (!id) + return + + const productStore = useProducts() + + try { + if (table === 'products') { + await productStore.loadProductById(id) + } else if (table === 'productinfos') { + + } + } catch (error) { + console.error("Errore durante l'aggiornamento della tabella in memoria:", error); + } + }, + async updateAllBookTableContent(options: any) { try { // aggiungi idapp ad options options.idapp = tools.getEnv('VITE_APP_ID') - return Api.SendReq('/apisqlsrv/updateAllBook', 'POST', { options }) - .then((res) => { + return await Api.SendReq('/apisqlsrv/updateAllBook', 'POST', { options }) + .then(async (res) => { + if (res?.data?.data?.logerror) { + return { error: 'Errore ' + res?.data?.data?.logerror } + } + await this.updateTablesInMemory(res.data.data) return res.data.data }).catch((error: any) => { console.error('Error fetchTableContent: ', error) + return { error: 'Errore ' + error } }) } catch (error) { console.error("Errore nel recupero della tabella:", error); diff --git a/src/views/admin/dbopmacro/dbopmacro.vue b/src/views/admin/dbopmacro/dbopmacro.vue index 18f991aa..548ea69b 100755 --- a/src/views/admin/dbopmacro/dbopmacro.vue +++ b/src/views/admin/dbopmacro/dbopmacro.vue @@ -21,6 +21,11 @@ color="positive" @click="EseguiFunz('UpdateStatFatturato')" > +

- - - + +