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

@@ -105,24 +105,13 @@
<span :class="dayjs(row.dueDate).diff(dayjs()) <= 0 ? ['text-rose-500'] : '' ">{{row.dueDate ? dayjs(row.dueDate).format("DD.MM.YY") : ''}}</span>
</template>
<template #paid-data="{row}">
<!--
<span v-if="dataStore.bankstatements.find(x => x.assignments.find(y => y.type === 'createdDocument' && y.id === row.id))" class="text-primary-500">Bezahlt</span>
-->
<!--
<span v-else :class="dayjs(row.dueDate).diff(dayjs()) <= 0 ? ['text-rose-500'] : ['text-cyan-500'] ">Offen</span>
-->
<!-- {{dataStore.bankstatements.find(x => x.assignments.find(y => y.id === row.id)) ? true : false}}-->
<div v-if="row.type === 'invoices' ||row.type === 'advanceInvoices'">
<span v-if="isPaid(row)" class="text-primary-500">Bezahlt</span>
<span v-else class="text-rose-600">Offen</span>
</div>
</template>
<template #amount-data="{row}">
<div
class="text-right font-bold"
v-if="row.type === 'incomingInvoice'"
>
{{getRowAmount(row) === 0 ? '' : `${String(getRowAmount(row).toFixed(2)).replace('.',',')}`}}
</div>
<div v-else class="text-right">
{{calculateDocSum(row.rows)}}
</div>
{{displayCurrency(calculateDocSum(row))}}
</template>
</UTable>
@@ -173,8 +162,7 @@ const items = ref([])
const selectedItem = ref(0)
const setupPage = async () => {
items.value = await useSupabaseSelect("createddocuments","*, customer(id,name)")
console.log(items.value)
items.value = await useSupabaseSelect("createddocuments","*, customer(id,name), statementallocations(id,amount)","documentDate")
}
setupPage()
@@ -257,15 +245,8 @@ const selectItem = (item) => {
}
const getRowAmount = (row) => {
let amount = 0
row.accounts.forEach(account => {
amount += account.amountNet
amount += account.amountTax
})
return amount
const displayCurrency = (value, currency = "€") => {
return `${Number(value).toFixed(2).replace(".",",")} ${currency}`
}
@@ -285,17 +266,28 @@ const filteredRows = computed(() => {
})
const calculateDocSum = (rows) => {
const calculateDocSum = (row) => {
let sum = 0
rows.forEach(row => {
if(row.mode !== "pagebreak") {
sum += row.price * row.quantity * ( Number(row.taxPercent) + 100)/100
row.rows.forEach(row => {
if(row.mode === "normal" || row.mode === "service" || row.mode === "free") {
sum += row.quantity * row.price * (1 - row.discountPercent / 100) * (1 + row.taxPercent / 100)
}
})
return sum.toFixed(2)
}
const isPaid = (item) => {
let amountPaid = 0
item.statementallocations.forEach(allocation => amountPaid += allocation.amount)
console.log(item.documentNumber)
console.log(amountPaid)
console.log(calculateDocSum(item))
return Number(amountPaid.toFixed(2)) === Number(calculateDocSum(item))
}
</script>
<style scoped>