- filtro se GAS o Prodotti

This commit is contained in:
Surya Paolo
2023-12-28 21:00:10 +01:00
parent 196b19ac66
commit ed76b9c1dd
12 changed files with 207 additions and 36 deletions

View File

@@ -18,6 +18,7 @@ export const shared_consts = {
LIMIT_NOTIF_FOR_USER: 200, LIMIT_NOTIF_FOR_USER: 200,
PROD: { PROD: {
TUTTI: 0,
GAS: 1, GAS: 1,
BOTTEGA: 2, BOTTEGA: 2,
}, },
@@ -47,8 +48,8 @@ export const shared_consts = {
value: 2, value: 2,
}, },
{ {
label: 'Litri (L)', label: 'Litri (Lt)',
short: 'L', short: 'Lt',
value: 3, value: 3,
}, },
{ {

View File

@@ -53,3 +53,8 @@
font-size: 1.15rem; font-size: 1.15rem;
font-weight: bold; font-weight: bold;
} }
.countdown_scadenza{
font-size: 1.15rem;
font-weight: bold;
}

View File

@@ -1,4 +1,4 @@
import { defineComponent, ref, toRef, computed, PropType, watch, onMounted, reactive } from 'vue' import { defineComponent, ref, toRef, computed, PropType, watch, onMounted, reactive, onBeforeUnmount } from 'vue'
import { useI18n } from '@src/boot/i18n' import { useI18n } from '@src/boot/i18n'
import { useUserStore } from '@store/UserStore' import { useUserStore } from '@store/UserStore'
import { useGlobalStore } from '@store/globalStore' import { useGlobalStore } from '@store/globalStore'
@@ -65,8 +65,12 @@ export default defineComponent({
const storeSelected = ref('') const storeSelected = ref('')
const gasordineSelected = ref('') const gasordineSelected = ref('')
const recgasordineSelected = ref(<any>null)
const arrordersCart = ref(<IOrderCart[]>[]) const arrordersCart = ref(<IOrderCart[]>[])
const timerInterval = ref(<any>null)
const timerLabelScadenza = ref('')
const openlistorders = ref(false) const openlistorders = ref(false)
const endload = ref(false) const endload = ref(false)
const myproduct = ref(<IProduct>{}) const myproduct = ref(<IProduct>{})
@@ -217,8 +221,33 @@ export default defineComponent({
watch(() => gasordineSelected.value, (newval, oldval) => { watch(() => gasordineSelected.value, (newval, oldval) => {
myorder.idGasordine = newval myorder.idGasordine = newval
recgasordineSelected.value = myproduct.value.gasordines.find((rec: any) => rec._id === gasordineSelected.value)
}) })
function mounted() {
load()
// Start the timer when the component is mounted
startTimer();
}
function beforeDestroy() {
// Clear the interval when the component is destroyed to prevent memory leaks
clearInterval(timerInterval.value);
}
function updateTimerLabel() {
if (recgasordineSelected.value)
timerLabelScadenza.value = tools.getCountDown(recgasordineSelected.value.dataora_chiusura_ordini)
else
timerLabelScadenza.value = ''
}
function startTimer() {
// Update the timer label every second
timerInterval.value = setInterval(() => updateTimerLabel(), 1000);
}
function load() { function load() {
updateproduct() updateproduct()
// console.log('Load', myproduct.value.name) // console.log('Load', myproduct.value.name)
@@ -234,22 +263,29 @@ export default defineComponent({
if (myproduct.value.gasordines && myproduct.value.gasordines.length === 1) { if (myproduct.value.gasordines && myproduct.value.gasordines.length === 1) {
myorder.idGasordine = myproduct.value.gasordines[0]._id myorder.idGasordine = myproduct.value.gasordines[0]._id
gasordineSelected.value = myorder.idGasordine!
} }
const ord = products.getOrderProductInCart(myproduct.value._id) const ord = products.getOrderProductInCart(myproduct.value._id)
if (ord) { if (ord) {
myorder.quantity = ord.quantity myorder.quantity = ord.quantity
myorder.quantitypreordered = ord.quantitypreordered myorder.quantitypreordered = ord.quantitypreordered
if (ord.idGasordine) if (ord.idGasordine) {
gasordineSelected.value = ord.idGasordine! gasordineSelected.value = ord.idGasordine!
recgasordineSelected.value = myproduct.value.gasordines.find((rec: IGasordine) => rec._id === ord.idGasordine!)
}
// Seleziona il Negozio che avevo già scelto nell'ordine ! // Seleziona il Negozio che avevo già scelto nell'ordine !
if (ord.idStorehouse) if (ord.idStorehouse)
storeSelected.value = ord.idStorehouse storeSelected.value = ord.idStorehouse
} }
if (gasordineSelected.value) {
recgasordineSelected.value = myproduct.value.gasordines.find((rec: IGasordine) => rec._id === gasordineSelected.value)
}
} }
// console.log('°°° ENDLOAD °°°') // console.log('°°° ENDLOAD °°°')
@@ -283,7 +319,8 @@ export default defineComponent({
}, 0)) }, 0))
} }
onMounted(load) onMounted(mounted)
onBeforeUnmount(beforeDestroy)
return { return {
visuListDisponibili, visuListDisponibili,
@@ -316,6 +353,8 @@ export default defineComponent({
listord, listord,
sumval, sumval,
getGasordines, getGasordines,
recgasordineSelected,
timerLabelScadenza,
} }
} }
}) })

View File

@@ -131,6 +131,20 @@
</q-item-label> </q-item-label>
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-item v-if="myproduct.gasordines && myproduct.gasordines.length >= 1">
<q-item-section avatar>
<q-icon color="blue" name="fas fa-hourglass-half" />
</q-item-section>
<q-item-section>
<q-item-label>
{{ t('gas.dataora_chiusura_ordini') }}
</q-item-label>
<q-item-label class="countdown_scadenza">
{{ timerLabelScadenza }}
</q-item-label>
</q-item-section>
</q-item>
</q-list> </q-list>
<div v-if="true"> <div v-if="true">
<div v-if="complete && myproduct.producer && myproduct.producer.city"> <div v-if="complete && myproduct.producer && myproduct.producer.city">
@@ -166,7 +180,7 @@
(cosa === shared_consts.PROD.GAS && products.getQtyAvailable(myproduct) > 0) (cosa === shared_consts.PROD.GAS && products.getQtyAvailable(myproduct) > 0)
" "
:clickable="tools.isManager()" :clickable="tools.isManager()"
@click="tools.isManager() ? visuListDisponibili() : null" @click="tools.isManager() && (myproduct.QuantitaOrdinateInAttesa && myproduct.QuantitaOrdinateInAttesa > 0) ? visuListDisponibili() : null"
> >
<q-item-section avatar> <q-item-section avatar>
<q-icon color="green" name="fas fa-store" /> <q-icon color="green" name="fas fa-store" />
@@ -200,7 +214,7 @@
<q-item <q-item
v-if="products.getQtyBookableAvailable(myproduct) > 0 || myproduct.bookableQty > 0" v-if="products.getQtyBookableAvailable(myproduct) > 0 || myproduct.bookableQty > 0"
:clickable="tools.isManager()" :clickable="tools.isManager()"
@click="tools.isManager() ? visuListBookable() : null" @click="tools.isManager() && (myproduct.QuantitaPrenotateInAttesa && myproduct.QuantitaPrenotateInAttesa > 0) ? visuListBookable() : null"
> >
<q-item-section avatar> <q-item-section avatar>
<q-icon color="blue" name="fas fa-edit" /> <q-icon color="blue" name="fas fa-edit" />

View File

@@ -74,6 +74,7 @@ export interface IOrder {
date_shipping?: Date date_shipping?: Date
date_delivered?: Date date_delivered?: Date
notes?: string notes?: string
modify_at?: Date
} }
export interface IProductsState { export interface IProductsState {

View File

@@ -1694,6 +1694,7 @@ const msg_it = {
bottega: 'Bottega', bottega: 'Bottega',
x_prodotti_gas: '{qta} prodotti', x_prodotti_gas: '{qta} prodotti',
x_prodotti_bottega: '{qta} prodotti', x_prodotti_bottega: '{qta} prodotti',
tutti: 'Tutti',
} }
}, },
}; };

View File

@@ -8281,6 +8281,33 @@ export const tools = {
strToVal(mystr: string) { strToVal(mystr: string) {
return parseInt(mystr) return parseInt(mystr)
},
pad(value: any) {
// Helper function to pad single-digit values with leading zeros
return value < 10 ? `0${value}` : value;
},
getCountDown(mydate: Date) {
const currentDate = new Date();
const targetTime = new Date(mydate).getTime();
// Calculate the difference in milliseconds
const countdown = targetTime - currentDate.getTime();
// Convert milliseconds to seconds
const countdownInSeconds = Math.floor(countdown / 1000);
const days = Math.floor(countdownInSeconds / (60 * 60 * 24));
const hours = Math.floor((countdownInSeconds % (60 * 60 * 24)) / (60 * 60));
const minutes = Math.floor((countdownInSeconds % (60 * 60)) / 60);
const seconds = countdownInSeconds % 60;
const gg = days > 0 ? 'giorni' : ''
const strgg = gg ? `${days} giorni` : ''
return (`${strgg} ${this.pad(hours)}:${this.pad(minutes)}:${this.pad(seconds)}`);
} }
// FINE ! // FINE !

View File

@@ -141,24 +141,31 @@ export const useProducts = defineStore('Products', {
return state.orders.length return state.orders.length
}, },
getOrdersCart: (state: IProductsState) => (tipoord: number): IOrderCart[] | undefined => { getOrdersCart: (state: IProductsState) => (tipoord: number, hasGasordine: any): IOrderCart[] | undefined => {
console.log('state.orders', state.orders)
if (tipoord === shared_consts.OrderStat.IN_CORSO.value) if (tipoord === shared_consts.OrderStat.IN_CORSO.value)
return state.orders.filter((rec: IOrderCart) => (rec.status ? rec.status : 0) <= shared_consts.OrderStatus.CHECKOUT_SENT) 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.CONFERMATI.value) else if (tipoord === shared_consts.OrderStat.CONFERMATI.value)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.ORDER_CONFIRMED) 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) else if (tipoord === shared_consts.OrderStat.PAGATI.value)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.PAYED) 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) else if (tipoord === shared_consts.OrderStat.DELIVERED.value)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.DELIVERED) 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) else if (tipoord === shared_consts.OrderStat.SHIPPED.value)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.SHIPPED) 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) else if (tipoord === shared_consts.OrderStat.RECEIVED.value)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.RECEIVED) 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) else if (tipoord === shared_consts.OrderStat.COMPLETATI.value)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.COMPLETED) 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) else if (tipoord === shared_consts.OrderStat.CANCELLATI.value)
return state.orders.filter((rec: IOrderCart) => rec.status === shared_consts.OrderStatus.CANCELED) return state.orders.filter((rec: IOrderCart) => (rec.status === shared_consts.OrderStatus.CANCELED)
&& (hasGasordine ? rec.items?.some(item => item.order.idGasordine) : true))
}, },
existProductInCart: (state: IProductsState) => (idproduct: string): boolean => { existProductInCart: (state: IProductsState) => (idproduct: string): boolean => {
@@ -260,7 +267,7 @@ export const useProducts = defineStore('Products', {
return ordercart.items!.some(item => { return ordercart.items!.some(item => {
if (item.order) if (item.order)
return (item.order.idProduct === idproduct) return (item.order.idProduct === idproduct)
&& (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT) && (item.order.status! <= shared_consts.OrderStatus.CHECKOUT_SENT)
}) })
}) })
// console.log('Ordini ', ris) // console.log('Ordini ', ris)
@@ -326,6 +333,8 @@ export const useProducts = defineStore('Products', {
quantity: order.quantity, quantity: order.quantity,
quantitypreordered: order.quantitypreordered, quantitypreordered: order.quantitypreordered,
idStorehouse: order.idStorehouse, idStorehouse: order.idStorehouse,
idGasordine: order.idGasordine,
//++Add Fields
} }
return myorder return myorder
@@ -541,6 +550,13 @@ export const useProducts = defineStore('Products', {
order.idStorehouse = globalStore.storehouses ? globalStore.storehouses[0]._id : '' order.idStorehouse = globalStore.storehouses ? globalStore.storehouses[0]._id : ''
} }
} }
if (!order.idGasordine && order.quantitypreordered > 0) {
if (product.gasordines.length === 1) {
order.idGasordine = product.gasordines[0]._id
} else {
order.idGasordine = globalStore.gasordines ? globalStore.gasordines[0]._id : ''
}
}
if (order.idStorehouse) { if (order.idStorehouse) {
neworder = this.createOrderByProduct(product, order) neworder = this.createOrderByProduct(product, order)
@@ -856,6 +872,17 @@ export const useProducts = defineStore('Products', {
return step return step
}, },
getNumQtaGas() {
const arrprod = this.getProducts(shared_consts.PROD.GAS)
return arrprod.length
},
getNumQtaBottega() {
const arrprod = this.getProducts(shared_consts.PROD.BOTTEGA)
return arrprod.length
}
}, },

View File

@@ -1,4 +1,4 @@
import { defineComponent, onMounted, ref } from 'vue' import { defineComponent, onMounted, ref, watch } from 'vue'
import { tools } from '@store/Modules/tools' import { tools } from '@store/Modules/tools'
import { useUserStore } from '@store/UserStore' import { useUserStore } from '@store/UserStore'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
@@ -31,6 +31,15 @@ export default defineComponent({
const myarrrec = ref(<any>{}) const myarrrec = ref(<any>{})
const myoldrec = ref(<any>{}) const myoldrec = ref(<any>{})
const cosa = ref(0)
const initialPagination = ref({
sortBy: 'desc',
descending: false,
rowsPerPage: 10,
// rowsNumber: xx if getting data from a server
})
const conferma_carrello = ref(false) const conferma_carrello = ref(false)
const conferma_ordine = ref(false) const conferma_ordine = ref(false)
const endload = ref(false) const endload = ref(false)
@@ -136,6 +145,10 @@ export default defineComponent({
} }
]) ])
watch(() => cosa.value, (newval, oldval) => {
})
// const { setValDb, getValDb } = MixinBase() // const { setValDb, getValDb } = MixinBase()
function getCols(props: any) { function getCols(props: any) {
@@ -143,8 +156,10 @@ export default defineComponent({
} }
function getOrdersCart(): IOrderCart[] | undefined { function getOrdersCart(): IOrderCart[] | undefined {
const ris = productStore.getOrdersCart(taborders.value) const hasGasordine: any = (cosa.value === shared_consts.PROD.TUTTI) ? undefined : (cosa.value === shared_consts.PROD.GAS)
// console.log(ris) console.log('hasgas', hasGasordine)
const ris = productStore.getOrdersCart(taborders.value, hasGasordine)
return ris return ris
} }
@@ -314,6 +329,8 @@ export default defineComponent({
getOrdersCartWithTotals, getOrdersCartWithTotals,
productStore, productStore,
t, t,
initialPagination,
cosa,
} }
} }
}) })

View File

@@ -2,6 +2,56 @@
<q-page> <q-page>
<CTitleBanner title="Ordini"></CTitleBanner> <CTitleBanner title="Ordini"></CTitleBanner>
<q-spinner v-if="!endload" color="primary" size="3em" :thickness="2" /> <q-spinner v-if="!endload" color="primary" size="3em" :thickness="2" />
<div class="q-gutter-md text-center">
<q-btn-toggle
v-model="cosa"
push
rounded
glossy
toggle-color="purple"
:options="[
{ value: shared_consts.PROD.TUTTI, slot: 'tutti' },
{ value: shared_consts.PROD.BOTTEGA, slot: 'bottega' },
{ value: shared_consts.PROD.GAS, slot: 'gas' },
]"
>
<template v-slot:tutti>
<div class="row items-center no-wrap">
<div class="text-center">
{{ t('gas.tutti') }}
<br />
{{ t('gas.x_prodotti_gas', { qta: productStore.getNumQtaGas()+productStore.getNumQtaBottega() }) }}
</div>
<q-icon right name="fas fa-user-friends" />
</div>
</template>
<template v-slot:gas>
<div class="row items-center no-wrap">
<div class="text-center">
{{ t('gas.ordina_sul_gas') }}
<br />
{{ t('gas.x_prodotti_gas', { qta: productStore.getNumQtaGas() }) }}
</div>
<q-icon right name="fas fa-user-friends" />
</div>
</template>
<template v-slot:bottega>
<div class="row items-center no-wrap">
<div class="text-center">
{{ t('gas.bottega') }}
<br />
{{
t('gas.x_prodotti_bottega', { qta: productStore.getNumQtaBottega() })
}}
</div>
<q-icon right name="fas fa-store" />
</div>
</template>
</q-btn-toggle>
</div>
˚
<div v-if="endload" class="panel"> <div v-if="endload" class="panel">
<q-tabs v-model="taborders" inline-label class="text-blue"> <q-tabs v-model="taborders" inline-label class="text-blue">
<span v-for="(stat, index) of shared_consts.OrderStat" :key="index"> <span v-for="(stat, index) of shared_consts.OrderStat" :key="index">
@@ -21,6 +71,7 @@
:hide-header="$q.screen.lt.sm" :hide-header="$q.screen.lt.sm"
:columns="columns" :columns="columns"
row-key="numorder" row-key="numorder"
:pagination="initialPagination"
:rows="getOrdersCartWithTotals()" :rows="getOrdersCartWithTotals()"
> >
<template v-if="$q.screen.lt.sm" v-slot:item="props"> <template v-if="$q.screen.lt.sm" v-slot:item="props">

View File

@@ -84,16 +84,6 @@ export default defineComponent({
} }
function getNumQtaGas() {
const arrprod = productStore.getProducts(shared_consts.PROD.GAS)
return arrprod.length
}
function getNumQtaBottega() {
const arrprod = productStore.getProducts(shared_consts.PROD.BOTTEGA)
return arrprod.length
}
onMounted(mounted) onMounted(mounted)
return { return {
@@ -105,8 +95,6 @@ export default defineComponent({
search, search,
cosa, cosa,
shared_consts, shared_consts,
getNumQtaGas,
getNumQtaBottega,
getCatProds, getCatProds,
cat, cat,
productStore, productStore,

View File

@@ -20,7 +20,7 @@
<div class="text-center"> <div class="text-center">
{{ t('gas.ordina_sul_gas') }} {{ t('gas.ordina_sul_gas') }}
<br /> <br />
{{ t('gas.x_prodotti_gas', { qta: getNumQtaGas() }) }} {{ t('gas.x_prodotti_gas', { qta: productStore.getNumQtaGas() }) }}
</div> </div>
<q-icon right name="fas fa-user-friends" /> <q-icon right name="fas fa-user-friends" />
</div> </div>
@@ -32,7 +32,7 @@
{{ t('gas.bottega') }} {{ t('gas.bottega') }}
<br /> <br />
{{ {{
t('gas.x_prodotti_bottega', { qta: getNumQtaBottega() }) t('gas.x_prodotti_bottega', { qta: productStore.getNumQtaBottega() })
}} }}
</div> </div>
<q-icon right name="fas fa-store" /> <q-icon right name="fas fa-store" />