Introduced central Sum for Createddocuments
This commit is contained in:
@@ -44,14 +44,14 @@ const setup = async () => {
|
||||
|
||||
accounts.value = (await supabase.from("accounts").select()).data
|
||||
|
||||
openDocuments.value = documents.filter(i => i.statementallocations.reduce((n,{amount}) => n + amount, 0).toFixed(2) !== getDocumentSum(i).toFixed(2))
|
||||
openDocuments.value = documents.filter(i => i.statementallocations.reduce((n,{amount}) => n + amount, 0).toFixed(2) !== useSum().getCreatedDocumentSum(i).toFixed(2))
|
||||
openDocuments.value = openDocuments.value.map(i => {
|
||||
|
||||
return {
|
||||
...i,
|
||||
docTotal: getDocumentSum(i, i.usedAdvanceInvoices.map(i => getDocumentSum(documents.find(x => x.id === i)))),
|
||||
docTotal: useSum().getCreatedDocumentSum(i),
|
||||
statementTotal: Number(i.statementallocations.reduce((n,{amount}) => n + amount, 0)),
|
||||
openSum: (Number(getDocumentSum(i, i.usedAdvanceInvoices.map(i => getDocumentSum(documents.find(x => x.id === i))))) - Number(i.statementallocations.reduce((n,{amount}) => n + amount, 0))).toFixed(2)
|
||||
openSum: (useSum().getCreatedDocumentSum(i) - Number(i.statementallocations.reduce((n,{amount}) => n + amount, 0))).toFixed(2)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -82,33 +82,6 @@ const separateIBAN = (input = "") => {
|
||||
return separates.join(" ")
|
||||
}
|
||||
|
||||
const getDocumentSum = (doc,advanceInvoices = []) => {
|
||||
let sum = 0
|
||||
|
||||
//console.log(advanceInvoices)
|
||||
|
||||
doc.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)
|
||||
}
|
||||
})
|
||||
|
||||
//console.log(sum)
|
||||
|
||||
if(advanceInvoices.length > 0) {
|
||||
advanceInvoices.forEach(i => {
|
||||
console.log(i)
|
||||
sum -= i
|
||||
})
|
||||
}
|
||||
|
||||
//console.log(sum)
|
||||
|
||||
|
||||
|
||||
return Number(sum.toFixed(2))
|
||||
}
|
||||
|
||||
const getInvoiceSum = (invoice) => {
|
||||
let sum = 0
|
||||
invoice.accounts.forEach(account => {
|
||||
@@ -408,7 +381,7 @@ setup()
|
||||
<template #header>
|
||||
<div class="flex flex-row justify-between">
|
||||
<span>{{document.customer ? document.customer.name : ""}} - {{document.documentNumber}}</span>
|
||||
<span class="font-semibold text-nowrap">{{displayCurrency(getDocumentSum(document))}}</span>
|
||||
<span class="font-semibold text-nowrap">{{displayCurrency(useSum().getCreatedDocumentSum(document))}}</span>
|
||||
</div>
|
||||
</template>
|
||||
<UButton
|
||||
@@ -416,7 +389,7 @@ setup()
|
||||
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))})"
|
||||
@click="saveAllocation({cd_id: document.id, bs_id: itemInfo.id, amount: Number(useSum().getCreatedDocumentSum(document))})"
|
||||
/>
|
||||
<UButton
|
||||
icon="i-heroicons-x-mark"
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<template #amount-data="{row}">
|
||||
<span v-if="row.type !== 'deliveryNotes'">{{displayCurrency(calculateDocSum(row))}}</span>
|
||||
<span v-if="row.type !== 'deliveryNotes'">{{displayCurrency(useSum().getCreatedDocumentSum(row))}}</span>
|
||||
</template>
|
||||
</UTable>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user