aggiornamento Ordini GAS filtri
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort } from 'model'
|
||||
import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IProductsState, IProductInfo, ICatProd, IUserShort, IGasordine } from 'model'
|
||||
|
||||
import { Api } from '@api'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
@@ -195,42 +195,52 @@ export const useProducts = defineStore('Products', {
|
||||
return state.cart
|
||||
},
|
||||
|
||||
getOrdersAllCart: (state: IProductsState) => (): IOrderCart[] => {
|
||||
return state.orders
|
||||
getOrdersAllCart: (state: IProductsState) => (idGasordine: string): IOrderCart[] => {
|
||||
return state.orders.filter((rec: IOrderCart) => {
|
||||
if ((idGasordine && !rec.items?.some(item => item.order.idGasordine === idGasordine))) {
|
||||
return false; // Skip records not matching gasordine condition
|
||||
}
|
||||
return true
|
||||
})
|
||||
},
|
||||
|
||||
getNumOrders: (state: IProductsState) => (): number => {
|
||||
return state.orders.length
|
||||
},
|
||||
|
||||
getOrdersCart: (state: IProductsState) => (tipoord: number, hasGasordine: any): IOrderCart[] | undefined => {
|
||||
if (tipoord === shared_consts.OrderStat.IN_CORSO.value)
|
||||
return state.orders.filter((rec: IOrderCart) => ((rec.status ? rec.status : 0) <= shared_consts.OrderStatus.CHECKOUT_SENT)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.PREPARED.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.PREPARED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.CONFERMATI.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.ORDER_CONFIRMED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.PAGATI.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.PAYED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.DELIVERED.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.DELIVERED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.SHIPPED.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.SHIPPED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.RECEIVED.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.RECEIVED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.COMPLETATI.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.COMPLETED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
else if (tipoord === shared_consts.OrderStat.CANCELLATI.value)
|
||||
return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.CANCELED)
|
||||
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
|
||||
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.idGasordine === idGasordine)) {
|
||||
return false; // Skip records not matching gasordine condition
|
||||
}
|
||||
|
||||
if (hasGasordine && !rec.items?.some(item => item.order.idGasordine)) {
|
||||
return false; // Skip records not matching gasordine condition
|
||||
}
|
||||
|
||||
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 => {
|
||||
@@ -627,6 +637,23 @@ export const useProducts = defineStore('Products', {
|
||||
})
|
||||
},
|
||||
|
||||
async getGestoreOrdini({ idGasordine }: { idGasordine: string }) {
|
||||
const userStore = useUserStore()
|
||||
|
||||
let useractive = this.userActive._id
|
||||
if (!useractive)
|
||||
useractive = userStore.my._id;
|
||||
|
||||
return Api.SendReq('/cart/' + useractive + '/gestord', 'POST', { idGasordine })
|
||||
.then((res) => {
|
||||
if (res)
|
||||
return res.data.arrout
|
||||
else
|
||||
return []
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
async addToCart({ product, order, addqty }: { product: IProduct, order: IOrder, addqty: boolean }) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
@@ -882,7 +909,7 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
|
||||
if (qta >= 0) {
|
||||
let totalPrice = this.cart.totalPrice ? this.cart.totalPrice.toFixed(2): 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 })
|
||||
}
|
||||
@@ -1075,9 +1102,60 @@ export const useProducts = defineStore('Products', {
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
getStrInfoOrder(t: any, order: IOrder) {
|
||||
let mystr = ''
|
||||
let qtyrisult: any
|
||||
|
||||
if (order.product) {
|
||||
let qtystr = ''
|
||||
let qtynum = 0
|
||||
if (order.quantity > 0)
|
||||
qtynum += order.quantity;
|
||||
if (order.quantitypreordered > 0)
|
||||
qtynum += order.quantitypreordered;
|
||||
|
||||
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 + '€';
|
||||
|
||||
}
|
||||
return mystr
|
||||
},
|
||||
|
||||
getGasordines() {
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const myarr: any = [{
|
||||
id: 0,
|
||||
label: 'Tutti',
|
||||
value: ''
|
||||
}]
|
||||
let ind = 1
|
||||
globalStore.gasordines.forEach((gasordine: IGasordine) => {
|
||||
myarr.push(
|
||||
{
|
||||
id: ind,
|
||||
label: gasordine.name,
|
||||
value: gasordine._id
|
||||
})
|
||||
|
||||
ind++
|
||||
})
|
||||
|
||||
return myarr
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user