fix: inaccurate .01 price
This commit is contained in:
parent
ec61c73342
commit
e12a87f496
3 changed files with 73 additions and 42 deletions
|
|
@ -57,11 +57,18 @@ const currentBtnOpen = ref<{ title: string; opened: boolean[] }[]>([
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function calcPrice(c: (typeof rows.value)[number]) {
|
function calcPrice(c: (typeof rows.value)[number]) {
|
||||||
const price = c.pricePerUnit * c.amount;
|
const originalPrice = c.pricePerUnit;
|
||||||
|
const finalPriceWithVat = precisionRound(
|
||||||
|
originalPrice +
|
||||||
|
(c.product.vatIncluded || c.vat !== 0
|
||||||
|
? 0
|
||||||
|
: originalPrice * (config.value?.vat || 0.07)),
|
||||||
|
);
|
||||||
|
const finalPriceNoVat = finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
||||||
|
|
||||||
|
const price = finalPriceNoVat * c.amount;
|
||||||
const vat = c.product.calcVat
|
const vat = c.product.calcVat
|
||||||
? (c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) *
|
? (finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07)
|
||||||
(config.value?.vat || 0.07) *
|
|
||||||
(!c.discount ? c.amount : 1)
|
|
||||||
: 0;
|
: 0;
|
||||||
return precisionRound(price + vat);
|
return precisionRound(price + vat);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -242,11 +242,19 @@ function getPrice(
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
const price = c.pricePerUnit * c.amount;
|
const originalPrice = c.pricePerUnit;
|
||||||
|
const finalPriceWithVat = precisionRound(
|
||||||
|
originalPrice +
|
||||||
|
(c.product.vatIncluded
|
||||||
|
? 0
|
||||||
|
: originalPrice * (config.value?.vat || 0.07)),
|
||||||
|
);
|
||||||
|
const finalPriceNoVat =
|
||||||
|
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
||||||
|
|
||||||
|
const price = finalPriceNoVat * c.amount;
|
||||||
const vat =
|
const vat =
|
||||||
(c.pricePerUnit * (c.discount ? c.amount : 1) - c.discount) *
|
(finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07);
|
||||||
(config.value?.vat || 0.07) *
|
|
||||||
(!c.discount ? c.amount : 1);
|
|
||||||
|
|
||||||
a.totalPrice = precisionRound(a.totalPrice + price);
|
a.totalPrice = precisionRound(a.totalPrice + price);
|
||||||
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
||||||
|
|
@ -704,12 +712,12 @@ function handleUpdateProductTable(
|
||||||
const pricePerUnit = c.pricePerUnit || 0;
|
const pricePerUnit = c.pricePerUnit || 0;
|
||||||
const discount = c.discount || 0;
|
const discount = c.discount || 0;
|
||||||
|
|
||||||
return precisionRound(
|
return (
|
||||||
pricePerUnit * c.amount -
|
pricePerUnit * c.amount -
|
||||||
discount +
|
discount +
|
||||||
(c.product.calcVat
|
(c.product.calcVat
|
||||||
? (pricePerUnit * c.amount - discount) * (config.value?.vat || 0.07)
|
? (pricePerUnit * c.amount - discount) * (config.value?.vat || 0.07)
|
||||||
: 0),
|
: 0)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -767,17 +775,15 @@ function toggleDeleteProduct(index: number) {
|
||||||
? currProduct.product.agentPrice
|
? currProduct.product.agentPrice
|
||||||
: currProduct.product.price;
|
: currProduct.product.price;
|
||||||
const pricePerUnit = currProduct.product.vatIncluded
|
const pricePerUnit = currProduct.product.vatIncluded
|
||||||
? precisionRound(price / (1 + (config.value?.vat || 0.07)))
|
? price / (1 + (config.value?.vat || 0.07))
|
||||||
: price;
|
: price;
|
||||||
const vat = precisionRound(
|
const vat =
|
||||||
(pricePerUnit * currProduct.amount - currProduct.discount) *
|
(pricePerUnit * currProduct.amount - currProduct.discount) *
|
||||||
(config.value?.vat || 0.07),
|
(config.value?.vat || 0.07);
|
||||||
);
|
const finalPrice =
|
||||||
const finalPrice = precisionRound(
|
|
||||||
pricePerUnit * currProduct.amount +
|
pricePerUnit * currProduct.amount +
|
||||||
vat -
|
vat -
|
||||||
Number(currProduct.discount || 0),
|
Number(currProduct.discount || 0);
|
||||||
);
|
|
||||||
|
|
||||||
currTempPaySplit.amount = currPaySplit.amount - finalPrice;
|
currTempPaySplit.amount = currPaySplit.amount - finalPrice;
|
||||||
currPaySplit.amount = currTempPaySplit.amount;
|
currPaySplit.amount = currTempPaySplit.amount;
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,23 @@ onMounted(async () => {
|
||||||
|
|
||||||
productList.value =
|
productList.value =
|
||||||
(data?.value?.productServiceList ?? data.value?.productServiceList).map(
|
(data?.value?.productServiceList ?? data.value?.productServiceList).map(
|
||||||
(v) => ({
|
(v) => {
|
||||||
|
const originalPrice = v.pricePerUnit;
|
||||||
|
const finalPriceWithVat = precisionRound(
|
||||||
|
originalPrice +
|
||||||
|
(v.product.vatIncluded || v.vat !== 0
|
||||||
|
? 0
|
||||||
|
: originalPrice * (config.value?.vat || 0.07)),
|
||||||
|
);
|
||||||
|
const finalPriceNoVat =
|
||||||
|
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
||||||
|
|
||||||
|
const price = finalPriceNoVat * v.amount;
|
||||||
|
const vat =
|
||||||
|
(finalPriceNoVat * v.amount - v.discount) *
|
||||||
|
(config.value?.vat || 0.07);
|
||||||
|
|
||||||
|
return {
|
||||||
id: v.product.id,
|
id: v.product.id,
|
||||||
code: v.product.code,
|
code: v.product.code,
|
||||||
detail: v.product.name,
|
detail: v.product.name,
|
||||||
|
|
@ -236,15 +252,9 @@ onMounted(async () => {
|
||||||
priceUnit: v.pricePerUnit || 0,
|
priceUnit: v.pricePerUnit || 0,
|
||||||
discount: v.discount || 0,
|
discount: v.discount || 0,
|
||||||
vat: v.vat || 0,
|
vat: v.vat || 0,
|
||||||
value: precisionRound(
|
value: precisionRound(price + (v.product.calcVat ? vat : 0)),
|
||||||
(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),
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
) || [];
|
) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,11 +263,19 @@ onMounted(async () => {
|
||||||
[]
|
[]
|
||||||
).reduce(
|
).reduce(
|
||||||
(a, c) => {
|
(a, c) => {
|
||||||
const price = precisionRound((c.pricePerUnit || 0) * c.amount);
|
const originalPrice = c.pricePerUnit;
|
||||||
const vat = precisionRound(
|
const finalPriceWithVat = precisionRound(
|
||||||
((c.pricePerUnit || 0) * c.amount - (c.discount || 0)) *
|
originalPrice +
|
||||||
(config.value?.vat || 0.07),
|
(c.product.vatIncluded || c.vat !== 0
|
||||||
|
? 0
|
||||||
|
: originalPrice * (config.value?.vat || 0.07)),
|
||||||
);
|
);
|
||||||
|
const finalPriceNoVat =
|
||||||
|
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
||||||
|
|
||||||
|
const price = finalPriceNoVat * c.amount;
|
||||||
|
const vat =
|
||||||
|
(finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07);
|
||||||
|
|
||||||
a.totalPrice = precisionRound(a.totalPrice + price);
|
a.totalPrice = precisionRound(a.totalPrice + price);
|
||||||
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
a.totalDiscount = precisionRound(a.totalDiscount + Number(c.discount));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue