Files
myprojplanet_vite/src/store/Products.ts

2432 lines
73 KiB
TypeScript
Raw Normal View History

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,
IPublisher,
ICollaneTotali,
} from 'model'
import { Api } from '@api'
import { serv_constants } from '@src/store/Modules/serv_constants'
import * as Types from '@src/store/Api/ApiTypes'
import { static_data } from '@src/db/static_data'
import { shared_consts } from '@src/common/shared_vuejs'
import { tools } from '@store/Modules/tools'
import { defineStore } from 'pinia'
import { useUserStore } from '@store/UserStore'
import { toolsext } from '@store/Modules/toolsext'
import { useGlobalStore } from './globalStore'
import { ref } from 'vue'
import objectId from '@src/js/objectId'
import { costanti } from '@costanti'
import translate from '@src/globalroutines/util'
import { useCatalogStore } from './CatalogStore'
2024-01-09 15:32:21 +01:00
function getRecordOrdersCartEmpty(): IOrderCart {
return {
numorder: 0,
numord_pers: 0,
userId: '',
user: null,
totalQty: 0,
totalPrice: 0,
totalPriceCalc: 0,
2024-01-09 15:32:21 +01:00
status: 0,
confermato: false,
consegnato: false,
pagato: false,
spedito: false,
ricevuto: false,
note: '',
2024-01-13 16:21:19 +01:00
note_per_gestore: '',
note_per_admin: '',
note_ordine_gas: '',
}
2024-01-09 15:32:21 +01:00
}
2023-12-27 02:58:23 +01:00
function getRecordProductInfoEmpty(): IProductInfo {
return {
code: '',
name: '',
description: '',
department: '',
catprods: [],
2024-01-12 13:03:07 +01:00
subcatprods: [],
2023-12-27 02:58:23 +01:00
color: '',
size: '',
weight: 0,
unit: 0,
stars: 0,
date: tools.getDateNow(),
icon: '',
imagefile: '',
}
2023-12-27 02:58:23 +01:00
}
function getRecordProductEmpty(): IProduct {
const tomorrow = tools.getDateNow()
tomorrow.setDate(tomorrow.getDate() + 1)
2023-12-27 02:58:23 +01:00
return {
productInfo: getRecordProductInfoEmpty(),
// _id: tools.getDateNow().toISOString(), // Create NEW
2023-12-27 02:58:23 +01:00
active: false,
idProducer: '',
idStorehouses: [],
2024-01-16 16:56:57 +01:00
idGasordine: '',
idScontisticas: [],
scontisticas: [],
idProvider: '',
producer: {},
2024-01-16 16:56:57 +01:00
gasordine: null,
storehouses: [],
provider: {},
price: 0.0,
quantityAvailable: 0,
bookableAvailableQty: 0,
minBuyQty: 1,
2023-12-29 21:17:25 +01:00
minStepQty: 1,
// maxBookableSinglePersQty: 0,
2024-01-09 15:32:21 +01:00
stockQty: 0,
// stockBloccatiQty: 0,
// bookedQtyOrdered: 0,
// bookedQtyConfirmed: 0,
// qtyToReachForGas: 0,
2024-01-09 15:32:21 +01:00
// maxbookableGASQty: 0,
// bookedGASQtyOrdered: 0,
// bookedGASQtyConfirmed: 0,
// bookableGASBloccatiQty: 0,
2024-01-09 15:32:21 +01:00
// canBeShipped: false,
// QuantitaOrdinateInAttesa: 0,
// QuantitaPrenotateInAttesa: 0,
// canBeBuyOnline: false,
}
2023-12-27 02:58:23 +01:00
}
2021-09-02 03:22:13 +02:00
export const useProducts = defineStore('Products', {
state: (): IProductsState => ({
products: [],
cart: { items: [], totalPrice: 0, totalQty: 0, userId: '' },
2021-09-02 21:29:24 +02:00
orders: [],
2023-12-27 02:58:23 +01:00
catprods: [],
2024-01-23 00:10:52 +01:00
catprods_gas: [],
authors: [],
publishers: [],
2024-01-12 13:03:07 +01:00
subcatprods: [],
2023-12-27 02:58:23 +01:00
productInfos: [],
userActive: { username: '', name: '', surname: '', _id: '' },
2021-09-02 03:22:13 +02:00
}),
getters: {
getCatProds:
(state: IProductsState) =>
(cosa: number): ICatProd[] => {
if (cosa === shared_consts.PROD.GAS) return state.catprods_gas
else if (cosa === shared_consts.PROD.BOTTEGA) return state.catprods
else return [...state.catprods, ...state.catprods_gas]
},
2023-12-27 02:58:23 +01:00
getCollane: (state: IProductsState) => (): ICollana[] => {
return state.collane
},
isDisponibile:
(state: IProductsState) =>
(product: IProduct): boolean => {
return product?.arrvariazioni?.[0]?.quantita > 1
},
isDisponibilitaOk:
(state: IProductsState) =>
(product: IProduct): boolean => {
return product?.arrvariazioni?.[0]?.quantita > 100
},
isQtaLimitata:
(state: IProductsState) =>
(product: IProduct): boolean => {
return (
product?.arrvariazioni?.[0]?.quantita > 50 && product?.arrvariazioni?.[0]?.quantita < 100
)
},
isInEsaurendo:
(state: IProductsState) =>
(product: IProduct): boolean => {
return (
product?.arrvariazioni?.[0]?.quantita > 0 && product.arrvariazioni?.[0]?.quantita < 50
)
},
isEsaurito:
(state: IProductsState) =>
(product: IProduct): boolean => {
return (
product?.arrvariazioni?.[0]?.quantita <= 0 &&
!state.isProssimaUscitaById(product.productInfo.idStatoProdotto) &&
!state.isPrevenditaById(product.productInfo.idStatoProdotto)
)
},
isPubblicatoById:
(state: IProductsState) =>
(idStatoProdotto: number): boolean => {
/*
2025-04-24 19:31:34 +02:00
1 In commercio
3 Ristampa
4 Prossima uscita/pubblicazione
6 In promozione
7 In fase di valutazione
8 Titolo in esaurimento (in attesa Nuova Edizione)
9 Titolo in esaurimento
20 Titolo in esaurimento (in att N.E Ricopertinata)
26 Titolo in Esaurimento (disponibile N.E.)
33 In commercio (digitale)
34 In prevendita
45 Vendita sito
46 2023 in commercio
47 Assoluto NO Reso
48 Titolo esaurito
*/
switch (idStatoProdotto) {
case 1: // In Commercio
case 3: // Ristampa
case 4: // Prossima uscita/pubblicazione
case 6: // In promozione
case 7: // In fase di valutazione
case 8: // 8 Titolo in esaurimento (in attesa Nuova Edizione)
case 9: // In Commercio
case 33: // In commercio (digitale)
case 34: // In prevendita
case 45: // Vendita sito
case 46: // 2023 in commercio
case 47: // Assoluto NO Reso
case 48: // Titolo esaurito
case undefined:
return true
default:
return false
2025-04-11 18:49:42 +02:00
}
},
isProssimaUscitaById:
(state: IProductsState) =>
(idStatoProdotto: number): boolean => {
// 4 - Prossima uscita
return idStatoProdotto === 4
},
isPrevenditaById:
(state: IProductsState) =>
(idStatoProdotto: number): boolean => {
// 4 - Prossima uscita
// 34 - In Prevendita
return idStatoProdotto === 34
},
isNovitaById:
(state: IProductsState) =>
(date_pub: Date): boolean => {
const sixMonthsAgo = new Date()
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6)
return new Date(date_pub).getTime() > sixMonthsAgo.getTime()
},
isPubblicato:
(state: IProductsState) =>
(productInfo: IProductInfo): boolean => {
return state.isPubblicatoById(productInfo.idStatoProdotto)
},
isNovita:
(state: IProductsState) =>
(productInfo: IProductInfo): boolean => {
return state.isNovitaById(productInfo.date_pub)
},
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)
},
isPrevendita:
(state: IProductsState) =>
(productInfo: IProductInfo): boolean => {
return state.isPrevenditaById(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 : ''
},
getCasaEditriceByIdPublisher:
(state: IProductsState) =>
(idPublisher: string): string => {
const rectrovato: IPublisher = state.publishers.find(
(editore: IPublisher) => editore._id === idPublisher
)
return rectrovato ? rectrovato.name : ''
},
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) {
const catprod = state.catprods.find((rec: ICatProd) => rec._id === idCatProd)
if (catprod && catprod.idArgomento && !myarr.includes(catprod.idArgomento.toString())) {
myarr.push(catprod.idArgomento.toString())
}
2025-03-26 23:23:35 +01:00
}
return myarr
},
getCatProdsByGas:
(state: IProductsState) =>
(idGasOrdine: string): ICatProd[] => {
let arrcat = state.catprods_gas
// Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato
if (idGasOrdine) {
arrcat = state.catprods_gas.filter((rec: ICatProd) => {
const arrprod = state.products.filter((prod: IProduct) => {
if (
prod.idGasordine === idGasOrdine &&
prod.productInfo.idCatProds?.includes(rec._id)
) {
return true
}
})
return arrprod.length > 0 ? true : false
})
} else {
return []
}
return arrcat
},
getCatProdsStrByCatProds:
(state: IProductsState) =>
(catProds: ICatProd[]): string => {
let mystr = ''
for (const catprod of catProds) {
let myarrcat = null
if (tools.isObject(catprod)) {
myarrcat = catprod
} else {
myarrcat = state.catprods.find((rec: ICatProd) => rec._id === catprod)
}
if (myarrcat) {
if (mystr) mystr += ' - '
mystr += myarrcat.name
}
}
return mystr
},
getSubCatProdsStrBySubCatProds:
(state: IProductsState) =>
(idSubCatProds: string[]): string => {
let mystr = ''
if (Array.isArray(idSubCatProds) && idSubCatProds.length > 0) {
const names = idSubCatProds
.map((id) => {
const subCatProd = state.subcatprods.find((rec: ISubCatProd) => rec._id === id)
return subCatProd ? subCatProd.name : ''
})
.filter((name) => name !== '')
mystr = names.join(' - ')
}
return mystr
},
getTotaleOrdineByOrdId:
(state: IProductsState) =>
(
idOrdine: string,
idGasordine: string,
totale: boolean,
mostra_solo_ordini_produttore: boolean,
status: number
): number => {
let arrprod = []
if (totale) {
arrprod = state.orders.filter((rec: IOrderCart) => {
if (
(idGasordine &&
!rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)) ||
rec.status !== status
) {
return false // Skip records not matching gasordine condition
}
return true
})
} else {
arrprod = state.orders.filter((rec: IOrderCart) => {
if (
(idGasordine &&
!rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)) ||
rec._id !== idOrdine
) {
return false // Skip records not matching gasordine condition
}
return true
})
}
let subtotalPrice = 0
arrprod.forEach((rec: IOrderCart) => {
rec.items?.forEach((item) => {
if (
item.order &&
((mostra_solo_ordini_produttore && item.order.idGasordine === idGasordine) ||
!mostra_solo_ordini_produttore)
) {
const qtyparz = item.order.quantity + item.order.quantitypreordered
subtotalPrice += item.order.price * qtyparz
}
})
})
return subtotalPrice
},
getCatProdDescrStrByIdCatProd:
(state: IProductsState) =>
(idCatProd: string): string => {
const myfirstcat = state.catprods.find((rec: ICatProd) => rec._id === idCatProd)
if (myfirstcat) {
return myfirstcat.descr_estesa!
}
return ''
},
getTotaliProdottiByIdCatProd:
(state: IProductsState) =>
(idCatProd: string): number => {
const myfirstcat = state.catprtotali!.find((rec: ICatPrTotali) => rec._id === idCatProd)
if (myfirstcat) {
return myfirstcat.quanti!
}
return 0
},
getTotaliProdottiByIdCollana:
(state: IProductsState) =>
(idCollana: string): number => {
const myfirstcat = state.collane.find((rec: ICollaneTotali) => rec._id === idCollana)
2024-10-31 23:23:06 +01:00
if (myfirstcat) {
return myfirstcat.quanti!
}
return 0
},
getSubCatProdsByGas:
(state: IProductsState) =>
(idGasOrdine: string, idCatProd: string): ISubCatProd[] => {
let arrcat = state.subcatprods
// Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato
if (idGasOrdine) {
arrcat = state.subcatprods.filter((rec: ISubCatProd) => {
const arrprod = state.products.filter((prod: IProduct) => {
if (
prod.idGasordine === idGasOrdine &&
prod.productInfo.idSubCatProds?.includes(rec._id) &&
prod.productInfo.idCatProds?.includes(idCatProd)
) {
return true
}
})
return arrprod.length > 0 ? true : false
})
} else {
return []
}
return arrcat
},
getAuthors: (state: IProductsState) => (): any[] => {
// Get the list of authors, for the q-select component using state.authors array
// [{name: xxx, value: _id }]
// add default value for q-select
const options = [
{
label: '[Tutti]',
value: '',
},
...state.authors.map((rec: IAuthor) => {
return { label: rec.name + (rec.surname ? ' ' + rec.surname : ''), value: rec._id }
}),
]
return options
},
2023-12-27 02:58:23 +01:00
getNumProdTot: (state: IProductsState) => (): number => {
return state.products.length
2023-12-27 02:58:23 +01:00
},
getProducts:
(state: IProductsState) =>
(cosa?: number): IProduct[] => {
if (!!cosa) {
return state.products.filter((rec: IProduct) => {
const hasGasOrdines = rec.idGasordine
2023-12-27 02:58:23 +01:00
if (
(cosa === shared_consts.PROD.GAS && hasGasOrdines) ||
(cosa === shared_consts.PROD.BOTTEGA && !hasGasOrdines)
) {
return true
}
2023-12-27 02:58:23 +01:00
return false
})
} else {
return state.products
}
},
2021-09-02 03:22:13 +02:00
updateDataProduct: (state: IProductsState) => (res: any) => {
if (res && res.data.product) {
// Update product from server
const indelem = state.products.findIndex(
(prod: IProduct) => prod._id === res.data.product._id
)
if (indelem >= 0) {
state.products[indelem] = { ...res.data.product }
2023-12-20 21:56:30 +01:00
/*if (!res.data.orders) {
// aggiorna anche tutti i product negli ordini !
let ordcart: IOrderCart
for (ordcart of state.orders) {
for (const item of ordcart.items!) {
if (item.order.idProduct === res.data.product.idProduct)
item.order.product = res.data.product
}
}
}*/
}
}
if (res && res.data.orders) {
state.orders = res.data.orders
}
if (res && res.data.cart) {
// console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
state.cart = res.data.cart
}
},
getProductByCode:
(state: IProductsState) =>
(code: string): IProduct => {
if (!code) {
return getRecordProductEmpty()
}
2023-12-27 02:58:23 +01:00
const prod = state.products.find((prod: IProduct) => {
if (prod.productInfo.code === code) return prod
else return null
})
return prod ? prod : getRecordProductEmpty()
},
2021-09-02 03:22:13 +02:00
getCart: (state: IProductsState) => (): ICart => {
return state.cart
2021-09-02 03:22:13 +02:00
},
getOrdersAllCart:
(state: IProductsState) =>
(idGasordine: string): IOrderCart[] => {
return state.orders.filter((rec: IOrderCart) => {
if (
idGasordine &&
!rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)
) {
return false // Skip records not matching gasordine condition
}
return true
})
},
2021-09-02 03:22:13 +02:00
getNumOrders: (state: IProductsState) => (): number => {
return state.orders.length
},
getOrdersCart:
(state: IProductsState) =>
(tipoord: number, hasGasordine: any, idGasordine: string): IOrderCart[] | undefined => {
return state.orders.filter((rec: IOrderCart) => {
if (
idGasordine &&
!rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)
) {
return false // Skip records not matching gasordine condition
}
2024-02-13 18:13:36 +01:00
if (hasGasordine && !rec.items?.some((item) => item.order && item.order.idGasordine)) {
return false // Skip records not matching gasordine condition
}
2024-02-13 18:13:36 +01:00
switch (tipoord) {
case shared_consts.OrderStat.IN_CORSO.value:
return !rec.status || rec.status <= shared_consts.OrderStatus.CHECKOUT_SENT
case shared_consts.OrderStat.PREPARED.value:
return rec.status === shared_consts.OrderStatus.PREPARED
case shared_consts.OrderStat.CONFERMATI.value:
return rec.status === shared_consts.OrderStatus.ORDER_CONFIRMED
case shared_consts.OrderStat.PAGATI.value:
return rec.status === shared_consts.OrderStatus.PAYED
case shared_consts.OrderStat.DELIVERED.value:
return rec.status === shared_consts.OrderStatus.DELIVERED
case shared_consts.OrderStat.SHIPPED.value:
return rec.status === shared_consts.OrderStatus.SHIPPED
case shared_consts.OrderStat.RECEIVED.value:
return rec.status === shared_consts.OrderStatus.RECEIVED
case shared_consts.OrderStat.COMPLETATI.value:
return rec.status === shared_consts.OrderStatus.COMPLETED
case shared_consts.OrderStat.CANCELLATI.value:
return rec.status === shared_consts.OrderStatus.CANCELED
default:
return false // Invalid tipoord
}
})
},
existProductInCart:
(state: IProductsState) =>
(idproduct: string): boolean => {
// console.log('.cart.items', this.cart.items)
if (state.cart.items) {
const ris = state.cart.items
.filter((item: IBaseOrder) => item.order.idProduct === idproduct)
.reduce((sum, rec) => sum + 1, 0)
return ris > 0
2024-02-13 18:13:36 +01:00
}
return false
},
getOrderProductInCart:
(state: IProductsState) =>
(idproduct: string): IOrder | null => {
// console.log('.cart.items', this.cart.items)
if (state.cart.items) {
const ris = state.cart.items.find((item: IBaseOrder) =>
item.order ? item.order.idProduct === idproduct : false
)
return ris ? ris.order : null
}
return null
},
2021-09-02 03:22:13 +02:00
getOrderProductInOrdersCart:
(state: IProductsState) =>
(idordercart: string, idproduct: string): IOrder | null => {
// console.log('.cart.items', this.cart.items)
if (state.orders) {
const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart)
if (orderscart) {
const ris = orderscart.items!.find(
(item: IBaseOrder) => item.order.idProduct === idproduct
)
return ris ? ris.order : null
}
}
return null
},
2021-09-02 03:22:13 +02:00
getOrdersCartById:
(state: IProductsState) =>
(idordercart: string): IOrderCart => {
if (state.orders) {
const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart)
return orderscart ?? getRecordOrdersCartEmpty()
}
return getRecordOrdersCartEmpty()
},
getSumQtyPreOrderInOrdersCart:
(state: IProductsState) =>
(idproduct: string): number => {
let totalQuantity = 0
2024-01-09 15:32:21 +01:00
if (state.orders) {
const orderscart = state.orders
if (orderscart) {
for (const myord of orderscart) {
if (myord.items) {
for (const item of myord.items) {
if (item.order) {
if (
item.order.idProduct === idproduct &&
item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT
) {
totalQuantity += item.order.quantitypreordered || 0
}
2023-12-21 01:34:39 +01:00
}
}
}
}
}
}
return totalQuantity
},
getSumQtyOrderProductInOrdersCart:
(state: IProductsState) =>
(idproduct: string): number => {
let totalQuantity = 0
2023-12-21 01:34:39 +01:00
if (state.orders) {
const orderscart = state.orders
if (orderscart) {
for (const myord of orderscart) {
if (myord.items) {
for (const item of myord.items) {
if (item.order) {
if (
item.order.idProduct === idproduct &&
item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT
) {
totalQuantity += item.order.quantity || 0
}
2023-12-17 19:19:10 +01:00
}
}
}
2023-12-17 19:19:10 +01:00
}
}
}
return totalQuantity
},
getOrdersCartByIdProduct:
(state: IProductsState) =>
(idproduct: string): IOrderCart[] | [] => {
try {
if (state.orders) {
const ris = state.orders.filter((orderscart: IOrderCart) => {
return orderscart.items!.some((item) => {
if (item.order)
return (
item.order.idProduct === idproduct &&
item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT
)
})
})
// console.log('Ordini ', ris)
return ris ? ris : []
}
} catch (e) {
console.error('Err', e)
2023-12-18 13:04:44 +01:00
}
return []
},
getOrdersCartInAttesaByIdProduct:
(state: IProductsState) =>
(idproduct: string): IOrderCart[] | [] => {
try {
if (state.orders) {
const ris = state.orders.filter((orderscart: IOrderCart) => {
return orderscart.items!.some((item) => {
if (item.order)
return (
item.order.idProduct === idproduct &&
item.order.status! <= shared_consts.OrderStatus.CHECKOUT_SENT
)
})
})
// console.log('Ordini ', ris)
return ris ? ris : []
}
} catch (e) {
console.error('Err', e)
}
return []
},
2023-12-27 02:58:23 +01:00
2021-09-02 03:22:13 +02:00
getRecordEmpty: (state: IProductsState) => (): IProduct => {
return getRecordProductEmpty()
2021-09-02 21:29:24 +02:00
},
2021-09-02 03:22:13 +02:00
},
actions: {
createOrderByProduct(product: IProduct, order: IOrder): IOrder {
const userStore = useUserStore()
2021-09-02 03:22:13 +02:00
const myorder: IOrder = {
userId: this.userActive._id,
idapp: import.meta.env.VITE_APP_ID,
2021-09-02 03:22:13 +02:00
status: shared_consts.OrderStatus.IN_CART,
2023-12-18 08:02:35 +01:00
TotalPriceProduct: 0,
TotalPriceProductCalc: 0,
2023-12-27 02:58:23 +01:00
idProduct: product._id,
product, // Copia tutto l'oggetto Product !
2023-12-27 02:58:23 +01:00
// Ordine:
2021-09-02 03:22:13 +02:00
price: product.price,
after_price: product.after_price,
quantity: order.quantity,
2023-12-20 21:56:30 +01:00
quantitypreordered: order.quantitypreordered,
idStorehouse: order.idStorehouse,
2023-12-28 21:00:10 +01:00
idGasordine: order.idGasordine,
//++Add Fields
}
2021-09-02 03:22:13 +02:00
return myorder
2021-09-02 03:22:13 +02:00
},
initcat() {
// rec.userId = this.userActive._id
2021-09-02 03:22:13 +02:00
return this.getRecordEmpty()
2021-09-02 03:22:13 +02:00
},
2023-12-27 02:58:23 +01:00
/*resetProducts() {
const arrprod = [...this.products]
this.products = []
this.products = [...arrprod]
},*/
2025-04-11 18:49:42 +02:00
async getProductById(id: string, forza?: boolean): Promise<IProduct> {
let prod = null
try {
if (!id) {
return null
}
if (this.products.length === 0 || forza) {
// Se non lo carico all'avvio, allora fai la chiamata al server
prod = await this.loadProductById(id)
} else {
prod = this.products.find((prod: IProduct) => prod._id === id)
}
} catch (e) {
console.error('Err', e)
2024-05-08 16:07:42 +02:00
}
2024-10-31 23:23:06 +01:00
return prod ? prod : getRecordProductEmpty()
2024-05-08 16:07:42 +02:00
},
async loadMyScrapingBook(isbn: string, forzacaricamento: boolean) {
return await Api.SendReq('/myscraping', 'POST', { isbn, forzacaricamento }).then((res) => {
if (res.data) {
return res.data.myscraping
}
})
return null
},
async loadProducts(loadonlyifempty?: boolean) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
2021-09-02 03:22:13 +02:00
//console.log('loadProducts')
2025-04-11 18:49:42 +02:00
// if (!globalStore.site.confpages.enableEcommerce)
// return null
2021-09-02 03:22:13 +02:00
// console.log('getProducts', 'userid=', this.userActive._id)
2021-09-02 03:22:13 +02:00
// if (this.userActive._id === '') {
2021-09-02 03:22:13 +02:00
// return new Types.AxiosError(0, null, 0, '')
// }
if (loadonlyifempty) {
if (this.products?.length > 0) return true
}
let ris = null
2021-09-02 03:22:13 +02:00
let myIdActiveSelected = userStore.my._id
if (tools.isSeller())
myIdActiveSelected = tools.getCookie(tools.COOK_SELCART, userStore.my._id, false)
const trovato = userStore.usersList.find(
(user: IUserShort) => user._id === myIdActiveSelected
)
if (trovato) this.userActive = trovato
else this.userActive = userStore.my
console.log('userActive', this.userActive)
ris = await Api.SendReq('/products', 'POST', { userId: this.userActive._id })
2021-09-02 03:22:13 +02:00
.then((res) => {
if (res.data.products) {
// console.log('aggiorna prodotti')
this.products = []
this.products = res.data.products
2021-09-02 03:22:13 +02:00
} else {
this.products = []
2021-09-02 03:22:13 +02:00
}
if (res.data.orders) {
this.orders = []
this.orders = res.data.orders
} else {
this.orders = []
}
return res
2021-09-02 03:22:13 +02:00
})
.catch((error) => {
console.log('error getProducts', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2021-09-02 03:22:13 +02:00
// ApiTables.aftercalling(ris, checkPending, 'categories')
return ris
2021-09-02 03:22:13 +02:00
},
2024-01-13 00:29:02 +01:00
async updateOrderByOrder(idOrdersCart: string, idOrder: string, paramstoupdate: any) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
2021-09-02 03:22:13 +02:00
2024-01-13 00:29:02 +01:00
// console.log('loadProducts')
if (!globalStore.site.confpages.enableEcommerce) return null
2021-09-02 03:22:13 +02:00
console.log('updateOrderByOrder', 'userid=', this.userActive._id)
2024-01-13 00:29:02 +01:00
let ris = null
2024-01-13 00:29:02 +01:00
ris = await Api.SendReq('/orders/updateord', 'POST', {
idOrdersCart,
idOrder,
paramstoupdate,
})
2024-01-13 00:29:02 +01:00
.then((res) => {
let myorderscart = res.data.orderscart
2024-01-13 00:29:02 +01:00
if (res) {
myorderscart = res.data && res.data.orderscart ? res.data.orderscart : null
2024-01-13 00:29:02 +01:00
if (myorderscart) {
const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id)
2024-01-13 00:29:02 +01:00
if (idord >= 0) {
console.log('aggiorna ordine')
this.orders[idord] = { ...myorderscart }
2024-01-13 00:29:02 +01:00
}
}
}
return myorderscart
2024-01-13 00:29:02 +01:00
})
.catch((error) => {
console.log('error updateOrderByOrder', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2024-01-13 00:29:02 +01:00
// ApiTables.aftercalling(ris, checkPending, 'categories')
return ris
2024-01-13 00:29:02 +01:00
},
async updateOrdersCartById(idOrdersCart: string, paramstoupdate: any) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
2024-01-13 00:29:02 +01:00
// console.log('loadProducts')
if (!globalStore.site.confpages.enableEcommerce) return null
2024-01-13 00:29:02 +01:00
console.log('updateOrdersCartById', 'userid=', this.userActive._id)
2024-01-13 00:29:02 +01:00
let ris = null
2024-01-13 00:29:02 +01:00
ris = await Api.SendReq('/orders/update', 'POST', { idOrdersCart, paramstoupdate })
.then((res) => {
let myorderscart = res.data.orderscart
2024-01-13 00:29:02 +01:00
if (res) {
if (myorderscart) {
const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id)
2024-01-13 00:29:02 +01:00
if (idord >= 0) {
console.log('aggiorna orderscart')
this.orders[idord] = myorderscart
2024-01-13 00:29:02 +01:00
}
}
}
return myorderscart
2024-01-13 00:29:02 +01:00
})
.catch((error) => {
console.log('error updateOrderByOrder', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2024-01-13 00:29:02 +01:00
// ApiTables.aftercalling(ris, checkPending, 'categories')
return ris
2024-01-13 00:29:02 +01:00
},
async loadProductById(id: string, forzacaricamento?: boolean) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
2024-01-13 00:29:02 +01:00
let ris = null
2021-09-02 03:22:13 +02:00
let myprod = null
2021-09-02 03:22:13 +02:00
if (this.products && !forzacaricamento) {
// cerca su this.products
myprod = this.products.find((prod: IProduct) => prod._id === id)
if (myprod) {
return myprod
}
}
2021-09-02 03:22:13 +02:00
2024-01-13 00:29:02 +01:00
ris = await Api.SendReq('/products/id/' + id, 'GET', null)
2021-09-02 03:22:13 +02:00
.then((res) => {
console.log('product', res.data.product)
if (res.data.product) {
// console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
this.updateDataProduct(res)
return res.data.product
2021-09-02 03:22:13 +02:00
} else {
return null
2021-09-02 03:22:13 +02:00
}
})
.catch((error) => {
console.log('error getProduct', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2021-09-02 03:22:13 +02:00
return ris
2021-09-02 03:22:13 +02:00
},
async loadOrders() {
// console.log('loadOrders')
const userStore = useUserStore()
const globalStore = useGlobalStore()
2021-09-02 03:22:13 +02:00
if (!globalStore.site.confpages.enableEcommerce) return null
2021-09-02 03:22:13 +02:00
if (!this.userActive._id) return null
// if (this.userActive._id === '') {
2021-09-02 03:22:13 +02:00
// return new Types.AxiosError(0, null, 0, '')
// }
let ris = null
2021-09-02 03:22:13 +02:00
ris = await Api.SendReq('/cart/' + this.userActive._id, 'GET', null)
2021-09-02 03:22:13 +02:00
.then((res) => {
if (res.data && res.data.cart) {
// console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
this.cart = res.data.cart
2021-09-02 03:22:13 +02:00
} else {
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
2021-09-02 03:22:13 +02:00
}
this.updateDataProduct(res)
return res
2021-09-02 03:22:13 +02:00
})
.catch((error) => {
console.log('error loadOrders', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2021-09-02 03:22:13 +02:00
// ApiTables.aftercalling(ris, checkPending, 'categories')
return ris
2021-09-02 03:22:13 +02:00
},
2021-09-02 21:29:24 +02:00
async removeFromCart({ order }: { order: IOrder }) {
const userStore = useUserStore()
2021-09-02 03:22:13 +02:00
return Api.SendReq('/cart/' + this.userActive._id, 'DELETE', { orderId: order._id }).then(
(res) => {
this.updateDataProduct(res)
2021-09-02 03:22:13 +02:00
return res
}
)
2021-09-02 03:22:13 +02:00
},
2024-02-13 18:13:36 +01:00
async getGestoreOrdini({ idGasordine }: { idGasordine: string }) {
const userStore = useUserStore()
2024-02-13 18:13:36 +01:00
let useractive = this.userActive._id
if (!useractive) useractive = userStore.my._id
2024-02-13 18:13:36 +01:00
return Api.SendReq('/cart/' + useractive + '/gestord', 'POST', { idGasordine }).then(
(res) => {
if (res) return res.data.arrout
else return []
}
)
2024-02-13 18:13:36 +01:00
},
async addToCart({
product,
order,
addqty,
}: {
product: IProduct
order: IOrder
addqty: boolean
}) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
2021-09-02 03:22:13 +02:00
if (!globalStore.site.confpages.enableEcommerce) return null
2021-09-02 03:22:13 +02:00
let neworder = null
// Controlla se esiste già nel carrello, allora semplicemente aggiungerò la quantità:
if (this.existProductInCart(product._id)) {
const ordcart = this.getOrderProductInCart(product._id)
if (ordcart) {
if (!addqty && ordcart.quantity + ordcart.quantitypreordered === 1) {
// sto per rimuovere l'ultimo pezzo, quindi cancello direttamente
const risrem = await this.removeFromCart({ order: ordcart })
if (risrem) {
order.quantity = 0
order.quantitypreordered = 0
return true
} else {
return false
}
}
return await this.addSubQtyToItem({
addqty,
subqty: !addqty,
order: ordcart,
}).then((res: any) => {
if (res && res.msgerr) {
return res
} else if (res && res.risult) {
order.quantity = res.myord.quantity
order.quantitypreordered = res.myord.quantitypreordered
}
return res
})
}
} else {
2023-12-20 21:56:30 +01:00
if (this.isQtyAvailableByProduct(product)) {
order.quantity = product.minBuyQty || 1
order.quantitypreordered = 0
2023-12-20 21:56:30 +01:00
} else {
if (this.isInPreorderByProduct(product)) {
order.quantitypreordered = product.minBuyQty || 1
order.quantity = 0
2023-12-20 21:56:30 +01:00
}
}
if (!order.idStorehouse) {
if (product.storehouses.length === 1) {
order.idStorehouse = product.storehouses[0]._id
} else {
2025-03-01 14:14:43 +01:00
try {
order.idStorehouse = globalStore.storehouses?.length
? globalStore.storehouses[0]._id
: ''
} catch (e) {}
}
}
2023-12-28 21:00:10 +01:00
if (!order.idGasordine && order.quantitypreordered > 0) {
2024-01-16 16:56:57 +01:00
if (product.gasordine && product.gasordine._id) {
order.idGasordine = product.gasordine._id
2023-12-28 21:00:10 +01:00
} else {
order.idGasordine = globalStore.gasordines?.length ? globalStore.gasordines[0]._id : ''
2023-12-28 21:00:10 +01:00
}
}
2023-12-18 12:11:22 +01:00
if (order.idStorehouse) {
neworder = this.createOrderByProduct(product, order)
2023-12-18 12:11:22 +01:00
}
}
2021-09-02 03:22:13 +02:00
2023-12-18 12:11:22 +01:00
// if (neworder && !neworder.idStorehouse)
// return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store')
2021-09-02 03:22:13 +02:00
console.log('addToCart', 'userid=', this.userActive._id, neworder)
2021-09-02 03:22:13 +02:00
let ris = null
2021-09-02 03:22:13 +02:00
ris = await Api.SendReq('/cart/' + this.userActive._id, 'POST', { order: neworder })
2021-09-02 03:22:13 +02:00
.then((res) => {
if (res.data.cart) {
// console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
this.cart = res.data.cart
2021-09-02 03:22:13 +02:00
} else {
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
2021-09-02 03:22:13 +02:00
}
this.updateDataProduct(res)
2021-09-02 03:22:13 +02:00
return { risult: !!res, myord: res.data.myord, msgerr: res.data.msgerr }
2021-09-02 03:22:13 +02:00
})
.catch((error) => {
console.log('error addToCart', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2021-09-02 03:22:13 +02:00
// ApiTables.aftercalling(ris, checkPending, 'categories')
return ris
2021-09-02 03:22:13 +02:00
},
async addSubQtyToItem({
addqty,
subqty,
order,
}: {
addqty: boolean
subqty: boolean
order: IOrder
}) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
2021-09-02 03:22:13 +02:00
if (!globalStore.site.confpages.enableEcommerce) return null
2021-09-02 03:22:13 +02:00
// console.log('addSubQtyToItem', 'userid=', this.userActive._id, order)
2021-09-02 03:22:13 +02:00
let ris = null
2021-09-02 03:22:13 +02:00
ris = await Api.SendReq('/cart/' + this.userActive._id, 'POST', { addqty, subqty, order })
.then((res: any) => {
this.updateDataProduct(res)
2021-09-02 03:22:13 +02:00
return { risult: !!res, myord: res.data.myord, msgerr: res.msgerr }
2021-09-02 03:22:13 +02:00
})
.catch((error) => {
console.log('error addSubQtyToItem', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2021-09-02 03:22:13 +02:00
// ApiTables.aftercalling(ris, checkPending, 'categories')
return ris
2021-09-02 03:22:13 +02:00
},
getOptions(sendmail: boolean) {
return {
sendmail,
}
2024-01-03 15:46:48 +01:00
},
async CreateOrdersCart({
cart_id,
status,
note,
}: {
cart_id: string
status: number
note: string
}) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
2021-09-02 03:22:13 +02:00
if (!globalStore.site.confpages.enableEcommerce) return null
2021-09-02 03:22:13 +02:00
if (!this.userActive._id) return null
let ris = null
2021-09-02 03:22:13 +02:00
ris = await Api.SendReq('/cart/' + this.userActive._id + '/createorderscart', 'POST', {
cart_id,
status,
note,
options: this.getOptions(true),
})
2023-12-13 19:18:00 +01:00
.then((res) => {
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_SENT) {
// Cancella il Carrello, ho creato l'ordine !
this.cart = {}
2023-12-13 19:18:00 +01:00
}
this.updateDataProduct(res)
2023-12-13 19:18:00 +01:00
return res.data.recOrderCart
2023-12-13 19:18:00 +01:00
})
.catch((error) => {
console.log('error UpdateStatusCart', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2023-12-13 19:18:00 +01:00
return ris
2023-12-13 19:18:00 +01:00
},
/*async UpdateStatusCart({ ordercart_id, status }: { ordercart_id: string, status: number }) {
2023-12-13 19:18:00 +01:00
const userStore = useUserStore()
const globalStore = useGlobalStore()
if (!globalStore.site.confpages.enableEcommerce)
return null
let ris = null
2024-01-03 15:46:48 +01:00
ris = await Api.SendReq('/cart/updatestatuscart', 'POST', { ordercart_id, status, options: this.getOptions() })
2021-09-02 03:22:13 +02:00
.then((res) => {
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_SENT) {
this.cart = {}
}
this.updateDataProduct(res)
2023-12-14 15:20:27 +01:00
2021-09-02 03:22:13 +02:00
return res.data.status
})
.catch((error) => {
console.log('error UpdateStatusCart', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error)
})
return ris
},*/
2024-01-03 15:46:48 +01:00
async UpdateOrderCartStatus({
order_id,
status,
sendmail,
}: {
order_id: string
status: number
sendmail: boolean
}) {
const userStore = useUserStore()
const globalStore = useGlobalStore()
if (!globalStore.site.confpages.enableEcommerce) return null
let ris = null
ris = await Api.SendReq('/cart/' + this.userActive._id + '/ordercartstatus', 'POST', {
order_id,
status,
options: this.getOptions(sendmail),
})
2021-09-02 03:22:13 +02:00
.then((res) => {
this.updateDataProduct(res)
return res.data.status
2021-09-02 03:22:13 +02:00
})
.catch((error) => {
console.log('error UpdateOrderCartStatus', error)
userStore.setErrorCatch(error)
return new Types.AxiosError(
serv_constants.RIS_CODE_ERR,
null,
toolsext.ERR_GENERICO,
error
)
})
2021-09-02 03:22:13 +02:00
return ris
2021-09-02 03:22:13 +02:00
},
async addtoCartBase({
$q,
t,
id,
order,
addqty,
}: {
$q: any
t: any
id: string
order: IOrder
addqty: boolean
}) {
let product = await this.getProductById(id)
return await this.addToCart({ product, order, addqty }).then((ris) => {
if (ris && ris.msgerr) {
tools.showNegativeNotif($q, ris.msgerr)
} else {
let strprod = t('ecomm.prodotto')
let msg = ''
console.log('ris', ris)
if (ris && ris.myord == null) {
msg = t('ecomm.prodotto_tolto')
tools.showNotif($q, msg)
return
}
if (ris === null || ris.myord == null) {
msg = t('ecomm.error_cart')
tools.showNegativeNotif($q, msg)
return
2023-12-21 01:34:39 +01:00
} else {
let qta = ris.myord.quantity + ris.myord.quantitypreordered
if (qta > 1 || qta === 0) strprod = t('ecomm.prodotti')
if (qta >= 0) {
let totalPrice = this.cart.totalPrice ? this.cart.totalPrice.toFixed(2) : 0
let tot = totalPrice + ' €'
msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta, tot })
2023-12-21 01:34:39 +01:00
}
}
if (ris === null || ris.myord.quantity === 0) tools.showNotif($q, msg)
else tools.showPositiveNotif($q, msg, undefined, 'prodotto')
}
//updateproduct()
2023-12-21 01:34:39 +01:00
return ris
})
2023-12-20 22:11:52 +01:00
},
2023-12-20 21:56:30 +01:00
2023-12-21 01:34:39 +01:00
getQuantityByOrder($t: any, order: IOrder): string {
let mystr = ''
2023-12-20 21:56:30 +01:00
if (order.quantity > 0) {
mystr += order.quantity
2023-12-20 21:56:30 +01:00
}
if (order.quantitypreordered > 0 && order.quantity > 0) {
mystr += ' ' + $t('ecomm.available')
mystr += ' + '
2023-12-21 01:34:39 +01:00
}
2023-12-20 21:56:30 +01:00
if (order.quantitypreordered > 0) {
mystr += ' ' + order.quantitypreordered + ' '
2023-12-20 21:56:30 +01:00
}
return mystr
2023-12-20 21:56:30 +01:00
},
2023-12-21 01:34:39 +01:00
isQtyAvailableByProduct(product: IProduct): boolean {
if (product) {
return product.quantityAvailable! > 0
2023-12-21 01:34:39 +01:00
}
return false
2023-12-21 01:34:39 +01:00
},
isInPreorderByProduct(product: IProduct): boolean {
if (product) {
return product.bookableAvailableQty! > 0
2023-12-21 01:34:39 +01:00
}
return false
2023-12-21 01:34:39 +01:00
},
isQtyAvailableByOrder(order: IOrder): boolean {
if (order && order.product) {
return this.isQtyAvailableByProduct(order.product)
2023-12-21 01:34:39 +01:00
}
return false
2023-12-21 01:34:39 +01:00
},
isInPreorderByOrder(order: IOrder): boolean {
if (order && order.product) {
return this.isInPreorderByProduct(order.product)
2023-12-21 01:34:39 +01:00
}
return false
2023-12-21 01:34:39 +01:00
},
getSingleGasordine(order: IOrder, short: boolean): string {
try {
const mygas = order.gasordine
if (mygas) {
if (short) return mygas.name!
else
return (
mygas.name +
' (' +
mygas.city +
') ' +
translate('gas.dataora_chiusura_ordini') +
': ' +
tools.getstrDateShort(mygas.dataora_chiusura_ordini) +
' ' +
translate('gas.data_arrivo_merce') +
': ' +
tools.getstrDateShort(mygas.data_arrivo_merce) +
' ' +
translate('gas.dataora_ritiro') +
': ' +
tools.getstrDateShort(mygas.dataora_ritiro)
)
} else return ''
} catch (e) {
return ''
}
},
getQtyAvailable(myproduct: IProduct): number {
let qty = myproduct.quantityAvailable!
return qty
},
getQtyBookableAvailable(myproduct: IProduct): number {
let qty = myproduct.bookableAvailableQty!
return qty
},
2023-12-29 21:17:25 +01:00
getQtyBloccataAvailable(myproduct: IProduct): number {
let qty = myproduct.stockBloccatiQty
return qty
2023-12-29 21:17:25 +01:00
},
getQtyBloccataBookableAvailable(myproduct: IProduct): number {
let qty = myproduct.bookableGASBloccatiQty
return qty
2023-12-29 21:17:25 +01:00
},
enableSubQty(myorder: IOrder): boolean {
let qty = myorder.quantity + myorder.quantitypreordered
return qty ? qty > 0 : false
},
2024-02-15 18:59:13 +01:00
CanDeleteIfSub(myorder: IOrder): boolean {
let qty = myorder.quantity + myorder.quantitypreordered
2024-02-15 18:59:13 +01:00
qty = qty - this.qtaNextSub(myorder, myorder.product!)
return qty === 0
2024-02-15 18:59:13 +01:00
},
enableAddQty(myorder: IOrder, myproduct: IProduct): boolean {
const globalStore = useGlobalStore()
if (globalStore.site.ecomm && globalStore.site.ecomm.enablePreOrders) {
return (
(this.getQtyBookableAvailable(myproduct) > 0 &&
(myproduct.maxBookableSinglePersQty === 0 ||
myorder.quantitypreordered + 1 < myproduct.maxBookableSinglePersQty)) ||
(this.getQtyAvailable(myproduct) > 0 &&
(myproduct.maxBookableSinglePersQty === 0 ||
myorder.quantity + 1 < myproduct.maxBookableSinglePersQty))
)
} else {
return (
this.getQtyAvailable(myproduct) > 0 &&
(myproduct.maxBookableSinglePersQty === 0 ||
myorder.quantity + 1 < myproduct.maxBookableSinglePersQty)
)
}
},
qtaNextAdd(myorder: IOrder, myproduct: IProduct): number {
let step = myproduct.minStepQty
if (this.getQtyAvailable(myproduct) > 0) {
if (myorder.quantity === 0) step = myproduct.minBuyQty
} else {
if (myorder.quantitypreordered === 0) step = myproduct.minBuyQty
}
2024-02-06 20:13:06 +01:00
if (step === 0) {
step = 1
2024-02-06 20:13:06 +01:00
}
return step
},
qtaNextSub(myorder: IOrder, myproduct: IProduct) {
let step = myproduct.minStepQty
let minqta = myproduct.minBuyQty
if (this.getQtyAvailable(myproduct) > 0) {
if (myorder.quantity === minqta) step = minqta
} else {
if (myorder.quantitypreordered === minqta) step = minqta
}
return step
},
2023-12-28 21:00:10 +01:00
getNumQtaGas() {
const arrprod = this.getProducts(shared_consts.PROD.GAS)
return arrprod.length
2023-12-28 21:00:10 +01:00
},
2024-01-23 00:10:52 +01:00
getNumQtaTutti() {
const arrprod = this.getProducts(shared_consts.PROD.TUTTI)
return arrprod.length
2024-01-23 00:10:52 +01:00
},
2023-12-28 21:00:10 +01:00
getNumQtaBottega() {
const arrprod = this.getProducts(shared_consts.PROD.BOTTEGA)
return arrprod.length
2024-01-09 15:32:21 +01:00
},
2023-12-28 21:00:10 +01:00
changeuserActive(valuerec: any) {
if (valuerec) {
console.log('valuerec', valuerec)
tools.setCookie(tools.COOK_SELCART, valuerec._id)
this.products = []
this.orders = []
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
this.loadOrders()
this.loadProducts()
}
},
2024-01-09 15:32:21 +01:00
async sendMailToTheBuyer(idOrdersCart: string, templemail_id: string, test: boolean) {
return await Api.SendReq('/orders/sendmail', 'POST', {
templemail_id,
idOrdersCart,
previewonly: tools.isDebug(),
test,
}).then((res) => {
console.log('res', res)
if (res) return res.data
else return null
})
2024-01-09 15:32:21 +01:00
},
2023-12-28 21:00:10 +01:00
2024-02-13 18:13:36 +01:00
getStrInfoOrder(t: any, order: IOrder) {
let mystr = ''
let qtyrisult: any
2024-02-13 18:13:36 +01:00
if (order.product) {
let qtystr = ''
let qtynum = 0
if (order.quantity > 0) qtynum += order.quantity
if (order.quantitypreordered > 0) qtynum += order.quantitypreordered
2024-02-13 18:13:36 +01:00
if (order.product.productInfo.sfuso && order.product.productInfo.weight)
qtyrisult = qtynum * order.product.productInfo.weight
else qtyrisult = qtynum + ' x ' + order.product.productInfo.weight
qtystr +=
qtyrisult +
' ' +
tools.getUnitsMeasure(
order.product.productInfo.unit,
true,
order.product.productInfo.weight
)
if (order.quantitypreordered > 0) qtystr += ' Pre-Ordinati'
mystr +=
'✅ [' +
qtystr +
'] ' +
order.product.productInfo.name +
' a ' +
order.price +
'€ ' +
(order.after_price ? order.after_price : '') +
'<br>Totale = ' +
order.TotalPriceProduct +
'€'
2024-02-13 18:13:36 +01:00
}
return mystr
2024-02-13 18:13:36 +01:00
},
getGasordineNameById(idGasordine: string) {
const globalStore = useGlobalStore()
const rec = globalStore.gasordines.find(
(gasordine: IGasordine) => gasordine._id === idGasordine
)
return rec ? rec.name : ''
},
2024-02-13 18:13:36 +01:00
getGasordines() {
const globalStore = useGlobalStore()
2024-02-13 18:13:36 +01:00
const myarr: any = [
{
id: 0,
label: 'Tutti',
value: '',
},
]
let ind = 1
if (globalStore.gasordines) {
globalStore.gasordines.forEach((gasordine: IGasordine) => {
if (gasordine) {
myarr.push({
id: ind,
label:
gasordine.name +
(gasordine.dataora_chiusura_ordini
? ' - chiusura: ' + tools.getstrDateShort(gasordine.dataora_chiusura_ordini)
: '') +
(gasordine.dataora_ritiro
? ' - consegna ' + tools.getstrDateShort(gasordine.dataora_ritiro)
: ''),
value: gasordine._id,
})
ind++
}
})
}
2024-02-13 18:13:36 +01:00
return myarr
2024-02-13 18:13:36 +01:00
},
2024-03-08 18:57:22 +01:00
getGasordinesActives() {
const globalStore = useGlobalStore()
2024-03-08 18:57:22 +01:00
return globalStore.gasordines.filter((rec) => rec.active)
2024-03-08 18:57:22 +01:00
},
getAutoriByArrayAuthors(authors?: IAuthor[]) {
2024-10-31 23:23:06 +01:00
// Gestione degli autori
let authorString = ''
2024-10-31 23:23:06 +01:00
if (authors && Array.isArray(authors)) {
// Crea un array di nomi completi
const fullNames = authors.map((author) => `${author.name} ${author.surname}`.trim())
2024-10-31 23:23:06 +01:00
// Formattazione degli autori
if (fullNames.length === 1) {
authorString = fullNames[0]
2024-10-31 23:23:06 +01:00
} else if (fullNames.length === 2) {
authorString = `${fullNames[0]} e ${fullNames[1]}`
2024-10-31 23:23:06 +01:00
} else if (fullNames.length > 2) {
const lastAuthor = fullNames.pop()
authorString = `${fullNames.join(', ')} e ${lastAuthor}`
2024-10-31 23:23:06 +01:00
}
}
return authorString
2024-10-31 23:23:06 +01:00
},
getkeyValStr(chiave: string, valore: any) {
try {
return ` ${chiave} = ${valore} `
} catch (e) {
return ` ${chiave}`
}
},
replaceKeyWordsByProduct(
optcatalogo: IOptCatalogo,
myproduct: IProduct,
testo: IText,
idPage?: string
) {
2024-11-19 19:19:14 +01:00
if (!myproduct || !testo.contenuto) {
return testo.contenuto
2024-10-31 23:23:06 +01:00
}
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) || ''
}
2024-10-31 23:23:06 +01:00
const maxDescriptionLength = testo.maxlength || 680
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
}
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
}
if (testo.contenuto.includes('{descrizione_estesa}')) {
let addtesto = false
const long_descr_macro = myproduct.productInfo.descrizione_completa_macro || ''
if (long_descr_macro.length > maxDescriptionLength && maxDescriptionLength > 0) {
addtesto = true
}
const addstrcontinua =
'<span class="book-link">👉🏻 <a href="{link_macro}" target="_blank">continua a leggere</a></span>'
let descrizione_completa_macro = addtesto
? long_descr_macro.substring(0, long_descr_macro.lastIndexOf(' ', maxDescriptionLength)) +
'...'
: long_descr_macro
if (addtesto) {
descrizione_completa_macro += addstrcontinua
}
replacements['{descrizione_estesa}'] = descrizione_completa_macro || ''
}
if (testo.contenuto.includes('{descrizione_breve_macro}')) {
const short_descr = myproduct.productInfo.descrizione_breve_macro || ''
replacements['{descrizione_breve_macro}'] =
short_descr.length > maxDescriptionLength && maxDescriptionLength > 0
? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...'
: short_descr
}
if (
testo.contenuto.includes('{descr_trafiletto_catalogo}') ||
testo.contenuto.includes('{descrizione_completa_macro}')
) {
const short_descr = myproduct.productInfo.descr_trafiletto_catalogo || ''
replacements['{descr_trafiletto_catalogo}'] =
short_descr.length > maxDescriptionLength && maxDescriptionLength > 0
? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...'
: short_descr
replacements['{descrizione_completa_macro}'] = replacements['{descr_trafiletto_catalogo}']
}
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
}
2024-10-31 23:23:06 +01:00
// Additional replacements based on the content
const keysToCheck = [
'{titolo}',
'{sottotitolo}',
'{categoria}',
'{sottocategoria}',
'{descr_categoria}',
'{pagine}',
'{isbn}',
'{misure}',
'{edizione}',
'{ristampa}',
'{argomento}',
'{date_pub}',
'{date_updated_fromGM}',
'{ranking_globale}',
'{venduti}',
'{formato}',
'{tipologia}',
'{stato}',
'{scalex}',
'{scaley}',
'{descr_trafiletto_catalogo}',
'{link_macro}',
'{qta}',
'{image_link}',
'{imagefile}',
'{casaeditrice}',
'{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 '{casaeditrice}':
replacements[key] = this.getCasaEditriceByIdPublisher(
myproduct.productInfo.idPublisher
)
break
2025-04-24 19:31:34 +02:00
case '{edizione}':
replacements[key] = myproduct.arrvariazioni?.[0]?.edizione || ''
break
2025-04-24 19:31:34 +02:00
case '{ristampa}':
replacements[key] = myproduct.arrvariazioni?.[0]?.ristampa || ''
break
case '{argomento}':
replacements[key] =
this.getCatProdsStrByCatProds(myproduct.productInfo.catprods!) || ''
break
case '{date_pub}':
replacements[key] = tools.getstrDateShort(myproduct.productInfo.date_pub) || ''
break
2025-04-24 19:31:34 +02:00
case '{date_updated_fromGM}':
replacements[key] =
tools.getstrDateShort(myproduct.productInfo.date_updated_fromGM) || ''
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 '{scalex}':
replacements[key] = optcatalogo.printable ? optcatalogo.areadistampa?.scalex : '1'
break
case '{scaley}':
replacements[key] = optcatalogo.printable ? optcatalogo.areadistampa?.scaley : '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 = `<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-ordini-by-idarticolo/${myproduct.productInfo.sku}" target="_blank">${myproduct.productInfo.totVen!}</a>`
const vLast3M = myproduct.productInfo.vLast3M! || 0
const vLast6M = myproduct.productInfo.vLast6M! || 0
const linkfatturati = `<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-fatturati-by-idarticolo/${myproduct.productInfo.sku}" target="_blank">${myproduct.productInfo.totFat! || 0}</a>`
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
}
}
}
2024-10-31 23:23:06 +01:00
// Esegue le sostituzioni
let result = testo.contenuto
2024-10-31 23:23:06 +01:00
for (const [key, value] of Object.entries(replacements)) {
result = result.replace(new RegExp(key, 'g'), value)
2024-10-31 23:23:06 +01:00
}
return result.trim()
2024-10-31 23:23:06 +01:00
},
getSubCatStrByProduct(myproductInfo: IProductInfo): string {
return this.getSubCatProdsStrBySubCatProds(myproductInfo.idSubCatProds || [])
},
getListProductBySumQuantity(idGasordine: string): ISingleProductOrdered[] {
const arrprod = this.orders.filter((rec: IOrderCart) => {
if (
idGasordine &&
!rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)
) {
return false // Skip records not matching gasordine condition
}
return true
})
const productMap = new Map<string, ISingleProductOrdered>()
arrprod.forEach((rec: IOrderCart) => {
rec.items?.forEach((item) => {
if (item.order && item.order.idGasordine === idGasordine) {
const productId: string = item.order.idProduct!
const qtyparz = item.order.quantity + item.order.quantitypreordered
if (productMap.has(productId)) {
const existingProduct: ISingleProductOrdered = productMap.get(productId)!
existingProduct.qty += qtyparz
existingProduct.subtotalPrice += item.order.price * qtyparz
existingProduct.subtotalPrice = Number(existingProduct.subtotalPrice.toFixed(2))
} else {
const sottocategoria =
item.order.product?.productInfo?.subcatprods &&
item.order.product?.productInfo?.subcatprods.length > 0
? item.order.product?.productInfo?.subcatprods[0].name
: ''
productMap.set(productId, {
subCat: sottocategoria,
strSubCatProds: this.getSubCatProdsStrBySubCatProds(
item.order.product?.productInfo?.idSubCatProds
),
index: productMap.size + 1,
idProduct: productId,
code: item.order.product?.productInfo.code,
codice_interno: item.order.product?.productInfo?.codice ?? '',
qty: qtyparz,
singlePrice: item.order.price,
subtotalPrice: Number((item.order.price * qtyparz).toFixed(2)),
productName: item.order.product?.productInfo?.name ?? '',
})
}
}
})
})
return Array.from(productMap.values())
},
getOptCatalogoTemplate() {
// Ottieni l'array delle pagine che in cataloghi sono dimensioni_def.isTemplate
let arr: any = []
const globalStore = useGlobalStore()
arr.push({ label: '[Nessuna]', value: '' })
for (const myelem of globalStore.myelems) {
if (
myelem.catalogo &&
myelem.catalogo.dimensioni_def &&
myelem.catalogo.dimensioni_def.isTemplate
) {
const page = globalStore.getPageById(myelem.idPage)
let pagename = page ? page.title! : ''
if (pagename) {
pagename = '[Pag: ' + pagename + '] '
}
const mylabel = pagename
arr.push({ label: mylabel, value: myelem._id })
}
}
return arr
},
getOptCatalogoPrintTemplate() {
// Ottieni l'array delle pagine che in cataloghi sono dimensioni_def.isTemplate
let arr: any = []
const globalStore = useGlobalStore()
arr.push({ label: '[Nessuna]', value: '' })
for (const myelem of globalStore.myelems) {
if (myelem.catalogo && myelem.catalogo.print_isTemplate) {
const page = globalStore.getPageById(myelem.idPage)
let pagename = page ? page.title! : ''
if (pagename) {
pagename = '[Pag: ' + pagename + '] '
}
const mylabel = pagename
arr.push({ label: mylabel, value: myelem._id })
}
}
return arr
},
getSchedeOpt(arrschede: ISchedaSingola[], tag?: string): any[] {
let arr: any = []
const globalStore = useGlobalStore()
arr.push({ label: '[Nessuna]', value: '' })
if (arrschede) {
arrschede.forEach((recscheda: ISchedaSingola) => {
let pagename = ''
if (recscheda.scheda) {
if (recscheda.idPageOrig) {
const page = globalStore.getPageById(recscheda.idPageOrig)
// const page = this.mypage?.find((page) => (`${page._id}`) === recscheda.idPageOrig)
pagename = page ? page.title! : ''
}
if (pagename) pagename = '[Pag: ' + pagename + '] '
const mylabel = pagename + (recscheda.scheda ? recscheda.scheda!.name : '')
if (!tag || mylabel.startsWith(tag)) {
arr.push({ label: mylabel, value: recscheda.scheda!._id })
}
}
})
}
return arr
},
addNewScheda(catalogo: IOptCatalogo) {
let maxorder = 0
catalogo!.arrSchede?.forEach((scheda) => {
if (scheda?.order > maxorder) {
maxorder = scheda.order
}
})
let testodef: IText = {}
testodef = tools.resetIText(testodef)
const defaultDimensioniPag = tools.resetRecIDimensioni(null)
defaultDimensioniPag.size = {
width: '800px',
height: '600px',
}
defaultDimensioniPag.margini = {
top: '12px',
bottom: '0px',
left: '0px',
right: '0px',
}
defaultDimensioniPag.padding = {
top: '0px',
bottom: '0px',
left: '0px',
right: '0px',
}
const defaultDimensioniRiga = tools.resetRecIDimensioni(null)
defaultDimensioniRiga.size = {
width: '800px',
height: '300px',
}
defaultDimensioniRiga.margini = {
top: '40px',
bottom: '0px',
left: '0px',
right: '0px',
}
defaultDimensioniRiga.padding = {
top: '0px',
bottom: '0px',
left: '0px',
right: '0px',
}
const defaultSchedaProdotto = tools.resetRecIDimensioni(null)
defaultSchedaProdotto.size = {
width: '360px',
height: '230px',
}
defaultSchedaProdotto.margini = {
top: '0px',
bottom: '0px',
left: '0px',
right: '0px',
}
defaultSchedaProdotto.padding = {
top: '0px',
bottom: '0px',
left: '0px',
right: '0px',
}
const dimensioni: IElementiScheda = {
pagina: {
dimensioni: defaultDimensioniPag,
testo_down: testodef,
testo_up: testodef,
testo_title: testodef,
},
riga: defaultDimensioniRiga,
scheda_prodotto: defaultSchedaProdotto,
immagine_prodotto: {
size: {
width: '150px',
height: '235px',
},
margini: {
top: '0px',
bottom: '0px',
left: '0px',
right: '0px',
},
padding: {
top: '0px',
bottom: '0px',
left: '0px',
right: '0px',
},
},
}
const newscheda: IMyScheda = {
_id: objectId(),
idapp: tools.appid()!,
isTemplate: false,
isPagIntro: false,
show_separatore: true,
name: 'Scheda Nuova',
dimensioni,
numschede_perRiga: 2,
numschede_perCol: 2,
testo_right_attaccato: {
contenuto: '',
maxlength: 0,
font: {
posiz_text: costanti.POSIZ_TESTO.A_DESTRA,
},
},
testo_right: {
contenuto: '',
maxlength: 0,
font: {
posiz_text: costanti.POSIZ_TESTO.A_DESTRA,
},
},
testo_bottom: {
contenuto: '',
maxlength: 0,
font: {
posiz_text: costanti.POSIZ_TESTO.IN_BASSO,
},
},
barcode: {
show: false,
format: '',
size: {
width: '2',
height: '100',
},
font: {
name: 'monospace',
size: '16px',
},
},
productTypes: [],
excludeproductTypes: [],
2025-04-24 19:31:34 +02:00
idTipologie: [],
editore: [],
argomenti: [],
author: '',
sort_field: '',
sort_dir: 0,
arrProdottiSpeciali: [],
etichette: {
novita: {
show: false,
months: 6,
},
bestseller: {
show: false,
quantiFattRaggiunti: 50,
},
},
}
if (!catalogo!.arrSchede) catalogo!.arrSchede = []
catalogo!.arrSchede.push({
_id: objectId(),
scheda: newscheda,
order: maxorder + 10,
numPagineMax: 0,
})
},
updateProductsByArray: (state: IProductsState) => (arrrec: IProduct[]) => {
if (arrrec && arrrec.length > 0) {
// update products array from this array
const myarr = state.products.filter(
(rec) => !arrrec.find((newrec) => newrec._id === rec._id)
)
state.products = myarr.concat(arrrec)
}
},
getPathByPage(idpag: string) {
let linkpage = ''
const globalStore = useGlobalStore()
if (idpag) {
const mypage = globalStore.getPageById(idpag)
if (mypage) linkpage = mypage.path!
}
return linkpage
},
populateDataWithlinkIdTemplate(optcatalogo: IOptCatalogo) {
// console.log('populateDataWithlinkIdTemplate')
const globalStore = useGlobalStore()
if (optcatalogo) {
try {
// LINK PAGINA
let idLinkTempl =optcatalogo.dimensioni_def.linkIdTemplate
if (idLinkTempl) {
const reccatalog = globalStore.sovrascriviPaginaDefaultFromTemplate(
idLinkTempl,
optcatalogo.dimensioni_def
)
if (reccatalog) {
optcatalogo.dimensioni_def.pagina = {
...reccatalog.dimensioni_def.pagina,
}
}
}
let idLinkPr = optcatalogo.print_linkIdTemplate
if (idLinkPr) {
const reccat2 = globalStore.sovrascriviAreadistampaFromTemplate(idLinkPr, optcatalogo)
if (reccat2) {
const optcatalogo2 = { ...optcatalogo }
// optcatalogo2.areadistampa = { ...reccat2.areadistampa};
optcatalogo2.areadistampa.margini = reccat2.areadistampa.margini
optcatalogo2.areadistampa.unit = reccat2.areadistampa.unit
optcatalogo2.areadistampa.scalex = reccat2.areadistampa.scalex
optcatalogo2.areadistampa.scaley = reccat2.areadistampa.scaley
optcatalogo2.areadistampa.scalecanvas = reccat2.areadistampa.scalecanvas
optcatalogo2.areadistampa.scale_printablex = reccat2.areadistampa.scale_printablex
optcatalogo2.areadistampa.scale_printabley = reccat2.areadistampa.scale_printabley
optcatalogo2.areadistampa.format = reccat2.areadistampa.format
optcatalogo2.areadistampa.format_printable = reccat2.areadistampa.format_printable
optcatalogo2.areadistampa.orientation = reccat2.areadistampa.orientation
optcatalogo2.areadistampa.compress = reccat2.areadistampa.compress
// optcatalogo = optcatalogo2;
// optcatalogo.areadistampa.margini = { left: '50'};
}
// console.log('areadistampa', optcatalogo.areadistampa)
}
for (const recscheda of optcatalogo.arrSchede!) {
let idtempl =recscheda.scheda?.linkIdTemplate
if (idtempl) {
// ricopia da Template:
let myscheda = globalStore.sovrascriviSchedaFromTemplate(
idtempl,
recscheda,
optcatalogo
)
if (myscheda) {
recscheda.scheda = { ...myscheda }
}
}
}
return optcatalogo
} catch (e) {
console.error('ERRORE in populateDataWithlinkIdTemplate', e)
}
}
// console.log(' FINE - populateDataWithlinkIdTemplate')
},
2024-02-13 18:13:36 +01:00
},
})