Speed up bank allocation updates

This commit is contained in:
2026-08-06 11:42:19 +02:00
parent f375d63655
commit c8a7f4f396

View File

@@ -39,26 +39,8 @@ const ownaccounts = ref([])
const loading = ref(true)
const setup = async () => {
loading.value = true
if (route.params.id) {
itemInfo.value = await useEntities("bankstatements").selectSingle(route.params.id, "*, statementallocations(*, cd_id(*), ii_id(*))", undefined, undefined, true)
console.log(itemInfo.value)
}
if (itemInfo.value) oldItemInfo.value = JSON.parse(JSON.stringify(itemInfo.value))
manualAllocationSum.value = calculateOpenSum.value
allocationDepreciationStartDate.value = dayjs(itemInfo.value?.date || new Date()).format("YYYY-MM-DD")
createddocuments.value = (await useEntities("createddocuments").select("*, statementallocations(*), customer(id,name)"))
const rebuildDocumentLists = () => {
const documents = createddocuments.value.filter(i => i.type === "invoices" || i.type === "advanceInvoices")
incominginvoices.value = (await useEntities("incominginvoices").select("*, statementallocations(*), vendor(id,name)")).filter(i => i.state === "Gebucht")
accounts.value = (await useEntities("accounts").selectSpecial("*", "number", true))
ownaccounts.value = (await useEntities("ownaccounts").select())
customers.value = (await useEntities("customers").select())
vendors.value = (await useEntities("vendors").select())
openDocuments.value = documents.filter(i => useSum().isOpenCreatedDocument(i, createddocuments.value))
openDocuments.value = openDocuments.value.map(i => {
@@ -72,8 +54,38 @@ const setup = async () => {
allocatedDocuments.value = documents.filter(i => i.statementallocations.find(x => x.bankstatement === itemInfo.value.id))
allocatedIncomingInvoices.value = incominginvoices.value.filter(i => i.statementallocations.find(x => x.bankstatement === itemInfo.value.id))
openIncomingInvoices.value = incominginvoices.value.filter(i =>
!i.archived && i.statementallocations.reduce((n, {amount}) => n + amount, 0).toFixed(2) !== getInvoiceSum(i, false)
)
}
openIncomingInvoices.value = (await useEntities("incominginvoices").select("*, statementallocations(*), vendor(*)")).filter(i => !i.archived && i.statementallocations.reduce((n, {amount}) => n + amount, 0).toFixed(2) !== getInvoiceSum(i, false))
const setup = async () => {
loading.value = true
const [statement, documentItems, invoiceItems, accountItems, ownAccountItems, customerItems, vendorItems] = await Promise.all([
route.params.id
? useEntities("bankstatements").selectSingle(route.params.id, "*, statementallocations(*, cd_id(*), ii_id(*))")
: Promise.resolve(itemInfo.value),
useEntities("createddocuments").select("*, statementallocations(*), customer(id,name)"),
useEntities("incominginvoices").select("*, statementallocations(*), vendor(*)"),
useEntities("accounts").selectSpecial("*", "number", true),
useEntities("ownaccounts").select(),
useEntities("customers").select(),
useEntities("vendors").select()
])
itemInfo.value = statement
if (itemInfo.value) oldItemInfo.value = JSON.parse(JSON.stringify(itemInfo.value))
manualAllocationSum.value = calculateOpenSum.value
allocationDepreciationStartDate.value = dayjs(itemInfo.value?.date || new Date()).format("YYYY-MM-DD")
createddocuments.value = documentItems
incominginvoices.value = invoiceItems.filter(i => i.state === "Gebucht")
accounts.value = accountItems
ownaccounts.value = ownAccountItems
customers.value = customerItems
vendors.value = vendorItems
rebuildDocumentLists()
if (itemInfo.value?.id) {
statementSuggestions.value = await useFunctions().useBankingStatementSuggestions(itemInfo.value.id)
@@ -189,7 +201,17 @@ const saveAllocation = async (allocation) => {
})
if (res) {
await setup()
itemInfo.value.statementallocations.push(res)
if (res.createddocument) {
const document = createddocuments.value.find(item => item.id === res.createddocument)
document?.statementallocations.push(res)
}
if (res.incominginvoice) {
const invoice = incominginvoices.value.find(item => item.id === res.incominginvoice)
invoice?.statementallocations.push(res)
}
rebuildDocumentLists()
manualAllocationSum.value = calculateOpenSum.value
accountToSave.value = null
vendorAccountToSave.value = null
customerAccountToSave.value = null
@@ -209,7 +231,15 @@ const removeAllocation = async (allocationId) => {
await useNuxtApp().$api(`/api/banking/statements/${allocationId}`, {
method: "DELETE"
})
await setup()
itemInfo.value.statementallocations = itemInfo.value.statementallocations.filter(item => item.id !== allocationId)
createddocuments.value.forEach(document => {
document.statementallocations = document.statementallocations.filter(item => item.id !== allocationId)
})
incominginvoices.value.forEach(invoice => {
invoice.statementallocations = invoice.statementallocations.filter(item => item.id !== allocationId)
})
rebuildDocumentLists()
manualAllocationSum.value = calculateOpenSum.value
}
const searchString = ref(tempStore.searchStrings["bankstatementsedit"] || '')