Changes
This commit is contained in:
190
spaces/pages/settings/banking/index.vue
Normal file
190
spaces/pages/settings/banking/index.vue
Normal file
@@ -0,0 +1,190 @@
|
||||
<script setup>
|
||||
|
||||
|
||||
import axios from "axios";
|
||||
|
||||
const dataStore = useDataStore()
|
||||
const route = useRoute()
|
||||
const supabase = useSupabaseClient()
|
||||
const toast = useToast()
|
||||
|
||||
const showAddBankRequisition = ref(false)
|
||||
const bicBankToAdd = ref("")
|
||||
const bankData = ref({})
|
||||
const reqData = ref({})
|
||||
|
||||
const setupPage = async () => {
|
||||
if(route.query.reqId) {
|
||||
const {data,error} = await axios({
|
||||
url:`http://localhost:3002/banking/requisitions/${route.query.reqId}`,
|
||||
method: "GET"
|
||||
})
|
||||
|
||||
if(data) {
|
||||
reqData.value = data
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const checkBIC = async () => {
|
||||
const {data,error} = await axios({
|
||||
url:`http://localhost:3002/banking/institutions/${bicBankToAdd.value}`,
|
||||
method: "GET",
|
||||
})
|
||||
|
||||
if(data) {
|
||||
bankData.value = data
|
||||
}
|
||||
|
||||
console.log(data)
|
||||
console.log(error)
|
||||
|
||||
}
|
||||
|
||||
const generateLink = async () => {
|
||||
const {data,error} = await axios({
|
||||
url:`http://localhost:3002/banking/link?tenant=${dataStore.currentTenant}&institution_id=${bankData.value.id}`,
|
||||
method: "POST",
|
||||
})
|
||||
|
||||
console.log(data)
|
||||
console.log(error)
|
||||
|
||||
if(data) {
|
||||
await navigateTo(data.link, {
|
||||
open: {
|
||||
target: "_blank"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const addAccount = async (account) => {
|
||||
|
||||
let accountData = {
|
||||
accountId: account.id,
|
||||
ownerName: account.owner_name,
|
||||
iban: account.iban,
|
||||
tenant: dataStore.currentTenant,
|
||||
bankId: account.institution_id
|
||||
}
|
||||
|
||||
const {data,error} = await supabase.from("bankaccounts").insert(accountData).select()
|
||||
if(error) {
|
||||
toast.add({title: "Es gab einen Fehler bei hinzufügen des Accounts", color:"rose"})
|
||||
} else if(data) {
|
||||
toast.add({title: "Account erfolgreich hinzugefügt"})
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
setupPage()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UDashboardNavbar title="Bankkonten">
|
||||
<template #right>
|
||||
<UButton
|
||||
@click="showAddBankRequisition = true"
|
||||
>
|
||||
+ Bankverbindung
|
||||
</UButton>
|
||||
<USlideover
|
||||
v-model="showAddBankRequisition"
|
||||
>
|
||||
<UCard
|
||||
class="h-full"
|
||||
>
|
||||
<template #header>
|
||||
<p>Bankverbindung hinzufügen</p>
|
||||
</template>
|
||||
|
||||
<UFormGroup
|
||||
label="BIC:"
|
||||
class="flex-auto"
|
||||
>
|
||||
<InputGroup class="w-full">
|
||||
<UInput
|
||||
v-model="bicBankToAdd"
|
||||
class="flex-auto"
|
||||
/>
|
||||
<UButton
|
||||
@click="checkBIC"
|
||||
>
|
||||
Check
|
||||
</UButton>
|
||||
</InputGroup>
|
||||
|
||||
</UFormGroup>
|
||||
<UAlert
|
||||
v-if="bankData.id && bankData.countries.includes('DE')"
|
||||
title="Bank gefunden"
|
||||
icon="i-heroicons-check"
|
||||
color="primary"
|
||||
variant="outline"
|
||||
class="mt-3"
|
||||
/>
|
||||
<UButton
|
||||
@click="generateLink"
|
||||
class="mt-3"
|
||||
>
|
||||
Verbinden
|
||||
</UButton>
|
||||
|
||||
</UCard>
|
||||
</USlideover>
|
||||
</template>
|
||||
</UDashboardNavbar>
|
||||
|
||||
<div
|
||||
v-for="account in reqData.accounts"
|
||||
class="p-2 m-3 flex justify-between"
|
||||
>
|
||||
{{account.iban}} - {{account.owner_name}}
|
||||
|
||||
<UButton
|
||||
@click="addAccount(account)"
|
||||
v-if="!dataStore.bankAccounts.find(i => i.accountId === account.id)"
|
||||
>
|
||||
+ Konto
|
||||
</UButton>
|
||||
</div>
|
||||
|
||||
<!-- <UButton @click="setupPage">Setup</UButton>
|
||||
<div v-if="route.query.reqId">
|
||||
{{reqData}}
|
||||
</div>-->
|
||||
|
||||
<UTable
|
||||
:rows="dataStore.bankAccounts"
|
||||
:columns="[
|
||||
{
|
||||
key: 'name',
|
||||
label: 'Name'
|
||||
},{
|
||||
key: 'iban',
|
||||
label: 'IBAN'
|
||||
},{
|
||||
key: 'bankId',
|
||||
label: 'Bank'
|
||||
},{
|
||||
key: 'ownerName',
|
||||
label: 'Kontoinhaber'
|
||||
},{
|
||||
key: 'balance',
|
||||
label: 'Saldo'
|
||||
},
|
||||
]"
|
||||
>
|
||||
|
||||
</UTable>
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user