Incoming Invoice GPT Update
This commit is contained in:
@@ -118,21 +118,35 @@ const totalCalculated = computed(() => {
|
||||
return { totalNet, totalAmount19Tax, totalAmount7Tax, totalGross }
|
||||
})
|
||||
|
||||
const hasAmount = (value) => value !== null && value !== undefined && value !== ""
|
||||
|
||||
const recalculateItem = (item, source) => {
|
||||
const taxRate = Number(taxOptions.value.find(i => i.key === item.taxType)?.percentage || 0);
|
||||
|
||||
if (source === 'net') {
|
||||
const calculateFromNet = () => {
|
||||
if(!hasAmount(item.amountNet)) return
|
||||
item.amountTax = Number((item.amountNet * (taxRate/100)).toFixed(2))
|
||||
item.amountGross = Number((Number(item.amountNet) + item.amountTax).toFixed(2))
|
||||
} else if (source === 'gross') {
|
||||
}
|
||||
const calculateFromGross = () => {
|
||||
if(!hasAmount(item.amountGross)) return
|
||||
item.amountNet = Number((item.amountGross / (1 + taxRate/100)).toFixed(2))
|
||||
item.amountTax = Number((item.amountGross - item.amountNet).toFixed(2))
|
||||
} else if (source === 'taxType') {
|
||||
if(item.amountNet) {
|
||||
item.amountTax = Number((item.amountNet * (taxRate/100)).toFixed(2))
|
||||
item.amountGross = Number((Number(item.amountNet) + item.amountTax).toFixed(2))
|
||||
}
|
||||
}
|
||||
|
||||
if (source === 'net') {
|
||||
calculateFromNet()
|
||||
} else if (source === 'gross') {
|
||||
calculateFromGross()
|
||||
} else if (source === 'taxType' || source === 'manual') {
|
||||
if(hasAmount(item.amountNet)) calculateFromNet()
|
||||
else if(hasAmount(item.amountGross)) calculateFromGross()
|
||||
}
|
||||
}
|
||||
|
||||
const moveGrossToNet = (item) => {
|
||||
if(!hasAmount(item.amountGross)) return
|
||||
item.amountNet = Number(item.amountGross)
|
||||
recalculateItem(item, 'net')
|
||||
}
|
||||
|
||||
// --- Saving ---
|
||||
@@ -401,24 +415,35 @@ const findIncomingInvoiceErrors = computed(() => {
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<div class="col-span-12 md:col-span-4">
|
||||
<UFormGroup :label="useNetMode ? 'Betrag (Netto)' : 'Betrag (Brutto)'">
|
||||
<div class="col-span-12 md:col-span-3">
|
||||
<UFormGroup label="Betrag (Netto)">
|
||||
<UInput
|
||||
type="number"
|
||||
step="0.01"
|
||||
:disabled="mode === 'show'"
|
||||
:model-value="useNetMode ? item.amountNet : item.amountGross"
|
||||
@update:model-value="(val) => {
|
||||
if(useNetMode) { item.amountNet = Number(val); recalculateItem(item, 'net') }
|
||||
else { item.amountGross = Number(val); recalculateItem(item, 'gross') }
|
||||
}"
|
||||
:disabled="mode === 'show' || !useNetMode"
|
||||
:model-value="item.amountNet"
|
||||
@update:model-value="(val) => { item.amountNet = Number(val); recalculateItem(item, 'net') }"
|
||||
>
|
||||
<template #trailing>€</template>
|
||||
</UInput>
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 md:col-span-4">
|
||||
<div class="col-span-12 md:col-span-3">
|
||||
<UFormGroup label="Betrag (Brutto)">
|
||||
<UInput
|
||||
type="number"
|
||||
step="0.01"
|
||||
:disabled="mode === 'show' || useNetMode"
|
||||
:model-value="item.amountGross"
|
||||
@update:model-value="(val) => { item.amountGross = Number(val); recalculateItem(item, 'gross') }"
|
||||
>
|
||||
<template #trailing>€</template>
|
||||
</UInput>
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 md:col-span-3">
|
||||
<UFormGroup label="Steuerschlüssel">
|
||||
<USelectMenu
|
||||
v-model="item.taxType"
|
||||
@@ -431,7 +456,7 @@ const findIncomingInvoiceErrors = computed(() => {
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<div class="col-span-6 md:col-span-4">
|
||||
<div class="col-span-6 md:col-span-3">
|
||||
<UFormGroup label="Steuerbetrag" help="Automatisch berechnet">
|
||||
<UInput :model-value="item.amountTax" disabled color="gray" >
|
||||
<template #trailing>€</template>
|
||||
@@ -439,6 +464,27 @@ const findIncomingInvoiceErrors = computed(() => {
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<div class="col-span-12 flex justify-end gap-2">
|
||||
<UButton
|
||||
size="xs"
|
||||
variant="outline"
|
||||
icon="i-heroicons-calculator"
|
||||
:disabled="mode === 'show'"
|
||||
@click="recalculateItem(item, 'manual')"
|
||||
>
|
||||
Steuer berechnen
|
||||
</UButton>
|
||||
<UButton
|
||||
size="xs"
|
||||
variant="soft"
|
||||
icon="i-heroicons-arrow-right"
|
||||
:disabled="mode === 'show' || !hasAmount(item.amountGross)"
|
||||
@click="moveGrossToNet(item)"
|
||||
>
|
||||
Brutto als Netto
|
||||
</UButton>
|
||||
</div>
|
||||
|
||||
<div class="col-span-12">
|
||||
<UInput v-model="item.description" :disabled="mode === 'show'" placeholder="Positionstext (optional)" icon="i-heroicons-bars-3-bottom-left" variant="none" class="border-b border-gray-100 dark:border-gray-800" />
|
||||
</div>
|
||||
@@ -527,4 +573,4 @@ const findIncomingInvoiceErrors = computed(() => {
|
||||
.resize {
|
||||
resize: both;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -4,7 +4,6 @@ const profileStore = useProfileStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const url = useRequestURL()
|
||||
const supabase = useSupabaseClient()
|
||||
const toast = useToast()
|
||||
|
||||
const showAddBankRequisition = ref(false)
|
||||
@@ -49,36 +48,45 @@ const generateLink = async (bankId) => {
|
||||
}
|
||||
|
||||
const addAccount = async (account) => {
|
||||
let accountData = {
|
||||
accountId: account.id,
|
||||
ownerName: account.owner_name,
|
||||
iban: account.iban,
|
||||
tenant: profileStore.currentTenant,
|
||||
bankId: account.institution_id
|
||||
}
|
||||
let accountData = {
|
||||
accountId: account.id,
|
||||
ownerName: account.owner_name,
|
||||
iban: account.iban,
|
||||
tenant: profileStore.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"})
|
||||
try {
|
||||
// Nutzung von useEntities statt direktem DB-Call
|
||||
// true als 2. Parameter verhindert den Redirect, da wir im Modal sind
|
||||
const res = await useEntities("bankaccounts").create(accountData, true)
|
||||
|
||||
if(res) {
|
||||
// useEntities feuert bereits einen Success-Toast ("X hinzugefügt")
|
||||
// Wir laden die Seite neu, um die Buttons im Modal zu aktualisieren (Hinzufügen -> Aktualisieren)
|
||||
await setupPage()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.add({title: "Es gab einen Fehler beim Hinzufügen des Accounts", color:"rose"})
|
||||
}
|
||||
}
|
||||
|
||||
const updateAccount = async (account) => {
|
||||
|
||||
let bankaccountId = bankaccounts.value.find(i => i.iban === account.iban).id
|
||||
let bankaccountId = bankaccounts.value.find(i => i.iban === account.iban).id
|
||||
|
||||
const res = await useEntities("bankaccounts").update(bankaccountId, {accountId: account.id, expired: false})
|
||||
// Fehlerbehandlung analog zu addAccount verbessert
|
||||
try {
|
||||
const res = await useEntities("bankaccounts").update(bankaccountId, {accountId: account.id, expired: false}, true)
|
||||
|
||||
if(!res) {
|
||||
console.log(error)
|
||||
toast.add({title: "Es gab einen Fehler bei aktualisieren des Accounts", color:"rose"})
|
||||
} else {
|
||||
toast.add({title: "Account erfolgreich aktualisiert"})
|
||||
reqData.value = null
|
||||
setupPage()
|
||||
}
|
||||
// useEntities feuert bereits einen Success-Toast
|
||||
// reqData.value = null // Das würde das Modal leeren, ggf. gewünscht? Im Original war es drin.
|
||||
setupPage()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
toast.add({title: "Es gab einen Fehler beim Aktualisieren des Accounts", color:"rose"})
|
||||
}
|
||||
}
|
||||
|
||||
setupPage()
|
||||
@@ -88,23 +96,23 @@ setupPage()
|
||||
<UDashboardNavbar title="Bankkonten">
|
||||
<template #right>
|
||||
<UButton
|
||||
@click="showAddBankRequisition = true"
|
||||
@click="showAddBankRequisition = true"
|
||||
>
|
||||
+ Bankverbindung
|
||||
</UButton>
|
||||
<USlideover
|
||||
v-model="showAddBankRequisition"
|
||||
v-model="showAddBankRequisition"
|
||||
>
|
||||
<UCard
|
||||
class="h-full"
|
||||
class="h-full"
|
||||
>
|
||||
<template #header>
|
||||
<p>Bankverbindung hinzufügen</p>
|
||||
</template>
|
||||
|
||||
<UFormGroup
|
||||
label="BIC:"
|
||||
class="flex-auto"
|
||||
label="BIC:"
|
||||
class="flex-auto"
|
||||
>
|
||||
<InputGroup class="w-full">
|
||||
<UInput
|
||||
@@ -113,7 +121,7 @@ setupPage()
|
||||
@keydown.enter="checkBIC"
|
||||
/>
|
||||
<UButton
|
||||
@click="checkBIC"
|
||||
@click="checkBIC"
|
||||
>
|
||||
Check
|
||||
</UButton>
|
||||
@@ -121,21 +129,21 @@ setupPage()
|
||||
|
||||
</UFormGroup>
|
||||
<UAlert
|
||||
v-if="showAlert && bankData.id && bankData.countries.includes('DE')"
|
||||
title="Bank gefunden"
|
||||
icon="i-heroicons-check-circle"
|
||||
color="primary"
|
||||
variant="outline"
|
||||
class="mt-3"
|
||||
:actions="[{ variant: 'solid', color: 'primary', label: 'Verbinden',click: generateLink }]"
|
||||
v-if="showAlert && bankData.id && bankData.countries.includes('DE')"
|
||||
title="Bank gefunden"
|
||||
icon="i-heroicons-check-circle"
|
||||
color="primary"
|
||||
variant="outline"
|
||||
class="mt-3"
|
||||
:actions="[{ variant: 'solid', color: 'primary', label: 'Verbinden',click: generateLink }]"
|
||||
/>
|
||||
<UAlert
|
||||
v-else-if="showAlert && !bankData.id"
|
||||
title="Bank nicht gefunden"
|
||||
icon="i-heroicons-x-circle"
|
||||
color="rose"
|
||||
variant="outline"
|
||||
class="mt-3"
|
||||
v-else-if="showAlert && !bankData.id"
|
||||
title="Bank nicht gefunden"
|
||||
icon="i-heroicons-x-circle"
|
||||
color="rose"
|
||||
variant="outline"
|
||||
class="mt-3"
|
||||
/>
|
||||
|
||||
</UCard>
|
||||
@@ -150,6 +158,7 @@ setupPage()
|
||||
</template>
|
||||
<div
|
||||
v-for="account in reqData.accounts"
|
||||
:key="account.id"
|
||||
class="p-2 m-3 flex justify-between"
|
||||
>
|
||||
{{account.iban}} - {{account.owner_name}}
|
||||
@@ -170,16 +179,9 @@ setupPage()
|
||||
</UCard>
|
||||
</UModal>
|
||||
|
||||
|
||||
|
||||
<!-- <UButton @click="setupPage">Setup</UButton>
|
||||
<div v-if="route.query.reqId">
|
||||
{{reqData}}
|
||||
</div>-->
|
||||
|
||||
<UTable
|
||||
:rows="bankaccounts"
|
||||
:columns="[
|
||||
:rows="bankaccounts"
|
||||
:columns="[
|
||||
{
|
||||
key: 'expired',
|
||||
label: 'Aktiv'
|
||||
@@ -202,10 +204,10 @@ setupPage()
|
||||
<span v-if="row.expired" class="text-rose-600">Ausgelaufen</span>
|
||||
<span v-else class="text-primary">Aktiv</span>
|
||||
<UButton
|
||||
v-if="row.expired"
|
||||
variant="outline"
|
||||
class="ml-2"
|
||||
@click="generateLink(row.bankId)"
|
||||
v-if="row.expired"
|
||||
variant="outline"
|
||||
class="ml-2"
|
||||
@click="generateLink(row.bankId)"
|
||||
>Aktualisieren</UButton>
|
||||
</template>
|
||||
<template #balance-data="{row}">
|
||||
@@ -220,4 +222,4 @@ setupPage()
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user