Manuelle Buchungen um zuweisbare Eingangsbelege erweitern
This commit is contained in:
@@ -0,0 +1 @@
|
||||
ALTER TABLE "statementallocations" ADD COLUMN "manual_invoice_side" text;
|
||||
@@ -225,6 +225,13 @@
|
||||
"when": 1776298200000,
|
||||
"tag": "0031_manual_statementallocations_tax_key",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 32,
|
||||
"version": "7",
|
||||
"when": 1776298800000,
|
||||
"tag": "0032_manual_statementallocations_invoice_side",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ export const statementallocations = pgTable("statementallocations", {
|
||||
incominginvoice: bigint("ii_id", { mode: "number" }).references(
|
||||
() => incominginvoices.id
|
||||
),
|
||||
manualInvoiceSide: text("manual_invoice_side"),
|
||||
|
||||
tenant: bigint("tenant", { mode: "number" })
|
||||
.notNull()
|
||||
|
||||
@@ -34,6 +34,8 @@ export default async function bankingRoutes(server: FastifyInstance) {
|
||||
const ContraCustomers = aliasedTable(customers, "contra_customers")
|
||||
const ContraVendors = aliasedTable(vendors, "contra_vendors")
|
||||
const ContraOwnaccounts = aliasedTable(ownaccounts, "contra_ownaccounts")
|
||||
const ManualInvoices = aliasedTable(incominginvoices, "manual_invoices")
|
||||
const ManualInvoiceVendors = aliasedTable(vendors, "manual_invoice_vendors")
|
||||
|
||||
const normalizeManualSide = (payload: any, keys: string[]) =>
|
||||
keys.filter((key) => payload[key] !== null && payload[key] !== undefined && payload[key] !== "")
|
||||
@@ -49,14 +51,24 @@ export default async function bankingRoutes(server: FastifyInstance) {
|
||||
next.contraVendor = null
|
||||
next.contraOwnaccount = null
|
||||
next.datevTaxKey = next.datevTaxKey ? String(next.datevTaxKey).trim() : null
|
||||
next.manualInvoiceSide = null
|
||||
return { data: next }
|
||||
}
|
||||
|
||||
const debitKeys = ["account", "customer", "vendor", "ownaccount"]
|
||||
const creditKeys = ["contraAccount", "contraCustomer", "contraVendor", "contraOwnaccount"]
|
||||
const hasManualInvoice = next.incominginvoice !== null && next.incominginvoice !== undefined && next.incominginvoice !== ""
|
||||
const debitSide = normalizeManualSide(next, debitKeys)
|
||||
const creditSide = normalizeManualSide(next, creditKeys)
|
||||
|
||||
if (hasManualInvoice) {
|
||||
if (next.manualInvoiceSide === "debit") debitSide.push("incominginvoice")
|
||||
else if (next.manualInvoiceSide === "credit") creditSide.push("incominginvoice")
|
||||
else return { error: "Für zugewiesene Eingangsbelege muss Soll oder Haben ausgewählt sein." }
|
||||
} else {
|
||||
next.manualInvoiceSide = null
|
||||
}
|
||||
|
||||
if (!next.manualBookingDate || !dayjs(next.manualBookingDate).isValid()) {
|
||||
return { error: "Für manuelle Buchungen ist ein gültiges Buchungsdatum erforderlich." }
|
||||
}
|
||||
@@ -745,6 +757,8 @@ export default async function bankingRoutes(server: FastifyInstance) {
|
||||
contraCustomer: ContraCustomers,
|
||||
contraVendor: ContraVendors,
|
||||
contraOwnaccount: ContraOwnaccounts,
|
||||
incominginvoice: ManualInvoices,
|
||||
incominginvoiceVendor: ManualInvoiceVendors,
|
||||
})
|
||||
.from(statementallocations)
|
||||
.leftJoin(accounts, eq(statementallocations.account, accounts.id))
|
||||
@@ -755,6 +769,8 @@ export default async function bankingRoutes(server: FastifyInstance) {
|
||||
.leftJoin(ContraCustomers, eq(statementallocations.contraCustomer, ContraCustomers.id))
|
||||
.leftJoin(ContraVendors, eq(statementallocations.contraVendor, ContraVendors.id))
|
||||
.leftJoin(ContraOwnaccounts, eq(statementallocations.contraOwnaccount, ContraOwnaccounts.id))
|
||||
.leftJoin(ManualInvoices, eq(statementallocations.incominginvoice, ManualInvoices.id))
|
||||
.leftJoin(ManualInvoiceVendors, eq(ManualInvoices.vendor, ManualInvoiceVendors.id))
|
||||
.where(and(
|
||||
eq(statementallocations.tenant, req.user.tenant_id),
|
||||
eq(statementallocations.archived, false),
|
||||
@@ -771,6 +787,10 @@ export default async function bankingRoutes(server: FastifyInstance) {
|
||||
contraCustomer: row.contraCustomer,
|
||||
contraVendor: row.contraVendor,
|
||||
contraOwnaccount: row.contraOwnaccount,
|
||||
incominginvoice: row.incominginvoice ? {
|
||||
...row.incominginvoice,
|
||||
vendor: row.incominginvoiceVendor,
|
||||
} : null,
|
||||
})))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
||||
@@ -341,11 +341,20 @@ export async function buildExportZip(
|
||||
const vendor = side === "credit" ? alloc.contraVendor : alloc.vendor;
|
||||
const customer = side === "credit" ? alloc.contraCustomer : alloc.customer;
|
||||
const ownaccount = side === "credit" ? alloc.contraOwnaccount : alloc.ownaccount;
|
||||
const incominginvoice = alloc.manualInvoiceSide === side ? alloc.incominginvoice : null;
|
||||
|
||||
if (account) return { number: account.number, name: account.label, type: "Sachkonto" };
|
||||
if (vendor) return { number: vendor.vendorNumber, name: vendor.name, type: "Kreditor" };
|
||||
if (customer) return { number: customer.customerNumber, name: customer.name, type: "Debitor" };
|
||||
if (ownaccount) return { number: ownaccount.number, name: ownaccount.name, type: "Eigenes Konto" };
|
||||
if (incominginvoice) {
|
||||
return {
|
||||
number: incominginvoice.vendor?.vendorNumber || "",
|
||||
name: `${incominginvoice.reference || "Eingangsbeleg"} ${incominginvoice.vendor?.name || ""}`.trim(),
|
||||
type: "Eingangsbeleg",
|
||||
reference: incominginvoice.reference || "",
|
||||
};
|
||||
}
|
||||
return { number: "", name: "", type: prefix };
|
||||
};
|
||||
|
||||
@@ -357,7 +366,8 @@ export async function buildExportZip(
|
||||
const credit = getManualBookingSide(alloc, "credit");
|
||||
const dateManual = dayjs(alloc.manualBookingDate).format("DDMM");
|
||||
const dateManualFull = dayjs(alloc.manualBookingDate).format("DD.MM.YYYY");
|
||||
bookingLines.push(`${displayCurrency(alloc.amount,true)};"S";;;;;${debit.number};${credit.number};"${alloc.datevTaxKey || ""}";${dateManual};"";;;"${`MB ${debit.number} an ${credit.number} ${escapeString(alloc.description)}`.substring(0,59)}";;;;;;;"Geschäftspartner";"${escapeString(debit.name || credit.name)}";"Kundennummer";"${debit.number}";"Belegnummer";"";"Leistungsdatum";"${dateManualFull}";"Belegdatum";"${dateManualFull}";;;;;;;;;;"";;;;;;;;Manuelle-Buchung;${alloc.id};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0;;;;"";;;;;;`);
|
||||
const belegnummer = debit.reference || credit.reference || "";
|
||||
bookingLines.push(`${displayCurrency(alloc.amount,true)};"S";;;;;${debit.number};${credit.number};"${alloc.datevTaxKey || ""}";${dateManual};"${belegnummer}";;;"${`MB ${debit.number} an ${credit.number} ${escapeString(alloc.description)}`.substring(0,59)}";;;;;;;"Geschäftspartner";"${escapeString(debit.name || credit.name)}";"Kundennummer";"${debit.number}";"Belegnummer";"${belegnummer}";"Leistungsdatum";"${dateManualFull}";"Belegdatum";"${dateManualFull}";;;;;;;;;;"";;;;;;;;Manuelle-Buchung;${alloc.id};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0;;;;"";;;;;;`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user