Introduced useSum Composable

This commit is contained in:
2025-02-19 19:06:02 +01:00
parent ac6aa470af
commit 79c169ef2a
2 changed files with 25 additions and 1 deletions

21
composables/useSum.js Normal file
View File

@@ -0,0 +1,21 @@
export const useSum = () => {
const getIncomingInvoiceSum = (invoice) => {
let sum = 0
invoice.accounts.forEach(account => {
console.log(account)
sum += account.amountTax
sum += account.amountNet
})
return sum.toFixed(2)
}
return {getIncomingInvoiceSum}
}

View File

@@ -1,5 +1,6 @@
<script setup> <script setup>
import dayjs from "dayjs" import dayjs from "dayjs"
import {useSum} from "~/composables/useSum.js";
definePageMeta({ definePageMeta({
middleware: "auth" middleware: "auth"
}) })
@@ -38,6 +39,8 @@ defineShortcuts({
const dataStore = useDataStore() const dataStore = useDataStore()
const router = useRouter() const router = useRouter()
const sum = useSum()
const items = ref([]) const items = ref([])
const selectedItem = ref(0) const selectedItem = ref(0)
@@ -169,7 +172,7 @@ const isPaid = (item) => {
{{row.vendor ? row.vendor.name : ""}} {{row.vendor ? row.vendor.name : ""}}
</template> </template>
<template #amount-data="{row}"> <template #amount-data="{row}">
{{displayCurrency(getInvoiceSum(row))}} {{displayCurrency(sum.getIncomingInvoiceSum(row))}}
</template> </template>
<template #dueDate-data="{row}"> <template #dueDate-data="{row}">
{{dayjs(row.dueDate).format("DD.MM.YYYY")}} {{dayjs(row.dueDate).format("DD.MM.YYYY")}}