Manuelle Buchungen um zuweisbare Eingangsbelege erweitern

This commit is contained in:
2026-04-23 17:52:56 +02:00
parent 9c608cbf71
commit 41e5a4021b
6 changed files with 82 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ const accounts = ref([])
const customers = ref([])
const vendors = ref([])
const ownaccounts = ref([])
const incomingInvoices = ref([])
const bookings = ref([])
const debitSearch = ref("")
const creditSearch = ref("")
@@ -51,8 +52,8 @@ const buildEntries = (rows, type, labelBuilder) =>
key: `${type}:${item.id}`,
id: item.id,
type,
number: item.number || item.vendorNumber || item.customerNumber || "",
name: item.label || item.name || "",
number: item.number || item.vendorNumber || item.customerNumber || item.reference || "",
name: item.label || item.name || item.vendor?.name || "",
label: labelBuilder(item),
typeLabel:
type === "account"
@@ -61,9 +62,23 @@ const buildEntries = (rows, type, labelBuilder) =>
? "Kreditoren"
: type === "customer"
? "Debitoren"
: "Zusätzliche Konten"
: type === "incominginvoice"
? "Eingangsbelege"
: "Zusätzliche Konten"
}))
const getIncomingInvoiceGross = (invoice) => {
return Number((invoice.accounts || []).reduce((sum, account) => {
return sum + Number(account.amountNet || 0) + Number(account.amountTax || 0)
}, 0))
}
const getIncomingInvoiceOpenAmount = (invoice) => {
const gross = getIncomingInvoiceGross(invoice)
const allocated = Number((invoice.statementallocations || []).reduce((sum, allocation) => sum + Number(allocation.amount || 0), 0))
return Math.abs(gross) - Math.abs(allocated)
}
const entryGroups = computed(() => ([
{
key: "account",
@@ -84,6 +99,11 @@ const entryGroups = computed(() => ([
key: "ownaccount",
label: "Zusätzliche Konten",
entries: buildEntries(ownaccounts.value, "ownaccount", (item) => `${item.number} - ${item.name}`)
},
{
key: "incominginvoice",
label: "Eingangsbelege",
entries: buildEntries(incomingInvoices.value, "incominginvoice", (item) => `${item.reference || "Ohne Referenz"} - ${item.vendor?.name || "Ohne Lieferant"} - Offen ${displayCurrency(getIncomingInvoiceOpenAmount(item))}`)
}
]))
@@ -129,6 +149,14 @@ const selectedCredit = computed(() => allEntries.value.find((item) => item.key =
const selectedTaxKey = computed(() => DATEV_TAX_KEY_ITEMS.find((item) => item.value === form.datevTaxKey))
const getBookingSide = (booking, side) => {
if (booking.incominginvoice && booking.manualInvoiceSide === side) {
return {
type: "Eingangsbeleg",
number: booking.incominginvoice?.reference || "",
name: booking.incominginvoice?.vendor?.name || booking.incominginvoice?.description || ""
}
}
const map = side === "credit"
? [
["contraAccount", "Sachkonto"],
@@ -161,6 +189,12 @@ const buildSidePayload = (sideKey, target) => {
if (!type || !id) return
const numericId = type === "ownaccount" ? id : Number(id)
if (type === "incominginvoice") {
return {
incominginvoice: numericId,
manualInvoiceSide: target
}
}
if (target === "debit") {
if (type === "account") return { account: numericId }
if (type === "customer") return { customer: numericId }
@@ -176,11 +210,12 @@ const buildSidePayload = (sideKey, target) => {
const loadData = async () => {
loading.value = true
const [accountRows, customerRows, vendorRows, ownaccountRows, bookingRows] = await Promise.all([
const [accountRows, customerRows, vendorRows, ownaccountRows, incomingInvoiceRows, bookingRows] = await Promise.all([
useEntities("accounts").selectSpecial("*", "number", true),
useEntities("customers").select(),
useEntities("vendors").select(),
useEntities("ownaccounts").select(),
useEntities("incominginvoices").select("*, vendor(*), statementallocations(id,amount)"),
useNuxtApp().$api("/api/banking/manual-bookings")
])
@@ -188,6 +223,9 @@ const loadData = async () => {
customers.value = customerRows || []
vendors.value = vendorRows || []
ownaccounts.value = ownaccountRows || []
incomingInvoices.value = (incomingInvoiceRows || [])
.filter((invoice) => invoice.state === "Gebucht" && !invoice.archived)
.filter((invoice) => getIncomingInvoiceOpenAmount(invoice) > 0.004)
bookings.value = (bookingRows || []).sort((a, b) => String(b.manualBookingDate || "").localeCompare(String(a.manualBookingDate || "")))
loading.value = false
}