feat: correct total tax on incoming invoices
This commit is contained in:
@@ -80,18 +80,17 @@ const formatDatevDate = (date: dayjs.ConfigType, format: string) => {
|
||||
return parsed.isValid() ? parsed.tz(DATEV_TIMEZONE).format(format) : "";
|
||||
};
|
||||
|
||||
const getIncomingInvoiceTaxReview = (account: any) => {
|
||||
const taxRate = account.taxType === "19" ? 19 : account.taxType === "7" ? 7 : null;
|
||||
if (taxRate === null) return null;
|
||||
const getIncomingInvoiceTaxOverride = (invoice: any) => {
|
||||
if (invoice.taxAmountOverride === null || invoice.taxAmountOverride === undefined || invoice.taxAmountOverride === "") return null;
|
||||
|
||||
const amountNet = Number(account.amountNet);
|
||||
const amountTax = Number(account.amountTax);
|
||||
if (!Number.isFinite(amountNet) || !Number.isFinite(amountTax)) return null;
|
||||
const calculatedTax = (invoice.accounts as any[] || []).reduce((sum, account) => sum + Number(account.amountTax || 0), 0);
|
||||
const overriddenTax = Number(invoice.taxAmountOverride);
|
||||
if (!Number.isFinite(overriddenTax) || Math.abs(overriddenTax - calculatedTax) < 0.005) return null;
|
||||
|
||||
const calculatedTax = Number((amountNet * (taxRate / 100)).toFixed(2));
|
||||
if (Math.abs(amountTax - calculatedTax) < 0.005) return null;
|
||||
|
||||
return `USt pruefen ${displayCurrency(amountTax, true)}`;
|
||||
return {
|
||||
amount: overriddenTax,
|
||||
correction: Number((overriddenTax - calculatedTax).toFixed(2)),
|
||||
};
|
||||
};
|
||||
|
||||
const getCreatedDocumentRevenueLines = (document: any) => {
|
||||
@@ -368,7 +367,12 @@ export async function buildExportZip(
|
||||
// ER
|
||||
incominginvoicesList.forEach(ii => {
|
||||
const accs = ii.accounts as any[] || [];
|
||||
accs.forEach(account => {
|
||||
const taxOverride = getIncomingInvoiceTaxOverride(ii);
|
||||
const correctionAccountIndex = taxOverride
|
||||
? Math.max(0, accs.findIndex(account => account.taxType === "19" || account.taxType === "7"))
|
||||
: -1;
|
||||
|
||||
accs.forEach((account, accountIndex) => {
|
||||
let file = filesIncomingInvoices.find(i => i.incominginvoice === ii.id);
|
||||
let accountData = accountsList.find(i => i.id === account.account);
|
||||
if (!accountData) return;
|
||||
@@ -381,10 +385,13 @@ export async function buildExportZip(
|
||||
else if(account.taxType === '7I') buschluessel = "18";
|
||||
else buschluessel = "-";
|
||||
|
||||
let amountGross =/* account.amountGross ? account.amountGross : */(account.amountNet || 0) + (account.amountTax || 0);
|
||||
let amountGross = Number(account.amountNet || 0) + Number(account.amountTax || 0);
|
||||
if (taxOverride && accountIndex === correctionAccountIndex) amountGross += taxOverride.correction;
|
||||
let shSelector = Math.sign(amountGross) === -1 ? "H" : "S";
|
||||
const taxReview = getIncomingInvoiceTaxReview(account);
|
||||
let text = `${taxReview ? `${taxReview} - ` : ""}ER ${ii.reference}: ${escapeString(ii.description)}`.substring(0,59);
|
||||
const taxReview = taxOverride && accountIndex === correctionAccountIndex
|
||||
? `USt pruefen ${displayCurrency(taxOverride.amount, true)} - `
|
||||
: "";
|
||||
let text = `${taxReview}ER ${ii.reference}: ${escapeString(ii.description)}`.substring(0,59);
|
||||
const vend = ii.vendor; // durch Mapping verfügbar
|
||||
|
||||
bookingLines.push(`${Math.abs(amountGross).toFixed(2).replace(".",",")};"${shSelector}";;;;;${accountData.number};${vend?.vendorNumber || ""};"${buschluessel}";${formatDatevDate(ii.date, "DDMM")};"${ii.reference}";;;"${text}";;;;;;${file ? `"BEDI ""${file.id}"""` : ""};"Geschäftspartner";"${vend?.name || ""}";"Kundennummer";"${vend?.vendorNumber || ""}";"Belegnummer";"${ii.reference}";"Leistungsdatum";"${formatDatevDate(ii.date, "DD.MM.YYYY")}";"Belegdatum";"${formatDatevDate(ii.date, "DD.MM.YYYY")}";;;;;;;;;;"";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0;;;;"";;;;;;;`);
|
||||
|
||||
Reference in New Issue
Block a user