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 =
|
||||
precisionRound(c.pricePerUnit * (1 + vatFactor)) / (1 + vatFactor);
|
||||
|
||||
const price =
|
||||
(pricePerUnit * c.amount * (1 + vatFactor) - c.discount) /
|
||||
(1 + vatFactor);
|
||||
|
|
|
|||
|
|
@ -405,12 +405,7 @@ function print() {
|
|||
<td>{{ v.detail }}</td>
|
||||
<td style="text-align: right">{{ v.amount }}</td>
|
||||
<td style="text-align: right">
|
||||
{{
|
||||
formatNumberDecimal(
|
||||
v.pricePerUnit * (1 + (v.vat > 0 ? config?.vat || 0.07 : 0)),
|
||||
2,
|
||||
)
|
||||
}}
|
||||
{{ formatNumberDecimal(v.pricePerUnit, 2) }}
|
||||
</td>
|
||||
<td style="text-align: right">
|
||||
{{ formatNumberDecimal(v.discount, 2) }}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
},
|
||||
{
|
||||
|
|
@ -401,7 +405,9 @@ function closeAble() {
|
|||
<td class="text-right">
|
||||
{{
|
||||
formatNumberDecimal(
|
||||
summaryPrice.totalPrice - summaryPrice.totalDiscount,
|
||||
summaryPrice.totalPrice -
|
||||
summaryPrice.totalDiscount -
|
||||
summaryPrice.vatExcluded,
|
||||
2,
|
||||
)
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -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<boolean[]>([]);
|
||||
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) {
|
|||
<q-td class="text-right" v-if="!creditNote">
|
||||
{{
|
||||
formatNumberDecimal(
|
||||
calcPricePerUnit(props.row.product) * props.row.list.length -
|
||||
(taskProduct.find(
|
||||
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),
|
||||
2,
|
||||
)?.discount || 0,
|
||||
)
|
||||
}}
|
||||
</q-td>
|
||||
|
|
@ -310,17 +287,16 @@ function taskOrderStatus(value: TaskStatus) {
|
|||
<q-td class="text-right" v-if="!creditNote">
|
||||
{{
|
||||
formatNumberDecimal(
|
||||
props.row.product.calcVat
|
||||
? precisionRound(
|
||||
(calcPricePerUnit(props.row.product) *
|
||||
props.row.list.length -
|
||||
(taskProduct.find(
|
||||
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)) *
|
||||
(config?.vat || 0.07),
|
||||
)
|
||||
)?.discount || 0) /
|
||||
(1 + (config?.vat || 0.07))) *
|
||||
0.07
|
||||
: 0,
|
||||
2,
|
||||
)
|
||||
}}
|
||||
</q-td>
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
<td>{{ v.product.product.code }}</td>
|
||||
<td>{{ v.product.product.name }}</td>
|
||||
<td style="text-align: right">
|
||||
{{
|
||||
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) }}
|
||||
</td>
|
||||
<td style="text-align: right">
|
||||
{{ formatNumberDecimal(calcPrice(v.list), 2) }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue