Merge branch 'develop' of ssh://risosrv:5522/~/repository/newfreeplanet into develop
This commit is contained in:
@@ -442,6 +442,18 @@ export const colTableProviders = [
|
||||
AddCol(DeleteRec),
|
||||
AddCol(DuplicateRec),
|
||||
]
|
||||
export const colTableGasordine = [
|
||||
AddCol({ name: 'active', label_trans: 'sites.active', fieldtype: costanti.FieldType.boolean }),
|
||||
AddCol({ name: 'name', label_trans: 'store.name' }),
|
||||
AddCol({ name: 'description', label_trans: 'store.description' }),
|
||||
AddCol({ name: 'referente', label_trans: 'store.referent' }),
|
||||
AddCol({ name: 'city', label_trans: 'store.city' }),
|
||||
AddCol({ name: 'img', label_trans: 'store.img' }),
|
||||
AddCol({ name: 'dataora_chiusura', label_trans: 'gas.dataora_chiusura', fieldtype: costanti.FieldType.date }),
|
||||
AddCol({ name: 'dataora_ritiro', label_trans: 'gas.dataora_ritiro', fieldtype: costanti.FieldType.date }),
|
||||
AddCol(DeleteRec),
|
||||
AddCol(DuplicateRec),
|
||||
]
|
||||
export const colTableScontistica = [
|
||||
AddCol({ name: 'code', label_trans: 'scontistica.code' }),
|
||||
AddCol({ name: 'description', label_trans: 'scontistica.description' }),
|
||||
@@ -1999,11 +2011,21 @@ export const colTableProducts = [
|
||||
label_trans: 'products.quantityAvailable',
|
||||
fieldtype: costanti.FieldType.number
|
||||
}),
|
||||
AddCol({
|
||||
name: 'bookableAvailableQty',
|
||||
label_trans: 'products.bookableAvailableQty',
|
||||
fieldtype: costanti.FieldType.number
|
||||
}),
|
||||
AddCol({
|
||||
name: 'stockQty',
|
||||
label_trans: 'products.stockQty',
|
||||
fieldtype: costanti.FieldType.number
|
||||
}),
|
||||
AddCol({
|
||||
name: 'bookableQty',
|
||||
label_trans: 'products.bookableQty',
|
||||
fieldtype: costanti.FieldType.number
|
||||
}),
|
||||
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 }),
|
||||
@@ -3563,6 +3585,13 @@ export const fieldsTable = {
|
||||
colkey: '_id',
|
||||
collabel: 'name',
|
||||
},
|
||||
{
|
||||
value: 'gasordines',
|
||||
label: 'Gas Ordini',
|
||||
columns: colTableGasordine,
|
||||
colkey: '_id',
|
||||
collabel: 'name',
|
||||
},
|
||||
{
|
||||
value: 'scontisticas',
|
||||
label: 'Scontistica',
|
||||
|
||||
@@ -8270,6 +8270,7 @@ export const tools = {
|
||||
},
|
||||
|
||||
|
||||
|
||||
// FINE !
|
||||
|
||||
// getLocale() {
|
||||
|
||||
@@ -30,6 +30,17 @@ export const useProducts = defineStore('Products', {
|
||||
const indelem = state.products.findIndex((prod: IProduct) => prod._id === res.data.product._id)
|
||||
if (indelem >= 0) {
|
||||
state.products[indelem] = { ...res.data.product }
|
||||
|
||||
/*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) {
|
||||
@@ -44,12 +55,15 @@ 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 }
|
||||
return prod ? prod : { active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0, stockQty: 0, bookableQty: 0 }
|
||||
},
|
||||
|
||||
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 }
|
||||
return prod ? prod : {
|
||||
active: false, img: '', code: '', name: '', storehouses: [], scontisticas: [], price: 0,
|
||||
stockQty: 0, bookableQty: 0
|
||||
}
|
||||
},
|
||||
|
||||
getCart: (state: IProductsState) => (): ICart => {
|
||||
@@ -109,6 +123,28 @@ export const useProducts = defineStore('Products', {
|
||||
return null
|
||||
},
|
||||
|
||||
getSumQtyPreOrderInOrdersCart: (state: IProductsState) => (idproduct: string): number => {
|
||||
let totalQuantity = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalQuantity
|
||||
},
|
||||
|
||||
getSumQtyOrderProductInOrdersCart: (state: IProductsState) => (idproduct: string): number => {
|
||||
let totalQuantity = 0;
|
||||
|
||||
@@ -120,7 +156,7 @@ export const useProducts = defineStore('Products', {
|
||||
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;
|
||||
totalQuantity += (item.order.quantity) || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -169,17 +205,6 @@ export const useProducts = defineStore('Products', {
|
||||
return []
|
||||
},
|
||||
|
||||
updateQuantityAvailable: (state: IProductsState) => (id: string): any => {
|
||||
|
||||
const indelem = state.products.findIndex((prod: IProduct) => prod._id === id)
|
||||
if (indelem >= 0) {
|
||||
state.products[indelem].quantityAvailable = state.products[indelem].stockQty
|
||||
if (state.products[indelem].QuantitaOrdinateInAttesa! > 0) {
|
||||
state.products[indelem].quantityAvailable! -= state.products[indelem].QuantitaOrdinateInAttesa!
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
getRecordEmpty: (state: IProductsState) => (): IProduct => {
|
||||
|
||||
const tomorrow = tools.getDateNow()
|
||||
@@ -205,9 +230,12 @@ export const useProducts = defineStore('Products', {
|
||||
color: '',
|
||||
size: '',
|
||||
quantityAvailable: 0,
|
||||
bookableAvailableQty: 0,
|
||||
stockQty: 0,
|
||||
bookableQty: 0,
|
||||
canBeShipped: false,
|
||||
QuantitaOrdinateInAttesa: 0,
|
||||
QuantitaPrenotateInAttesa: 0,
|
||||
canBeBuyOnline: false,
|
||||
weight: 0,
|
||||
unit: 0,
|
||||
@@ -241,6 +269,7 @@ export const useProducts = defineStore('Products', {
|
||||
weight: product.weight,
|
||||
|
||||
quantity: order.quantity,
|
||||
quantitypreordered: order.quantitypreordered,
|
||||
idStorehouse: order.idStorehouse,
|
||||
idScontisticas: product.idScontisticas,
|
||||
}
|
||||
@@ -411,12 +440,13 @@ export const useProducts = defineStore('Products', {
|
||||
const ordcart = this.getOrderProductInCart(product._id)
|
||||
if (ordcart) {
|
||||
|
||||
if (!addqty && ordcart.quantity === 1) {
|
||||
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
|
||||
@@ -429,14 +459,22 @@ export const useProducts = defineStore('Products', {
|
||||
order: ordcart,
|
||||
}).then((res: any) => {
|
||||
if (res && res.risult) {
|
||||
order.quantity = res.qty
|
||||
order.quantity = res.myord.quantity
|
||||
order.quantitypreordered = res.myord.quantitypreordered
|
||||
}
|
||||
return res;
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (order.quantity === 0)
|
||||
if (this.isQtyAvailableByProduct(product)) {
|
||||
order.quantity = 1
|
||||
order.quantitypreordered = 0
|
||||
} else {
|
||||
if (this.isInPreorderByProduct(product)) {
|
||||
order.quantitypreordered = 1
|
||||
order.quantity = 0
|
||||
}
|
||||
}
|
||||
|
||||
if (!order.idStorehouse) {
|
||||
if (product.storehouses.length === 1) {
|
||||
@@ -467,7 +505,7 @@ export const useProducts = defineStore('Products', {
|
||||
}
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return { risult: !!res, qty: order.quantity }
|
||||
return { risult: !!res, myord: res.data.myord }
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addToCart', error)
|
||||
@@ -496,7 +534,7 @@ export const useProducts = defineStore('Products', {
|
||||
.then((res) => {
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return { risult: !!res, qty: res.data.qty }
|
||||
return { risult: !!res, myord: res.data.myord }
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addSubQtyToItem', error)
|
||||
@@ -598,34 +636,86 @@ export const useProducts = defineStore('Products', {
|
||||
async addtoCartBase({ $q, t, code, order, addqty }: { $q: any, t: any, code: string, order: IOrder, addqty: boolean }) {
|
||||
let product = this.getProductByCode(code)
|
||||
|
||||
return this.addToCart({ product, order, addqty }).then((ris) => {
|
||||
let strprod = t('ecomm.prodotto')
|
||||
return await this.addToCart({ product, order, addqty })
|
||||
.then((ris) => {
|
||||
let strprod = t('ecomm.prodotto')
|
||||
|
||||
if (order.quantity > 1 || order.quantity === 0)
|
||||
strprod = t('ecomm.prodotti')
|
||||
|
||||
let msg = ''
|
||||
if (ris === null)
|
||||
msg = t('ecomm.error_cart')
|
||||
else {
|
||||
|
||||
if (order.quantity === 0) {
|
||||
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
|
||||
} else {
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: order.quantity })
|
||||
|
||||
let qta = ris.myord.quantity + ris.myord.quantitypreordered
|
||||
if (qta > 1 || qta === 0)
|
||||
strprod = t('ecomm.prodotti')
|
||||
|
||||
if (qta > 0) {
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//updateproduct()
|
||||
|
||||
this.updateQuantityAvailable(product._id)
|
||||
if (ris === null || ris.myord.quantity === 0)
|
||||
tools.showNotif($q, msg)
|
||||
else
|
||||
tools.showPositiveNotif($q, msg)
|
||||
|
||||
if (ris === null || order.quantity === 0)
|
||||
tools.showNotif($q, msg)
|
||||
else
|
||||
tools.showPositiveNotif($q, msg)
|
||||
return ris
|
||||
})
|
||||
},
|
||||
|
||||
})
|
||||
}
|
||||
getQuantityByOrder($t: any, order: IOrder): string {
|
||||
let mystr = '';
|
||||
if (order.quantity > 0) {
|
||||
mystr += order.quantity
|
||||
}
|
||||
if ((order.quantitypreordered > 0) && (order.quantity > 0)) {
|
||||
mystr += ' ' + $t('ecomm.available')
|
||||
mystr += ' + '
|
||||
}
|
||||
if (order.quantitypreordered > 0) {
|
||||
mystr += ' ' + order.quantitypreordered + ' ' + $t('ecomm.preord');
|
||||
}
|
||||
return mystr
|
||||
},
|
||||
|
||||
isQtyAvailableByProduct(product: IProduct): boolean {
|
||||
if (product) {
|
||||
return (product.quantityAvailable! > 0)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isInPreorderByProduct(product: IProduct): boolean {
|
||||
if (product) {
|
||||
return (product.bookableAvailableQty! > 0)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isQtyAvailableByOrder(order: IOrder): boolean {
|
||||
if (order && order.product) {
|
||||
return this.isQtyAvailableByProduct(order.product)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
isInPreorderByOrder(order: IOrder): boolean {
|
||||
if (order && order.product) {
|
||||
return this.isInPreorderByProduct(order.product)
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
storehouses: [],
|
||||
scontisticas: [],
|
||||
providers: [],
|
||||
gasordines: [],
|
||||
departments: [],
|
||||
categories: [],
|
||||
sharewithus: [],
|
||||
@@ -309,6 +310,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 === 'gasordines') ris = state.gasordines
|
||||
else if (table === 'scontisticas') ris = state.scontisticas
|
||||
else if (table === 'groups') ris = state.groups
|
||||
else if (table === 'resps') ris = state.resps
|
||||
@@ -1537,6 +1539,7 @@ export const useGlobalStore = defineStore('GlobalStore', {
|
||||
this.producers = (res.data.producers) ? [...res.data.producers] : []
|
||||
this.storehouses = (res.data.storehouses) ? [...res.data.storehouses] : []
|
||||
this.providers = (res.data.providers) ? [...res.data.providers] : []
|
||||
this.gasordines = (res.data.gasordines) ? [...res.data.gasordines] : []
|
||||
this.scontisticas = (res.data.scontisticas) ? [...res.data.scontisticas] : []
|
||||
this.groups = (res.data.groups) ? [...res.data.groups] : []
|
||||
this.resps = (res.data.resps) ? [...res.data.resps] : []
|
||||
|
||||
Reference in New Issue
Block a user