- Categorie

- ProductInfo
This commit is contained in:
Surya Paolo
2023-12-27 02:58:23 +01:00
parent c27c293fbf
commit 6be8ccc906
30 changed files with 612 additions and 198 deletions

View File

@@ -417,6 +417,13 @@ export const colTablecategories = [
AddCol(DuplicateRec),
]
export const colTableCatProd = [
AddCol({ name: 'name', label_trans: 'categories.name' }),
AddCol({ name: 'img', label_trans: 'categories.img' }),
AddCol(DeleteRec),
AddCol(DuplicateRec),
]
export const colTableStorehouse = [
AddCol({ name: 'name', label_trans: 'store.name' }),
AddCol({ name: 'description', label_trans: 'store.description' }),
@@ -1955,8 +1962,7 @@ export const colTableIscrittiArcadei = [
AddCol(DuplicateRec),
]
export const colTableProducts = [
AddCol({ name: 'active', label_trans: 'products.active', fieldtype: costanti.FieldType.boolean }),
export const colTableProductInfos = [
AddCol({ name: 'code', label_trans: 'products.code', required: true }),
AddCol({ name: 'codice_EAN', label_trans: 'products.codice_EAN' }),
AddCol({ name: 'barcode', label_trans: 'products.barcode' }),
@@ -1964,7 +1970,41 @@ export const colTableProducts = [
AddCol({ name: 'description', label_trans: 'products.description', fieldtype: costanti.FieldType.html }),
AddCol({ name: 'icon', label_trans: 'products.icon' }),
AddCol({ name: 'img', label_trans: 'products.img' }),
// AddCol({ name: 'idProducer', label_trans: 'products.idProducer' }),
AddCol({
name: 'department',
label_trans: 'products.department',
fieldtype: costanti.FieldType.select,
jointable: 'departments',
}),
AddCol({
name: 'idCatProds',
label_trans: 'products.category',
fieldtype: costanti.FieldType.multiselect,
jointable: 'catprods',
}),
AddCol({ name: 'color', label_trans: 'products.color' }),
AddCol({ name: 'size', label_trans: 'products.size' }),
AddCol({ name: 'weight', label_trans: 'products.weight', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'vegan', label_trans: 'products.vegan', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'unit', label_trans: 'products.unit',
fieldtype: costanti.FieldType.select, jointable: 'units', }),
AddCol({ name: 'stars', label_trans: 'products.stars', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'date', label_trans: 'products.date', fieldtype: costanti.FieldType.date }),
AddCol({ name: 'ingredienti', label_trans: 'products.ingredienti' }),
AddCol({ name: 'valori_nutrizionali', label_trans: 'products.valori_nutrizionali' }),
AddCol({ name: 'note', label_trans: 'products.note' }),
AddCol(DeleteRec),
AddCol(DuplicateRec),
]
export const colTableProducts = [
AddCol({ name: 'active', label_trans: 'products.active', fieldtype: costanti.FieldType.boolean }),
AddCol({
name: 'idProductInfo',
label_trans: 'products.productInfo',
fieldtype: costanti.FieldType.select,
jointable: 'productinfos',
}),
AddCol({
name: 'idProducer',
label_trans: 'products.producer',
@@ -1995,39 +2035,19 @@ export const colTableProducts = [
fieldtype: costanti.FieldType.multiselect,
jointable: 'scontisticas',
}),
AddCol({
name: 'department',
label_trans: 'products.department',
fieldtype: costanti.FieldType.select,
jointable: 'departments',
}),
// AddCol({ name: 'department', label_trans: 'products.department' }),
AddCol({
name: 'category',
label_trans: 'products.category',
fieldtype: costanti.FieldType.multiselect,
jointable: 'categorys',
}),
AddCol({ name: 'price', label_trans: 'products.price', fieldtype: costanti.FieldType.number, required: true }),
AddCol({ name: 'price_acquistato', label_trans: 'products.price_acquistato', fieldtype: costanti.FieldType.number, required: true }),
AddCol({ name: 'after_price', label_trans: 'products.after_price' }),
AddCol({ name: 'color', label_trans: 'products.color' }),
AddCol({ name: 'size', label_trans: 'products.size' }),
/*AddCol({
name: 'quantityAvailable',
label_trans: 'products.quantityAvailable',
fieldtype: costanti.FieldType.number
}),
AddCol({
name: 'bookableAvailableQty',
label_trans: 'products.bookableAvailableQty',
fieldtype: costanti.FieldType.number
}), */
AddCol({
name: 'minBuyQty',
label_trans: 'products.minBuyQty',
fieldtype: costanti.FieldType.number
}),
AddCol({
name: 'maxBookableQty',
label_trans: 'products.maxBookableQty',
fieldtype: costanti.FieldType.number
}),
AddCol({
name: 'stockQty',
label_trans: 'products.stockQty',
@@ -2040,15 +2060,6 @@ export const colTableProducts = [
}),
AddCol({ name: 'canBeShipped', label_trans: 'products.canBeShipped', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'canBeBuyOnline', label_trans: 'products.canBeBuyOnline', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'weight', label_trans: 'products.weight', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'vegan', label_trans: 'products.vegan', fieldtype: costanti.FieldType.boolean }),
AddCol({ name: 'unit', label_trans: 'products.unit',
fieldtype: costanti.FieldType.select, jointable: 'units', }),
AddCol({ name: 'stars', label_trans: 'products.stars', fieldtype: costanti.FieldType.number }),
AddCol({ name: 'date', label_trans: 'products.date', fieldtype: costanti.FieldType.date }),
AddCol({ name: 'ingredienti', label_trans: 'products.ingredienti' }),
AddCol({ name: 'valori_nutrizionali', label_trans: 'products.valori_nutrizionali' }),
AddCol({ name: 'note', label_trans: 'products.note' }),
AddCol(DeleteRec),
AddCol(DuplicateRec),
]
@@ -3560,7 +3571,14 @@ export const fieldsTable = {
label: 'Prodotti',
columns: colTableProducts,
colkey: '_id',
collabel: 'name',
collabel: '_id',
},
{
value: 'productinfos',
label: 'Info Prodotti',
columns: colTableProductInfos,
colkey: '_id',
collabel: (rec: any) => `${rec.name} (${rec.code})`,
},
{
value: 'producers',
@@ -3597,6 +3615,13 @@ export const fieldsTable = {
colkey: '_id',
collabel: 'name',
},
{
value: 'catprods',
label: 'Categorie',
columns: colTableCatProd,
colkey: '_id',
collabel: 'name',
},
{
value: 'gasordines',
label: 'Gas Ordini',

View File

@@ -8253,7 +8253,7 @@ export const tools = {
},
getWeightTotalByOrder(order: IOrder) {
return (order.product && order.product.weight ? order.product.weight : 1) * (order.quantitypreordered | 0 + order.quantity | 0)
return (order.product && order.product.productInfo && order.product.productInfo.weight ? order.product.productInfo.weight : 1) * (order.quantitypreordered | 0 + order.quantity | 0)
},
isPartecipero(myrec: any) {
@@ -8275,7 +8275,13 @@ export const tools = {
return inputString.replace('\\', '').replace(/"/g, '')
},
isObjectEmpty(obj: any) {
return Object.keys(obj).length === 0;
},
strToVal(mystr: string) {
return parseInt(mystr)
}
// FINE !

View File

@@ -1,4 +1,4 @@
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState } from 'model'
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd } from 'model'
import { Api } from '@api'
import { serv_constants } from '@src/store/Modules/serv_constants'
@@ -14,25 +14,69 @@ import { ref } from 'vue'
import translate from '@src/globalroutines/util'
function getRecordProductInfoEmpty(): IProductInfo {
return {
code: '',
name: '',
description: '',
department: '',
catprods: [],
color: '',
size: '',
weight: 0,
unit: 0,
stars: 0,
date: tools.getDateNow(),
icon: '',
img: '',
}
}
function getRecordProductEmpty() {
return {
active: false,
productInfo: {
img: '', code: '', name: '',
},
storehouses: [], scontisticas: [],
price: 0, stockQty: 0, bookableQty: 0, gasordines: [],
idGasordines: [], minBuyQty: 1, maxBookableQty: 0,
}
}
export const useProducts = defineStore('Products', {
state: (): IProductsState => ({
products: [],
cart: { items: [], totalPrice: 0, totalQty: 0, userId: '' },
orders: [],
catprods: [],
productInfos: [],
}),
getters: {
getCatProds: (state: IProductsState) => (): ICatProd[] => {
return state.catprods
},
getNumProdTot: (state: IProductsState) => (): number => {
return state.products.length
},
getProducts: (state: IProductsState) => (cosa?: number): IProduct[] => {
if (!!cosa) {
let ris = null
if (cosa === shared_consts.PROD.GAS) {
ris = state.products.filter((rec) => (rec.idGasordines && rec.idGasordines.length > 0))
} else if (cosa === shared_consts.PROD.BOTTEGA) {
ris = state.products.filter((rec) => (!rec.idGasordines || (rec.idGasordines && rec.idGasordines.length === 0)))
}
return ris ? ris : []
return state.products.filter((rec: IProduct) => {
const hasGasOrdines = rec.idGasordines && rec.idGasordines.length > 0;
if ((cosa === shared_consts.PROD.GAS && hasGasOrdines) ||
(cosa === shared_consts.PROD.BOTTEGA && ((!hasGasOrdines || (hasGasOrdines && rec.idGasordines?.length === 0))))) {
return true;
}
return false;
});
} else {
return state.products
return state.products;
}
},
@@ -65,18 +109,24 @@ export const useProducts = defineStore('Products', {
},
getProductById: (state: IProductsState) => (id: string): IProduct => {
const prod = state.products.find((prod: IProduct) => prod._id === id)
return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0, stockQty: 0, bookableQty: 0, gasordines: [], idGasordines: [], minBuyQty: 1 }
return prod ? prod : getRecordProductEmpty()
},
getProductByCode: (state: IProductsState) => (code: string): IProduct => {
const prod = state.products.find((prod: IProduct) => prod.code === code)
return prod ? prod : {
active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0,
gasordines: [], idGasordines: [],
stockQty: 0, bookableQty: 0, minBuyQty: 1
if (!code) {
return getRecordProductEmpty()
}
const prod = state.products.find((prod: IProduct) => {
if (prod.productInfo.code === code)
return prod
else
return null
})
return prod ? prod : getRecordProductEmpty()
},
getCart: (state: IProductsState) => (): ICart => {
@@ -218,12 +268,14 @@ export const useProducts = defineStore('Products', {
return []
},
getRecordEmpty: (state: IProductsState) => (): IProduct => {
const tomorrow = tools.getDateNow()
tomorrow.setDate(tomorrow.getDate() + 1)
return {
productInfo: getRecordProductInfoEmpty(),
// _id: tools.getDateNow().toISOString(), // Create NEW
active: false,
idProducer: '',
@@ -236,63 +288,40 @@ export const useProducts = defineStore('Products', {
producer: {},
storehouses: [],
provider: {},
code: '',
name: '',
description: '',
department: '',
category: '',
price: 0.0,
color: '',
size: '',
quantityAvailable: 0,
bookableAvailableQty: 0,
stockQty: 0,
minBuyQty: 1,
maxBookableQty: 0,
bookableQty: 0,
canBeShipped: false,
QuantitaOrdinateInAttesa: 0,
QuantitaPrenotateInAttesa: 0,
canBeBuyOnline: false,
weight: 0,
unit: 0,
stars: 0,
date: tools.getDateNow(),
icon: '',
img: '',
}
},
},
actions: {
getProductsByCategory(category: string): any[] {
return this.products.filter((rec) => rec.category === category)
},
createOrderByProduct(product: IProduct, order: IOrder): IOrder {
const userStore = useUserStore()
const myorder: IOrder = {
userId: userStore.my._id,
idapp: process.env.APP_ID,
idProduct: product._id,
idProducer: product.idProducer,
status: shared_consts.OrderStatus.IN_CART,
TotalPriceProduct: 0,
idProduct: product._id,
product, // Copia tutto l'oggetto Product !
// Ordine:
price: product.price,
after_price: product.after_price,
color: product.color,
size: product.size,
weight: product.weight,
quantity: order.quantity,
quantitypreordered: order.quantitypreordered,
idStorehouse: order.idStorehouse,
idGasordine: order.idGasordine,
idScontisticas: product.idScontisticas,
}
if (product.storehouses.length === 1) {
myorder.idStorehouse = product.storehouses[0]._id
idStorehouse: order.idStorehouse,
}
return myorder
@@ -306,6 +335,12 @@ export const useProducts = defineStore('Products', {
},
/*resetProducts() {
const arrprod = [...this.products]
this.products = []
this.products = [...arrprod]
},*/
async loadProducts() {
const userStore = useUserStore()
@@ -484,11 +519,11 @@ export const useProducts = defineStore('Products', {
}
} else {
if (this.isQtyAvailableByProduct(product)) {
order.quantity = 1
order.quantity = product.minBuyQty | 1
order.quantitypreordered = 0
} else {
if (this.isInPreorderByProduct(product)) {
order.quantitypreordered = 1
order.quantitypreordered = product.minBuyQty | 1
order.quantity = 0
}
}
@@ -650,8 +685,8 @@ export const useProducts = defineStore('Products', {
return ris
},
async addtoCartBase({ $q, t, code, order, addqty }: { $q: any, t: any, code: string, order: IOrder, addqty: boolean }) {
let product = this.getProductByCode(code)
async addtoCartBase({ $q, t, id, order, addqty }: { $q: any, t: any, id: string, order: IOrder, addqty: boolean }) {
let product = this.getProductById(id)
return await this.addToCart({ product, order, addqty })
.then((ris) => {

View File

@@ -122,6 +122,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
storehouses: [],
scontisticas: [],
providers: [],
catprods: [],
gasordines: [],
departments: [],
categories: [],
@@ -282,6 +283,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
let ris: any = []
const calendarStore = useCalendarStore()
const Products = useProducts()
const circuitStore = useCircuitStore()
const userStore = useUserStore()
const messageStore = useMessageStore()
@@ -310,6 +312,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
else if (table === 'producers') ris = state.producers
else if (table === 'storehouses') ris = state.storehouses
else if (table === 'providers') ris = state.providers
else if (table === 'productinfos') ris = Products.productInfos
else if (table === 'gasordines') ris = state.gasordines
else if (table === 'scontisticas') ris = state.scontisticas
else if (table === 'groups') ris = state.groups
@@ -317,6 +320,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
else if (table === 'workers') ris = state.workers
else if (table === 'departments') ris = state.departments
else if (table === 'categorys') ris = state.categories
else if (table === 'catprods') ris = Products.catprods
else if (table === 'sharewithus') ris = state.sharewithus
else if (table === 'paymenttypes') ris = state.paymenttypes
else if (table === 'circuits') ris = circuitStore.listcircuits
@@ -1536,9 +1540,13 @@ export const useGlobalStore = defineStore('GlobalStore', {
this.paymenttypes = (res.data.paymenttypes) ? [...res.data.paymenttypes] : []
this.gallery = (res.data.gallery) ? [...res.data.gallery] : []
this.calzoom = (res.data.calzoom) ? [...res.data.calzoom] : []
Products.productInfos = (res.data.productInfos) ? [...res.data.productInfos] : []
this.producers = (res.data.producers) ? [...res.data.producers] : []
this.storehouses = (res.data.storehouses) ? [...res.data.storehouses] : []
this.providers = (res.data.providers) ? [...res.data.providers] : []
Products.catprods = (res.data.catprods) ? [...res.data.catprods] : []
this.gasordines = (res.data.gasordines) ? [...res.data.gasordines] : []
this.scontisticas = (res.data.scontisticas) ? [...res.data.scontisticas] : []
this.groups = (res.data.groups) ? [...res.data.groups] : []