204 lines
4.0 KiB
Vue
204 lines
4.0 KiB
Vue
<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 axiosBaseUrl = "https://backend.fedeo.de"
|
|
|
|
const setupPage = async () => {
|
|
if(route.query.ref) {
|
|
const {data,error} = await axios({
|
|
url:`${axiosBaseUrl}/banking/requisitions/${route.query.ref}`,
|
|
method: "GET",
|
|
auth: {
|
|
username: "frontend",
|
|
password: "Xt9Zn9RDSpdbr"
|
|
}
|
|
})
|
|
|
|
if(data) {
|
|
reqData.value = data
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
const checkBIC = async () => {
|
|
const {data,error} = await axios({
|
|
url:`${axiosBaseUrl}/banking/institutions/${bicBankToAdd.value}`,
|
|
method: "GET",
|
|
auth: {
|
|
username: "frontend",
|
|
password: "Xt9Zn9RDSpdbr"
|
|
}
|
|
})
|
|
|
|
if(data) {
|
|
bankData.value = data
|
|
}
|
|
|
|
console.log(data)
|
|
console.log(error)
|
|
|
|
}
|
|
|
|
const generateLink = async () => {
|
|
const {data,error} = await axios({
|
|
url:`${axiosBaseUrl}/banking/link?tenant=${dataStore.currentTenant}&institution_id=${bankData.value.id}`,
|
|
method: "POST",
|
|
auth: {
|
|
username: "frontend",
|
|
password: "Xt9Zn9RDSpdbr"
|
|
}
|
|
})
|
|
|
|
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> |