From 8d5e158d59c45e1f93e30eb8718d4a9f8e315bc0 Mon Sep 17 00:00:00 2001 From: florianfederspiel Date: Tue, 2 Sep 2025 19:10:59 +0200 Subject: [PATCH] New Backend changes --- composables/useEntities.ts | 20 ++++++++++++++++++- pages/banking/index.vue | 6 ++---- pages/banking/statements/[mode]/[[id]].vue | 23 +++++++++++----------- pages/createDocument/edit/[[id]].vue | 2 +- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/composables/useEntities.ts b/composables/useEntities.ts index 281a0f1..c9489c0 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/index.vue b/pages/banking/index.vue index 6a07653..a2ebb1f 100644 --- a/pages/banking/index.vue +++ b/pages/banking/index.vue @@ -10,17 +10,15 @@ defineShortcuts({ } }) -const profileStore = useProfileStore() const tempStore = useTempStore() const router = useRouter() -const supabase = useSupabaseClient() const bankstatements = ref([]) const bankaccounts = ref([]) const setupPage = async () => { - bankstatements.value = (await supabase.from("bankstatements").select("*, statementallocations(*)").is("archived",false).eq('tenant', profileStore.currentTenant).order("date", {ascending:false})).data - bankaccounts.value = await useSupabaseSelect("bankaccounts") + bankstatements.value = (await useEntities("bankstatements").select("*, statementallocations(*)", "date", false)) + bankaccounts.value = await useEntities("bankaccounts").select() } const templateColumns = [ diff --git a/pages/banking/statements/[mode]/[[id]].vue b/pages/banking/statements/[mode]/[[id]].vue index 8a0a06a..00b206e 100644 --- a/pages/banking/statements/[mode]/[[id]].vue +++ b/pages/banking/statements/[mode]/[[id]].vue @@ -37,20 +37,20 @@ const ownaccounts = ref([]) const loading = ref(true) const setup = async () => { if(route.params.id) { - itemInfo.value = (await supabase.from("bankstatements").select("*, statementallocations(*, cd_id(*), ii_id(*))").eq("id",route.params.id).single()).data //dataStore.bankstatements.find(i => i.id === Number(route.params.id)) + itemInfo.value = await useEntities("bankstatements").selectSingle(route.params.id,"*, statementallocations(*, cd_id(*), ii_id(*))", undefined, undefined, true) } if(itemInfo.value) oldItemInfo.value = JSON.parse(JSON.stringify(itemInfo.value)) manualAllocationSum.value = calculateOpenSum.value - createddocuments.value = (await useSupabaseSelect("createddocuments","*, statementallocations(*), customer(id,name)")) + createddocuments.value = (await useEntities("createddocuments").select("*, statementallocations(*), customer(id,name)")) const documents = createddocuments.value.filter(i => i.type === "invoices" ||i.type === "advanceInvoices") - const incominginvoices = (await useSupabaseSelect("incominginvoices","*, statementallocations(*), vendor(id,name)")).filter(i => i.state === "Gebucht") + const incominginvoices = (await useEntities("incominginvoices").select("*, statementallocations(*), vendor(id,name)")).filter(i => i.state === "Gebucht") - accounts.value = (await supabase.from("accounts").select().order("number",{ascending: true})).data - ownaccounts.value = (await supabase.from("ownaccounts").select()).data - customers.value = (await supabase.from("customers").select()).data - vendors.value = (await supabase.from("vendors").select()).data + 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 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 => { @@ -69,15 +69,12 @@ const setup = async () => { allocatedIncomingInvoices.value = incominginvoices.filter(i => i.statementallocations.find(x => x.bs_id === itemInfo.value.id)) console.log(allocatedDocuments.value) console.log(allocatedIncomingInvoices.value) - //openIncomingInvoices.value = (await useSupabaseSelect("incominginvoices","*, statementallocations(*), vendor(*)")).filter(i => i.statementallocations.length === 0 ) - openIncomingInvoices.value = (await useSupabaseSelect("incominginvoices","*, statementallocations(*), vendor(*)")).filter(i => i.statementallocations.reduce((n,{amount}) => n + amount, 0).toFixed(2) !== getInvoiceSum(i,false)) + openIncomingInvoices.value = (await useEntities("incominginvoices").select("*, statementallocations(*), vendor(*)")).filter(i => i.statementallocations.reduce((n,{amount}) => n + amount, 0).toFixed(2) !== getInvoiceSum(i,false)) //console.log(openIncomingInvoices.value) // return incominginvoices.value.filter(i => bankstatements.value.filter(x => x.assignments.find(y => y.type === 'incomingInvoice' && y.id === i.id)).length === 0) - let allocations = (await supabase.from("createddocuments").select(`*, statementallocations(*)`).eq("id",50)).data - loading.value = false } @@ -149,7 +146,7 @@ const showMoreWithoutRecipe = ref(false) const showMoreText = ref(false) const saveAllocation = async (allocation) => { - + //TODO: BACKEND CHANGE SAVE/REMOVE console.log(allocation) const {data,error} = await supabase.from("statementallocations").insert({ @@ -354,7 +351,9 @@ const archiveStatement = async () => { Konto: +