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

@ -432,7 +432,12 @@ watch(
/> />
</q-td> </q-td>
<q-td align="right"> <q-td align="right">
{{ formatNumberDecimal(props.row.pricePerUnit, 2) }} {{
formatNumberDecimal(
props.row.pricePerUnit * props.row.amount,
2,
)
}}
</q-td> </q-td>
<q-td align="right"> <q-td align="right">
{{ {{

View file

@ -79,7 +79,7 @@ export default {
calculateVat: 'Calculate VAT', calculateVat: 'Calculate VAT',
discountAfterVat: 'Discount after vat', discountAfterVat: 'Discount after vat',
totalAfterDiscount: 'Total after discount', totalAfterDiscount: 'Total after discount',
totalVatExcluded: 'Tax exemption amount', totalVatExcluded: 'Tax-exempt amoun',
totalVatIncluded: 'Taxable amount', totalVatIncluded: 'Taxable amount',
vat: 'VAT {msg}', vat: 'VAT {msg}',
totalAmount: 'Total amount (Baht)', totalAmount: 'Total amount (Baht)',

View file

@ -81,7 +81,7 @@ export default {
discountAfterVat: 'ส่วนลดหลังคำนวณภาษี', discountAfterVat: 'ส่วนลดหลังคำนวณภาษี',
calculateVat: 'คำนวณภาษี', calculateVat: 'คำนวณภาษี',
totalAfterDiscount: 'จำนวนเงินหลังหักส่วนลด', totalAfterDiscount: 'จำนวนเงินหลังหักส่วนลด',
totalVatExcluded: 'จำนวนเงินยกเว้นภาษี', totalVatExcluded: 'จำนวนเงินที่ไม่มี/ยกเว้นภาษี',
totalVatIncluded: 'จำนวนเงินที่คำนวณภาษี', totalVatIncluded: 'จำนวนเงินที่คำนวณภาษี',
vat: 'ภาษีมูลค่าเพิ่ม {msg}', vat: 'ภาษีมูลค่าเพิ่ม {msg}',
totalAmount: 'จำนวนเงินรวมทั้งสิ้น (บาท)', totalAmount: 'จำนวนเงินรวมทั้งสิ้น (บาท)',

View file

@ -259,7 +259,7 @@ function getPrice(
a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat; a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat;
a.vatExcluded = c.product.calcVat a.vatExcluded = c.product.calcVat
? a.vatExcluded ? a.vatExcluded
: precisionRound(a.vatExcluded + vat); : precisionRound(a.vatExcluded + price);
a.finalPrice = precisionRound( a.finalPrice = precisionRound(
a.totalPrice - a.totalPrice -
a.totalDiscount + a.totalDiscount +

View file

@ -44,6 +44,7 @@ type Product = {
discount: number; discount: number;
vat: number; vat: number;
value: number; value: number;
calcVat: boolean;
}; };
type SummaryPrice = { type SummaryPrice = {
@ -250,6 +251,7 @@ onMounted(async () => {
discount: v.discount || 0, discount: v.discount || 0,
vat: v.vat || 0, vat: v.vat || 0,
value: precisionRound(price + (v.product.calcVat ? vat : 0)), value: precisionRound(price + (v.product.calcVat ? vat : 0)),
calcVat: v.product.calcVat,
}; };
}, },
) || []; ) || [];
@ -276,7 +278,7 @@ onMounted(async () => {
a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat; a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat;
a.vatExcluded = c.product.calcVat a.vatExcluded = c.product.calcVat
? a.vatExcluded ? a.vatExcluded
: precisionRound(a.vatExcluded + vat); : precisionRound(a.vatExcluded + price);
a.finalPrice = precisionRound( a.finalPrice = precisionRound(
a.totalPrice - a.totalPrice -
a.totalDiscount + a.totalDiscount +
@ -363,7 +365,17 @@ function print() {
{{ formatNumberDecimal(v.discount, 2) }} {{ formatNumberDecimal(v.discount, 2) }}
</td> </td>
<td style="text-align: right"> <td style="text-align: right">
{{ formatNumberDecimal(v.vat, 2) }} {{
formatNumberDecimal(
v.calcVat
? precisionRound(
(v.priceUnit * v.amount - v.discount) *
(config?.vat || 0.07),
)
: 0,
2,
)
}}
</td> </td>
<td style="text-align: right"> <td style="text-align: right">
{{ formatNumberDecimal(v.value, 2) }} {{ formatNumberDecimal(v.value, 2) }}

View file

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

View file

@ -86,7 +86,9 @@ function calcPrice(
: pricePerUnit; : pricePerUnit;
const priceDiscountNoVat = priceNoVat * amount - discount; 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); return precisionRound(priceNoVat * amount + rawVatTotal);
} }

View file

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