feat: flowaccount handle installments
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
All checks were successful
Spell Check / Spell Check with Typos (push) Successful in 4s
This commit is contained in:
parent
334fb57b46
commit
3454e46212
1 changed files with 51 additions and 52 deletions
|
|
@ -289,13 +289,55 @@ const flowAccount = {
|
||||||
|
|
||||||
const quotation = data.quotation;
|
const quotation = data.quotation;
|
||||||
const customer = quotation.customerBranch;
|
const customer = quotation.customerBranch;
|
||||||
const product =
|
|
||||||
|
const summary = {
|
||||||
|
subTotal: 0,
|
||||||
|
discountAmount: 0,
|
||||||
|
vatableAmount: 0,
|
||||||
|
exemptAmount: 0,
|
||||||
|
vatAmount: 0,
|
||||||
|
grandTotal: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const products = (
|
||||||
quotation.payCondition === PayCondition.BillFull ||
|
quotation.payCondition === PayCondition.BillFull ||
|
||||||
quotation.payCondition === PayCondition.Full
|
quotation.payCondition === PayCondition.Full
|
||||||
? quotation.productServiceList
|
? quotation.productServiceList
|
||||||
: quotation.productServiceList.filter((lhs) =>
|
: quotation.productServiceList.filter((lhs) =>
|
||||||
data.installments.some((rhs) => rhs.no === lhs.installmentNo),
|
data.installments.some((rhs) => rhs.no === lhs.installmentNo),
|
||||||
);
|
)
|
||||||
|
).map((v) => {
|
||||||
|
// TODO: Use product's VAT field (not implemented) instead.
|
||||||
|
const VAT_RATE = VAT_DEFAULT;
|
||||||
|
|
||||||
|
summary.subTotal +=
|
||||||
|
precisionRound(v.pricePerUnit * (1 + (v.vat > 0 ? VAT_RATE : 0))) * v.amount;
|
||||||
|
summary.discountAmount += v.discount;
|
||||||
|
|
||||||
|
const total =
|
||||||
|
precisionRound(v.pricePerUnit * (1 + (v.vat > 0 ? VAT_RATE : 0))) * v.amount -
|
||||||
|
(v.discount ?? 0);
|
||||||
|
|
||||||
|
if (v.vat > 0) {
|
||||||
|
summary.vatableAmount += precisionRound(total / (1 + VAT_RATE));
|
||||||
|
summary.vatAmount += v.vat;
|
||||||
|
} else {
|
||||||
|
summary.exemptAmount += total;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary.grandTotal += total;
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: ProductAndServiceType.ProductNonInv,
|
||||||
|
name: v.product.name,
|
||||||
|
pricePerUnit: precisionRound(v.pricePerUnit),
|
||||||
|
quantity: v.amount,
|
||||||
|
discountAmount: v.discount,
|
||||||
|
vatRate: v.vat === 0 ? 0 : Math.round(VAT_RATE * 100),
|
||||||
|
total,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
contactCode: customer.code,
|
contactCode: customer.code,
|
||||||
contactName: customer.contactName || "-",
|
contactName: customer.contactName || "-",
|
||||||
|
|
@ -333,45 +375,12 @@ const flowAccount = {
|
||||||
discounPercentage: 0,
|
discounPercentage: 0,
|
||||||
discountAmount: quotation.totalDiscount,
|
discountAmount: quotation.totalDiscount,
|
||||||
|
|
||||||
subTotal:
|
subTotal: summary.subTotal,
|
||||||
quotation.payCondition === "BillSplitCustom" ||
|
totalAfterDiscount: summary.subTotal - summary.discountAmount,
|
||||||
quotation.payCondition === "BillSplit" ||
|
vatableAmount: summary.vatableAmount,
|
||||||
quotation.payCondition === "SplitCustom" ||
|
exemptAmount: summary.exemptAmount,
|
||||||
quotation.payCondition === "Split"
|
vatAmount: summary.vatAmount,
|
||||||
? 0
|
grandTotal: summary.grandTotal,
|
||||||
: quotation.totalPrice,
|
|
||||||
vatableAmount:
|
|
||||||
quotation.payCondition === "BillSplitCustom" ||
|
|
||||||
quotation.payCondition === "BillSplit" ||
|
|
||||||
quotation.payCondition === "SplitCustom" ||
|
|
||||||
quotation.payCondition === "Split"
|
|
||||||
? 0
|
|
||||||
: quotation.totalPrice - quotation.totalDiscount - quotation.vatExcluded,
|
|
||||||
exemptAmount:
|
|
||||||
quotation.payCondition === "BillSplitCustom" ||
|
|
||||||
quotation.payCondition === "BillSplit" ||
|
|
||||||
quotation.payCondition === "SplitCustom" ||
|
|
||||||
quotation.payCondition === "Split"
|
|
||||||
? 0
|
|
||||||
: quotation.vatExcluded,
|
|
||||||
totalAfterDiscount:
|
|
||||||
quotation.payCondition === "BillSplitCustom" ||
|
|
||||||
quotation.payCondition === "BillSplit" ||
|
|
||||||
quotation.payCondition === "SplitCustom" ||
|
|
||||||
quotation.payCondition === "Split"
|
|
||||||
? 0
|
|
||||||
: quotation.finalPrice,
|
|
||||||
vatAmount:
|
|
||||||
quotation.payCondition === "BillSplitCustom" ||
|
|
||||||
quotation.payCondition === "BillSplit" ||
|
|
||||||
quotation.payCondition === "SplitCustom" ||
|
|
||||||
quotation.payCondition === "Split"
|
|
||||||
? 0
|
|
||||||
: quotation.vat,
|
|
||||||
grandTotal:
|
|
||||||
quotation.payCondition === "BillSplitCustom" || quotation.payCondition === "SplitCustom"
|
|
||||||
? data.installments.reduce((a, c) => a + c.amount, 0)
|
|
||||||
: quotation.finalPrice,
|
|
||||||
|
|
||||||
remarks: htmlToText(
|
remarks: htmlToText(
|
||||||
convertTemplate(quotation.remark ?? "", {
|
convertTemplate(quotation.remark ?? "", {
|
||||||
|
|
@ -389,17 +398,7 @@ const flowAccount = {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
items: product.map((v) => ({
|
items: products,
|
||||||
type: ProductAndServiceType.ProductNonInv,
|
|
||||||
name: v.product.name,
|
|
||||||
pricePerUnit: precisionRound(v.pricePerUnit),
|
|
||||||
quantity: v.amount,
|
|
||||||
discountAmount: v.discount,
|
|
||||||
total:
|
|
||||||
precisionRound(v.pricePerUnit * (1 + (v.vat > 0 ? VAT_DEFAULT : 0))) * v.amount -
|
|
||||||
(v.discount ?? 0),
|
|
||||||
vatRate: v.vat === 0 ? 0 : Math.round(VAT_DEFAULT * 100),
|
|
||||||
})),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return await flowAccountAPI.createReceipt(payload, false);
|
return await flowAccountAPI.createReceipt(payload, false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue