diff --git a/src/components/05_quotation/ProductItem.vue b/src/components/05_quotation/ProductItem.vue index 597107ce..5276ff60 100644 --- a/src/components/05_quotation/ProductItem.vue +++ b/src/components/05_quotation/ProductItem.vue @@ -57,7 +57,6 @@ const currentBtnOpen = ref<{ title: string; opened: boolean[] }[]>([ ]); function calcPrice(c: (typeof rows.value)[number]) { - console.log(c); const originalPrice = c.pricePerUnit; const finalPriceWithVat = precisionRound( originalPrice + originalPrice * (config.value?.vat || 0.07), diff --git a/src/pages/03_customer-management/components/employer/EmployerFormBusiness.vue b/src/pages/03_customer-management/components/employer/EmployerFormBusiness.vue index c99ef26c..5f3ab63f 100644 --- a/src/pages/03_customer-management/components/employer/EmployerFormBusiness.vue +++ b/src/pages/03_customer-management/components/employer/EmployerFormBusiness.vue @@ -71,7 +71,7 @@ watch( (newValue) => { if (newValue !== undefined && typeof newValue === 'string') { const numericValue = newValue.replace(/,/g, ''); - wageRateText.value = ThaiBahtText(numericValue); + wageRateText.value = ThaiBahtText(numericValue) || 'ศูนย์บาทถ้วน'; wageRate.value = parseFloat(numericValue); } }, diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue index c1edbf4d..4ea677b6 100644 --- a/src/pages/05_quotation/QuotationForm.vue +++ b/src/pages/05_quotation/QuotationForm.vue @@ -704,18 +704,22 @@ function handleUpdateProductTable( newInstallmentNo: number; }, ) { + handleChangePayType(quotationFormData.value.payCondition); // calc price const calc = (c: QuotationPayload['productServiceList'][number]) => { - const pricePerUnit = c.pricePerUnit || 0; - const discount = c.discount || 0; - - return ( - pricePerUnit * c.amount - - discount + - (c.product.calcVat - ? (pricePerUnit * c.amount - discount) * (config.value?.vat || 0.07) - : 0) + const originalPrice = c.pricePerUnit || 0; + const finalPriceWithVat = precisionRound( + originalPrice * (1 + (config.value?.vat || 0.07)), ); + const finalPriceNoVat = + finalPriceWithVat / (1 + (config.value?.vat || 0.07)); + + const price = finalPriceNoVat * c.amount; + const vat = c.product.calcVat + ? (finalPriceNoVat * c.amount - (c.discount || 0)) * + (config.value?.vat || 0.07) + : 0; + return precisionRound(price + vat); }; // installment @@ -2057,23 +2061,20 @@ watch(
- {{ $t('general.view', { msg: $t('general.example') }) }} - + --> - ({{ ThaiBahtText(summaryPrice.finalPrice) }}) + ({{ ThaiBahtText(summaryPrice.finalPrice) || 'ศูนย์บาทถ้วน' }})
(); const props = defineProps<{ + taskListGroup?: { + product: RequestWork['productService']['product']; + list: (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + responsibleInstitution: (string | { group: string })[]; + } | null; + })[]; + }[]; creditNote?: boolean; fetchParams?: Parameters[0]; }>(); @@ -39,6 +51,20 @@ const taskList = defineModel< }); const open = defineModel('open', { default: false }); +const tempGroupEdit = defineModel< + { + product: RequestWork['productService']['product']; + list: (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + responsibleInstitution: (string | { group: string })[]; + } | null; + })[]; + }[] +>('tempGroupEdit', { default: [] }); const selectedEmployee = ref< (RequestWork & { taskStatus: TaskStatus; @@ -56,15 +82,28 @@ let group = computed(() => data.value.reduce< { product: RequestWork['productService']['product']; - list: RequestWork[]; + list: (RequestWork & { + _template?: { + id: string; + templateName: string; + templateStepName: string; + step: number; + responsibleInstitution: (string | { group: string })[]; + } | null; + })[]; }[] >((acc, curr) => { let exist = acc.find( (item) => curr.productService.productId == item.product.id, ); - if (exist) exist.list.push(curr); - else acc.push({ product: curr.productService.product, list: [curr] }); + if (exist) exist.list.push({ ...curr, _template: getTemplateData(curr) }); + else + acc.push({ + product: curr.productService.product, + // list: [curr], + list: [{ ...curr, _template: getTemplateData(curr) }], + }); return acc; }, []), @@ -74,7 +113,12 @@ let state = reactive({ search: '', }); -onMounted(getList); +onMounted(async () => { + await getList(); + if (tempGroupEdit.value.length === 0) { + tempGroupEdit.value = JSON.parse(JSON.stringify(group.value)); + } +}); watch(() => state.search, getList); async function getList() { @@ -90,35 +134,11 @@ async function getList() { data.value = res.result; } -// function toggle(item: RequestWork) { -// switch (selected(item)) { -// case true: -// return deselect(item); -// case false: -// return select(item); -// } -// } - -// function select(item: RequestWork) { -// if (selected(item)) return; -// selectedEmployee.value = selectedEmployee.value -// ? selectedEmployee.value.concat(item) -// : [item]; -// } - -// function deselect(item: RequestWork) { -// const idx = selectedEmployee.value?.findIndex((v) => v.id === item.id); -// if (idx !== -1) selectedEmployee.value?.splice(idx, 1); -// } - -// function selected(item: RequestWork): boolean { -// return !!selectedEmployee.value?.some((v) => v.id === item.id); -// } -// - function getStep(requestWork: RequestWork) { const target = requestWork.stepStatus.find( - (v) => v.workStatus === RequestWorkStatus.Ready, + (v) => + v.workStatus === RequestWorkStatus.Ready || + v.workStatus === RequestWorkStatus.InProgress, ); return target?.step || 0; } @@ -135,6 +155,7 @@ function getTemplateData(requestWork: RequestWork) { step: step.order, templateName: flow.name, templateStepName: step.name || '-', + responsibleInstitution: step.responsibleInstitution || [], }; } @@ -149,17 +170,22 @@ function submit() { const curr = v.stepStatus.find( (s) => s.workStatus === - (props.creditNote - ? RequestWorkStatus.Canceled - : RequestWorkStatus.Ready), + (props.creditNote + ? RequestWorkStatus.Canceled + : RequestWorkStatus.Ready) || + s.workStatus === + (props.creditNote + ? RequestWorkStatus.Canceled + : RequestWorkStatus.InProgress), ); if (curr) { const task: Task = { ...curr, attributes: curr.attributes, - workStatus: props.creditNote - ? RequestWorkStatus.Canceled - : RequestWorkStatus.Ready, + workStatus: + curr.workStatus || props.creditNote + ? RequestWorkStatus.Ready + : RequestWorkStatus.Canceled, taskOrderId: '', requestWork: selectedEmployee.value[i], }; @@ -183,9 +209,13 @@ function close() { } function onDialogOpen() { + // assign selected to group + !props.creditNote && assignTempGroup(); + + // match group to check selectedEmployee.value = []; if (taskList.value.length === 0) return; - const matchingItems = group.value + const matchingItems = tempGroupEdit.value .flatMap((g) => g.list) .filter((l) => l.stepStatus.some((s) => @@ -194,6 +224,28 @@ function onDialogOpen() { ); selectedEmployee.value = JSON.parse(JSON.stringify(matchingItems)); } + +function assignTempGroup() { + if (!props.taskListGroup) return; + props.taskListGroup.forEach((newGroup) => { + const existingGroup = tempGroupEdit.value.find( + (g) => g.product.id === newGroup.product.id, + ); + + if (existingGroup) { + newGroup.list.forEach((newItem) => { + if (!existingGroup.list.some((item) => item.id === newItem.id)) { + existingGroup.list.push(newItem); + } + }); + } else { + tempGroupEdit.value.push({ + ...newGroup, + list: [...newGroup.list], // Ensure a new reference + }); + } + }); +}
-