Cahnges in Invoice allocation in statements

This commit is contained in:
2024-08-09 11:52:11 +02:00
parent baa06b60fb
commit 4ded159c49
3 changed files with 175 additions and 55 deletions

View File

@@ -1,6 +1,7 @@
<script setup>
import dayjs from "dayjs";
import {filter} from "vuedraggable/dist/vuedraggable.common.js";
definePageMeta({
middleware: "auth"
@@ -22,6 +23,8 @@ const itemInfo = ref({statementallocations:[]})
const oldItemInfo = ref({})
const openDocuments = ref([])
const allocatedDocuments = ref([])
const openIncomingInvoices = ref([])
const setup = async () => {
if(route.params.id) {
@@ -29,7 +32,14 @@ const setup = async () => {
}
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))
const documents = (await useSupabaseSelect("createddocuments","*, statementallocations(*), customer(id,name)")).filter(i => i.type === "invoices" ||i.type === "advanceInvoices")
openDocuments.value = documents.filter(i => i.statementallocations.length === 0 )
allocatedDocuments.value = documents.filter(i => i.statementallocations.find(x => x.bs_id === itemInfo.value.id))
openIncomingInvoices.value = (await useSupabaseSelect("incominginvoices","*, statementallocations(*)")).filter(i => i.statementallocations.length === 0 || i.statementallocations.find(x => x.bs_id === itemInfo.value.id))
console.log(openIncomingInvoices.value)
// return incominginvoices.value.filter(i => bankstatements.value.filter(x => x.assignments.find(y => y.type === 'incomingInvoice' && y.id === i.id)).length === 0)
let allocations = (await supabase.from("createddocuments").select(`*, statementallocations(*)`).eq("id",50)).data
@@ -80,6 +90,21 @@ const calculateOpenSum = computed(() => {
return startingAmount.toFixed(2)
})
const calculateAllocatedSum = computed(() => {
let startingAmount = 0
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
})
const saveAllocations = async () => {
let allocationsToBeSaved = itemInfo.value.statementallocations.filter(i => !i.id)
@@ -90,6 +115,32 @@ const saveAllocations = async () => {
}
const saveAllocation = async (allocation) => {
const {data,error} = await supabase.from("statementallocations").insert({
...allocation,
tenant: dataStore.currentTenant
}).select()
if(data) {
await setup()
}
}
const removeAllocation = async (allocationId) => {
const {data,error} = await supabase.from("statementallocations").delete().eq("id",allocationId)
await setup()
}
const searchString = ref("")
const filteredRows = computed(() => {
return useSearch(searchString.value, openDocuments.value)
})
setup()
@@ -179,9 +230,9 @@ setup()
</span>
<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 || 0).toFixed(2).replace(".",",")}} {{itemInfo.currency}}</span>
<span v-if="itemInfo.amount > 0" class="text-primary-500 font-semibold text-nowrap">{{displayCurrency(itemInfo.amount)}}</span>
<span v-else-if="itemInfo.amount < 0" class="text-rose-600 font-semibold text-nowrap">{{displayCurrency(itemInfo.amount)}}</span>
<span v-else>{{displayCurrency(itemInfo.amount)}}</span>
</div>
</template>
@@ -202,12 +253,13 @@ setup()
{{dayjs(itemInfo.valueDate).format("DD.MM.YYYY")}}
</td>
</tr>
<tr class="flex-row flex justify-between">
<tr class="flex-row flex justify-between text-right">
<td>
<span class="font-semibold">Partner:</span>
</td>
<td>
{{itemInfo.amount > 0 ? itemInfo.debName : itemInfo.credName}}
</td>
</tr>
<tr class="flex-row flex justify-between">
@@ -284,18 +336,19 @@ setup()
class="w-2/5 mx-auto"
v-if="itemInfo.amount > 0 "
>
<UDivider>
<span>Offene Summe: {{displayCurrency(calculateOpenSum)}}</span>
<UDivider v-if="allocatedDocuments.length > 0">
<span>Zugewiesene Summe: {{displayCurrency(calculateAllocatedSum)}}</span>
</UDivider>
<UCard
class="mt-5"
: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"
v-for="document in allocatedDocuments"
>
<template #header>
<div class="flex flex-row justify-between">
<span>{{dataStore.getCustomerById(document.customer).name}} - {{document.documentNumber}}</span>
<span class="font-semibold text-primary-500">{{displayCurrency(getDocumentSum(document))}}</span>
<span>{{document.customer ? document.customer.name : ""}} - {{document.documentNumber}}</span>
<span class="font-semibold text-primary-500 text-nowrap">{{displayCurrency(getDocumentSum(document))}}</span>
</div>
</template>
<UButton
@@ -303,7 +356,7 @@ setup()
variant="outline"
class="mr-3"
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))})"
@click="saveAllocation({cd_id: document.id, bs_id: itemInfo.id, amount: Number(getDocumentSum(document))})"
/>
<UButton
icon="i-heroicons-x-mark"
@@ -311,7 +364,56 @@ setup()
color="rose"
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)"
@click="removeAllocation(itemInfo.statementallocations.find(i => i.cd_id === document.id).id)"
/>
<UButton
variant="outline"
icon="i-heroicons-arrow-right-end-on-rectangle"
@click="router.push(`/createDocument/show/${document.id}`)"
/>
</UCard>
<UDivider class="mt-3">
<span>Offene Summe: {{displayCurrency(calculateOpenSum)}}</span>
</UDivider>
<UInput
id="searchinput"
v-model="searchString"
icon="i-heroicons-funnel"
autocomplete="off"
placeholder="Suche..."
class="hidden lg:block mt-3"
@keydown.esc="$event.target.blur()"
>
<template #trailing>
<UKbd value="/" />
</template>
</UInput>
<UCard
class="mt-5"
: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 filteredRows"
>
<template #header>
<div class="flex flex-row justify-between">
<span>{{document.customer ? document.customer.name : ""}} - {{document.documentNumber}}</span>
<span class="font-semibold text-primary-500 text-nowrap">{{displayCurrency(getDocumentSum(document))}}</span>
</div>
</template>
<UButton
icon="i-heroicons-check"
variant="outline"
class="mr-3"
v-if="!itemInfo.statementallocations.find(i => i.cd_id === document.id)"
@click="saveAllocation({cd_id: document.id, bs_id: itemInfo.id, amount: Number(getDocumentSum(document))})"
/>
<UButton
icon="i-heroicons-x-mark"
variant="outline"
color="rose"
class="mr-3"
v-if="itemInfo.statementallocations.find(i => i.cd_id === document.id)"
@click="removeAllocation(itemInfo.statementallocations.find(i => i.ii_id === document.id).id)"
/>
<UButton
@@ -331,34 +433,34 @@ setup()
</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()"
:ui="{ring: /*itemInfo.assignments.find(i => i.id === invoice.id)*/ false ? 'ring-primary-500' : 'ring-gray-200 dark:ring-gray-800'}"
v-for="item in openIncomingInvoices"
>
<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>
<span>{{dataStore.getVendorById(item.vendor).name}} - {{item.reference}}</span>
<span class="font-semibold text-rose-600 text-nowrap">-{{displayCurrency(getInvoiceSum(item))}}</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})"
v-if="!itemInfo.statementallocations.find(i => i.ii_id === item.id)"
@click="saveAllocation({ii_id: item.id, bs_id: itemInfo.id, amount: Number(getInvoiceSum(item))})"
/>
<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)"
v-if="itemInfo.statementallocations.find(i => i.ii_id === item.id)"
@click="removeAllocation(itemInfo.statementallocations.find(i => i.ii_id === item.id).id)"
/>
<UButton
variant="outline"
icon="i-heroicons-arrow-right-end-on-rectangle"
@click="router.push(`/incominginvoices/show/${invoice.id}`)"
@click="router.push(`/incominginvoices/show/${item.id}`)"
/>
</UCard>