88 lines
3.0 KiB
Vue
88 lines
3.0 KiB
Vue
<script setup>
|
|
|
|
let unpaidInvoicesSum = ref(0)
|
|
let unpaidInvoicesCount = ref(0)
|
|
let draftInvoicesSum = ref(0)
|
|
let draftInvoicesCount = ref(0)
|
|
let unallocatedStatements = ref(0)
|
|
const setupPage = async () => {
|
|
let documents = (await useSupabaseSelect("createddocuments","*, statementallocations(*), customer(id,name)")).filter(i => i.type === "invoices" ||i.type === "advanceInvoices"||i.type === "cancellationInvoices").filter(i => !i.archived)
|
|
|
|
let draftDocuments = documents.filter(i => i.state === "Entwurf")
|
|
let finalizedDocuments = documents.filter(i => i.state === "Gebucht")
|
|
|
|
|
|
|
|
finalizedDocuments = finalizedDocuments.filter(i => i.statementallocations.reduce((n,{amount}) => n + amount, 0).toFixed(2) !== useSum().getCreatedDocumentSum(i, documents).toFixed(2))
|
|
|
|
finalizedDocuments.forEach(i => {
|
|
unpaidInvoicesSum.value += useSum().getCreatedDocumentSum(i, documents) - i.statementallocations.reduce((n,{amount}) => n + amount, 0)
|
|
})
|
|
unpaidInvoicesCount.value = finalizedDocuments.length
|
|
|
|
draftDocuments.forEach(i => {
|
|
draftInvoicesSum.value += useSum().getCreatedDocumentSum(i, documents) - i.statementallocations.reduce((n,{amount}) => n + amount, 0)
|
|
})
|
|
draftInvoicesCount.value = draftDocuments.length
|
|
|
|
let bankstatements = (await useSupabaseSelect("bankstatements","*, statementallocations(*)","date",true)).filter(i => !i.archived)
|
|
unallocatedStatements.value = bankstatements.filter(i => Number(calculateOpenSum(i)) !== 0).length
|
|
}
|
|
|
|
setupPage()
|
|
|
|
const calculateOpenSum = (statement) => {
|
|
/*let startingAmount = statement.amount || 0
|
|
|
|
statement.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)*/
|
|
|
|
let startingAmount = 0
|
|
|
|
statement.statementallocations.forEach(item => {
|
|
startingAmount += Math.abs(item.amount)
|
|
})
|
|
|
|
return (Math.abs(statement.amount) - startingAmount).toFixed(2)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<table>
|
|
<tr>
|
|
<td>Offene Rechnungen:</td>
|
|
<td
|
|
v-if="unpaidInvoicesSum > 0"
|
|
class="text-rose-600 font-bold text-nowrap"
|
|
>{{unpaidInvoicesCount}} Stk / {{useCurrency(unpaidInvoicesSum)}}</td>
|
|
<td v-else class="text-primary-500 font-bold text-no-wrap">0 Stk / 0,00€</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Angelegte Rechnungsentwürfe:</td>
|
|
<td
|
|
v-if="draftInvoicesSum > 0"
|
|
class="text-rose-600 font-bold text-nowrap"
|
|
>{{draftInvoicesCount}} Stk / {{useCurrency(draftInvoicesSum)}}</td>
|
|
<td v-else class="text-primary-500 font-bold text-no-wrap">0 Stk / 0,00€</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Nicht zugewiesene Bankbuchungen:</td>
|
|
<td>
|
|
<span v-if="unallocatedStatements > 0" class="text-rose-600 font-bold">{{unallocatedStatements}}</span>
|
|
<span v-else class="text-primary-500 font-bold">0</span>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</template>
|
|
|
|
<style scoped>
|
|
|
|
</style> |