From 6ab83e7ed587083db1cf4fe3e56c6a6bbae95661 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Tue, 9 Jan 2024 15:32:21 +0100 Subject: [PATCH] aggiorna --- src/components/CCart/CCart.scss | 8 + src/components/CCart/CCart.ts | 267 ++++++++++++++++++ src/components/CCart/CCart.vue | 52 ++++ src/components/CCart/index.ts | 1 + src/components/COrdersCart/COrdersCart.scss | 12 + src/components/COrdersCart/COrdersCart.ts | 206 ++++++++++++++ src/components/COrdersCart/COrdersCart.vue | 50 ++++ src/components/COrdersCart/index.ts | 1 + src/components/CSingleCart/CSingleCart.ts | 18 +- src/components/CSingleCart/CSingleCart.vue | 22 +- src/model/Products.ts | 4 +- src/rootgen/admin/cash/cash.scss | 0 src/rootgen/admin/cash/cash.ts | 24 -- src/rootgen/admin/cash/cash.vue | 32 --- src/router/routesECommerce.ts | 35 +-- src/statics/lang/it.js | 4 + src/store/Modules/fieldsTable.ts | 39 +-- src/store/Products.ts | 34 ++- src/store/UserStore.ts | 18 +- src/store/index.ts | 1 + src/views/ecommerce/cash/cash.scss | 14 + src/views/ecommerce/cash/cash.ts | 116 ++++++++ src/views/ecommerce/cash/cash.vue | 116 ++++++++ src/views/ecommerce/cash/index.ts | 1 + src/views/ecommerce/checkOut/checkOut.ts | 211 +------------- src/views/ecommerce/checkOut/checkOut.vue | 80 +----- src/views/ecommerce/orderInfo/orderInfo.ts | 16 ++ src/views/ecommerce/orderInfo/orderInfo.vue | 223 ++++++--------- src/views/ecommerce/orderscart/index.ts | 1 + .../ecommerce/orderscart/orderscart.scss | 5 + src/views/ecommerce/orderscart/orderscart.ts | 55 ++++ src/views/ecommerce/orderscart/orderscart.vue | 18 ++ .../ecommerce/productsList/productsList.ts | 2 +- 33 files changed, 1137 insertions(+), 549 deletions(-) create mode 100755 src/components/CCart/CCart.scss create mode 100755 src/components/CCart/CCart.ts create mode 100755 src/components/CCart/CCart.vue create mode 100755 src/components/CCart/index.ts create mode 100755 src/components/COrdersCart/COrdersCart.scss create mode 100755 src/components/COrdersCart/COrdersCart.ts create mode 100755 src/components/COrdersCart/COrdersCart.vue create mode 100755 src/components/COrdersCart/index.ts delete mode 100755 src/rootgen/admin/cash/cash.scss delete mode 100755 src/rootgen/admin/cash/cash.ts delete mode 100755 src/rootgen/admin/cash/cash.vue create mode 100755 src/views/ecommerce/cash/cash.scss create mode 100755 src/views/ecommerce/cash/cash.ts create mode 100755 src/views/ecommerce/cash/cash.vue create mode 100755 src/views/ecommerce/cash/index.ts create mode 100755 src/views/ecommerce/orderscart/index.ts create mode 100755 src/views/ecommerce/orderscart/orderscart.scss create mode 100755 src/views/ecommerce/orderscart/orderscart.ts create mode 100755 src/views/ecommerce/orderscart/orderscart.vue diff --git a/src/components/CCart/CCart.scss b/src/components/CCart/CCart.scss new file mode 100755 index 00000000..4067f7bb --- /dev/null +++ b/src/components/CCart/CCart.scss @@ -0,0 +1,8 @@ +$heightBtn: 100%; + +.card .product-image { + height: 300px; +} +.insert{ + cursor:pointer; +} \ No newline at end of file diff --git a/src/components/CCart/CCart.ts b/src/components/CCart/CCart.ts new file mode 100755 index 00000000..dae13526 --- /dev/null +++ b/src/components/CCart/CCart.ts @@ -0,0 +1,267 @@ +import { defineComponent, onMounted, ref, computed } from 'vue' +import { tools } from '@store/Modules/tools' +import { useUserStore } from '@store/UserStore' +import { useRouter } from 'vue-router' +import { useGlobalStore } from '@store/globalStore' +import { useProducts } from '@store/Products' +import { useI18n } from '@/boot/i18n' +import { toolsext } from '@store/Modules/toolsext' +import { useQuasar } from 'quasar' +import { costanti } from '@costanti' +import { ICart, IOrder, IOrderCart, IProduct, IShareWithUs } from '@src/model/Products' + +import { shared_consts } from '@src/common/shared_vuejs' + +import { CSingleCart } from '../CSingleCart' +import { CTitleBanner } from '@components' + +export default defineComponent({ + name: 'CCart', + props: { + iscash: { + type: Boolean, + required: false, + default: false, + }, + idOrdersCart: { + type: String, + required: false, + default: null, + }, + + }, + components: { CSingleCart, CTitleBanner }, + setup(props) { + const userStore = useUserStore() + const globalStore = useGlobalStore() + const productStore = useProducts() + const $router = useRouter() + const $q = useQuasar() + const { t } = useI18n(); + + const mycart = ref({}) + const myrec = ref([]) + const oldrec = ref([]) + const note = ref('') + const endload = ref(false) + const recOrderCart = ref({}) + + const search = ref('') + + const statusnow = computed(() => (): number => { + if (recOrderCart.value) { + return recOrderCart.value.status + } + return 0 + }) + + function mounted() { + // Inizializza + load() + } + + function getOrdersCart() { + if (props.iscash) { + return productStore.getOrdersCartById(props.idOrdersCart) + } else { + return productStore.getCart() + } + + } + + function getItemsCart() { + const cart = getOrdersCart() + return cart.items || null + } + + function getNumItems(): number { + const cart = getOrdersCart() + if (!!cart.items) + return cart.items.length || 0 + else + return 0 + } + + function getCart(): ICart { + return getOrdersCart() + } + + function getNote() { + const cart = getOrdersCart() + return cart.note + } + + function change_field(fieldname: string) { + if (myrec.value[fieldname] !== oldrec.value[fieldname]) { + myrec.value[fieldname] = oldrec.value[fieldname] + + const mydata = { + [fieldname]: myrec.value[fieldname] + } + + const aggiorna = fieldname !== 'status' + tools.saveFieldToServer($q, 'carts', mycart.value._id, mydata, aggiorna) + oldrec.value[fieldname] = myrec.value[fieldname] + } + } + + function myTotalPrice(): string { + if (productStore.cart && productStore.cart.totalPrice) { + return productStore.cart.totalPrice.toFixed(2) + } else { + return '0' + } + } + + function myTotalQty(): number { + if (productStore.cart) { + return productStore.cart.totalQty! + } else { + return 0 + } + } + + async function load() { + mycart.value = getCart() + myrec.value = Object.keys(mycart) + oldrec.value = myrec.value + note.value = mycart.value.note! + + let options = {}; + + if (mycart.value) { + recOrderCart.value = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status: 0, note: note.value }) + } + + console.log('myrec', myrec.value) + + endload.value = true + } + + function CanBeShipped() { + return productStore.cart.items ? productStore.cart.items.filter((rec: any) => rec.order.product.canBeShipped).length : false + } + + function CanBeBuyOnline() { + return productStore.cart.items ? productStore.cart.items.filter((rec: any) => rec.order.product.canBeBuyOnline).length : false + } + + function getnumsteps() { + let numsteps = 1 + + if (CanBeShipped()) + numsteps++ + if (CanBeBuyOnline()) + numsteps++ + + return numsteps + } + + function docheckout() { + + // Può essere spedito? + + if (CanBeShipped()) { + // mostra form di spedizione + } + + if (CanBeBuyOnline()) { + // mostra form di acquisto Online + } + } + + function completeOrder() { + $q.dialog({ + message: t('ecomm.conferma_acq', { qty: myTotalQty() }), + ok: { + label: t('dialog.yes'), + push: true + }, + cancel: { + label: t('dialog.cancel') + }, + title: t('ecomm.order') + }).onOk(async () => { + const status = shared_consts.OrderStatus.CHECKOUT_SENT + + recOrderCart.value = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status, note: note.value }) + + // statusnow.value = myordercart ? myordercart.status : 0 + + if (recOrderCart.value.status === status) { + tools.showPositiveNotif($q, t('ecomm.ord_confirmed')) + setTimeout(() => { + $router.push('/orderinfo') + }, 2000) + } else { + tools.showNegativeNotif($q, t('ecomm.ord_not_confirmed')) + } + // change_field('status') + // change_field('status') + }) + } + + function getActualIdStorehouse(myprod: IProduct) { + // Ottieni il negozio attualmente selezionato: + // Se ce n'è solo 1 allora prendi quello ! + if (myprod.storehouses.length === 1) { + return myprod.storehouses[0]._id + } else { + // Ottieni il negozio attualmente scelto ! + return '' + } + } + + function getActualGasordine(myprod: IProduct) { + // Ottieni il negozio attualmente selezionato: + // Se ce n'è solo 1 allora prendi quello ! + if (myprod.gasordines.length === 1) { + return myprod.gasordines[0]._id + } else { + // Ottieni il gasordine attualmente scelto ! + return '' + } + } + + async function insertArticolo() { + let lowerSearchText = search.value.trim(); + + const myprod = productStore.getProductByCode(lowerSearchText); + if (myprod && myprod.active) { + let myorder: IOrder = { + quantity: 1, quantitypreordered: 0, + TotalPriceProduct: 0, price: 0, + idStorehouse: getActualIdStorehouse(myprod), + idGasordine: getActualGasordine(myprod), + } + await productStore.addtoCartBase({ $q, t, id: myprod._id, order: myorder, addqty: true }) + search.value = '' + load() + } + } + + onMounted(mounted) + + return { + userStore, + costanti, + tools, + toolsext, + completeOrder, + getNumItems, + myTotalPrice, + getItemsCart, + getNote, + change_field, + note, + statusnow, + shared_consts, + myTotalQty, + recOrderCart, + mycart, + endload, + search, + insertArticolo, + } + } +}) diff --git a/src/components/CCart/CCart.vue b/src/components/CCart/CCart.vue new file mode 100755 index 00000000..573e2cfd --- /dev/null +++ b/src/components/CCart/CCart.vue @@ -0,0 +1,52 @@ + + + + + diff --git a/src/components/CCart/index.ts b/src/components/CCart/index.ts new file mode 100755 index 00000000..771a6e15 --- /dev/null +++ b/src/components/CCart/index.ts @@ -0,0 +1 @@ +export {default as CCart} from './CCart.vue' diff --git a/src/components/COrdersCart/COrdersCart.scss b/src/components/COrdersCart/COrdersCart.scss new file mode 100755 index 00000000..674aaa26 --- /dev/null +++ b/src/components/COrdersCart/COrdersCart.scss @@ -0,0 +1,12 @@ +$heightBtn: 100%; + +.card .product-image { + height: 300px; +} +.insert{ + cursor:pointer; +} + +.numorder{ + font-weight: bold; +} \ No newline at end of file diff --git a/src/components/COrdersCart/COrdersCart.ts b/src/components/COrdersCart/COrdersCart.ts new file mode 100755 index 00000000..2dea713f --- /dev/null +++ b/src/components/COrdersCart/COrdersCart.ts @@ -0,0 +1,206 @@ +import { defineComponent, onMounted, ref, computed } from 'vue' +import { tools } from '@store/Modules/tools' +import { useUserStore } from '@store/UserStore' +import { useRouter } from 'vue-router' +import { useGlobalStore } from '@store/globalStore' +import { useProducts } from '@store/Products' +import { useI18n } from '@/boot/i18n' +import { toolsext } from '@store/Modules/toolsext' +import { useQuasar } from 'quasar' +import { costanti } from '@costanti' +import { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IShareWithUs } from '@src/model/Products' + +import { shared_consts } from '@src/common/shared_vuejs' + +import { CSingleCart } from '../CSingleCart' +import { CTitleBanner } from '@components' + +export default defineComponent({ + name: 'COrdersCart', + props: { + iscash: { + type: Boolean, + required: false, + default: false, + }, + idOrdersCart: { + type: String, + required: false, + default: null, + }, + + }, + components: { CSingleCart, CTitleBanner }, + setup(props) { + const userStore = useUserStore() + const globalStore = useGlobalStore() + const productStore = useProducts() + const $router = useRouter() + const $q = useQuasar() + const { t } = useI18n(); + + const myrec = ref([]) + const oldrec = ref([]) + const note = ref('') + const endload = ref(false) + const recOrderCart = ref({}) + + const search = ref('') + + const statusnow = computed(() => (): number => { + if (recOrderCart.value) { + return recOrderCart.value.status + } + return 0 + }) + + function mounted() { + // Inizializza + load() + } + + function getItems(): IBaseOrder[] | [] { + return recOrderCart.value.items ?? [] + } + + function getNumItems(): number { + const itemsord = getItems() + if (itemsord) + return itemsord.length || 0 + else + return 0 + } + + function change_field(fieldname: string) { + if (myrec.value[fieldname] !== oldrec.value[fieldname]) { + myrec.value[fieldname] = oldrec.value[fieldname] + + const mydata = { + [fieldname]: myrec.value[fieldname] + } + + const aggiorna = false + tools.saveFieldToServer($q, 'orderscarts', recOrderCart.value._id, mydata, aggiorna) + oldrec.value[fieldname] = myrec.value[fieldname] + } + } + + function myTotalPrice(): string { + if (recOrderCart.value) { + return recOrderCart.value.totalPrice.toFixed(2) + } else { + return '0' + } + } + + function myTotalQty(): number { + if (recOrderCart.value) { + return recOrderCart.value.totalQty + } else { + return 0 + } + } + + function load() { + recOrderCart.value = productStore.getOrdersCartById(props.idOrdersCart) + if (recOrderCart.value) { + oldrec.value = myrec.value + note.value = recOrderCart.value.note! + } + endload.value = true + } + + function CanBeShipped() { + return recOrderCart.value.items ? recOrderCart.value.items.filter((rec: any) => rec.order.product.canBeShipped).length : false + } + + function CanBeBuyOnline() { + return recOrderCart.value.items ? recOrderCart.value.items.filter((rec: any) => rec.order.product.canBeBuyOnline).length : false + } + + function getnumsteps() { + let numsteps = 1 + + if (CanBeShipped()) + numsteps++ + if (CanBeBuyOnline()) + numsteps++ + + return numsteps + } + + function docheckout() { + + // Può essere spedito? + + if (CanBeShipped()) { + // mostra form di spedizione + } + + if (CanBeBuyOnline()) { + // mostra form di acquisto Online + } + } + + function getActualIdStorehouse(myprod: IProduct) { + // Ottieni il negozio attualmente selezionato: + // Se ce n'è solo 1 allora prendi quello ! + if (myprod.storehouses.length === 1) { + return myprod.storehouses[0]._id + } else { + // Ottieni il negozio attualmente scelto ! + return '' + } + } + + function getActualGasordine(myprod: IProduct) { + // Ottieni il negozio attualmente selezionato: + // Se ce n'è solo 1 allora prendi quello ! + if (myprod.gasordines.length === 1) { + return myprod.gasordines[0]._id + } else { + // Ottieni il gasordine attualmente scelto ! + return '' + } + } + + async function insertArticolo() { + let lowerSearchText = search.value.trim(); + + const myprod = productStore.getProductByCode(lowerSearchText); + if (myprod && myprod.active) { + let myorder: IOrder = { + quantity: 1, quantitypreordered: 0, + TotalPriceProduct: 0, price: 0, + idStorehouse: getActualIdStorehouse(myprod), + idGasordine: getActualGasordine(myprod), + } + await productStore.addtoCartBase({ $q, t, id: myprod._id, order: myorder, addqty: true }) + search.value = '' + load() + } + } + + onMounted(mounted) + + return { + userStore, + costanti, + tools, + toolsext, + getNumItems, + myTotalPrice, + getItems, + change_field, + note, + statusnow, + shared_consts, + myTotalQty, + recOrderCart, + endload, + search, + insertArticolo, + t, + } + } +}) diff --git a/src/components/COrdersCart/COrdersCart.vue b/src/components/COrdersCart/COrdersCart.vue new file mode 100755 index 00000000..2b60b0f4 --- /dev/null +++ b/src/components/COrdersCart/COrdersCart.vue @@ -0,0 +1,50 @@ + + + + + diff --git a/src/components/COrdersCart/index.ts b/src/components/COrdersCart/index.ts new file mode 100755 index 00000000..007cded4 --- /dev/null +++ b/src/components/COrdersCart/index.ts @@ -0,0 +1 @@ +export {default as COrdersCart} from './COrdersCart.vue' diff --git a/src/components/CSingleCart/CSingleCart.ts b/src/components/CSingleCart/CSingleCart.ts index 569091ed..6552e29d 100755 --- a/src/components/CSingleCart/CSingleCart.ts +++ b/src/components/CSingleCart/CSingleCart.ts @@ -9,7 +9,6 @@ import { useProducts } from '@store/Products' import { useI18n } from '@src/boot/i18n' import { useQuasar } from 'quasar' - export default defineComponent({ name: 'CSingleCart', props: { @@ -17,11 +16,21 @@ export default defineComponent({ type: Object as PropType, required: true, }, + editmode: { + type: Boolean, + required: false, + default: false, + }, showall: { type: Boolean, required: false, default: false, }, + idOrdersCart: { + type: String, + required: false, + default: '', + }, nomodif: { type: Boolean, required: false, @@ -93,7 +102,12 @@ export default defineComponent({ } function removeFromCard() { - products.removeFromCart({ order: order.value }) + if (props.idOrdersCart) { + // + } else { + products.removeFromCart({ order: order.value }) + } + } function getRisparmio(): string { diff --git a/src/components/CSingleCart/CSingleCart.vue b/src/components/CSingleCart/CSingleCart.vue index 46876704..8b8c6c65 100755 --- a/src/components/CSingleCart/CSingleCart.vue +++ b/src/components/CSingleCart/CSingleCart.vue @@ -41,7 +41,27 @@ }) " > -
+
+ + +
+
{{ order.quantity + order.quantitypreordered }}
diff --git a/src/model/Products.ts b/src/model/Products.ts index 1e7ebb4d..996824fc 100755 --- a/src/model/Products.ts +++ b/src/model/Products.ts @@ -212,7 +212,7 @@ export interface IOrderCart { numorder: number numord_pers: number userId: string - user: IUserFields, + user: IUserFields | null, totalQty: number totalPrice: number department?: string @@ -230,7 +230,7 @@ export interface IOrderCart { date_spedito?: Date ricevuto: boolean date_ricevuto?: Date - created_at: Date + created_at?: Date note: string } diff --git a/src/rootgen/admin/cash/cash.scss b/src/rootgen/admin/cash/cash.scss deleted file mode 100755 index e69de29b..00000000 diff --git a/src/rootgen/admin/cash/cash.ts b/src/rootgen/admin/cash/cash.ts deleted file mode 100755 index 3cc52450..00000000 --- a/src/rootgen/admin/cash/cash.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { defineComponent } from 'vue' - -import { CImgText } from '../../../components/CImgText/index' -import { CCard } from '@/components/CCard' -import { CMyPage } from '@/components/CMyPage' -import { CTitleBanner } from '@/components/CTitleBanner' -import { CGridTableRec } from '@/components/CGridTableRec' - -import { colTableCash } from '@src/store/Modules/fieldsTable' -import MixinMetaTags from '@/mixins/mixin-metatags' - -export default defineComponent({ - name: 'Cash', - components: { CImgText, CCard, CMyPage, CTitleBanner, CGridTableRec }, - setup() { - - const { setmeta } = MixinMetaTags() - - return { - colTableCash, - setmeta, - } - } -}) diff --git a/src/rootgen/admin/cash/cash.vue b/src/rootgen/admin/cash/cash.vue deleted file mode 100755 index f1758201..00000000 --- a/src/rootgen/admin/cash/cash.vue +++ /dev/null @@ -1,32 +0,0 @@ - - - diff --git a/src/router/routesECommerce.ts b/src/router/routesECommerce.ts index 2d3d15f4..fcd21151 100644 --- a/src/router/routesECommerce.ts +++ b/src/router/routesECommerce.ts @@ -72,10 +72,10 @@ function getRoutesEcomm(site: ISites) { { active: true, order: 30, - path: '/admin/ecommerce/productInfos', - materialIcon: 'fas fa-lemon', - name: 'pages.productInfos', - component: () => import('@/rootgen/admin/productInfos/productInfos.vue'), + path: '/admin/ecommerce/cash', + materialIcon: 'fas fa-cash-register', + name: 'pages.cash', + component: () => import('@/views/ecommerce/cash/cash.vue'), inmenu: true, submenu: true, level_parent: 0, @@ -86,10 +86,10 @@ function getRoutesEcomm(site: ISites) { { active: true, order: 30, - path: '/admin/ecommerce/cash', - materialIcon: 'fas fa-cash-register', - name: 'pages.cash', - component: () => import('@/rootgen/admin/cash/cash.vue'), + path: '/admin/ecommerce/productInfos', + materialIcon: 'fas fa-lemon', + name: 'pages.productInfos', + component: () => import('@/rootgen/admin/productInfos/productInfos.vue'), inmenu: true, submenu: true, level_parent: 0, @@ -245,15 +245,6 @@ function getRoutesEcomm(site: ISites) { inmenu: false, infooter: false, }, - { - active: true, - order: 30, - path: '/admin/ecommerce/cash', - name: 'pages.cash', - component: () => import('@/rootgen/admin/cash/cash.vue'), - inmenu: false, - infooter: false, - }, { active: true, order: 31, @@ -354,6 +345,16 @@ function getRoutesEcomm(site: ISites) { inmenu: false, infooter: false }, + { + active: true, + order: 1000, + path: '/orderscart/:idorderscart', + materialIcon: 'event', + name: 'otherpages.orderscart', + component: () => import('@/views/ecommerce/orderscart/orderscart.vue'), + inmenu: false, + infooter: false + }, ] diff --git a/src/statics/lang/it.js b/src/statics/lang/it.js index f315296f..e70adb35 100755 --- a/src/statics/lang/it.js +++ b/src/statics/lang/it.js @@ -112,6 +112,7 @@ const msg_it = { myactivities: 'Attività', myactivities2: 'Mie Attività', product: 'Prodotto', + orderscart: 'Ordini', sito_offline: 'Sito in Aggiornamento', modifprof: 'Modifica', modifgrp: 'Modifica Gruppo', @@ -1711,6 +1712,7 @@ const msg_it = { offerta_gas: 'Offerta valida al raggiungimento di {qta} {unit}', offerta_gas_raggiunta: 'Complimenti! Gli ordini hanno superato il minimo quantitativo di {qta} {unit}', note: 'Note', + apriordine: 'Apri Ordine', }, gas: { name: 'Ordine Gas', @@ -1727,6 +1729,8 @@ const msg_it = { numorder: 'Ordine', totalQty: 'totalQty', totalQtyPreordered: 'totalQty PreOrd', + numero_ordine: 'Numero d\'Ordine', + nome: 'Nominativo', }, cash: { creatorUserId: 'Creatore', diff --git a/src/store/Modules/fieldsTable.ts b/src/store/Modules/fieldsTable.ts index 794a7643..f887c980 100755 --- a/src/store/Modules/fieldsTable.ts +++ b/src/store/Modules/fieldsTable.ts @@ -2395,36 +2395,6 @@ const colTableEvents = [ AddCol(DuplicateRec), ] -export const colTableCash = [ - AddCol({ name: '_id', label_trans: 'event._id' }), - AddCol({ name: 'creatorUserId', label_trans: 'order.users', fieldtype: costanti.FieldType.select, jointable: 'users' }), - AddCol({ - name: 'idCashCategory', - label_trans: 'Category.idCashCategory', - fieldtype: costanti.FieldType.select, - jointable: 'cashcategory', - }), - AddCol({ name: 'fromUsername', label_trans: 'cash.fromUsername', fieldtype: costanti.FieldType.string }), - AddCol({ name: 'toUsername', label_trans: 'cash.toUsername', fieldtype: costanti.FieldType.string }), - AddCol({ name: 'idOrdersCart', label_trans: 'cash.orderscart', fieldtype: costanti.FieldType.select, jointable: 'orderscart' }), - AddCol({ name: 'type', label_trans: 'cash.type', fieldtype: costanti.FieldType.select, jointable: toolsext.TABTYPECASH }), - AddCol({ - name: 'date_payment', label_trans: 'cash.date_payment', fieldtype: costanti.FieldType.onlydate, - sortable: true, - }), - AddCol({ name: 'price', label_trans: 'products.price', fieldtype: costanti.FieldType.number }), - AddCol({ name: 'causale', label_trans: 'cash.causale' }), - AddCol({ name: 'note', label_trans: 'cash.note' }), - AddCol({ name: 'internal', label_trans: 'cash.internal', fieldtype: costanti.FieldType.boolean }), - AddCol({ name: 'extra', label_trans: 'cash.extra', fieldtype: costanti.FieldType.boolean }), - AddCol({ name: 'confirmed', label_trans: 'cash.confirmed', fieldtype: costanti.FieldType.boolean }), - AddCol({ - name: 'date_created', label_trans: 'reg.pub_created', fieldtype: costanti.FieldType.onlydate, - sortable: true, - }), - AddCol(DeleteRec), - AddCol(DuplicateRec), -] export const fields = { colSettings: [ @@ -3703,7 +3673,7 @@ export const fieldsTable = { collabel: '_id', }, { - value: 'orderscart', + value: 'orderscarts', label: 'Ordini', columns: colTableOrdersCart, colkey: '_id', @@ -3723,13 +3693,6 @@ export const fieldsTable = { colkey: '_id', collabel: 'name', }, - { - value: 'cashs', - label: 'Cassa', - columns: colTableCash, - colkey: '_id', - collabel: 'causale', - }, { value: 'departments', label: 'Uffici', diff --git a/src/store/Products.ts b/src/store/Products.ts index 0d6cff5e..63f68683 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -14,6 +14,24 @@ import { ref } from 'vue' import translate from '@src/globalroutines/util' +function getRecordOrdersCartEmpty(): IOrderCart { + return { + numorder: 0, + numord_pers: 0, + userId: '', + user: null, + totalQty: 0, + totalPrice: 0, + status: 0, + confermato: false, + consegnato: false, + pagato: false, + spedito: false, + ricevuto: false, + note: '', + } +} + function getRecordProductInfoEmpty(): IProductInfo { return { code: '', @@ -57,19 +75,19 @@ function getRecordProductEmpty(): IProduct { minBuyQty: 1, minStepQty: 1, maxBookableSinglePersQty: 0, - + stockQty: 0, stockBloccatiQty: 0, bookedQtyOrdered: 0, bookedQtyConfirmed: 0, qtyToReachForGas: 0, - + maxbookableGASQty: 0, bookedGASQtyOrdered: 0, bookedGASQtyConfirmed: 0, bookableGASBloccatiQty: 0, - + canBeShipped: false, QuantitaOrdinateInAttesa: 0, QuantitaPrenotateInAttesa: 0, @@ -228,6 +246,14 @@ export const useProducts = defineStore('Products', { return null }, + getOrdersCartById: (state: IProductsState) => (idordercart: string): IOrderCart => { + if (state.orders) { + const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart) + return orderscart ?? getRecordOrdersCartEmpty() + } + return getRecordOrdersCartEmpty() + }, + getSumQtyPreOrderInOrdersCart: (state: IProductsState) => (idproduct: string): number => { let totalQuantity = 0; @@ -688,7 +714,7 @@ export const useProducts = defineStore('Products', { return ris }, - + async UpdateOrderCartStatus({ order_id, status }: { order_id: string, status: number }) { diff --git a/src/store/UserStore.ts b/src/store/UserStore.ts index 83eff783..a743a910 100755 --- a/src/store/UserStore.ts +++ b/src/store/UserStore.ts @@ -1117,10 +1117,10 @@ export const useUserStore = defineStore('UserStore', { this.usersList = [...usersList] }, - setlang($q: any, $router: Router, newstr: string) { + setlang($q: any, router: Router, newstr: string) { console.log('SETLANG', newstr) this.lang = newstr - toolsext.setLangAtt($q, $router, newstr) + toolsext.setLangAtt($q, router, newstr) tools.localStSetItem(toolsext.localStorage.lang, this.lang) }, @@ -1258,7 +1258,7 @@ export const useUserStore = defineStore('UserStore', { }, - async signin($router: Router, authData: ISigninOptions) { + async signin(router: Router, authData: ISigninOptions) { console.log('LOGIN signin') const globalStore = useGlobalStore() @@ -1321,7 +1321,7 @@ export const useUserStore = defineStore('UserStore', { }).then((code) => { if (code === tools.OK) { - return this.setGlobal($router, true) + return this.setGlobal(router, true) .then(() => { return code }) @@ -1338,7 +1338,7 @@ export const useUserStore = defineStore('UserStore', { async logout() { const globalStore = useGlobalStore() - // const $router = useRouter() + console.log('logout') @@ -1375,7 +1375,7 @@ export const useUserStore = defineStore('UserStore', { }) }, - async setGlobal($router: Router, isLogged: boolean) { + async setGlobal(router: Router, isLogged: boolean) { console.log('setGlobal', isLogged) const globalStore = useGlobalStore() @@ -1405,7 +1405,7 @@ export const useUserStore = defineStore('UserStore', { if (globalStore.site.confpages.enableProj) await projects.dbLoad({ checkPending: true, onlyiffirsttime: true }) - globalStore.addDynamicPages($router) + globalStore.addDynamicPages(router) static_data.lang_available = globalStore.getLangAvailable() @@ -1426,7 +1426,7 @@ export const useUserStore = defineStore('UserStore', { // console.log('setGlobal: END') }, - async autologin_FromLocalStorage($router: Router, $q: any) { + async autologin_FromLocalStorage(router: Router, $q: any) { try { const globalStore = useGlobalStore() @@ -1454,7 +1454,7 @@ export const useUserStore = defineStore('UserStore', { isLogged = tools.isLogged() } - return await this.setGlobal($router, isLogged) + return await this.setGlobal(router, isLogged) .then((loadstorage: any) => { // console.log('RISULT setGlobal:', loadstorage) if (loadstorage) { diff --git a/src/store/index.ts b/src/store/index.ts index ed7db632..4af1ef97 100755 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,3 +1,4 @@ import { createPinia } from 'pinia'; export default createPinia(); + diff --git a/src/views/ecommerce/cash/cash.scss b/src/views/ecommerce/cash/cash.scss new file mode 100755 index 00000000..a5c7424d --- /dev/null +++ b/src/views/ecommerce/cash/cash.scss @@ -0,0 +1,14 @@ +$heightBtn: 100%; + +.card .product-image { + height: 300px; +} + +.container{ + margin-top: 4px; + margin-bottom: 4px; +} + +.prod_trov{ + font-style: italic; +} \ No newline at end of file diff --git a/src/views/ecommerce/cash/cash.ts b/src/views/ecommerce/cash/cash.ts new file mode 100755 index 00000000..fd14e6f5 --- /dev/null +++ b/src/views/ecommerce/cash/cash.ts @@ -0,0 +1,116 @@ +import { defineComponent, onMounted, ref, watch, computed } from 'vue' +import { tools } from '@store/Modules/tools' +import { useUserStore } from '@store/UserStore' +import { useRouter } from 'vue-router' +import { useGlobalStore } from '@store/globalStore' +import { useProducts } from '@store/Products' +import { useI18n } from '@/boot/i18n' +import { toolsext } from '@store/Modules/toolsext' +import { useQuasar } from 'quasar' +import { costanti } from '@costanti' + +import { shared_consts } from '@/common/shared_vuejs' +import { CProductCard } from '@src/components/CProductCard' +import { IProduct } from '@src/model' + + +export default defineComponent({ + name: 'cash', + components: { CProductCard }, + props: {}, + setup() { + const userStore = useUserStore() + const globalStore = useGlobalStore() + const productStore = useProducts() + const $router = useRouter() + const $q = useQuasar() + const { t } = useI18n() + + const search = ref('') + + const cosa = ref(0) + const cat = ref('') + const loadpage = ref(false) + + watch(() => cosa.value, (newval, oldval) => { + tools.setCookie(tools.COOK_COSA_PRODOTTI, cosa.value.toString()) + }) + + const getArrProducts = computed(() => { + let arrprod = productStore.getProducts(cosa.value) + let catstr = cat.value; + let lowerSearchText = search.value.toLowerCase().trim(); + if ((!lowerSearchText || (lowerSearchText && lowerSearchText.length < 2)) && !catstr) { + return arrprod + } + + return arrprod.filter((product: IProduct) => { + let lowerName = product.productInfo.name!.toLowerCase(); + let hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr)); + + // Use a regular expression to match whole words + let codeMatch = new RegExp(`\\b${lowerSearchText}\\b`, 'i'); + let nameMatch = new RegExp(`\\b${lowerSearchText}`, 'i'); + + // Check if any word in lowerName starts with lowerSearchText + let anyWordStartsWithSearch = lowerName.split(/\s+/).some(word => nameMatch.test(word)); + + return (codeMatch.test(product.productInfo.code!) || anyWordStartsWithSearch) && hasCategoria; + }); + }) + + /*function getProducts() { + let arrprod = productStore.getProducts(cosa.value) + if (!search.value) { + return arrprod + } + + let lowerSearchText = search.value.toLowerCase(); + let catstr = cat.value; + + return arrprod.filter((product: IProduct) => { + let lowerName = product.productInfo.name!.toLowerCase(); + const hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr)); + return (product.productInfo.code!.includes(search.value) || lowerName.includes(lowerSearchText)) && hasCategoria + }); + }*/ + + async function mounted() { + loadpage.value = false + await productStore.loadProducts() + cosa.value = tools.getCookie(tools.COOK_COSA_PRODOTTI, shared_consts.PROD.BOTTEGA, true) + // Inizializza + loadpage.value = true + } + + function getCatProds() { + let arrcat = productStore.getCatProds() + let riscat: any = [{ label: 'Tutti', value: '', icon: undefined, color: undefined }] + for (const rec of arrcat) { + riscat.push({ label: rec.name, value: rec._id, icon: rec.icon, color: rec.color }) + } + + return riscat + } + + + onMounted(mounted) + + return { + userStore, + costanti, + tools, + toolsext, + getArrProducts, + search, + cosa, + shared_consts, + getCatProds, + cat, + productStore, + t, + loadpage, + } + } +}) + diff --git a/src/views/ecommerce/cash/cash.vue b/src/views/ecommerce/cash/cash.vue new file mode 100755 index 00000000..60349265 --- /dev/null +++ b/src/views/ecommerce/cash/cash.vue @@ -0,0 +1,116 @@ + + + + + diff --git a/src/views/ecommerce/cash/index.ts b/src/views/ecommerce/cash/index.ts new file mode 100755 index 00000000..4e112e89 --- /dev/null +++ b/src/views/ecommerce/cash/index.ts @@ -0,0 +1 @@ +export {default as ProductsList} from './cash.vue' diff --git a/src/views/ecommerce/checkOut/checkOut.ts b/src/views/ecommerce/checkOut/checkOut.ts index ef1f01bb..8d8aa1bf 100755 --- a/src/views/ecommerce/checkOut/checkOut.ts +++ b/src/views/ecommerce/checkOut/checkOut.ts @@ -13,209 +13,19 @@ import { ICart, IOrder, IOrderCart, IProduct, IShareWithUs } from '@src/model/Pr import { shared_consts } from '@src/common/shared_vuejs' import { CSingleCart } from '../../../components/CSingleCart' +import { CCart } from '../../../components/CCart' import { CTitleBanner } from '@components' export default defineComponent({ name: 'checkOut', - components: { CSingleCart, CTitleBanner }, + components: { CSingleCart, CTitleBanner, CCart }, props: {}, setup() { const userStore = useUserStore() - const globalStore = useGlobalStore() - const productStore = useProducts() - const $router = useRouter() - const $q = useQuasar() const { t } = useI18n(); - const mycart = ref({}) - const myrec = ref([]) - const oldrec = ref([]) - const note = ref('') - const endload = ref(false) - const recOrderCart = ref({}) - - const search = ref('') - - const statusnow = computed(() => (): number => { - if (recOrderCart.value) { - return recOrderCart.value.status - } - return 0 - }) - function mounted() { - // Inizializza - load() - } - - function getItemsCart() { - const cart = productStore.getCart() - return cart.items || null - } - - function getNumItems(): number { - const cart = productStore.getCart() - if (!!cart.items) - return cart.items.length || 0 - else - return 0 - } - - function getCart(): ICart { - return productStore.getCart() - } - - function getNote() { - const cart = productStore.getCart() - return cart.note - } - - function change_field(fieldname: string) { - if (myrec.value[fieldname] !== oldrec.value[fieldname]) { - myrec.value[fieldname] = oldrec.value[fieldname] - - const mydata = { - [fieldname]: myrec.value[fieldname] - } - - const aggiorna = fieldname !== 'status' - tools.saveFieldToServer($q, 'carts', mycart.value._id, mydata, aggiorna) - oldrec.value[fieldname] = myrec.value[fieldname] - } - } - - function myTotalPrice(): string { - if (productStore.cart && productStore.cart.totalPrice) { - return productStore.cart.totalPrice.toFixed(2) - } else { - return '0' - } - } - - function myTotalQty(): number { - if (productStore.cart) { - return productStore.cart.totalQty! - } else { - return 0 - } - } - - async function load() { - mycart.value = getCart() - myrec.value = Object.keys(mycart) - oldrec.value = myrec.value - note.value = mycart.value.note! - - let options = {}; - - if (mycart.value) { - recOrderCart.value = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status: 0, note: note.value }) - } - - console.log('myrec', myrec.value) - - endload.value = true - } - - function CanBeShipped() { - return productStore.cart.items ? productStore.cart.items.filter((rec: any) => rec.order.product.canBeShipped).length : false - } - - function CanBeBuyOnline() { - return productStore.cart.items ? productStore.cart.items.filter((rec: any) => rec.order.product.canBeBuyOnline).length : false - } - - function getnumsteps() { - let numsteps = 1 - - if (CanBeShipped()) - numsteps++ - if (CanBeBuyOnline()) - numsteps++ - - return numsteps - } - - function docheckout() { - - // Può essere spedito? - - if (CanBeShipped()) { - // mostra form di spedizione - } - - if (CanBeBuyOnline()) { - // mostra form di acquisto Online - } - } - - function completeOrder() { - $q.dialog({ - message: t('ecomm.conferma_acq', { qty: myTotalQty() }), - ok: { - label: t('dialog.yes'), - push: true - }, - cancel: { - label: t('dialog.cancel') - }, - title: t('ecomm.order') - }).onOk(async () => { - const status = shared_consts.OrderStatus.CHECKOUT_SENT - - recOrderCart.value = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status, note: note.value }) - - // statusnow.value = myordercart ? myordercart.status : 0 - - if (recOrderCart.value.status === status) { - tools.showPositiveNotif($q, t('ecomm.ord_confirmed')) - setTimeout(() => { - $router.push('/orderinfo') - }, 2000) - } else { - tools.showNegativeNotif($q, t('ecomm.ord_not_confirmed')) - } - // change_field('status') - // change_field('status') - }) - } - - function getActualIdStorehouse(myprod: IProduct) { - // Ottieni il negozio attualmente selezionato: - // Se ce n'è solo 1 allora prendi quello ! - if (myprod.storehouses.length === 1) { - return myprod.storehouses[0]._id - } else { - // Ottieni il negozio attualmente scelto ! - return '' - } - } - - function getActualGasordine(myprod: IProduct) { - // Ottieni il negozio attualmente selezionato: - // Se ce n'è solo 1 allora prendi quello ! - if (myprod.gasordines.length === 1) { - return myprod.gasordines[0]._id - } else { - // Ottieni il gasordine attualmente scelto ! - return '' - } - } - - async function insertArticolo() { - let lowerSearchText = search.value.trim(); - - const myprod = productStore.getProductByCode(lowerSearchText); - if (myprod && myprod.active) { - let myorder: IOrder = { quantity: 1, quantitypreordered: 0, - TotalPriceProduct: 0, price: 0, - idStorehouse: getActualIdStorehouse(myprod), - idGasordine: getActualGasordine(myprod), - } - await productStore.addtoCartBase({ $q, t, id: myprod._id, order: myorder, addqty: true }) - search.value = '' - load() - } + // Inizializza } onMounted(mounted) @@ -225,21 +35,8 @@ export default defineComponent({ costanti, tools, toolsext, - completeOrder, - getNumItems, - myTotalPrice, - getItemsCart, - getNote, - change_field, - note, - statusnow, shared_consts, - myTotalQty, - recOrderCart, - mycart, - endload, - search, - insertArticolo, + t, } } }) diff --git a/src/views/ecommerce/checkOut/checkOut.vue b/src/views/ecommerce/checkOut/checkOut.vue index 219369cc..2cfc5199 100755 --- a/src/views/ecommerce/checkOut/checkOut.vue +++ b/src/views/ecommerce/checkOut/checkOut.vue @@ -1,82 +1,8 @@ diff --git a/src/views/ecommerce/orderInfo/orderInfo.ts b/src/views/ecommerce/orderInfo/orderInfo.ts index 75ef25db..91e6dcf1 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.ts +++ b/src/views/ecommerce/orderInfo/orderInfo.ts @@ -48,6 +48,14 @@ export default defineComponent({ const statusnow = ref(0) const arrnumstatus = ref([]) const columns = ref([ + { + name: 'apri', + align: 'center', + required: false, + label: 'Apri', + field: 'apri', + sortable: false + }, { name: 'numorder', required: true, @@ -89,6 +97,14 @@ export default defineComponent({ ]) const columns_Admin = ref([ + { + name: 'apri', + align: 'center', + required: false, + label: 'Apri', + field: 'apri', + sortable: false + }, { name: 'numorder', required: true, diff --git a/src/views/ecommerce/orderInfo/orderInfo.vue b/src/views/ecommerce/orderInfo/orderInfo.vue index c68b6f07..004f2807 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.vue +++ b/src/views/ecommerce/orderInfo/orderInfo.vue @@ -4,76 +4,58 @@
- - - + + + - - -
-˚ + + +
+ ˚
- +
- +