From 42f101b505c9a941a629d9183d00b5eba5b8bbb4 Mon Sep 17 00:00:00 2001 From: szewczyw Date: Thu, 13 Mar 2025 09:24:47 +0100 Subject: [PATCH] added duplication --- components.d.ts | 1 + src/components/MainForm.vue | 7 ++- src/components/OrdersSelector.vue | 8 ++-- src/main.ts | 2 +- src/router/router.ts | 4 +- src/stores/orders.store.ts | 72 +++++++++++++++++-------------- src/stores/siteControl.store.ts | 38 ++++++---------- src/views/MainView.vue | 2 +- 8 files changed, 67 insertions(+), 67 deletions(-) diff --git a/components.d.ts b/components.d.ts index 0654243..37c2623 100644 --- a/components.d.ts +++ b/components.d.ts @@ -13,6 +13,7 @@ declare module 'vue' { ConfirmationModal: typeof import('./src/components/ConfirmationModal.vue')['default'] ConfirmedForm: typeof import('./src/components/ConfirmedForm.vue')['default'] DataTable: typeof import('primevue/datatable')['default'] + Divider: typeof import('primevue/divider')['default'] IconCommunity: typeof import('./src/components/icons/IconCommunity.vue')['default'] IconDocumentation: typeof import('./src/components/icons/IconDocumentation.vue')['default'] IconEcosystem: typeof import('./src/components/icons/IconEcosystem.vue')['default'] diff --git a/src/components/MainForm.vue b/src/components/MainForm.vue index add9596..959b4c0 100644 --- a/src/components/MainForm.vue +++ b/src/components/MainForm.vue @@ -244,8 +244,10 @@ onBeforeUnmount( function () {
-

NOWE ZAMÓWIENIE

-

ZAMÓWIENIE NR {{order.MZN_MZNID}}

+

NOWE ZAMÓWIENIE

+

ZAMÓWIENIE NR {{order.MZN_MZNID}}

+

DUPLIKACJA ZAMÓWIENIA NR {{order.MZN_MZNID}}

+
@@ -402,6 +404,7 @@ onBeforeUnmount( function () {

+

diff --git a/src/components/OrdersSelector.vue b/src/components/OrdersSelector.vue index 7103829..69985a9 100644 --- a/src/components/OrdersSelector.vue +++ b/src/components/OrdersSelector.vue @@ -58,9 +58,9 @@ const datesWithOrders = computed( ()=>{ return datesWithOrders; }) -function viewOrder(order : Order) { +function viewOrder(order : Order, clone: boolean) { order.loading = true; - siteControlStore.viewOrder(order.MZN_UUID); + siteControlStore.viewOrder(order.MZN_UUID, clone); } async function fetchOrders(event : Event | null) { @@ -177,7 +177,9 @@ fetchOrders(null);
{{Number(product.MZE_TwrIlosc).toFixed(2) + " " + product.MZE_TwrJm}}
- + + +
diff --git a/src/main.ts b/src/main.ts index 378485c..7857381 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,7 +52,7 @@ watch ( export const axiosInstance = axios.create({ - baseURL: 'https://zamowienia.mleczarnia-kuzma.pl/api', + baseURL: 'https://zamowienia-test.mleczarnia-kuzma.pl/api', withCredentials: true }); diff --git a/src/router/router.ts b/src/router/router.ts index b451b37..3efbc2f 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -8,8 +8,8 @@ export const router = createRouter({ routes: [ { path: '/', component: MainView }, { path: '/login', component: LoginView }, - { path: '/summary', component: SummaryView, }, - { path: '/orders', component: OrdersView} + { path: '/summary', component: SummaryView}, + { path: '/orders', component: OrdersView}, ] }); diff --git a/src/stores/orders.store.ts b/src/stores/orders.store.ts index ba2da85..de360c6 100644 --- a/src/stores/orders.store.ts +++ b/src/stores/orders.store.ts @@ -11,6 +11,7 @@ export const useOrdersStore = defineStore('orders', () => { const deliveryDate = ref(); const orderDate = ref(); const additionalNotes = ref(); + const orderToClone = ref(); async function fetchOrders() { const response = await axiosInstance.get('/zamowienia', {withCredentials: true}); @@ -72,45 +73,52 @@ export const useOrdersStore = defineStore('orders', () => { return datesTemp; } - async function loadOrder(uuidString: string, confirmed: boolean, contractor: Ref, contractors: Ref>, categories: Ref>, route: Ref, routes: Ref|undefined>) { - const response = await axiosInstance.get('/zamowienie/' + uuidString); - const tempOrder = response.data; - console.log(tempOrder); - if(confirmed) { - tempOrder.MZN_Bufor = 0; + function updateStores(contractor: Ref, contractors: Ref>, tempOrder, route: Ref, routes: Ref | undefined>, uuidString: string) { + contractor.value = contractors.value?.find((contractor) => contractor.Knt_KntId == tempOrder.MZN_PodID) + route.value = routes.value?.find((route) => route.MZT_MZTID == tempOrder.MZN_MZTID) + deliveryDate.value = new Date(tempOrder.MZN_DataDos) + orderDate.value = new Date(tempOrder.MZN_DataZam) + if(!orderToClone.value) { + uuid.value = uuidString + }else { + uuid.value = undefined } + order.value = tempOrder + additionalNotes.value = tempOrder.MZN_Uwagi + } - contractor.value = contractors.value?.find((contractor) => contractor.Knt_KntId == tempOrder.MZN_PodID); - route.value = routes.value?.find((route) => route.MZT_MZTID == tempOrder.MZN_MZTID); - deliveryDate.value = new Date(tempOrder.MZN_DataDos); - orderDate.value = new Date(tempOrder.MZN_DataZam); - uuid.value = uuidString; - order.value = tempOrder; - additionalNotes.value = tempOrder.MZN_Uwagi; - - if(categories.value == undefined) { - return; - } - - for(const orderProduct of tempOrder.MZamElem){ - for(const category of categories.value) { - const product = category.Towary.find(product => (product.Twr_TwrId == orderProduct.MZE_TwrId)); - if(product != undefined && orderProduct.MZE_TwrCena != null) { - console.log(product); - if(orderProduct.MZE_TwrJm == product.Twr_JM) { - product.Twr_Cena = orderProduct.MZE_TwrCena.slice(0, -2); - } else if(orderProduct.Twr_Cena == product.Twr_JMZ) { - product.Twr_CenaZ = orderProduct.MZE_TwrCena.slice(0, -2); + function setOrderQuantities(tempOrder, categories: Ref>) { + for (const orderProduct of tempOrder.MZamElem) { + for (const category of categories.value) { + const product = category.Towary.find(product => (product.Twr_TwrId == orderProduct.MZE_TwrId)) + if (product != undefined && orderProduct.MZE_TwrCena != null) { + console.log(product) + if (orderProduct.MZE_TwrJm == product.Twr_JM) { + product.Twr_Cena = orderProduct.MZE_TwrCena.slice(0, -2) + } else if (orderProduct.Twr_Cena == product.Twr_JMZ) { + product.Twr_CenaZ = orderProduct.MZE_TwrCena.slice(0, -2) } - product.Quantity = orderProduct.MZE_TwrIlosc.slice(0, -2); - product.ChosenOption = orderProduct.MZE_TwrJm; - category.isVisible = true; - break; + product.Quantity = orderProduct.MZE_TwrIlosc.slice(0, -2) + product.ChosenOption = orderProduct.MZE_TwrJm + category.isVisible = true + break } } } } - return {orders, order, uuid, deliveryDate, orderDate, dates, additionalNotes, fetchOrders, loadOrder, fetchOrdersByDay, fetchOrdersByBuffer, fetchOrdersByDateStartAndEnd, fetchDates, getOrderDates} + async function loadOrder(uuidString: string, confirmed: boolean, contractor: Ref, contractors: Ref>, categories: Ref>, route: Ref, routes: Ref|undefined>) { + const response = await axiosInstance.get('/zamowienie/' + uuidString); + const tempOrder = response.data; + console.log(tempOrder); + + if(confirmed)tempOrder.MZN_Bufor = 0; + + updateStores(contractor, contractors, tempOrder, route, routes, uuidString) + if(categories.value == undefined) return; + setOrderQuantities(tempOrder, categories) + } + + return {orders,orderToClone, order, uuid, deliveryDate, orderDate, dates, additionalNotes, fetchOrders, loadOrder, fetchOrdersByDay, fetchOrdersByBuffer, fetchOrdersByDateStartAndEnd, fetchDates, getOrderDates} }) \ No newline at end of file diff --git a/src/stores/siteControl.store.ts b/src/stores/siteControl.store.ts index da9df5a..602cc29 100644 --- a/src/stores/siteControl.store.ts +++ b/src/stores/siteControl.store.ts @@ -14,6 +14,11 @@ export const useSiteControlStore = defineStore('siteControl', () => { const isDarkTheme = ref(false); const isLoading = ref(true); + const orderStore = useOrdersStore(); + const contractorsStore = useContractorsStore(); + const categoriesStore = useCategoriesStore(); + const routeStore = useRoutesStore(); + async function switchToForm() { await router.push("/"); @@ -21,21 +26,9 @@ export const useSiteControlStore = defineStore('siteControl', () => { async function switchToOrders() { await router.push("/orders"); - // const orderStore = useOrdersStore(); - // const { orders } = storeToRefs(orderStore); - // isLoading.value = true; - // const date = new Date(Date.now()); - // const startDate = new Date(date.getFullYear(), date.getMonth(), (date.getDate() - 2)); - // const endDate = new Date(date.getFullYear()+1, date.getMonth(), date.getDay()); - // orders.value = await orderStore.fetchOrdersByDateStartAndEnd(startDate, endDate, null); - // console.log(orders.value); - // isLoading.value = false; - } + } async function switchToTable() { - // const ordersStore = useOrdersStore(); - // const { orders } = storeToRefs(ordersStore); - // orders.value = await ordersStore.fetchOrdersByDay(new Date(Date.now()), null); await router.push("/summary"); } @@ -43,17 +36,14 @@ export const useSiteControlStore = defineStore('siteControl', () => { isDarkTheme.value = !!window?.matchMedia?.('(prefers-color-scheme:dark)')?.matches; } - async function viewOrder(uuid : string) { - const orderStore = useOrdersStore(); - const contractorsStore = useContractorsStore(); - const categoriesStore = useCategoriesStore(); - const routeStore = useRoutesStore(); + async function viewOrder(uuid : string, clone:boolean ) { shownComponent.value = "mainForm"; isLoading.value = true; await categoriesStore.fetchCategories(); const { contractor, contractors } = storeToRefs(contractorsStore); const { categories } = storeToRefs(categoriesStore); const { route, routes } = storeToRefs( routeStore ); + orderStore.orderToClone = clone; await orderStore.loadOrder(uuid, false, contractor, contractors, categories, route, routes); isLoading.value=false; await router.push("/"); @@ -61,11 +51,7 @@ export const useSiteControlStore = defineStore('siteControl', () => { } async function newOrder(redirect : boolean) { - const ordersStore = useOrdersStore(); - const contractorsStore = useContractorsStore(); - const categoriesStore = useCategoriesStore(); - const routeStore = useRoutesStore(); - const { order, uuid, deliveryDate, orderDate, additionalNotes } = storeToRefs(ordersStore); + const { order, uuid, deliveryDate, orderDate, additionalNotes } = storeToRefs(orderStore); const { contractor } = storeToRefs(contractorsStore); const { route } = storeToRefs(routeStore); contractor.value = undefined; @@ -76,11 +62,11 @@ export const useSiteControlStore = defineStore('siteControl', () => { route.value = undefined; additionalNotes.value = undefined; await categoriesStore.fetchCategories(); - if (redirect) { + if (redirect) + { await router.push("/"); window.scrollTo(0,0); } } - - return {isLoading, showConfirmationModal, showCancellationModal, isDarkTheme, shownComponent, switchToForm, switchToOrders, switchToTable, checkTheme, viewOrder, newOrder}; + return {isLoading, showConfirmationModal, showCancellationModal, isDarkTheme, shownComponent, switchToForm, switchToOrders, switchToTable, checkTheme, viewOrder ,newOrder}; }) \ No newline at end of file diff --git a/src/views/MainView.vue b/src/views/MainView.vue index e133e4a..08c2cc9 100644 --- a/src/views/MainView.vue +++ b/src/views/MainView.vue @@ -5,7 +5,7 @@