DATEV-Erlöskonten für Ausgangsbelege aufteilen #179
This commit is contained in:
@@ -34,17 +34,28 @@ const getCreatedDocumentTotal = (item: any) => {
|
|||||||
let totalNet = 0;
|
let totalNet = 0;
|
||||||
let total19:number = 0;
|
let total19:number = 0;
|
||||||
let total7:number = 0;
|
let total7:number = 0;
|
||||||
|
let net19 = 0;
|
||||||
|
let net7 = 0;
|
||||||
|
let net0 = 0;
|
||||||
const rows = Array.isArray(item.rows) ? item.rows : [];
|
const rows = Array.isArray(item.rows) ? item.rows : [];
|
||||||
rows.forEach((row: any) => {
|
rows.forEach((row: any) => {
|
||||||
if (!['pagebreak', 'title', 'text'].includes(row.mode)) {
|
if (!['pagebreak', 'title', 'text'].includes(row.mode)) {
|
||||||
|
const taxPercent = Number(row.taxPercent);
|
||||||
let rowPrice = Number(Number(row.quantity) * Number(row.price) * (1 - Number(row.discountPercent) / 100)).toFixed(3);
|
let rowPrice = Number(Number(row.quantity) * Number(row.price) * (1 - Number(row.discountPercent) / 100)).toFixed(3);
|
||||||
totalNet = totalNet + Number(rowPrice);
|
totalNet = totalNet + Number(rowPrice);
|
||||||
if (row.taxPercent === 19) total19 += Number(rowPrice) * Number(0.19);
|
if (taxPercent === 19) {
|
||||||
else if (row.taxPercent === 7) total7 += Number(rowPrice) * Number(0.07);
|
net19 += Number(rowPrice);
|
||||||
|
total19 += Number(rowPrice) * Number(0.19);
|
||||||
|
} else if (taxPercent === 7) {
|
||||||
|
net7 += Number(rowPrice);
|
||||||
|
total7 += Number(rowPrice) * Number(0.07);
|
||||||
|
} else if (taxPercent === 0) {
|
||||||
|
net0 += Number(rowPrice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
totalNet, total19, total7,
|
totalNet, total19, total7, net19, net7, net0,
|
||||||
totalGross: Number(totalNet.toFixed(2)) + Number(total19.toFixed(2)) + Number(total7.toFixed(2))
|
totalGross: Number(totalNet.toFixed(2)) + Number(total19.toFixed(2)) + Number(total7.toFixed(2))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -58,13 +69,31 @@ const displayCurrency = (input: number, onlyAbs = false) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getCreatedDocumentDatevTaxKey = (document: { taxType?: string | null }) => {
|
const getCreatedDocumentDatevTaxKey = (document: { taxType?: string | null }) => {
|
||||||
return document.taxType === "13b UStG" ? "46" : "";
|
return document.taxType === "13b UStG" ? "46" : "3";
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCreatedDocumentPaymentDatevTaxKey = (document: { taxType?: string | null }) => {
|
const getCreatedDocumentPaymentDatevTaxKey = (document: { taxType?: string | null }) => {
|
||||||
return document.taxType === "13b UStG" ? "46" : "3";
|
return document.taxType === "13b UStG" ? "46" : "3";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getCreatedDocumentRevenueLines = (document: any) => {
|
||||||
|
const totals = getCreatedDocumentTotal(document);
|
||||||
|
|
||||||
|
if (document.taxType === "13b UStG") {
|
||||||
|
return [{ account: "8337", amount: totals.totalGross }];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.taxType === "19 UStG") {
|
||||||
|
return [{ account: "8192", amount: totals.totalGross }];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{ account: "8400", amount: Number(totals.net19.toFixed(2)) },
|
||||||
|
{ account: "8334", amount: Number(totals.net7.toFixed(2)) },
|
||||||
|
{ account: "8290", amount: Number(totals.net0.toFixed(2)) },
|
||||||
|
].filter((line) => line.amount !== 0);
|
||||||
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// MAIN EXPORT FUNCTION
|
// MAIN EXPORT FUNCTION
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
@@ -297,25 +326,24 @@ export async function buildExportZip(
|
|||||||
// AR
|
// AR
|
||||||
createddocumentsList.forEach(cd => {
|
createddocumentsList.forEach(cd => {
|
||||||
let file = filesCreateddocuments.find(i => i.createddocument === cd.id);
|
let file = filesCreateddocuments.find(i => i.createddocument === cd.id);
|
||||||
let total = 0;
|
|
||||||
let typeString = "";
|
let typeString = "";
|
||||||
|
|
||||||
if(cd.type === "invoices") {
|
if(cd.type === "invoices") {
|
||||||
total = getCreatedDocumentTotal(cd).totalGross;
|
|
||||||
typeString = "AR";
|
typeString = "AR";
|
||||||
} else if(cd.type === "advanceInvoices") {
|
} else if(cd.type === "advanceInvoices") {
|
||||||
total = getCreatedDocumentTotal(cd).totalGross;
|
|
||||||
typeString = "ARAbschlag";
|
typeString = "ARAbschlag";
|
||||||
} else if(cd.type === "cancellationInvoices") {
|
} else if(cd.type === "cancellationInvoices") {
|
||||||
total = getCreatedDocumentTotal(cd).totalGross;
|
|
||||||
typeString = "ARStorno";
|
typeString = "ARStorno";
|
||||||
}
|
}
|
||||||
|
|
||||||
let shSelector = Math.sign(total) === -1 ? "H" : "S";
|
|
||||||
const cust = cd.customer; // durch Mapping verfügbar
|
const cust = cd.customer; // durch Mapping verfügbar
|
||||||
const datevTaxKey = getCreatedDocumentDatevTaxKey(cd);
|
const datevTaxKey = getCreatedDocumentDatevTaxKey(cd);
|
||||||
|
const revenueLines = getCreatedDocumentRevenueLines(cd);
|
||||||
|
|
||||||
bookingLines.push(`${displayCurrency(total,true)};"${shSelector}";;;;;${cust?.customerNumber || ""};8400;"${datevTaxKey}";${dayjs(cd.documentDate).format("DDMM")};"${cd.documentNumber}";;;"${`${typeString} ${cd.documentNumber} - ${cust?.name || ""}`.substring(0,59)}";;;;;;${file ? `"BEDI ""${file.id}"""` : ""};"Geschäftspartner";"${cust?.name || ""}";"Kundennummer";"${cust?.customerNumber || ""}";"Belegnummer";"${cd.documentNumber}";"Leistungsdatum";"${dayjs(cd.deliveryDate).format("DD.MM.YYYY")}";"Belegdatum";"${dayjs(cd.documentDate).format("DD.MM.YYYY")}";;;;;;;;;;"";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0;;;;"";;;;;;;`);
|
revenueLines.forEach((revenueLine) => {
|
||||||
|
let shSelector = Math.sign(revenueLine.amount) === -1 ? "H" : "S";
|
||||||
|
bookingLines.push(`${displayCurrency(revenueLine.amount,true)};"${shSelector}";;;;;${cust?.customerNumber || ""};${revenueLine.account};"${datevTaxKey}";${dayjs(cd.documentDate).format("DDMM")};"${cd.documentNumber}";;;"${`${typeString} ${cd.documentNumber} - ${cust?.name || ""}`.substring(0,59)}";;;;;;${file ? `"BEDI ""${file.id}"""` : ""};"Geschäftspartner";"${cust?.name || ""}";"Kundennummer";"${cust?.customerNumber || ""}";"Belegnummer";"${cd.documentNumber}";"Leistungsdatum";"${dayjs(cd.deliveryDate).format("DD.MM.YYYY")}";"Belegdatum";"${dayjs(cd.documentDate).format("DD.MM.YYYY")}";;;;;;;;;;"";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0;;;;"";;;;;;;`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ER
|
// ER
|
||||||
|
|||||||
Reference in New Issue
Block a user