refactor: calculate value

This commit is contained in:
Thanaphon Frappet 2024-10-18 11:00:49 +07:00
parent 8f880fd34d
commit 81e5873e4c

View file

@ -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<string>('asdasd\d \n อะไรครับdasdasd');
const note = ref<string>('');
const productList = ref<Product[]>([
{
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(