export const BANK_ALLOCATION_TAX_ITEMS = [ { value: "9", label: "19 % Vorsteuer", rate: 19, kind: "input" }, { value: "8", label: "7 % Vorsteuer", rate: 7, kind: "input" }, { value: "3", label: "19 % Umsatzsteuer", rate: 19, kind: "output" }, { value: "2", label: "7 % Umsatzsteuer", rate: 7, kind: "output" }, { value: "40", label: "Ohne Umsatzsteuer", rate: 0, kind: "none" }, ] export const isDirectBankAllocation = (allocation: any) => Boolean( allocation?.bankstatement && (allocation.account || allocation.ownaccount) && !allocation.createddocument && !allocation.incominginvoice && !allocation.customer && !allocation.vendor && !allocation.archived ) // The signed bank amount always remains gross. Refunds retain their sign. export function getBankAllocationAmounts(allocation: any) { const amountGross = Number(allocation?.amount || 0) const tax = isDirectBankAllocation(allocation) ? BANK_ALLOCATION_TAX_ITEMS.find(item => item.value === String(allocation.datevTaxKey)) : undefined const rate = tax?.rate || 0 const amountNet = Number((amountGross / (1 + rate / 100)).toFixed(2)) const amountTax = Number((amountGross - amountNet).toFixed(2)) return { amountGross, amountNet, amountTax, rate, kind: tax?.kind || "none" } } export function getBankAllocationTaxBreakdown(allocation: any) { const output = { net19: 0, tax19: 0, net7: 0, tax7: 0, net0: 0 } const input = { ...output } if (!isDirectBankAllocation(allocation)) return { output, input } const { amountNet, amountTax, rate, kind } = getBankAllocationAmounts(allocation) if (kind === "none") return { output, input } const target = kind === "input" ? input : output const sign = kind === "input" ? -1 : 1 if (rate === 19) { target.net19 = amountNet * sign target.tax19 = amountTax * sign } else if (rate === 7) { target.net7 = amountNet * sign target.tax7 = amountTax * sign } return { output, input } }