feat: correct total tax on incoming invoices
This commit is contained in:
@@ -287,6 +287,12 @@ const getIncomingInvoiceTaxBreakdown = (invoice: any): TaxBreakdown => {
|
||||
}
|
||||
});
|
||||
|
||||
if (invoice?.taxAmountOverride !== null && invoice?.taxAmountOverride !== undefined && invoice?.taxAmountOverride !== "") {
|
||||
const correction = Number(invoice.taxAmountOverride) - breakdown.tax19 - breakdown.tax7;
|
||||
if (breakdown.tax19 !== 0 || breakdown.net19 !== 0) breakdown.tax19 += correction;
|
||||
else if (breakdown.tax7 !== 0 || breakdown.net7 !== 0) breakdown.tax7 += correction;
|
||||
}
|
||||
|
||||
return {
|
||||
net19: roundMoney(breakdown.net19),
|
||||
tax19: roundMoney(breakdown.tax19),
|
||||
@@ -297,9 +303,14 @@ const getIncomingInvoiceTaxBreakdown = (invoice: any): TaxBreakdown => {
|
||||
};
|
||||
|
||||
const getIncomingInvoiceSignedAmount = (invoice: any) => {
|
||||
const amount = (invoice.accounts || []).reduce((sum: number, account: any) => {
|
||||
return sum + Number(account.amountNet || 0) + Number(account.amountTax || 0);
|
||||
}, 0);
|
||||
const totals = (invoice.accounts || []).reduce((result: { net: number, tax: number }, account: any) => ({
|
||||
net: result.net + Number(account.amountNet || 0),
|
||||
tax: result.tax + Number(account.amountTax || 0),
|
||||
}), { net: 0, tax: 0 });
|
||||
const tax = invoice.taxAmountOverride !== null && invoice.taxAmountOverride !== undefined && invoice.taxAmountOverride !== ""
|
||||
? Number(invoice.taxAmountOverride)
|
||||
: totals.tax;
|
||||
const amount = totals.net + tax;
|
||||
|
||||
return roundMoney(invoice.expense === false ? amount : amount * -1);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user