From 1e660682a6d60118b1d2c87549c089663e04a057 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:40:16 +0700 Subject: [PATCH] feat: add installments validate --- .../04_product-service/FormServiceWork.vue | 8 ++-- .../WorkManagementComponent.vue | 11 ++--- src/i18n/eng.ts | 2 + src/i18n/tha.ts | 2 + src/pages/04_product-service/MainPage.vue | 42 ++++++++++--------- src/stores/product-service/types.ts | 1 + 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/components/04_product-service/FormServiceWork.vue b/src/components/04_product-service/FormServiceWork.vue index 8ba05f21..d3c3454b 100644 --- a/src/components/04_product-service/FormServiceWork.vue +++ b/src/components/04_product-service/FormServiceWork.vue @@ -23,6 +23,7 @@ const props = defineProps<{ readonly?: boolean; separator?: boolean; treeView?: boolean; + installments?: number; priceDisplay?: { price: boolean; @@ -188,9 +189,10 @@ watch( :key="work.id" :index="index" :length="workItems.length" - :workIndex="index" - :readonly="readonly" - :priceDisplay="priceDisplay" + :work-index="index" + :readonly + :price-display + :installments v-model:work-name="workItems[index].name" v-model:product-items="work.product" v-model:attributes="work.attributes" diff --git a/src/components/04_product-service/WorkManagementComponent.vue b/src/components/04_product-service/WorkManagementComponent.vue index 3566317b..b95d5617 100644 --- a/src/components/04_product-service/WorkManagementComponent.vue +++ b/src/components/04_product-service/WorkManagementComponent.vue @@ -18,7 +18,7 @@ const optionStore = useOptionStore(); const workflowStore = useWorkflowTemplate(); const { fetchListOfWork } = productServiceStore; -const { splitPay, workNameItems } = storeToRefs(productServiceStore); +const { workNameItems } = storeToRefs(productServiceStore); const { data: workflowData } = storeToRefs(workflowStore); @@ -28,6 +28,7 @@ const props = withDefaults( length: number; index: number; readonly?: boolean; + installments?: number; priceDisplay?: { price: boolean; @@ -445,7 +446,7 @@ watch( diff --git a/src/i18n/eng.ts b/src/i18n/eng.ts index c5b62894..8d883b9a 100644 --- a/src/i18n/eng.ts +++ b/src/i18n/eng.ts @@ -1026,6 +1026,8 @@ export default { 'An error has occurred, causing the system to be unable to function. Please try again later.', invalideData: 'The information is incorrect. Please try again later.', authFailed: 'Authentication Failed. Please try again later. ', + installmentsValidateFailed: + 'Validation failed. Each installment must include at least one product. Please review and update the installments accordingly.', }, }, diff --git a/src/i18n/tha.ts b/src/i18n/tha.ts index b852671b..88b0ecde 100644 --- a/src/i18n/tha.ts +++ b/src/i18n/tha.ts @@ -1012,6 +1012,8 @@ export default { 'เกิดข้อผิดพลาดทำให้ระบบไม่สามารถทำงานได้ กรุณาลองใหม่ในภายหลัง', invalideData: 'ข้อมูลไม่ถูกต้อง กรุณาตรวจสอบใหม่อีกครั้ง', authFailed: 'การยืนยันตัวตนล้มเหลว กรุณาลองใหม่ในภายหลัง', + installmentsValidateFailed: + 'ข้อมูลงวดไม่ถูกต้อง กรุณาตรวจสอบและยืนยันว่าแต่ละงวดมีสินค้าอย่างน้อยหนึ่งรายการ', }, }, diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index 9e2d6471..7cec3858 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -97,7 +97,7 @@ const { deleteWork, } = productServiceStore; -const { workNameItems, splitPay } = storeToRefs(productServiceStore); +const { workNameItems } = storeToRefs(productServiceStore); const allStat = ref<{ mode: string; count: number }[]>([]); const stat = ref< { @@ -916,7 +916,7 @@ const prevService = ref({ const currentService = ref(); -async function assignFormDataProductService(id: string) { +async function assignFormService(id: string) { const res = await fetchListServiceById(id); if (res) { @@ -942,6 +942,7 @@ async function assignFormDataProductService(id: string) { status: res.status, productGroupId: res.productGroupId, selectedImage: res.selectedImage, + installments: res.installments, }; formService.value = { ...prevService.value }; @@ -962,13 +963,6 @@ async function assignFormDataProductService(id: string) { formService.value.work = prevService.value.work; workItems.value = res.work.map((item) => { - const maxInstallmentsNo = item.productOnWork.map( - (productOnWorkItem) => productOnWorkItem.installmentNo || 0, - ); - - if (splitPay.value < Math.max(...maxInstallmentsNo)) - splitPay.value = Math.max(...maxInstallmentsNo); - return { id: item.id, name: item.name, @@ -1085,7 +1079,6 @@ function clearFormService() { productGroupId: '', }; tempWorkItems.value = []; - splitPay.value = 0; workItems.value = []; selectProduct.value = []; dialogService.value = false; @@ -1151,16 +1144,19 @@ async function submitService(notClose = false) { if (res) { allStat.value[1].count = allStat.value[1].count + 1; stat.value[1].count = stat.value[1].count + 1; + } else { + return; } totalService.value = totalService.value + 1; productAndServiceTab.value = 'service'; } if (dialogServiceEdit.value) { - await editService(currentIdService.value, { + const res = await editService(currentIdService.value, { ...formService.value, status: statusToggle.value ? formService.value.status : 'INACTIVE', }); + if (!res) return; } if (!notClose) clearFormService(); @@ -1191,17 +1187,21 @@ async function submitProduct(notClose = false) { if (res) { allStat.value[2].count = allStat.value[2].count + 1; stat.value[2].count = stat.value[2].count + 1; + } else { + return; } productAndServiceTab.value = 'product'; } if (dialogProductEdit.value) { - await editProduct(currentIdProduct.value, { + const res = await editProduct(currentIdProduct.value, { ...formProduct.value, status: statusToggle.value ? 'ACTIVE' : 'INACTIVE', document: formProductDocument.value, }); + + if (!res) return; } totalProduct.value = totalProduct.value + 1; if (!notClose) clearFormProduct(); @@ -1246,7 +1246,7 @@ function submitAddWorkProduct() { if (!productExists) { workItems.value[currentWorkIndex.value].product.push({ ...i, - installmentNo: splitPay.value > 0 ? 1 : 0, + installmentNo: !!formService.value.installments ? 1 : 0, nameEn: '', }); workItems.value[currentWorkIndex.value].attributes.workflowStep.forEach( @@ -2896,7 +2896,7 @@ watch( if (props.row.type === 'service') { currentIdService = props.row.id; infoServiceEdit = false; - assignFormDataProductService(props.row.id); + assignFormService(props.row.id); dialogServiceEdit = true; } } @@ -2915,7 +2915,7 @@ watch( if (props.row.type === 'service') { currentIdService = props.row.id; infoServiceEdit = false; - assignFormDataProductService(props.row.id); + assignFormService(props.row.id); dialogServiceEdit = true; } } @@ -2931,7 +2931,7 @@ watch( if (props.row.type === 'service') { currentIdService = props.row.id; infoServiceEdit = true; - assignFormDataProductService(props.row.id); + assignFormService(props.row.id); dialogServiceEdit = true; } } @@ -2986,7 +2986,7 @@ watch( if (row.type === 'service') { currentIdService = row.id; infoServiceEdit = false; - assignFormDataProductService(row.id); + assignFormService(row.id); dialogServiceEdit = true; } } @@ -3002,7 +3002,7 @@ watch( if (row.type === 'service') { currentIdService = row.id; infoServiceEdit = true; - assignFormDataProductService(row.id); + assignFormService(row.id); dialogServiceEdit = true; } } @@ -4082,7 +4082,7 @@ watch( class="split-pay q-mx-sm" input-class="text-caption text-right" type="number" - v-model="splitPay" + v-model="formService.installments" /> {{ $t('quotation.receiptDialog.installments') }} @@ -4158,6 +4158,7 @@ watch( v-model:workflow="currWorkflow" :tree-view="serviceTreeView" :service="formService" + :installments="formService.installments" dense @add-product=" async (index) => { @@ -4513,7 +4514,7 @@ watch( class="split-pay q-mx-sm" input-class="text-caption text-right" type="number" - v-model="splitPay" + v-model="formService.installments" /> {{ $t('quotation.receiptDialog.installments') }} @@ -4547,6 +4548,7 @@ watch( :service="formService" :tree-view="serviceTreeView" :readonly="!infoServiceEdit" + :installments="formService.installments" :price-display="priceDisplay" dense @add-product=" diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index a7d794be..3116de51 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -124,6 +124,7 @@ export interface ServiceById { productGroupId: string; selectedImage: string; registeredBranchId: string; + installments: number; } export interface ProductOnWork {