fix: calc price order
This commit is contained in:
parent
492f341e68
commit
7c3a9818c2
6 changed files with 90 additions and 123 deletions
|
|
@ -254,6 +254,7 @@ function getPrice(
|
||||||
|
|
||||||
const pricePerUnit =
|
const pricePerUnit =
|
||||||
precisionRound(c.pricePerUnit * (1 + vatFactor)) / (1 + vatFactor);
|
precisionRound(c.pricePerUnit * (1 + vatFactor)) / (1 + vatFactor);
|
||||||
|
|
||||||
const price =
|
const price =
|
||||||
(pricePerUnit * c.amount * (1 + vatFactor) - c.discount) /
|
(pricePerUnit * c.amount * (1 + vatFactor) - c.discount) /
|
||||||
(1 + vatFactor);
|
(1 + vatFactor);
|
||||||
|
|
|
||||||
|
|
@ -405,12 +405,7 @@ function print() {
|
||||||
<td>{{ v.detail }}</td>
|
<td>{{ v.detail }}</td>
|
||||||
<td style="text-align: right">{{ v.amount }}</td>
|
<td style="text-align: right">{{ v.amount }}</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{
|
{{ formatNumberDecimal(v.pricePerUnit, 2) }}
|
||||||
formatNumberDecimal(
|
|
||||||
v.pricePerUnit * (1 + (v.vat > 0 ? config?.vat || 0.07 : 0)),
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{ formatNumberDecimal(v.discount, 2) }}
|
{{ formatNumberDecimal(v.discount, 2) }}
|
||||||
|
|
|
||||||
|
|
@ -202,40 +202,44 @@ onMounted(async () => {
|
||||||
})
|
})
|
||||||
.reduce(
|
.reduce(
|
||||||
(a, c) => {
|
(a, c) => {
|
||||||
const priceNoVat = c.product.serviceChargeVatIncluded
|
const vatFactor = c.product.serviceChargeCalcVat
|
||||||
? c.pricePerUnit / (1 + (config.value?.vat || 0.07))
|
? (config.value?.vat ?? 0.07)
|
||||||
: c.pricePerUnit;
|
: 0;
|
||||||
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 rawVatTotal = priceDiscountNoVat * (config.value?.vat || 0.07);
|
const pricePerUnit =
|
||||||
const rawVat = rawVatTotal / c.amount;
|
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({
|
product.value.push({
|
||||||
id: c.product.id,
|
id: c.product.id,
|
||||||
code: c.product.code,
|
code: c.product.code,
|
||||||
detail: c.product.name,
|
detail: c.product.name,
|
||||||
priceUnit: precisionRound(priceNoVat),
|
priceUnit: precisionRound(pricePerUnit),
|
||||||
amount: c.amount,
|
amount: c.amount,
|
||||||
discount: c.discount,
|
discount: c.discount,
|
||||||
vat: c.product.serviceChargeCalcVat ? precisionRound(rawVat) : 0,
|
vat: c.product.serviceChargeCalcVat ? precisionRound(vat) : 0,
|
||||||
value: precisionRound(
|
value: precisionRound(
|
||||||
priceNoVat * c.amount +
|
pricePerUnit * c.amount +
|
||||||
(c.product.serviceChargeCalcVat ? rawVatTotal : 0),
|
(c.product.serviceChargeCalcVat ? vat : 0),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
a.totalPrice = a.totalPrice + priceDiscountNoVat;
|
a.totalPrice = precisionRound(a.totalPrice + price + discount);
|
||||||
a.totalDiscount = a.totalDiscount + Number(c.discount);
|
a.totalDiscount = precisionRound(a.totalDiscount + discount);
|
||||||
a.vat = c.product.calcVat ? a.vat + rawVatTotal : a.vat;
|
a.vat = precisionRound(a.vat + vat);
|
||||||
a.vatExcluded = c.product.calcVat
|
a.vatExcluded = c.product.serviceChargeCalcVat
|
||||||
? a.vatExcluded
|
? a.vatExcluded
|
||||||
: precisionRound(a.vatExcluded + priceDiscountNoVat);
|
: precisionRound(a.vatExcluded + price);
|
||||||
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
|
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -401,7 +405,9 @@ function closeAble() {
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
summaryPrice.totalPrice - summaryPrice.totalDiscount,
|
summaryPrice.totalPrice -
|
||||||
|
summaryPrice.totalDiscount -
|
||||||
|
summaryPrice.vatExcluded,
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ import { storeToRefs } from 'pinia';
|
||||||
import BadgeComponent from 'src/components/BadgeComponent.vue';
|
import BadgeComponent from 'src/components/BadgeComponent.vue';
|
||||||
import { TaskStatus } from 'src/stores/task-order/types';
|
import { TaskStatus } from 'src/stores/task-order/types';
|
||||||
|
|
||||||
|
import { useTaskOrderForm } from '../form';
|
||||||
|
|
||||||
|
const taskOrderFormStore = useTaskOrderForm();
|
||||||
|
|
||||||
const currentBtnOpen = ref<boolean[]>([]);
|
const currentBtnOpen = ref<boolean[]>([]);
|
||||||
const configStore = useConfigStore();
|
const configStore = useConfigStore();
|
||||||
const { data: config } = storeToRefs(configStore);
|
const { data: config } = storeToRefs(configStore);
|
||||||
|
|
@ -61,60 +65,28 @@ function openList(index: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcPricePerUnit(product: RequestWork['productService']['product']) {
|
function calcPricePerUnit(product: RequestWork['productService']['product']) {
|
||||||
const val = props.creditNote
|
return product.serviceCharge;
|
||||||
? 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcPrice(
|
function calcPrice(
|
||||||
product: RequestWork['productService']['product'],
|
product: RequestWork['productService']['product'],
|
||||||
amount: number,
|
amount: number,
|
||||||
) {
|
) {
|
||||||
const pricePerUnit = props.creditNote
|
const vatFactor = product.serviceChargeCalcVat
|
||||||
? props.agentPrice
|
? (config.value?.vat ?? 0.07)
|
||||||
? 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)
|
|
||||||
: 0;
|
: 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) {
|
function taskOrderStatus(value: TaskStatus) {
|
||||||
|
|
@ -247,7 +219,7 @@ function taskOrderStatus(value: TaskStatus) {
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
calcPricePerUnit(props.row.product) +
|
calcPricePerUnit(props.row.product) +
|
||||||
(props.row.product.calcVat
|
(props.row.product.serviceChargeCalcVat
|
||||||
? calcPricePerUnit(props.row.product) *
|
? calcPricePerUnit(props.row.product) *
|
||||||
(config?.vat || 0.07)
|
(config?.vat || 0.07)
|
||||||
: 0),
|
: 0),
|
||||||
|
|
@ -298,11 +270,16 @@ function taskOrderStatus(value: TaskStatus) {
|
||||||
<q-td class="text-right" v-if="!creditNote">
|
<q-td class="text-right" v-if="!creditNote">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
calcPricePerUnit(props.row.product) * props.row.list.length -
|
props.row.product.serviceChargeCalcVat
|
||||||
(taskProduct.find(
|
? (calcPricePerUnit(props.row.product) *
|
||||||
(v) => v.productId === props.row.product.id,
|
props.row.list.length *
|
||||||
)?.discount || 0),
|
(1 + (config?.vat || 0.07))) /
|
||||||
2,
|
(1 + (config?.vat || 0.07))
|
||||||
|
: calcPricePerUnit(props.row.product) *
|
||||||
|
props.row.list.length -
|
||||||
|
taskProduct.find(
|
||||||
|
(v) => v.productId === props.row.product.id,
|
||||||
|
)?.discount || 0,
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
@ -310,17 +287,16 @@ function taskOrderStatus(value: TaskStatus) {
|
||||||
<q-td class="text-right" v-if="!creditNote">
|
<q-td class="text-right" v-if="!creditNote">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
props.row.product.calcVat
|
props.row.product.serviceChargeCalcVat
|
||||||
? precisionRound(
|
? ((calcPricePerUnit(props.row.product) *
|
||||||
(calcPricePerUnit(props.row.product) *
|
props.row.list.length *
|
||||||
props.row.list.length -
|
(1 + (config?.vat || 0.07)) -
|
||||||
(taskProduct.find(
|
taskProduct.find(
|
||||||
(v) => v.productId === props.row.product.id,
|
(v) => v.productId === props.row.product.id,
|
||||||
)?.discount || 0)) *
|
)?.discount || 0) /
|
||||||
(config?.vat || 0.07),
|
(1 + (config?.vat || 0.07))) *
|
||||||
)
|
0.07
|
||||||
: 0,
|
: 0,
|
||||||
2,
|
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
</q-td>
|
</q-td>
|
||||||
|
|
|
||||||
|
|
@ -128,32 +128,33 @@ function getPrice(
|
||||||
})[];
|
})[];
|
||||||
}[],
|
}[],
|
||||||
) {
|
) {
|
||||||
return list.reduce(
|
const value = list.reduce(
|
||||||
(a, c) => {
|
(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 amount = c.list.length;
|
||||||
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.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;
|
const vat = price * vatFactor;
|
||||||
a.totalDiscount = a.totalDiscount + Number(discount);
|
|
||||||
a.vat = c.product.serviceChargeCalcVat ? a.vat + rawVatTotal : a.vat;
|
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 = c.product.serviceChargeCalcVat
|
||||||
? a.vatExcluded
|
? a.vatExcluded
|
||||||
: precisionRound(a.vatExcluded + priceDiscountNoVat);
|
: precisionRound(a.vatExcluded + price);
|
||||||
a.finalPrice = a.totalPrice - a.totalDiscount + a.vat;
|
a.finalPrice = precisionRound(a.totalPrice - a.totalDiscount + a.vat);
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -164,6 +165,8 @@ function getPrice(
|
||||||
finalPrice: 0,
|
finalPrice: 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTemplateData(
|
function getTemplateData(
|
||||||
|
|
|
||||||
|
|
@ -237,12 +237,7 @@ onMounted(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function calcPricePerUnit(product: RequestWork['productService']['product']) {
|
function calcPricePerUnit(product: RequestWork['productService']['product']) {
|
||||||
return product.vatIncluded
|
return agentPrice.value ? product.agentPrice : product.price;
|
||||||
? (agentPrice.value ? product.agentPrice : product.price) /
|
|
||||||
(1 + (config.value?.vat || 0.07))
|
|
||||||
: agentPrice.value
|
|
||||||
? product.agentPrice
|
|
||||||
: product.price;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcPrice(c: RequestWork[]): number {
|
function calcPrice(c: RequestWork[]): number {
|
||||||
|
|
@ -319,16 +314,7 @@ function closeAble() {
|
||||||
<td>{{ v.product.product.code }}</td>
|
<td>{{ v.product.product.code }}</td>
|
||||||
<td>{{ v.product.product.name }}</td>
|
<td>{{ v.product.product.name }}</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{
|
{{ formatNumberDecimal(calcPricePerUnit(v.product.product), 2) }}
|
||||||
formatNumberDecimal(
|
|
||||||
calcPricePerUnit(v.product.product) +
|
|
||||||
(v.product.product.calcVat
|
|
||||||
? calcPricePerUnit(v.product.product) *
|
|
||||||
(config?.vat || 0.07)
|
|
||||||
: 0),
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{ formatNumberDecimal(calcPrice(v.list), 2) }}
|
{{ formatNumberDecimal(calcPrice(v.list), 2) }}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue