From 1b4c06b18221614d15de1ae88f2e608e407147df Mon Sep 17 00:00:00 2001 From: puriphatt <162551324+puriphatt@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:01:52 +0700 Subject: [PATCH] fix/refactor: quotation installment (#121) * refactor/feat: i18n * chore: clean log * refactor: type * refactor: installment and product table state relation * refactor: handle split custom --------- Co-authored-by: Thanaphon Frappet --- src/components/05_quotation/ProductItem.vue | 52 ++++- src/i18n/eng.ts | 2 + src/i18n/tha.ts | 2 + src/pages/05_quotation/QuotationForm.vue | 215 +++++++++++++++++- src/pages/05_quotation/QuotationFormInfo.vue | 100 ++++---- .../QuotationFormProductSelect.vue | 9 +- src/pages/05_quotation/form.ts | 2 - src/pages/05_quotation/utils.ts | 12 +- src/stores/quotations/types.ts | 32 ++- src/utils/string-template.ts | 8 +- 10 files changed, 357 insertions(+), 77 deletions(-) diff --git a/src/components/05_quotation/ProductItem.vue b/src/components/05_quotation/ProductItem.vue index c5c514ef..6ef1544e 100644 --- a/src/components/05_quotation/ProductItem.vue +++ b/src/components/05_quotation/ProductItem.vue @@ -6,7 +6,7 @@ import { storeToRefs } from 'pinia'; import WorkerItem from './WorkerItem.vue'; import DeleteButton from '../button/DeleteButton.vue'; import { precisionRound } from 'src/utils/arithmetic'; -import { QuotationPayload } from 'stores/quotations/types'; +import { ProductServiceList, QuotationPayload } from 'stores/quotations/types'; import { formatNumberDecimal, commaInput } from 'stores/utils'; import { useConfigStore } from 'stores/config'; @@ -14,6 +14,7 @@ const props = defineProps<{ readonly?: boolean; agentPrice: boolean; installmentInput?: boolean; + maxInstallment?: number | null; employeeRows?: { foreignRefNo: string; employeeName: string; @@ -29,6 +30,13 @@ const props = defineProps<{ defineEmits<{ (e: 'delete', index: number): void; + ( + e: 'updateTable', + data: QuotationPayload['productServiceList'][number], + opt?: { + newInstallmentNo: number; + }, + ): void; }>(); const configStore = useConfigStore(); @@ -224,6 +232,26 @@ watch( } }, ); + +watch( + () => props.maxInstallment, + () => { + if (!props.maxInstallment) return; + let test: ProductServiceList[] = []; + const items = groupByServiceId( + rows.value.map((v, i) => Object.assign(v, { i })), + ) || [{ title: '', product: [] }]; + + items.forEach((p) => { + test = test.concat(p.product.flatMap((item) => item)); + }); + test.forEach((p) => { + if ((props.maxInstallment || 0) < (p.installmentNo || 0)) { + p.installmentNo = Number(props.maxInstallment); + } + }); + }, +);