diff --git a/src/common/shared_vuejs.ts b/src/common/shared_vuejs.ts index e31f1675..cd89cea9 100755 --- a/src/common/shared_vuejs.ts +++ b/src/common/shared_vuejs.ts @@ -18,6 +18,7 @@ export const shared_consts = { LIMIT_NOTIF_FOR_USER: 200, PROD: { + TUTTI: 0, GAS: 1, BOTTEGA: 2, }, @@ -47,8 +48,8 @@ export const shared_consts = { value: 2, }, { - label: 'Litri (L)', - short: 'L', + label: 'Litri (Lt)', + short: 'Lt', value: 3, }, { diff --git a/src/components/CProductCard/CProductCard.scss b/src/components/CProductCard/CProductCard.scss index 9590e6ab..497d9d94 100755 --- a/src/components/CProductCard/CProductCard.scss +++ b/src/components/CProductCard/CProductCard.scss @@ -52,4 +52,9 @@ .label-qta{ font-size: 1.15rem; font-weight: bold; +} + +.countdown_scadenza{ + font-size: 1.15rem; + font-weight: bold; } \ No newline at end of file diff --git a/src/components/CProductCard/CProductCard.ts b/src/components/CProductCard/CProductCard.ts index f276ba09..9a1a1e26 100755 --- a/src/components/CProductCard/CProductCard.ts +++ b/src/components/CProductCard/CProductCard.ts @@ -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 { useUserStore } from '@store/UserStore' import { useGlobalStore } from '@store/globalStore' @@ -65,8 +65,12 @@ export default defineComponent({ const storeSelected = ref('') const gasordineSelected = ref('') + const recgasordineSelected = ref(null) const arrordersCart = ref([]) + const timerInterval = ref(null) + const timerLabelScadenza = ref('') + const openlistorders = ref(false) const endload = ref(false) const myproduct = ref({}) @@ -217,8 +221,33 @@ export default defineComponent({ watch(() => gasordineSelected.value, (newval, oldval) => { 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() { updateproduct() // console.log('Load', myproduct.value.name) @@ -234,22 +263,29 @@ export default defineComponent({ if (myproduct.value.gasordines && myproduct.value.gasordines.length === 1) { myorder.idGasordine = myproduct.value.gasordines[0]._id + gasordineSelected.value = myorder.idGasordine! } - const ord = products.getOrderProductInCart(myproduct.value._id) if (ord) { myorder.quantity = ord.quantity myorder.quantitypreordered = ord.quantitypreordered - if (ord.idGasordine) + if (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 ! if (ord.idStorehouse) storeSelected.value = ord.idStorehouse } + + if (gasordineSelected.value) { + recgasordineSelected.value = myproduct.value.gasordines.find((rec: IGasordine) => rec._id === gasordineSelected.value) + } + } // console.log('°°° ENDLOAD °°°') @@ -283,7 +319,8 @@ export default defineComponent({ }, 0)) } - onMounted(load) + onMounted(mounted) + onBeforeUnmount(beforeDestroy) return { visuListDisponibili, @@ -316,6 +353,8 @@ export default defineComponent({ listord, sumval, getGasordines, + recgasordineSelected, + timerLabelScadenza, } } }) diff --git a/src/components/CProductCard/CProductCard.vue b/src/components/CProductCard/CProductCard.vue index 84dfae1e..f83bd961 100755 --- a/src/components/CProductCard/CProductCard.vue +++ b/src/components/CProductCard/CProductCard.vue @@ -131,6 +131,20 @@ + + + + + + + + {{ t('gas.dataora_chiusura_ordini') }} + + + {{ timerLabelScadenza }} + + +
@@ -166,7 +180,7 @@ (cosa === shared_consts.PROD.GAS && products.getQtyAvailable(myproduct) > 0) " :clickable="tools.isManager()" - @click="tools.isManager() ? visuListDisponibili() : null" + @click="tools.isManager() && (myproduct.QuantitaOrdinateInAttesa && myproduct.QuantitaOrdinateInAttesa > 0) ? visuListDisponibili() : null" > @@ -200,7 +214,7 @@ diff --git a/src/model/Products.ts b/src/model/Products.ts index 05d26a5e..dc7b0789 100755 --- a/src/model/Products.ts +++ b/src/model/Products.ts @@ -74,6 +74,7 @@ export interface IOrder { date_shipping?: Date date_delivered?: Date notes?: string + modify_at?: Date } export interface IProductsState { diff --git a/src/statics/lang/it.js b/src/statics/lang/it.js index cf305010..0fda1b56 100755 --- a/src/statics/lang/it.js +++ b/src/statics/lang/it.js @@ -1694,6 +1694,7 @@ const msg_it = { bottega: 'Bottega', x_prodotti_gas: '{qta} prodotti', x_prodotti_bottega: '{qta} prodotti', + tutti: 'Tutti', } }, }; diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index dd5f5b3a..b80350eb 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -8281,6 +8281,33 @@ export const tools = { strToVal(mystr: string) { 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 ! diff --git a/src/store/Products.ts b/src/store/Products.ts index 1dec85a3..a60ca189 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -141,24 +141,31 @@ export const useProducts = defineStore('Products', { return state.orders.length }, - getOrdersCart: (state: IProductsState) => (tipoord: number): IOrderCart[] | undefined => { - console.log('state.orders', state.orders) + 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) + 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) - 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) - 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) - 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) - 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) - 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) - 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) - 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 => { @@ -260,7 +267,7 @@ export const useProducts = defineStore('Products', { return ordercart.items!.some(item => { if (item.order) 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) @@ -326,6 +333,8 @@ export const useProducts = defineStore('Products', { quantity: order.quantity, quantitypreordered: order.quantitypreordered, idStorehouse: order.idStorehouse, + idGasordine: order.idGasordine, + //++Add Fields } return myorder @@ -541,6 +550,13 @@ export const useProducts = defineStore('Products', { 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) { neworder = this.createOrderByProduct(product, order) @@ -856,6 +872,17 @@ export const useProducts = defineStore('Products', { 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 + } + + }, diff --git a/src/views/ecommerce/orderInfo/orderInfo.ts b/src/views/ecommerce/orderInfo/orderInfo.ts index c076fc34..74d4681d 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.ts +++ b/src/views/ecommerce/orderInfo/orderInfo.ts @@ -1,4 +1,4 @@ -import { defineComponent, onMounted, ref } from 'vue' +import { defineComponent, onMounted, ref, watch } from 'vue' import { tools } from '@store/Modules/tools' import { useUserStore } from '@store/UserStore' import { useRouter } from 'vue-router' @@ -31,6 +31,15 @@ export default defineComponent({ const myarrrec = ref({}) const myoldrec = ref({}) + 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_ordine = ref(false) const endload = ref(false) @@ -136,6 +145,10 @@ export default defineComponent({ } ]) + watch(() => cosa.value, (newval, oldval) => { + + }) + // const { setValDb, getValDb } = MixinBase() function getCols(props: any) { @@ -143,8 +156,10 @@ export default defineComponent({ } function getOrdersCart(): IOrderCart[] | undefined { - const ris = productStore.getOrdersCart(taborders.value) - // console.log(ris) + const hasGasordine: any = (cosa.value === shared_consts.PROD.TUTTI) ? undefined : (cosa.value === shared_consts.PROD.GAS) + console.log('hasgas', hasGasordine) + const ris = productStore.getOrdersCart(taborders.value, hasGasordine) + return ris } @@ -314,6 +329,8 @@ export default defineComponent({ getOrdersCartWithTotals, productStore, t, + initialPagination, + cosa, } } }) diff --git a/src/views/ecommerce/orderInfo/orderInfo.vue b/src/views/ecommerce/orderInfo/orderInfo.vue index 575caf01..eae06334 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.vue +++ b/src/views/ecommerce/orderInfo/orderInfo.vue @@ -2,6 +2,56 @@ + +
+ + + + + + +
@@ -21,6 +71,7 @@ :hide-header="$q.screen.lt.sm" :columns="columns" row-key="numorder" + :pagination="initialPagination" :rows="getOrdersCartWithTotals()" >