From 81e5873e4cb526a428d86a04a9b1c998a6b134b4 Mon Sep 17 00:00:00 2001 From: Thanaphon Frappet Date: Fri, 18 Oct 2024 11:00:49 +0700 Subject: [PATCH] refactor: calculate value --- src/pages/05_quotation/peview/ViewForm.vue | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/pages/05_quotation/peview/ViewForm.vue b/src/pages/05_quotation/peview/ViewForm.vue index 510f0b0b..71e25681 100644 --- a/src/pages/05_quotation/peview/ViewForm.vue +++ b/src/pages/05_quotation/peview/ViewForm.vue @@ -8,8 +8,8 @@ import ThaiBahtText from 'thai-baht-text'; import useOptionStore from 'stores/options'; import { formatNumberDecimal } from 'stores/utils'; import { useQuotationForm } from 'pages/05_quotation/form'; -import { commaInput } from 'stores/utils'; import { useConfigStore } from 'stores/config'; +import { commaInput } from 'stores/utils'; // NOTE Import Types import { BankBook } from 'stores/branch/types'; @@ -44,7 +44,7 @@ type SummaryPrice = { finalPrice: number; }; -const note = ref('asdasd\d \n อะไรครับdasdasd'); +const note = ref(''); const productList = ref([ { id: 'cm14grwo30002z8ch55keto89', @@ -159,17 +159,25 @@ onMounted(async () => { data.value = JSON.parse(sessionStorage.getItem('quotation-preview') || '{}'); - if (data.value) { - productList.value = data.value?.productServiceList.map((v) => ({ - id: v.product.id, - code: v.product.code, - detail: v.product.detail, - amount: v.amount, - priceUnit: v.pricePerUnit || 0, - discount: v.discount || 0, - vat: v.vat || 0, - value: 0, - })); + if (data) { + productList.value = + data.value?.productServiceList.map((v) => ({ + id: v.product.id, + code: v.product.code, + detail: v.product.detail, + amount: v.amount || 0, + priceUnit: v.pricePerUnit || 0, + discount: v.discount || 0, + vat: v.vat || 0, + value: precisionRound( + (v.pricePerUnit || 0) * v.amount - + (v.discount || 0) + + (v.product.calcVat + ? ((v.pricePerUnit || 0) * v.amount - (v.discount || 0)) * + (config.value?.vat || 0.07) + : 0), + ), + })) || []; } summaryPrice.value = obj.productServiceList.reduce(