Incoming Invoice GPT Update

This commit is contained in:
2026-02-15 12:31:03 +01:00
parent 474b3e762c
commit be706a70f8
4 changed files with 252 additions and 78 deletions

View File

@@ -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>