From 34c5764472c6a6483ecb43da719989a0f7ea59a5 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Sun, 7 Sep 2025 19:20:50 +0200 Subject: [PATCH] Added select-special Fixed Banking Page --- composables/useEntities.ts | 20 ++++++++++++++++++- pages/banking/statements/[mode]/[[id]].vue | 23 +++++++++++++--------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/composables/useEntities.ts b/composables/useEntities.ts index 281a0f1..9aa2c21 100644 --- a/composables/useEntities.ts +++ b/composables/useEntities.ts @@ -36,6 +36,24 @@ export const useEntities = ( return data } + const selectSpecial = async ( + select: string = "*", + sortColumn: string | null = null, + ascending: boolean = false, + ) => { + + const res = await useNuxtApp().$api(`/api/resource-special/${relation}`, { + method: "GET", + params: { + select, + sort: sortColumn || undefined, + asc: ascending + } + }) + + return res || [] + } + const selectSingle = async ( idToEq: string | number, select: string = "*", @@ -113,7 +131,7 @@ export const useEntities = ( return res } - return {select, create, update, archive, selectSingle} + return {select, create, update, archive, selectSingle, selectSpecial} } diff --git a/pages/banking/statements/[mode]/[[id]].vue b/pages/banking/statements/[mode]/[[id]].vue index 00b206e..71a1d2d 100644 --- a/pages/banking/statements/[mode]/[[id]].vue +++ b/pages/banking/statements/[mode]/[[id]].vue @@ -36,6 +36,7 @@ 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) } @@ -48,9 +49,9 @@ const setup = async () => { const incominginvoices = (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()).data - customers.value = (await useEntities("customers").select()).data - vendors.value = (await useEntities("vendors").select()).data + ownaccounts.value = (await useEntities("ownaccounts").select()) + customers.value = (await useEntities("customers").select()) + vendors.value = (await useEntities("vendors").select()) openDocuments.value = documents.filter(i => i.statementallocations.reduce((n,{amount}) => n + amount, 0).toFixed(2) !== useSum().getCreatedDocumentSum(i,createddocuments.value).toFixed(2)) openDocuments.value = openDocuments.value.map(i => { @@ -149,12 +150,14 @@ const saveAllocation = async (allocation) => { //TODO: BACKEND CHANGE SAVE/REMOVE console.log(allocation) - const {data,error} = await supabase.from("statementallocations").insert({ - ...allocation, - tenant: profileStore.currentTenant - }).select() + const res = await useNuxtApp().$api("/api/banking/statements",{ + method: "POST", + body: { + data: allocation + } + }) - if(data) { + if(res) { await setup() accountToSave.value = null vendorAccountToSave.value = null @@ -168,7 +171,9 @@ const saveAllocation = async (allocation) => { } const removeAllocation = async (allocationId) => { - const {data,error} = await supabase.from("statementallocations").delete().eq("id",allocationId) + const res = await useNuxtApp().$api(`/api/banking/statements/${allocationId}`,{ + method: "DELETE" + }) await setup() }