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) => {
|
||||
|
||||
@@ -12,17 +12,15 @@ export const useSum = () => {
|
||||
}
|
||||
|
||||
const getIncomingInvoiceSum = (invoice) => {
|
||||
let sum = 0
|
||||
invoice.accounts.forEach(account => {
|
||||
const totals = (invoice.accounts || []).reduce((result, account) => ({
|
||||
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
|
||||
|
||||
|
||||
sum += account.amountTax
|
||||
sum += account.amountNet
|
||||
|
||||
|
||||
|
||||
})
|
||||
return sum.toFixed(2)
|
||||
return (totals.net + tax).toFixed(2)
|
||||
}
|
||||
|
||||
const getCreatedDocumentSum = (createddocument,createddocuments = []) => {
|
||||
|
||||
@@ -152,6 +152,12 @@ export const getIncomingInvoiceTaxBreakdown = (invoice: any) => {
|
||||
}
|
||||
})
|
||||
|
||||
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: Number(breakdown.net19.toFixed(2)),
|
||||
tax19: Number(breakdown.tax19.toFixed(2)),
|
||||
|
||||
Reference in New Issue
Block a user