refactor: use agent price
This commit is contained in:
parent
82793dc7a8
commit
fd62732642
2 changed files with 41 additions and 9 deletions
|
|
@ -1122,6 +1122,7 @@ function storeDataLocal() {
|
||||||
},
|
},
|
||||||
selectedWorker: selectedWorker.value,
|
selectedWorker: selectedWorker.value,
|
||||||
createdBy: quotationFormState.value.createdBy('tha'),
|
createdBy: quotationFormState.value.createdBy('tha'),
|
||||||
|
agentPrice: agentPrice.value,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import {
|
||||||
QuotationPayload,
|
QuotationPayload,
|
||||||
Details,
|
Details,
|
||||||
QuotationFull,
|
QuotationFull,
|
||||||
|
ProductRelation,
|
||||||
} from 'src/stores/quotations/types';
|
} from 'src/stores/quotations/types';
|
||||||
|
|
||||||
// NOTE: Import Components
|
// NOTE: Import Components
|
||||||
|
|
@ -40,11 +41,12 @@ type Product = {
|
||||||
code: string;
|
code: string;
|
||||||
detail: string;
|
detail: string;
|
||||||
amount: number;
|
amount: number;
|
||||||
priceUnit: number;
|
pricePerUnit: number;
|
||||||
discount: number;
|
discount: number;
|
||||||
vat: number;
|
vat: number;
|
||||||
value: number;
|
value: number;
|
||||||
calcVat: boolean;
|
calcVat: boolean;
|
||||||
|
product: ProductRelation;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SummaryPrice = {
|
type SummaryPrice = {
|
||||||
|
|
@ -60,6 +62,8 @@ const branch = ref<Branch>();
|
||||||
const productList = ref<Product[]>([]);
|
const productList = ref<Product[]>([]);
|
||||||
const bankList = ref<BankBook[]>([]);
|
const bankList = ref<BankBook[]>([]);
|
||||||
|
|
||||||
|
const agentPrice = ref(false);
|
||||||
|
|
||||||
const elements = ref<HTMLElement[]>([]);
|
const elements = ref<HTMLElement[]>([]);
|
||||||
const chunks = ref<Product[][]>([[]]);
|
const chunks = ref<Product[][]>([[]]);
|
||||||
const attachmentList = ref<
|
const attachmentList = ref<
|
||||||
|
|
@ -194,6 +198,8 @@ onMounted(async () => {
|
||||||
customer.value = resCustomerBranch;
|
customer.value = resCustomerBranch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
agentPrice.value = data.value.agentPrice || parsed?.meta?.agentPrice;
|
||||||
|
|
||||||
details.value = {
|
details.value = {
|
||||||
code: parsed?.meta?.source?.code ?? data.value?.code,
|
code: parsed?.meta?.source?.code ?? data.value?.code,
|
||||||
createdAt:
|
createdAt:
|
||||||
|
|
@ -247,11 +253,12 @@ onMounted(async () => {
|
||||||
code: v.product.code,
|
code: v.product.code,
|
||||||
detail: v.product.name,
|
detail: v.product.name,
|
||||||
amount: v.amount || 0,
|
amount: v.amount || 0,
|
||||||
priceUnit: v.pricePerUnit || 0,
|
pricePerUnit: v.pricePerUnit || 0,
|
||||||
discount: v.discount || 0,
|
discount: v.discount || 0,
|
||||||
vat: v.vat || 0,
|
vat: v.vat || 0,
|
||||||
value: precisionRound(price + (v.product.calcVat ? vat : 0)),
|
value: precisionRound(price + (v.product.calcVat ? vat : 0)),
|
||||||
calcVat: v.product.calcVat,
|
calcVat: v.product.calcVat,
|
||||||
|
product: v.product,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
) || [];
|
) || [];
|
||||||
|
|
@ -273,10 +280,13 @@ onMounted(async () => {
|
||||||
const vat =
|
const vat =
|
||||||
(finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07);
|
(finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07);
|
||||||
|
|
||||||
|
const calcVat =
|
||||||
|
c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat'];
|
||||||
|
|
||||||
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));
|
||||||
a.vat = c.product.calcVat ? precisionRound(a.vat + vat) : a.vat;
|
a.vat = calcVat ? precisionRound(a.vat + vat) : a.vat;
|
||||||
a.vatExcluded = c.product.calcVat
|
a.vatExcluded = calcVat
|
||||||
? a.vatExcluded
|
? a.vatExcluded
|
||||||
: precisionRound(a.vatExcluded + price);
|
: precisionRound(a.vatExcluded + price);
|
||||||
a.finalPrice = precisionRound(
|
a.finalPrice = precisionRound(
|
||||||
|
|
@ -285,7 +295,6 @@ onMounted(async () => {
|
||||||
a.vat -
|
a.vat -
|
||||||
Number(data.value?.discount || 0),
|
Number(data.value?.discount || 0),
|
||||||
);
|
);
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -300,6 +309,20 @@ onMounted(async () => {
|
||||||
assignData();
|
assignData();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function calcPrice(c: Product) {
|
||||||
|
const originalPrice = c.pricePerUnit;
|
||||||
|
const finalPriceWithVat = precisionRound(
|
||||||
|
originalPrice + originalPrice * (config.value?.vat || 0.07),
|
||||||
|
);
|
||||||
|
const finalPriceNoVat = finalPriceWithVat / (1 + (config.value?.vat || 0.07));
|
||||||
|
|
||||||
|
const price = finalPriceNoVat * c.amount - c.discount;
|
||||||
|
const vat = c.product[agentPrice.value ? 'agentPriceCalcVat' : 'calcVat']
|
||||||
|
? (finalPriceNoVat * c.amount - c.discount) * (config.value?.vat || 0.07)
|
||||||
|
: 0;
|
||||||
|
return precisionRound(price + vat);
|
||||||
|
}
|
||||||
|
|
||||||
watch(elements, () => {});
|
watch(elements, () => {});
|
||||||
|
|
||||||
function print() {
|
function print() {
|
||||||
|
|
@ -359,7 +382,15 @@ 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.priceUnit, 2) }}
|
{{
|
||||||
|
formatNumberDecimal(
|
||||||
|
v.pricePerUnit +
|
||||||
|
(v.product[agentPrice ? 'agentPriceCalcVat' : 'calcVat']
|
||||||
|
? v.pricePerUnit * (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) }}
|
||||||
|
|
@ -367,9 +398,9 @@ function print() {
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{
|
{{
|
||||||
formatNumberDecimal(
|
formatNumberDecimal(
|
||||||
v.calcVat
|
v.product.calcVat
|
||||||
? precisionRound(
|
? precisionRound(
|
||||||
(v.priceUnit * v.amount - v.discount) *
|
(v.pricePerUnit * v.amount - v.discount) *
|
||||||
(config?.vat || 0.07),
|
(config?.vat || 0.07),
|
||||||
)
|
)
|
||||||
: 0,
|
: 0,
|
||||||
|
|
@ -378,7 +409,7 @@ function print() {
|
||||||
}}
|
}}
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{{ formatNumberDecimal(v.value, 2) }}
|
{{ formatNumberDecimal(calcPrice(v), 2) }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue