feat: correct total tax on incoming invoices
This commit is contained in:
@@ -222,13 +222,24 @@ export const getIncomingInvoiceImmediateExpenseNet = (invoice: any) => {
|
||||
}
|
||||
|
||||
export const getIncomingInvoiceImmediateExpenseGross = (invoice: any) => {
|
||||
return Number(((invoice?.accounts || []).reduce((sum: number, account: any) => {
|
||||
const immediateAccounts = (invoice?.accounts || []).filter((account: any) => {
|
||||
const normalized = normalizeIncomingInvoiceAccount(account, invoice?.date)
|
||||
return !isDepreciationBookingMode(normalized.bookingMode)
|
||||
})
|
||||
const gross = immediateAccounts.reduce((sum: number, account: any) => {
|
||||
const normalized = normalizeIncomingInvoiceAccount(account, invoice?.date)
|
||||
if (isDepreciationBookingMode(normalized.bookingMode)) return sum
|
||||
|
||||
const amountGross = Number(normalized.amountGross)
|
||||
return sum + (Number.isFinite(amountGross) ? amountGross : Number(normalized.amountNet || 0) + Number(normalized.amountTax || 0))
|
||||
}, 0)).toFixed(2))
|
||||
}, 0)
|
||||
const calculatedTax = (invoice?.accounts || []).reduce((sum: number, account: any) => sum + Number(account.amountTax || 0), 0)
|
||||
const correction = immediateAccounts.length > 0
|
||||
&& invoice?.taxAmountOverride !== null
|
||||
&& invoice?.taxAmountOverride !== undefined
|
||||
&& invoice?.taxAmountOverride !== ""
|
||||
? Number(invoice.taxAmountOverride) - calculatedTax
|
||||
: 0
|
||||
|
||||
return Number((gross + correction).toFixed(2))
|
||||
}
|
||||
|
||||
export const getIncomingInvoiceDepreciationRows = (invoice: any, rangeStart: any, rangeEnd: any) => {
|
||||
|
||||
Reference in New Issue
Block a user