From 56b433dae3f127d2c1dae041fd6adcb08eefe890 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Wed, 20 Dec 2023 21:56:30 +0100 Subject: [PATCH 1/3] Aggiornamento modifiche preOrdini --- src/components/CProductCard/CProductCard.scss | 4 + src/components/CProductCard/CProductCard.ts | 70 +++++++++----- src/components/CProductCard/CProductCard.vue | 91 ++++++++++++++----- src/components/CSingleCart/CSingleCart.ts | 36 ++++++-- src/components/CSingleCart/CSingleCart.vue | 4 +- src/mixins/mixin-users.ts | 2 +- src/model/Products.ts | 6 +- src/statics/lang/it.js | 3 + src/store/Modules/fieldsTable.ts | 10 ++ src/store/Modules/tools.ts | 1 + src/store/Products.ts | 91 +++++++++++++++++-- src/views/ecommerce/orderInfo/orderInfo.ts | 1 + src/views/ecommerce/orderInfo/orderInfo.vue | 4 +- 13 files changed, 252 insertions(+), 71 deletions(-) diff --git a/src/components/CProductCard/CProductCard.scss b/src/components/CProductCard/CProductCard.scss index 45a9c435..c5714358 100755 --- a/src/components/CProductCard/CProductCard.scss +++ b/src/components/CProductCard/CProductCard.scss @@ -18,6 +18,10 @@ font-size: 1.2rem; } +.prod_preorder{ + font-size: 1.2rem; +} + .prod_qtywarn{ padding-left: 10px; font-size: 1rem; diff --git a/src/components/CProductCard/CProductCard.ts b/src/components/CProductCard/CProductCard.ts index 74009690..83b0a44b 100755 --- a/src/components/CProductCard/CProductCard.ts +++ b/src/components/CProductCard/CProductCard.ts @@ -88,33 +88,39 @@ export default defineComponent({ } - products.addToCart({ product: myproduct.value, order: myorder, addqty: add }).then((ris) => { - let strprod = t('ecomm.prodotto') + if (myproduct.value) { + products.addToCart({ product: myproduct.value, order: myorder, addqty: add }).then((ris: any) => { + let strprod = t('ecomm.prodotto') - if (myorder.quantity > 1 || myorder.quantity === 0) - strprod = t('ecomm.prodotti') - - let msg = '' - if (ris === null) - msg = t('ecomm.error_cart') - else { - - if (myorder.quantity === 0) { - msg = t('ecomm.prodotto_tolto') + let msg = '' + console.log('ris', ris) + 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: myorder.quantity }) + + let qta = ris.myord.quantity + ris.myord.quantitypreordered + if (qta > 1 || qta === 0) + strprod = t('ecomm.prodotti') + + if (qta === 0) { + msg = t('ecomm.prodotto_tolto') + } else { + msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta }) + } + } - } + updateproduct() - updateproduct() + if (ris === null || ris.myord.quantity === 0) + tools.showNotif($q, msg) + else + tools.showPositiveNotif($q, msg) - if (ris === null || myorder.quantity === 0) - tools.showNotif($q, msg) - else - tools.showPositiveNotif($q, msg) - - }) + }) + } } function getnumstore() { @@ -141,13 +147,13 @@ export default defineComponent({ function updateproduct() { myproduct.value = products.getProduct(props.code) - products.updateQuantityAvailable(myproduct.value._id) + // products.updateQuantityAvailable(myproduct.value._id) } function getStorehouses() { if (!myproduct.value) return [] - + const myarr: any = [] let ind = 1 myproduct.value.storehouses.forEach((store) => { @@ -175,6 +181,11 @@ export default defineComponent({ return qty } + function getQtyBookableAvailable() { + let qty = myproduct.value.bookableAvailableQty! + return qty + } + function getQtyWarn() { if (myorder.quantity > 0) { return t('ecomm.di_cui_x_in_carrello', { qty: myorder.quantity }) @@ -182,6 +193,13 @@ export default defineComponent({ return '' } + function getQtyWarnPreOrdered() { + if (myorder.quantitypreordered > 0) { + return t('ecomm.di_cui_x_in_carrello', { qty: myorder.quantitypreordered }) + } + return '' + } + watch(() => props.code, (newval, oldval) => { console.log('change code') load() @@ -206,6 +224,7 @@ export default defineComponent({ const ord = products.getOrderProductInCart(myproduct.value._id) if (ord) { myorder.quantity = ord.quantity + myorder.quantitypreordered = ord.quantitypreordered } } @@ -222,7 +241,8 @@ export default defineComponent({ } function enableSubQty() { - return myorder.quantity ? myorder.quantity > 0 : false + let qty = myorder.quantity + myorder.quantitypreordered + return qty ? qty > 0 : false } function enableAddQty() { @@ -262,6 +282,8 @@ export default defineComponent({ endload, shared_consts, site, + getQtyWarnPreOrdered, + getQtyBookableAvailable, } } }) diff --git a/src/components/CProductCard/CProductCard.vue b/src/components/CProductCard/CProductCard.vue index 71a251e4..69e18183 100755 --- a/src/components/CProductCard/CProductCard.vue +++ b/src/components/CProductCard/CProductCard.vue @@ -51,16 +51,17 @@ myproduct.after_price }} - +
{{ sconti.description }} -
+
- @@ -116,29 +117,18 @@ - - {{ t('ecomm.preorders') }} - - - {{ t('ecomm.available') }} - + {{ t('ecomm.available') }} - - {{ -getQtyAvailable() }} - - - {{ getQtyAvailable() }} - + {{ getQtyAvailable() }}
{{ getQtyWarn() }}
{{ @@ -152,6 +142,43 @@ + + + + + + + + {{ t('ecomm.preorders') }} + + + + {{ getQtyBookableAvailable() }} + +
+ {{ + getQtyWarnPreOrdered() + }} + +
+ {{ + $t('ecomm.qta_prenotate_in_attesa', { + qty: myproduct.QuantitaPrenotateInAttesa, + }) + }} +
+
+
+
+
{{ myorder.quantity }}
+
+ Preord.: {{ myorder.quantitypreordered }} +
@@ -221,7 +255,7 @@
- {{ - singleord.order.quantity - }} + + {{ singleord.order.quantity }} + + {{ singleord.order.quantitypreordered }}
diff --git a/src/components/CSingleCart/CSingleCart.ts b/src/components/CSingleCart/CSingleCart.ts index d0886fbe..c630c6fd 100755 --- a/src/components/CSingleCart/CSingleCart.ts +++ b/src/components/CSingleCart/CSingleCart.ts @@ -40,14 +40,29 @@ export default defineComponent({ } function addsubqty(addqty: boolean, subqty: boolean) { - if (addqty) { - if (props.order.quantity >= 10) - return false - } + if (products.isQtyAvailableByOrder(props.order)) { + if (addqty) { + if (props.order.quantity >= 20) + return false + } - if (subqty) { - if (props.order.quantity === 0) - return false + if (subqty) { + if (props.order.quantity === 0) + return false + } + } else { + + if (products.isInPreorderByOrder(props.order)) { + if (addqty) { + if (props.order.quantitypreordered >= 20) + return false + } + + if (subqty) { + if (props.order.quantitypreordered === 0) + return false + } + } } products.addSubQtyToItem({ @@ -56,14 +71,15 @@ export default defineComponent({ order: props.order, }).then((res: any) => { if (res.risult) { - order.value.quantity = res.qty + order.value.quantity = res.myord.quantity + order.value.quantitypreordered = res.myord.quantitypreordered } }) } function isApplicatoSconto() { - const totalipotetico = order.value.price! * order.value.quantity - if (totalipotetico > order.value.TotalPriceProduct!) { + const totalipotetico = order.value.price * (order.value.quantity + order.value.quantitypreordered) + if (totalipotetico > order.value.TotalPriceProduct) { return true } return false diff --git a/src/components/CSingleCart/CSingleCart.vue b/src/components/CSingleCart/CSingleCart.vue index 92081d2a..d78dc4f7 100755 --- a/src/components/CSingleCart/CSingleCart.vue +++ b/src/components/CSingleCart/CSingleCart.vue @@ -22,14 +22,14 @@
{{ order.quantity }}
--> -
{{ order.quantity }}
+
{{ order.quantity + order.quantitypreordered }}
- €  {{ (order.price * order.quantity).toFixed(2) }} + €  {{ ((order.price * order.quantity) + (order.price * order.quantitypreordered)).toFixed(2) }}
€ {{ order.TotalPriceProduct ? order.TotalPriceProduct.toFixed(2) : 0 }}
diff --git a/src/mixins/mixin-users.ts b/src/mixins/mixin-users.ts index bdf36765..81a70019 100755 --- a/src/mixins/mixin-users.ts +++ b/src/mixins/mixin-users.ts @@ -51,7 +51,7 @@ export default function () { if (!!arrcart) { if (!!arrcart.items) { // @ts-ignore - const total = arrcart.items.reduce((sum, item) => sum + item.order.quantity, 0) + const total = arrcart.items.reduce((sum, item) => sum + item.order.quantity + item.order.quantitypreordered , 0) return total } } diff --git a/src/model/Products.ts b/src/model/Products.ts index bfcaa892..f53c8529 100755 --- a/src/model/Products.ts +++ b/src/model/Products.ts @@ -22,8 +22,11 @@ export interface IProduct { color?: string, size?: string, quantityAvailable?: number, + bookableAvailableQty?: number, QuantitaOrdinateInAttesa?: number, - stockQty?: number, + QuantitaPrenotateInAttesa?: number, + stockQty: number, + bookableQty: number, canBeShipped?: boolean, canBeBuyOnline?: boolean, weight?: number, @@ -54,6 +57,7 @@ export interface IOrder { color?: string size?: string quantity: number + quantitypreordered: number weight?: number stars?: number product?: IProduct diff --git a/src/statics/lang/it.js b/src/statics/lang/it.js index c5593a46..d62625fa 100755 --- a/src/statics/lang/it.js +++ b/src/statics/lang/it.js @@ -62,6 +62,8 @@ const msg_it = { quantity: 'Quantità', quantityAvailable: 'Disponibili', stockQty: 'In Magazzino', + bookableQty: 'Prenotabili', + bookableAvailableQty: 'Disponib. Prenotabili', weight: 'Peso', unit: 'Unità di Misura', stars: 'Voto', @@ -1661,6 +1663,7 @@ const msg_it = { carrello: 'Carrello', settings: 'Impostazioni', qta_in_attesa: '(Ordinati In attesa {qty})', + qta_prenotate_in_attesa: '(Preordinate In attesa {qty})', }, }, diff --git a/src/store/Modules/fieldsTable.ts b/src/store/Modules/fieldsTable.ts index a31ea586..53113c14 100755 --- a/src/store/Modules/fieldsTable.ts +++ b/src/store/Modules/fieldsTable.ts @@ -1999,11 +1999,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 }), diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index b7f9c7b0..26c174a9 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -8270,6 +8270,7 @@ export const tools = { }, + // FINE ! // getLocale() { diff --git a/src/store/Products.ts b/src/store/Products.ts index 6a191b58..92c44106 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -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,7 +55,10 @@ export const useProducts = defineStore('Products', { getProduct: (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 => { @@ -115,7 +129,7 @@ export const useProducts = defineStore('Products', { for (const item of myord.items) { if (item.order) { if (item.order.idProduct === idproduct) { - totalQuantity += item.order.quantity || 0; + totalQuantity += (item.order.quantity + item.order.quantitypreordered) || 0; } } } @@ -146,7 +160,7 @@ export const useProducts = defineStore('Products', { return [] }, - updateQuantityAvailable: (state: IProductsState) => (id: string): any => { + /* updateQuantityAvailable: (state: IProductsState) => (id: string): any => { const indelem = state.products.findIndex((prod: IProduct) => prod._id === id) if (indelem >= 0) { @@ -154,9 +168,14 @@ export const useProducts = defineStore('Products', { if (state.products[indelem].QuantitaOrdinateInAttesa! > 0) { state.products[indelem].quantityAvailable! -= state.products[indelem].QuantitaOrdinateInAttesa! } + state.products[indelem].bookableAvailableQty = state.products[indelem].bookableQty + if (state.products[indelem].QuantitaPrenotateInAttesa! > 0) { + state.products[indelem].bookableAvailableQty! -= state.products[indelem].QuantitaPrenotateInAttesa! + } } - }, + },*/ + getRecordEmpty: (state: IProductsState) => (): IProduct => { const tomorrow = tools.getDateNow() @@ -182,9 +201,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, @@ -218,6 +240,7 @@ export const useProducts = defineStore('Products', { weight: product.weight, quantity: order.quantity, + quantitypreordered: order.quantitypreordered, idStorehouse: order.idStorehouse, idScontisticas: product.idScontisticas, } @@ -388,12 +411,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 @@ -406,14 +430,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.quantitypreordered = 0 order.quantity = 1 + } else { + if (this.isInPreorderByProduct(product)) { + order.quantity = 0 + order.quantitypreordered = 1 + } + } neworder = this.createOrderByProduct(product, order) } @@ -434,7 +466,7 @@ export const useProducts = defineStore('Products', { } this.updateDataProduct(res) - return { risult: !!res, qty: order.quantity } + return { risult: !!res } }) .catch((error) => { console.log('error addToCart', error) @@ -463,7 +495,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) @@ -562,6 +594,47 @@ export const useProducts = defineStore('Products', { return ris }, + + getQuantityByOrder(order: IOrder): string { + let mystr = ''; + if (order.quantity > 0) { + mystr += order.quantity + } + if (order.quantitypreordered > 0) { + mystr += ' Prenotata :' + order.quantitypreordered + } + 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; + }, + + }, }) diff --git a/src/views/ecommerce/orderInfo/orderInfo.ts b/src/views/ecommerce/orderInfo/orderInfo.ts index 82049b99..11b27da5 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.ts +++ b/src/views/ecommerce/orderInfo/orderInfo.ts @@ -312,6 +312,7 @@ export default defineComponent({ getCols, endload, getOrdersCartWithTotals, + productStore, } } }) diff --git a/src/views/ecommerce/orderInfo/orderInfo.vue b/src/views/ecommerce/orderInfo/orderInfo.vue index 4543361e..31e2a655 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.vue +++ b/src/views/ecommerce/orderInfo/orderInfo.vue @@ -57,7 +57,7 @@ v-if="!!item && item.order && item.order.product" > {{ item.order.product.name }} ({{ - item.order.quantity + productStore.getQuantityByOrder(item.order) }})
@@ -141,7 +141,7 @@
{{ item.order.product.name }} ({{ - item.order.quantity + productStore.getQuantityByOrder(item.order) }})
From 31014b21c01c743ba31d9a3262958315dc2bec45 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Thu, 21 Dec 2023 01:34:39 +0100 Subject: [PATCH 2/3] Corretto incongruenze OrdersCart --- src/components/CProductCard/CProductCard.ts | 36 ++++- src/components/CProductCard/CProductCard.vue | 15 +- src/components/CSingleCart/CSingleCart.vue | 82 ++++++++--- src/statics/lang/it.js | 3 +- src/store/Products.ts | 137 ++++++++++++------- src/views/ecommerce/checkOut/checkOut.ts | 2 +- src/views/ecommerce/orderInfo/orderInfo.vue | 4 +- 7 files changed, 198 insertions(+), 81 deletions(-) diff --git a/src/components/CProductCard/CProductCard.ts b/src/components/CProductCard/CProductCard.ts index 7a60817a..2056283f 100755 --- a/src/components/CProductCard/CProductCard.ts +++ b/src/components/CProductCard/CProductCard.ts @@ -10,7 +10,7 @@ import { CCopyBtn } from '../CCopyBtn' import { func_tools, toolsext } from '@store/Modules/toolsext' -import { IOrder, IOrderCart, IProduct } from '@src/model' +import { IBaseOrder, IOrder, IOrderCart, IProduct } from '@src/model' import { tools } from '@store/Modules/tools' import { useProducts } from '@store/Products' @@ -43,11 +43,15 @@ export default defineComponent({ const globalStore = useGlobalStore() const products = useProducts() + const listord = ref([]) + const sumval = ref(0) + const site = ref(globalStore.site) const myorder = reactive({ idapp: process.env.APP_ID, quantity: 0, + quantitypreordered: 0, idStorehouse: '', idProvider: '' }) @@ -87,7 +91,11 @@ export default defineComponent({ return false } - await products.addtoCartBase({ $q, t, code: myproduct.value.code!, order: myorder, addqty: add }) + const ris = await products.addtoCartBase({ $q, t, code: myproduct.value.code!, order: myorder, addqty: add }) + updateproduct() + if (ris && ris.myord) { + + } } function getnumstore() { @@ -214,16 +222,36 @@ export default defineComponent({ function enableAddQty() { if (site.value.ecomm && site.value.ecomm.enablePreOrders) { - return true + return getQtyBookableAvailable() > 0 || getQtyAvailable() > 0 } else { return getQtyAvailable() > 0 } } + function visuListDisponibili() { + openlistorders.value = true + sumval.value = products.getSumQtyOrderProductInOrdersCart(myproduct.value._id) + + listord.value = arrordersCart.value.filter((ordercart: IOrderCart) => ordercart.items!.reduce((accumulator, item) => { + return accumulator + item.order.quantity + }, 0)) + } + + function visuListBookable() { + openlistorders.value = true + sumval.value = products.getSumQtyPreOrderInOrdersCart(myproduct.value._id) + + listord.value = arrordersCart.value.filter((ordercart: IOrderCart) => ordercart.items!.reduce((accumulator, item) => { + return accumulator + item.order.quantitypreordered + }, 0)) + } + onMounted(load) return { + visuListDisponibili, + visuListBookable, addtoCart, iconWhishlist, getmycardcl, @@ -251,6 +279,8 @@ export default defineComponent({ site, getQtyWarnPreOrdered, getQtyBookableAvailable, + listord, + sumval, } } }) diff --git a/src/components/CProductCard/CProductCard.vue b/src/components/CProductCard/CProductCard.vue index 9e774f2e..e7e1a1ea 100755 --- a/src/components/CProductCard/CProductCard.vue +++ b/src/components/CProductCard/CProductCard.vue @@ -109,12 +109,12 @@ @@ -146,9 +146,9 @@
@@ -210,7 +210,6 @@ class="self-center no-outline" tabindex="0" > - Preord.: {{ myorder.quantitypreordered }} @@ -298,7 +297,7 @@ @@ -347,7 +346,7 @@ Totali: {{ - products.getSumQtyOrderProductInOrdersCart(myproduct._id) + sumval }}   diff --git a/src/components/CSingleCart/CSingleCart.vue b/src/components/CSingleCart/CSingleCart.vue index ae745d84..bbbd758f 100755 --- a/src/components/CSingleCart/CSingleCart.vue +++ b/src/components/CSingleCart/CSingleCart.vue @@ -1,45 +1,89 @@ diff --git a/src/statics/lang/it.js b/src/statics/lang/it.js index 80bd1958..3e30b08c 100755 --- a/src/statics/lang/it.js +++ b/src/statics/lang/it.js @@ -1651,7 +1651,8 @@ const msg_it = { ord_not_confirmed: 'E\' avvenuto un errore. Ordine non Confermato. Ricaricare la pagina e riprovare.', btn_cassa: 'Vai alla Cassa', available: 'Disponibili', - preorders: 'In Prenotazione', + preorders: 'Pre-Ordinabili', + preord: 'Pre-Ordinate', di_cui_x_in_carrello: '(nel tuo carrello: {qty})', evaso: 'Ordine Evaso', consegnato: 'Ordine Consegnato', diff --git a/src/store/Products.ts b/src/store/Products.ts index 91b8fb26..a2f263fe 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -123,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; @@ -134,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 + item.order.quantitypreordered) || 0; + totalQuantity += (item.order.quantity) || 0; } } } @@ -183,22 +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! - } - state.products[indelem].bookableAvailableQty = state.products[indelem].bookableQty - if (state.products[indelem].QuantitaPrenotateInAttesa! > 0) { - state.products[indelem].bookableAvailableQty! -= state.products[indelem].QuantitaPrenotateInAttesa! - } - } - - },*/ - getRecordEmpty: (state: IProductsState) => (): IProduct => { const tomorrow = tools.getDateNow() @@ -461,16 +467,15 @@ export const useProducts = defineStore('Products', { } } else { if (this.isQtyAvailableByProduct(product)) { - order.quantitypreordered = 0 order.quantity = 1 + order.quantitypreordered = 0 } else { if (this.isInPreorderByProduct(product)) { - order.quantity = 0 order.quantitypreordered = 1 + order.quantity = 0 } } - if (!order.idStorehouse) { if (product.storehouses.length === 1) { order.idStorehouse = product.storehouses[0]._id @@ -500,7 +505,7 @@ export const useProducts = defineStore('Products', { } this.updateDataProduct(res) - return { risult: !!res } + return { risult: !!res, myord: res.data.myord } }) .catch((error) => { console.log('error addToCart', error) @@ -631,49 +636,87 @@ 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') - let msg = '' - console.log('ris', ris) - if (ris === null || ris.myord == null) { - msg = t('ecomm.error_cart') - tools.showNegativeNotif($q, msg) - return - } else { - - let qta = ris.myord.quantity + ris.myord.quantitypreordered - if (qta > 1 || qta === 0) - strprod = t('ecomm.prodotti') - - if (qta === 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: qta }) + + 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() - //updateproduct() + if (ris === null || ris.myord.quantity === 0) + tools.showNotif($q, msg) + else + tools.showPositiveNotif($q, msg) - if (ris === null || ris.myord.quantity === 0) - tools.showNotif($q, msg) - else - tools.showPositiveNotif($q, msg) - - }) + return ris + }) }, - getQuantityByOrder(order: IOrder): string { + 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 += ' Prenotata :' + order.quantitypreordered + 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; + }, + }, }) diff --git a/src/views/ecommerce/checkOut/checkOut.ts b/src/views/ecommerce/checkOut/checkOut.ts index 15db645f..b9fdebcc 100755 --- a/src/views/ecommerce/checkOut/checkOut.ts +++ b/src/views/ecommerce/checkOut/checkOut.ts @@ -183,7 +183,7 @@ export default defineComponent({ const myprod = productStore.getProductByCode(lowerSearchText); if (myprod && myprod.active) { - let myorder: IOrder = { quantity: 1, price: 0, TotalPriceProduct: 0 } + let myorder: IOrder = { quantity: 1, quantitypreordered: 0, price: 0, TotalPriceProduct: 0 } await productStore.addtoCartBase({ $q, t, code: myprod.code!, order: myorder, addqty: true }) search.value = '' load() diff --git a/src/views/ecommerce/orderInfo/orderInfo.vue b/src/views/ecommerce/orderInfo/orderInfo.vue index 31e2a655..cc796023 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.vue +++ b/src/views/ecommerce/orderInfo/orderInfo.vue @@ -57,7 +57,7 @@ v-if="!!item && item.order && item.order.product" > {{ item.order.product.name }} ({{ - productStore.getQuantityByOrder(item.order) + productStore.getQuantityByOrder($t, item.order) }})
@@ -141,7 +141,7 @@
{{ item.order.product.name }} ({{ - productStore.getQuantityByOrder(item.order) + productStore.getQuantityByOrder($t, item.order) }})
From 53208ab1ad8ab6677e5843cf72d74022dceb7dec Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Thu, 21 Dec 2023 02:23:58 +0100 Subject: [PATCH 3/3] ++GasOrdini --- src/db/lang/ws_it.js | 2 ++ src/model/GlobalStore.ts | 3 +- src/model/Products.ts | 15 ++++++++++ src/rootgen/admin/gasordini/gasordini.scss | 0 src/rootgen/admin/gasordini/gasordini.ts | 34 ++++++++++++++++++++++ src/rootgen/admin/gasordini/gasordini.vue | 31 ++++++++++++++++++++ src/router/routesECommerce.ts | 14 +++++++++ src/store/Modules/fieldsTable.ts | 19 ++++++++++++ src/store/globalStore.ts | 3 ++ 9 files changed, 120 insertions(+), 1 deletion(-) create mode 100755 src/rootgen/admin/gasordini/gasordini.scss create mode 100755 src/rootgen/admin/gasordini/gasordini.ts create mode 100755 src/rootgen/admin/gasordini/gasordini.vue diff --git a/src/db/lang/ws_it.js b/src/db/lang/ws_it.js index 232bedc4..1a174f2f 100755 --- a/src/db/lang/ws_it.js +++ b/src/db/lang/ws_it.js @@ -36,6 +36,7 @@ const msg_website_it = { categories: 'Categorie', storehouses: 'Magazzino', providers: 'Fornitori', + gasordine: 'Gas Ordine', scontisticas: 'Scontistica', departments: 'Uffici', orders: 'Ordini Ricevuti', @@ -125,6 +126,7 @@ const msg_website_it = { only_residenti: 'Solo Residenti', only_consiglio: 'Solo Consiglieri', color: 'Colore', + gasordini: 'Gas Ordini', }, msg: { myAppName: 'Più che Buono', diff --git a/src/model/GlobalStore.ts b/src/model/GlobalStore.ts index 3e2b2568..122a67b6 100755 --- a/src/model/GlobalStore.ts +++ b/src/model/GlobalStore.ts @@ -1,7 +1,7 @@ import { IAction } from '@src/model/Projects' import { IFriends, IGroupShort, IMyGroup, IPaymentType } from '@src/model/UserStore' import { - IDepartment, IProducer, IShareWithUs, IStorehouse, IProvider, IScontistica, ICategory + IDepartment, IProducer, IShareWithUs, IStorehouse, IProvider, IScontistica, ICategory, IGasordine } from '@src/model/Products' import { IUserFields, IUserProfile } from '@src/model/UserStore' @@ -442,6 +442,7 @@ export interface IGlobalState { calzoom: ICalZoom[], producers: IProducer[], providers: IProvider[], + gasordines: IGasordine[], scontisticas: IScontistica[], storehouses: IStorehouse[], departments: IDepartment[], diff --git a/src/model/Products.ts b/src/model/Products.ts index f53c8529..6ec3d02a 100755 --- a/src/model/Products.ts +++ b/src/model/Products.ts @@ -49,6 +49,7 @@ export interface IOrder { idProduct?: string idProducer?: string idProvider?: string + idGasordine?: string idStorehouse?: string idScontisticas?: string[] price: number @@ -65,6 +66,7 @@ export interface IOrder { storehouse?: IStorehouse scontisticas?: IScontistica[] provider?: IProvider + gasordine?: IGasordine date_created?: Date date_checkout?: Date date_payment?: Date @@ -130,6 +132,19 @@ export interface IProvider { website?: string, } +export interface IGasordine { + _id?: any + idapp?: string + active: boolean + name?: string, + description?: string, + referent?: string, + city?: string, + img?: string, + dataora_chiusura?: Date, + dataora_ritiro?: Date, +} + export interface IScontistica { _id?: any idapp?: string diff --git a/src/rootgen/admin/gasordini/gasordini.scss b/src/rootgen/admin/gasordini/gasordini.scss new file mode 100755 index 00000000..e69de29b diff --git a/src/rootgen/admin/gasordini/gasordini.ts b/src/rootgen/admin/gasordini/gasordini.ts new file mode 100755 index 00000000..cd8fd89f --- /dev/null +++ b/src/rootgen/admin/gasordini/gasordini.ts @@ -0,0 +1,34 @@ + +import { colTableGasordine } from '@src/store/Modules/fieldsTable' + +import { CImgText } from '../../../components/CImgText/index' + +import { defineComponent } from 'vue' +import { CCard } from '../../../components/CCard' +import { CMyPage } from '../../../components/CMyPage' +import { CTitleBanner } from '../../../components/CTitleBanner' +import { CGridTableRec } from '../../../components/CGridTableRec' + +import MixinMetaTags from '../../../mixins/mixin-metatags' + +export default defineComponent({ + name: 'GasOrdini', + components: { CImgText, CCard, CMyPage, CTitleBanner, CGridTableRec }, + setup() { + const pagination = { + sortBy: 'name', + descending: false, + page: 2, + rowsPerPage: 5 + // rowsNumber: xx if getting data from a server + } + + const { setmeta } = MixinMetaTags() + + return { + colTableGasordine, + setmeta, + } + } + +}) diff --git a/src/rootgen/admin/gasordini/gasordini.vue b/src/rootgen/admin/gasordini/gasordini.vue new file mode 100755 index 00000000..d8e1697c --- /dev/null +++ b/src/rootgen/admin/gasordini/gasordini.vue @@ -0,0 +1,31 @@ + + + diff --git a/src/router/routesECommerce.ts b/src/router/routesECommerce.ts index 88ae206b..9f8934d1 100644 --- a/src/router/routesECommerce.ts +++ b/src/router/routesECommerce.ts @@ -125,6 +125,20 @@ function getRoutesEcomm(site: ISites) { onlyManager: true, onlyEditor: true }, + { + active: true, + order: 30, + path: '/admin/ecommerce/gasordini', + materialIcon: 'fas fa-file-alt', + name: 'pages.gasordini', + component: () => import('@/rootgen/admin/gasordini/gasordini.vue'), + inmenu: true, + submenu: true, + level_parent: 0, + level_child: 0.5, + onlyManager: true, + onlyEditor: true + }, { active: true, order: 30, diff --git a/src/store/Modules/fieldsTable.ts b/src/store/Modules/fieldsTable.ts index 53113c14..b49288c2 100755 --- a/src/store/Modules/fieldsTable.ts +++ b/src/store/Modules/fieldsTable.ts @@ -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' }), @@ -3573,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', diff --git a/src/store/globalStore.ts b/src/store/globalStore.ts index d8bd8614..2a74aad2 100644 --- a/src/store/globalStore.ts +++ b/src/store/globalStore.ts @@ -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] : []