feat: adjust price to respect its calc vat

This commit is contained in:
Methapon2001 2025-01-28 17:56:23 +07:00
parent fba9adc5f3
commit 82793dc7a8
4 changed files with 50 additions and 25 deletions

View file

@ -199,7 +199,7 @@ onMounted(async () => {
}) })
.reduce( .reduce(
(a, c) => { (a, c) => {
const priceNoVat = c.product.vatIncluded const priceNoVat = c.product.serviceChargeVatIncluded
? c.pricePerUnit / (1 + (config.value?.vat || 0.07)) ? c.pricePerUnit / (1 + (config.value?.vat || 0.07))
: c.pricePerUnit; : c.pricePerUnit;
const adjustedPriceWithVat = precisionRound( const adjustedPriceWithVat = precisionRound(
@ -219,9 +219,10 @@ onMounted(async () => {
priceUnit: precisionRound(priceNoVat), priceUnit: precisionRound(priceNoVat),
amount: c.amount, amount: c.amount,
discount: c.discount, discount: c.discount,
vat: c.product.calcVat ? precisionRound(rawVat) : 0, vat: c.product.serviceChargeCalcVat ? precisionRound(rawVat) : 0,
value: precisionRound( value: precisionRound(
priceNoVat * c.amount + (c.product.calcVat ? rawVatTotal : 0), priceNoVat * c.amount +
(c.product.serviceChargeCalcVat ? rawVatTotal : 0),
), ),
}); });

View file

@ -56,18 +56,25 @@ function openList(index: number) {
} }
function calcPricePerUnit(product: RequestWork['productService']['product']) { function calcPricePerUnit(product: RequestWork['productService']['product']) {
return product.vatIncluded const val = props.creditNote
? (props.creditNote ? props.agentPrice
? product.agentPrice
: product.price
: product.serviceCharge;
if (
product[
props.creditNote
? props.agentPrice ? props.agentPrice
? product.agentPrice ? 'agentPriceCalcVat'
: product.price : 'calcVat'
: product.serviceCharge) / : 'serviceChargeCalcVat'
(1 + (config.value?.vat || 0.07)) ]
: props.creditNote ) {
? props.agentPrice return val / (1 + (config.value?.vat || 0.07));
? product.agentPrice } else {
: product.price return val;
: product.serviceCharge; }
} }
function calcPrice( function calcPrice(
@ -81,12 +88,24 @@ function calcPrice(
: product.serviceCharge; : product.serviceCharge;
const discount = const discount =
taskProduct.value.find((v) => v.productId === product.id)?.discount || 0; taskProduct.value.find((v) => v.productId === product.id)?.discount || 0;
const priceNoVat = product.vatIncluded const priceNoVat = product[
props.creditNote
? props.agentPrice
? 'agentPriceVatIncluded'
: 'vatIncluded'
: 'serviceChargeVatIncluded'
]
? pricePerUnit / (1 + (config.value?.vat || 0.07)) ? pricePerUnit / (1 + (config.value?.vat || 0.07))
: pricePerUnit; : pricePerUnit;
const priceDiscountNoVat = priceNoVat * amount - discount; const priceDiscountNoVat = priceNoVat * amount - discount;
const rawVatTotal = product.calcVat const rawVatTotal = product[
props.creditNote
? props.agentPrice
? 'agentPriceCalcVat'
: 'calcVat'
: 'serviceChargeCalcVat'
]
? priceDiscountNoVat * (config.value?.vat || 0.07) ? priceDiscountNoVat * (config.value?.vat || 0.07)
: 0; : 0;

View file

@ -135,7 +135,7 @@ function getPrice(
const discount = const discount =
taskProduct.value.find((v) => v.productId === c.product.id)?.discount || taskProduct.value.find((v) => v.productId === c.product.id)?.discount ||
0; 0;
const priceNoVat = c.product.vatIncluded const priceNoVat = c.product.serviceChargeVatIncluded
? pricePerUnit / (1 + (config.value?.vat || 0.07)) ? pricePerUnit / (1 + (config.value?.vat || 0.07))
: pricePerUnit; : pricePerUnit;
const adjustedPriceWithVat = precisionRound( const adjustedPriceWithVat = precisionRound(
@ -149,8 +149,8 @@ function getPrice(
a.totalPrice = a.totalPrice + priceDiscountNoVat; a.totalPrice = a.totalPrice + priceDiscountNoVat;
a.totalDiscount = a.totalDiscount + Number(discount); a.totalDiscount = a.totalDiscount + Number(discount);
a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat; a.vat = c.product.serviceChargeCalcVat ? a.vat + rawVatTotal : a.vat;
a.vatExcluded = c.product.calcVat a.vatExcluded = c.product.serviceChargeCalcVat
? a.vatExcluded ? a.vatExcluded
: precisionRound(a.vatExcluded + priceDiscountNoVat); : precisionRound(a.vatExcluded + priceDiscountNoVat);
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat; a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;

View file

@ -195,12 +195,13 @@ function getPrice(
) { ) {
return list.reduce( return list.reduce(
(a, c) => { (a, c) => {
const pricePerUnit = quotationData.value?.agentPrice const agentPrice = !!quotationData.value?.agentPrice;
? c.product.agentPrice const pricePerUnit = agentPrice ? c.product.agentPrice : c.product.price;
: c.product.price;
const amount = c.list.length; const amount = c.list.length;
const discount = 0; const discount = 0;
const priceNoVat = c.product.vatIncluded const priceNoVat = c.product[
agentPrice ? 'agentPriceVatIncluded' : 'vatIncluded'
]
? pricePerUnit / (1 + (config.value?.vat || 0.07)) ? pricePerUnit / (1 + (config.value?.vat || 0.07))
: pricePerUnit; : pricePerUnit;
const priceDiscountNoVat = priceNoVat * amount - discount; const priceDiscountNoVat = priceNoVat * amount - discount;
@ -210,8 +211,12 @@ function getPrice(
a.totalPrice = a.totalPrice + priceDiscountNoVat; a.totalPrice = a.totalPrice + priceDiscountNoVat;
a.totalDiscount = a.totalDiscount + Number(discount); a.totalDiscount = a.totalDiscount + Number(discount);
a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat; a.vat = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
a.vatExcluded = c.product.calcVat ? a.vatExcluded : a.vat + rawVatTotal; ? a.vat + rawVatTotal
: a.vat;
a.vatExcluded = c.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
? a.vatExcluded
: a.vat + rawVatTotal;
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat; a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
return a; return a;
}, },