diff --git a/src/pages/05_quotation/QuotationForm.vue b/src/pages/05_quotation/QuotationForm.vue
index fa018fb5..2f94dca0 100644
--- a/src/pages/05_quotation/QuotationForm.vue
+++ b/src/pages/05_quotation/QuotationForm.vue
@@ -254,6 +254,7 @@ function getPrice(
const pricePerUnit =
precisionRound(c.pricePerUnit * (1 + vatFactor)) / (1 + vatFactor);
+
const price =
(pricePerUnit * c.amount * (1 + vatFactor) - c.discount) /
(1 + vatFactor);
diff --git a/src/pages/05_quotation/preview/ViewForm.vue b/src/pages/05_quotation/preview/ViewForm.vue
index f154ef98..d65d3c37 100644
--- a/src/pages/05_quotation/preview/ViewForm.vue
+++ b/src/pages/05_quotation/preview/ViewForm.vue
@@ -405,12 +405,7 @@ function print() {
{{ v.detail }} |
{{ v.amount }} |
- {{
- formatNumberDecimal(
- v.pricePerUnit * (1 + (v.vat > 0 ? config?.vat || 0.07 : 0)),
- 2,
- )
- }}
+ {{ formatNumberDecimal(v.pricePerUnit, 2) }}
|
{{ formatNumberDecimal(v.discount, 2) }}
diff --git a/src/pages/09_task-order/document_view/MainPage.vue b/src/pages/09_task-order/document_view/MainPage.vue
index b631dbb1..a28cb966 100644
--- a/src/pages/09_task-order/document_view/MainPage.vue
+++ b/src/pages/09_task-order/document_view/MainPage.vue
@@ -202,40 +202,44 @@ onMounted(async () => {
})
.reduce(
(a, c) => {
- const priceNoVat = c.product.serviceChargeVatIncluded
- ? c.pricePerUnit / (1 + (config.value?.vat || 0.07))
- : c.pricePerUnit;
- const adjustedPriceWithVat = precisionRound(
- priceNoVat * (1 + (config.value?.vat || 0.07)),
- );
- const adjustedPriceNoVat =
- adjustedPriceWithVat / (1 + (config.value?.vat || 0.07));
- const priceDiscountNoVat = adjustedPriceNoVat * c.amount - c.discount;
+ const vatFactor = c.product.serviceChargeCalcVat
+ ? (config.value?.vat ?? 0.07)
+ : 0;
- const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07);
- const rawVat = rawVatTotal / c.amount;
+ const pricePerUnit =
+ precisionRound(c.product.serviceCharge * (1 + vatFactor)) /
+ (1 + vatFactor);
+
+ const amount = c.amount;
+ const discount = c.discount || 0;
+
+ const price =
+ (pricePerUnit * amount * (1 + vatFactor) - discount) /
+ (1 + vatFactor);
+
+ const vat = price * vatFactor;
product.value.push({
id: c.product.id,
code: c.product.code,
detail: c.product.name,
- priceUnit: precisionRound(priceNoVat),
+ priceUnit: precisionRound(pricePerUnit),
amount: c.amount,
discount: c.discount,
- vat: c.product.serviceChargeCalcVat ? precisionRound(rawVat) : 0,
+ vat: c.product.serviceChargeCalcVat ? precisionRound(vat) : 0,
value: precisionRound(
- priceNoVat * c.amount +
- (c.product.serviceChargeCalcVat ? rawVatTotal : 0),
+ pricePerUnit * c.amount +
+ (c.product.serviceChargeCalcVat ? vat : 0),
),
});
- a.totalPrice = a.totalPrice + priceDiscountNoVat;
- a.totalDiscount = a.totalDiscount + Number(c.discount);
- a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat;
- a.vatExcluded = c.product.calcVat
+ a.totalPrice = precisionRound(a.totalPrice + price + discount);
+ a.totalDiscount = precisionRound(a.totalDiscount + discount);
+ a.vat = precisionRound(a.vat + vat);
+ a.vatExcluded = c.product.serviceChargeCalcVat
? a.vatExcluded
- : precisionRound(a.vatExcluded + priceDiscountNoVat);
- a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
+ : precisionRound(a.vatExcluded + price);
+ a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
return a;
},
{
@@ -398,7 +402,9 @@ function closeAble() {
|
{{
formatNumberDecimal(
- summaryPrice.totalPrice - summaryPrice.totalDiscount,
+ summaryPrice.totalPrice -
+ summaryPrice.totalDiscount -
+ summaryPrice.vatExcluded,
2,
)
}}
diff --git a/src/pages/09_task-order/expansion/ProductExpansion.vue b/src/pages/09_task-order/expansion/ProductExpansion.vue
index 97a1f3bc..3190b966 100644
--- a/src/pages/09_task-order/expansion/ProductExpansion.vue
+++ b/src/pages/09_task-order/expansion/ProductExpansion.vue
@@ -14,6 +14,10 @@ import { storeToRefs } from 'pinia';
import BadgeComponent from 'src/components/BadgeComponent.vue';
import { TaskStatus } from 'src/stores/task-order/types';
+import { useTaskOrderForm } from '../form';
+
+const taskOrderFormStore = useTaskOrderForm();
+
const currentBtnOpen = ref([]);
const configStore = useConfigStore();
const { data: config } = storeToRefs(configStore);
@@ -61,60 +65,28 @@ function openList(index: number) {
}
function calcPricePerUnit(product: RequestWork['productService']['product']) {
- const val = props.creditNote
- ? props.agentPrice
- ? product.agentPrice
- : product.price
- : product.serviceCharge;
-
- if (
- product[
- props.creditNote
- ? props.agentPrice
- ? 'agentPriceCalcVat'
- : 'calcVat'
- : 'serviceChargeCalcVat'
- ]
- ) {
- return val / (1 + (config.value?.vat || 0.07));
- } else {
- return val;
- }
+ return product.serviceCharge;
}
function calcPrice(
product: RequestWork['productService']['product'],
amount: number,
) {
- const pricePerUnit = props.creditNote
- ? props.agentPrice
- ? product.agentPrice
- : product.price
- : product.serviceCharge;
- const discount =
- taskProduct.value.find((v) => v.productId === product.id)?.discount || 0;
- const priceNoVat = product[
- props.creditNote
- ? props.agentPrice
- ? 'agentPriceVatIncluded'
- : 'vatIncluded'
- : 'serviceChargeVatIncluded'
- ]
- ? pricePerUnit / (1 + (config.value?.vat || 0.07))
- : pricePerUnit;
- const priceDiscountNoVat = priceNoVat * amount - discount;
-
- const rawVatTotal = product[
- props.creditNote
- ? props.agentPrice
- ? 'agentPriceCalcVat'
- : 'calcVat'
- : 'serviceChargeCalcVat'
- ]
- ? priceDiscountNoVat * (config.value?.vat || 0.07)
+ const vatFactor = product.serviceChargeCalcVat
+ ? (config.value?.vat ?? 0.07)
: 0;
- return precisionRound(priceNoVat * amount + rawVatTotal);
+ const discount =
+ taskProduct.value.find((v) => v.productId === product.id)?.discount || 0;
+
+ const pricePerUnit = precisionRound(product.serviceCharge);
+
+ const price =
+ (pricePerUnit * amount * (1 + vatFactor) - discount) / (1 + vatFactor);
+
+ const vat = price * vatFactor;
+
+ return price + vat;
}
function taskOrderStatus(value: TaskStatus) {
@@ -247,7 +219,7 @@ function taskOrderStatus(value: TaskStatus) {
{{
formatNumberDecimal(
calcPricePerUnit(props.row.product) +
- (props.row.product.calcVat
+ (props.row.product.serviceChargeCalcVat
? calcPricePerUnit(props.row.product) *
(config?.vat || 0.07)
: 0),
@@ -298,11 +270,16 @@ function taskOrderStatus(value: TaskStatus) {
{{
formatNumberDecimal(
- calcPricePerUnit(props.row.product) * props.row.list.length -
- (taskProduct.find(
- (v) => v.productId === props.row.product.id,
- )?.discount || 0),
- 2,
+ props.row.product.serviceChargeCalcVat
+ ? (calcPricePerUnit(props.row.product) *
+ props.row.list.length *
+ (1 + (config?.vat || 0.07))) /
+ (1 + (config?.vat || 0.07))
+ : calcPricePerUnit(props.row.product) *
+ props.row.list.length -
+ taskProduct.find(
+ (v) => v.productId === props.row.product.id,
+ )?.discount || 0,
)
}}
@@ -310,17 +287,16 @@ function taskOrderStatus(value: TaskStatus) {
{{
formatNumberDecimal(
- props.row.product.calcVat
- ? precisionRound(
- (calcPricePerUnit(props.row.product) *
- props.row.list.length -
- (taskProduct.find(
- (v) => v.productId === props.row.product.id,
- )?.discount || 0)) *
- (config?.vat || 0.07),
- )
+ props.row.product.serviceChargeCalcVat
+ ? ((calcPricePerUnit(props.row.product) *
+ props.row.list.length *
+ (1 + (config?.vat || 0.07)) -
+ taskProduct.find(
+ (v) => v.productId === props.row.product.id,
+ )?.discount || 0) /
+ (1 + (config?.vat || 0.07))) *
+ 0.07
: 0,
- 2,
)
}}
diff --git a/src/pages/09_task-order/order_view/MainPage.vue b/src/pages/09_task-order/order_view/MainPage.vue
index 12c4fdfb..53ca7fba 100644
--- a/src/pages/09_task-order/order_view/MainPage.vue
+++ b/src/pages/09_task-order/order_view/MainPage.vue
@@ -128,32 +128,33 @@ function getPrice(
})[];
}[],
) {
- return list.reduce(
+ const value = list.reduce(
(a, c) => {
- const pricePerUnit = c.product.serviceCharge;
+ const vatFactor = c.product.serviceChargeCalcVat
+ ? (config.value?.vat ?? 0.07)
+ : 0;
+
+ const pricePerUnit =
+ precisionRound(c.product.serviceCharge * (1 + vatFactor)) /
+ (1 + vatFactor);
+
const amount = c.list.length;
const discount =
taskProduct.value.find((v) => v.productId === c.product.id)?.discount ||
0;
- const priceNoVat = c.product.serviceChargeVatIncluded
- ? pricePerUnit / (1 + (config.value?.vat || 0.07))
- : pricePerUnit;
- const adjustedPriceWithVat = precisionRound(
- priceNoVat * (1 + (config.value?.vat || 0.07)),
- );
- const adjustedPriceNoVat =
- adjustedPriceWithVat / (1 + (config.value?.vat || 0.07));
- const priceDiscountNoVat = adjustedPriceNoVat * amount - discount;
- const rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07);
+ const price =
+ (pricePerUnit * amount * (1 + vatFactor) - discount) / (1 + vatFactor);
- a.totalPrice = a.totalPrice + priceDiscountNoVat;
- a.totalDiscount = a.totalDiscount + Number(discount);
- a.vat = c.product.serviceChargeCalcVat ? a.vat + rawVatTotal : a.vat;
+ const vat = price * vatFactor;
+
+ a.totalPrice = precisionRound(a.totalPrice + price + discount);
+ a.totalDiscount = precisionRound(a.totalDiscount + discount);
+ a.vat = precisionRound(a.vat + vat);
a.vatExcluded = c.product.serviceChargeCalcVat
? a.vatExcluded
- : precisionRound(a.vatExcluded + priceDiscountNoVat);
- a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
+ : precisionRound(a.vatExcluded + price);
+ a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
return a;
},
{
@@ -164,6 +165,8 @@ function getPrice(
finalPrice: 0,
},
);
+
+ return value;
}
function getTemplateData(
diff --git a/src/pages/11_credit-note/document-view/MainPage.vue b/src/pages/11_credit-note/document-view/MainPage.vue
index 0ebbe50e..f8231467 100644
--- a/src/pages/11_credit-note/document-view/MainPage.vue
+++ b/src/pages/11_credit-note/document-view/MainPage.vue
@@ -237,12 +237,7 @@ onMounted(async () => {
});
function calcPricePerUnit(product: RequestWork['productService']['product']) {
- return product.vatIncluded
- ? (agentPrice.value ? product.agentPrice : product.price) /
- (1 + (config.value?.vat || 0.07))
- : agentPrice.value
- ? product.agentPrice
- : product.price;
+ return agentPrice.value ? product.agentPrice : product.price;
}
function calcPrice(c: RequestWork[]): number {
@@ -319,16 +314,7 @@ function closeAble() {
| {{ v.product.product.code }} |
{{ v.product.product.name }} |
- {{
- formatNumberDecimal(
- calcPricePerUnit(v.product.product) +
- (v.product.product.calcVat
- ? calcPricePerUnit(v.product.product) *
- (config?.vat || 0.07)
- : 0),
- 2,
- )
- }}
+ {{ formatNumberDecimal(calcPricePerUnit(v.product.product), 2) }}
|
{{ formatNumberDecimal(calcPrice(v.list), 2) }}
| |