refactor: edit calc vat

This commit is contained in:
Thanaphon Frappet 2025-01-24 11:49:33 +07:00
parent 42575eb5ba
commit ca9264d758
8 changed files with 33 additions and 11 deletions

View file

@ -214,8 +214,10 @@ onMounted(async () => {
priceUnit: precisionRound(priceNoVat),
amount: c.amount,
discount: c.discount,
vat: precisionRound(rawVat),
value: precisionRound(priceNoVat * c.amount + rawVatTotal),
vat: c.product.calcVat ? precisionRound(rawVat) : 0,
value: precisionRound(
priceNoVat * c.amount + (c.product.calcVat ? rawVatTotal : 0),
),
});
a.totalPrice = a.totalPrice + priceDiscountNoVat;
@ -223,7 +225,7 @@ onMounted(async () => {
a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat;
a.vatExcluded = c.product.calcVat
? a.vatExcluded
: a.vatExcluded + rawVatTotal;
: precisionRound(a.vatExcluded + priceNoVat);
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
return a;
},

View file

@ -86,7 +86,9 @@ function calcPrice(
: pricePerUnit;
const priceDiscountNoVat = priceNoVat * amount - discount;
const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07);
const rawVatTotal = product.calcVat
? priceDiscountNoVat * (config.value?.vat || 0.07)
: 0;
return precisionRound(priceNoVat * amount + rawVatTotal);
}

View file

@ -41,6 +41,7 @@ import {
UserTaskStatus,
} from 'src/stores/task-order/types';
import { RequestWork } from 'src/stores/request-list';
import { precisionRound } from 'src/utils/arithmetic';
const taskOrderFormStore = useTaskOrderForm();
const taskOrderStore = useTaskOrderStore();
@ -146,7 +147,7 @@ function getPrice(
a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat;
a.vatExcluded = c.product.calcVat
? a.vatExcluded
: a.vatExcluded + rawVatTotal;
: precisionRound(a.vatExcluded + priceNoVat);
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
return a;
},