Changes
This commit is contained in:
@@ -16,16 +16,26 @@ const dataStore = useDataStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const mode = ref(route.params.mode || "show")
|
||||
const supabase = useSupabaseClient()
|
||||
|
||||
const itemInfo = ref({})
|
||||
const itemInfo = ref({statementallocations:[]})
|
||||
const oldItemInfo = ref({})
|
||||
|
||||
const setup = () => {
|
||||
const openDocuments = ref([])
|
||||
|
||||
const setup = async () => {
|
||||
if(route.params.id) {
|
||||
itemInfo.value = dataStore.bankstatements.find(i => i.id === Number(route.params.id))
|
||||
itemInfo.value = (await supabase.from("bankstatements").select("*, statementallocations(*)").eq("id",route.params.id).single()).data //dataStore.bankstatements.find(i => i.id === Number(route.params.id))
|
||||
}
|
||||
if(itemInfo.value) oldItemInfo.value = JSON.parse(JSON.stringify(itemInfo.value))
|
||||
|
||||
openDocuments.value = (await supabase.from("createddocuments").select("*, statementallocations(*)")).data.filter(i => i.statementallocations.length === 0 || i.statementallocations.find(x => x.bs_id === itemInfo.value.id))
|
||||
|
||||
|
||||
let allocations = (await supabase.from("createddocuments").select(`*, statementallocations(*)`).eq("id",50)).data
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const displayCurrency = (value, currency = "€") => {
|
||||
@@ -57,18 +67,29 @@ const getInvoiceSum = (invoice) => {
|
||||
}
|
||||
|
||||
const calculateOpenSum = computed(() => {
|
||||
let startingAmount = itemInfo.value.amount
|
||||
let startingAmount = itemInfo.value.amount || 0
|
||||
|
||||
itemInfo.value.assignments.forEach(item => {
|
||||
if(item.type === "createdDocument") {
|
||||
let doc = dataStore.getCreatedDocumentById(item.id)
|
||||
startingAmount = startingAmount - getDocumentSum(doc)
|
||||
itemInfo.value.statementallocations.forEach(item => {
|
||||
if(item.cd_id) {
|
||||
startingAmount = startingAmount - item.amount
|
||||
} else if(item.ii_id) {
|
||||
startingAmount = Number(startingAmount) + item.amount
|
||||
}
|
||||
})
|
||||
|
||||
return startingAmount.toFixed(2)
|
||||
})
|
||||
|
||||
const saveAllocations = async () => {
|
||||
let allocationsToBeSaved = itemInfo.value.statementallocations.filter(i => !i.id)
|
||||
|
||||
for await (let i of allocationsToBeSaved) {
|
||||
await dataStore.createNewItem("statementallocations", i)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
setup()
|
||||
|
||||
@@ -89,13 +110,13 @@ setup()
|
||||
</template>
|
||||
<template #center>
|
||||
<h1
|
||||
:class="['text-xl','font-medium', ... itemInfo.incomingInvoice || itemInfo.createdDocument ? ['text-primary-500'] : ['text-rose-600']]"
|
||||
:class="['text-xl','font-medium', Number(calculateOpenSum) === 0 ? ['text-primary-500'] : ['text-rose-600']]"
|
||||
>Kontobewegung bearbeiten</h1>
|
||||
</template>
|
||||
<template #right>
|
||||
<UButton
|
||||
v-if="mode === 'edit'"
|
||||
@click="dataStore.updateItem('bankstatements',itemInfo,oldItemInfo)"
|
||||
@click="saveAllocations"
|
||||
>
|
||||
Speichern
|
||||
</UButton>
|
||||
@@ -160,11 +181,11 @@ setup()
|
||||
|
||||
<span v-if="itemInfo.amount > 0" class="text-primary-500 font-semibold">{{itemInfo.amount.toFixed(2).replace(".",",")}} {{itemInfo.currency}}</span>
|
||||
<span v-else-if="itemInfo.amount < 0" class="text-rose-600 font-semibold">{{itemInfo.amount.toFixed(2).replace(".",",")}} {{itemInfo.currency}}</span>
|
||||
<span v-else>{{itemInfo.amount.toFixed(2).replace(".",",")}} {{itemInfo.currency}}</span>
|
||||
<span v-else>{{(itemInfo.amount || 0).toFixed(2).replace(".",",")}} {{itemInfo.currency}}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<table class="w-full">
|
||||
<table class="w-full" v-if="itemInfo.id">
|
||||
<tr class="flex-row flex justify-between">
|
||||
<td>
|
||||
<span class="font-semibold">Buchungsdatum:</span>
|
||||
@@ -207,26 +228,36 @@ setup()
|
||||
</tr>
|
||||
<tr class="flex-row flex justify-between">
|
||||
<td colspan="2">
|
||||
<span class="font-semibold">Verknüpftes Dokument:</span>
|
||||
<span class="font-semibold">Verknüpfte Dokumente:</span>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<tr
|
||||
class="flex-row flex justify-between mb-3"
|
||||
v-for="item in itemInfo.assignments"
|
||||
v-for="item in itemInfo.statementallocations"
|
||||
>
|
||||
|
||||
<td>
|
||||
<!-- <span v-if="itemInfo.createdDocument"><nuxt-link :to="`/createDocument/show/${itemInfo.createdDocument}`">{{dataStore.createddocuments.find(i => i.id === itemInfo.createdDocument).documentNumber}}</nuxt-link></span>
|
||||
<span v-else-if="itemInfo.incomingInvoice"><nuxt-link :to="`/incominInvoices/show/${itemInfo.incomingInvoice}`">{{dataStore.getIncomingInvoiceById(itemInfo.incomingInvoice).reference}}</nuxt-link></span>-->
|
||||
<span v-if="item.type === 'createdDocument'">
|
||||
{{dataStore.getCreatedDocumentById(item.id).documentNumber}}
|
||||
<span v-if="item.cd_id">
|
||||
{{dataStore.getCreatedDocumentById(item.cd_id).documentNumber}}
|
||||
</span>
|
||||
<span v-else-if="item.ii_id">
|
||||
{{dataStore.getVendorById(dataStore.getIncomingInvoiceById(item.ii_id).vendor).name}} - {{dataStore.getIncomingInvoiceById(item.ii_id).reference}}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<UButton
|
||||
variant="outline"
|
||||
icon="i-heroicons-arrow-right-end-on-rectangle"
|
||||
@click="router.push(`/createDocument/show/${item.id}`)"
|
||||
@click="router.push(`/createDocument/show/${item.cd_id}`)"
|
||||
v-if="item.cd_id"
|
||||
/>
|
||||
<UButton
|
||||
variant="outline"
|
||||
icon="i-heroicons-arrow-right-end-on-rectangle"
|
||||
@click="router.push(`/incominginvoices/show/${item.ii_id}`)"
|
||||
v-else-if="item.ii_id"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -253,15 +284,13 @@ setup()
|
||||
class="w-2/5 mx-auto"
|
||||
v-if="itemInfo.amount > 0 "
|
||||
>
|
||||
<UDivider
|
||||
label="Test"
|
||||
>
|
||||
<UDivider>
|
||||
<span>Offene Summe: {{displayCurrency(calculateOpenSum)}}</span>
|
||||
</UDivider>
|
||||
<UCard
|
||||
class="mt-5"
|
||||
:ui="{ring: itemInfo.assignments.find(i => i.id === document.id) ? 'ring-primary-500' : 'ring-gray-200 dark:ring-gray-800'}"
|
||||
v-for="document in dataStore.getOpenDocuments()"
|
||||
:ui="{ring: itemInfo.statementallocations.find(i => i.cd_id === document.id) ? 'ring-primary-500' : 'ring-gray-200 dark:ring-gray-800'}"
|
||||
v-for="document in openDocuments"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex flex-row justify-between">
|
||||
@@ -273,57 +302,68 @@ setup()
|
||||
icon="i-heroicons-check"
|
||||
variant="outline"
|
||||
class="mr-3"
|
||||
v-if="!itemInfo.assignments.find(i => i.id === document.id)"
|
||||
@click="itemInfo.assignments.push({type: 'createdDocument',id: document.id})"
|
||||
v-if="!itemInfo.statementallocations.find(i => i.cd_id === document.id)"
|
||||
@click="itemInfo.statementallocations.push({cd_id: document.id, bs_id: itemInfo.id, amount: Number(getDocumentSum(document))})"
|
||||
/>
|
||||
<UButton
|
||||
icon="i-heroicons-x-mark"
|
||||
variant="outline"
|
||||
color="rose"
|
||||
v-if="itemInfo.assignments.find(i => i.id === document.id)"
|
||||
@click="itemInfo.assignments = itemInfo.assignments.filter(i => i.id !== document.id)"
|
||||
class="mr-3"
|
||||
v-if="itemInfo.statementallocations.find(i => i.cd_id === document.id)"
|
||||
@click="itemInfo.statementallocations = itemInfo.statementallocations.filter(i => i.cd_id !== document.id)"
|
||||
/>
|
||||
|
||||
<UButton
|
||||
variant="outline"
|
||||
icon="i-heroicons-arrow-right-end-on-rectangle"
|
||||
@click="router.push(`/createDocument/show/${document.id}`)"
|
||||
/>
|
||||
</UCard>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<UCard
|
||||
class="w-4/5 mx-auto mt-5"
|
||||
v-else-if="itemInfo.amount < 0 && !itemInfo.incomingInvoice"
|
||||
v-for="invoice in dataStore.getOpenIncomingInvoices()"
|
||||
<div
|
||||
class="w-2/5 mx-auto"
|
||||
v-if="itemInfo.amount < 0 "
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex flex-row justify-between">
|
||||
<span>{{dataStore.getVendorById(invoice.vendor).name}} - {{invoice.reference}}</span>
|
||||
<span class="font-semibold text-rose-600">-{{displayCurrency(getInvoiceSum(invoice))}}</span>
|
||||
</div>
|
||||
</template>
|
||||
<table class="w-full">
|
||||
<tr class="flex flex-row justify-between">
|
||||
<td><span class="font-semibold">Belegdatum:</span></td>
|
||||
<td>{{dayjs(invoice.date).format("DD.MM.YYYY")}}</td>
|
||||
</tr>
|
||||
<tr class="flex flex-row justify-between">
|
||||
<td><span class="font-semibold">Fälligkeitsdatum:</span></td>
|
||||
<td>{{dayjs(invoice.dueDate).format("DD.MM.YYYY")}}</td>
|
||||
</tr>
|
||||
<tr class="flex flex-row justify-between">
|
||||
<td colspan="2"><span class="font-semibold">Beschreibung:</span></td>
|
||||
</tr>
|
||||
<tr class="flex flex-row justify-between">
|
||||
<td colspan="2">{{invoice.description}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</UCard>
|
||||
<UDivider>
|
||||
<span>Offene Summe: {{displayCurrency(calculateOpenSum)}}</span>
|
||||
</UDivider>
|
||||
<UCard
|
||||
class="mt-5"
|
||||
:ui="{ring: itemInfo.assignments.find(i => i.id === invoice.id) ? 'ring-primary-500' : 'ring-gray-200 dark:ring-gray-800'}"
|
||||
v-for="invoice in dataStore.getOpenIncomingInvoices()"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex flex-row justify-between">
|
||||
<span>{{dataStore.getVendorById(invoice.vendor).name}} - {{invoice.reference}}</span>
|
||||
<span class="font-semibold text-rose-600">-{{displayCurrency(getInvoiceSum(invoice))}}</span>
|
||||
</div>
|
||||
</template>
|
||||
<UButton
|
||||
icon="i-heroicons-check"
|
||||
variant="outline"
|
||||
class="mr-3"
|
||||
v-if="!itemInfo.assignments.find(i => i.id === invoice.id)"
|
||||
@click="itemInfo.assignments.push({type: 'incomingInvoice',id: invoice.id})"
|
||||
/>
|
||||
<UButton
|
||||
icon="i-heroicons-x-mark"
|
||||
variant="outline"
|
||||
color="rose"
|
||||
class="mr-3"
|
||||
v-if="itemInfo.assignments.find(i => i.id === invoice.id)"
|
||||
@click="itemInfo.assignments = itemInfo.assignments.filter(i => i.id !== invoice.id)"
|
||||
/>
|
||||
<UButton
|
||||
variant="outline"
|
||||
icon="i-heroicons-arrow-right-end-on-rectangle"
|
||||
@click="router.push(`/incominginvoices/show/${invoice.id}`)"
|
||||
/>
|
||||
|
||||
</UCard>
|
||||
</div>
|
||||
</UDashboardPanelContent>
|
||||
|
||||
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user