Added select-special

Fixed Banking Page
This commit is contained in:
2025-09-07 19:20:50 +02:00
parent 9f59b94336
commit 34c5764472
2 changed files with 33 additions and 10 deletions

View File

@@ -36,6 +36,24 @@ export const useEntities = (
return data 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 ( const selectSingle = async (
idToEq: string | number, idToEq: string | number,
select: string = "*", select: string = "*",
@@ -113,7 +131,7 @@ export const useEntities = (
return res return res
} }
return {select, create, update, archive, selectSingle} return {select, create, update, archive, selectSingle, selectSpecial}
} }

View File

@@ -36,6 +36,7 @@ const ownaccounts = ref([])
const loading = ref(true) const loading = ref(true)
const setup = async () => { const setup = async () => {
loading.value = true
if(route.params.id) { if(route.params.id) {
itemInfo.value = await useEntities("bankstatements").selectSingle(route.params.id,"*, statementallocations(*, cd_id(*), ii_id(*))", undefined, undefined, true) 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") const incominginvoices = (await useEntities("incominginvoices").select("*, statementallocations(*), vendor(id,name)")).filter(i => i.state === "Gebucht")
accounts.value = (await useEntities("accounts").selectSpecial("*","number",true)) accounts.value = (await useEntities("accounts").selectSpecial("*","number",true))
ownaccounts.value = (await useEntities("ownaccounts").select()).data ownaccounts.value = (await useEntities("ownaccounts").select())
customers.value = (await useEntities("customers").select()).data customers.value = (await useEntities("customers").select())
vendors.value = (await useEntities("vendors").select()).data 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 = 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 => { openDocuments.value = openDocuments.value.map(i => {
@@ -149,12 +150,14 @@ const saveAllocation = async (allocation) => {
//TODO: BACKEND CHANGE SAVE/REMOVE //TODO: BACKEND CHANGE SAVE/REMOVE
console.log(allocation) console.log(allocation)
const {data,error} = await supabase.from("statementallocations").insert({ const res = await useNuxtApp().$api("/api/banking/statements",{
...allocation, method: "POST",
tenant: profileStore.currentTenant body: {
}).select() data: allocation
}
})
if(data) { if(res) {
await setup() await setup()
accountToSave.value = null accountToSave.value = null
vendorAccountToSave.value = null vendorAccountToSave.value = null
@@ -168,7 +171,9 @@ const saveAllocation = async (allocation) => {
} }
const removeAllocation = async (allocationId) => { 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() await setup()
} }