Introduced central Sum for Createddocuments
This commit is contained in:
@@ -16,6 +16,111 @@ export const useSum = () => {
|
||||
return sum.toFixed(2)
|
||||
}
|
||||
|
||||
return {getIncomingInvoiceSum}
|
||||
const getCreatedDocumentSum = (createddocument) => {
|
||||
let totalNet = 0
|
||||
let total19 = 0
|
||||
let total7 = 0
|
||||
|
||||
createddocument.rows.forEach(row => {
|
||||
if(!['pagebreak','title','text'].includes(row.mode)){
|
||||
let rowPrice = Number(Number(row.quantity) * Number(row.price) * (1 - Number(row.discountPercent) /100) ).toFixed(3)
|
||||
totalNet = totalNet + Number(rowPrice)
|
||||
|
||||
if(row.taxPercent === 19) {
|
||||
total19 = total19 + Number(rowPrice * 0.19)
|
||||
} else if(row.taxPercent === 7) {
|
||||
total7 = total7 + Number(rowPrice * 0.07)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
let totalGross = Number(totalNet.toFixed(2)) + Number(total19.toFixed(2)) + Number(total7.toFixed(2))
|
||||
|
||||
let totalGrossAlreadyPaid = 0
|
||||
|
||||
createddocument.usedAdvanceInvoices.forEach(advanceInvoiceId => {
|
||||
let advanceInvoice = createddocuments.value.find(i => i.id === advanceInvoiceId)
|
||||
|
||||
let priceNet = advanceInvoice.rows.find(i => i.advanceInvoiceData).price
|
||||
|
||||
let partSum = priceNet * ((100 + advanceInvoice.rows.find(i => i.advanceInvoiceData).taxPercent) / 100)
|
||||
|
||||
totalGrossAlreadyPaid += partSum
|
||||
})
|
||||
|
||||
|
||||
let sumToPay = totalGross - totalGrossAlreadyPaid
|
||||
|
||||
return sumToPay
|
||||
}
|
||||
|
||||
const getCreatedDocumentSumDetailed = (createddocument) => {
|
||||
let totalNet = 0
|
||||
let total19 = 0
|
||||
let total7 = 0
|
||||
|
||||
createddocument.rows.forEach(row => {
|
||||
if(!['pagebreak','title','text'].includes(row.mode)){
|
||||
let rowPrice = Number(Number(row.quantity) * Number(row.price) * (1 - Number(row.discountPercent) /100) ).toFixed(3)
|
||||
totalNet = totalNet + Number(rowPrice)
|
||||
|
||||
if(row.taxPercent === 19) {
|
||||
total19 = total19 + Number(rowPrice * 0.19)
|
||||
} else if(row.taxPercent === 7) {
|
||||
total7 = total7 + Number(rowPrice * 0.07)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
//Title Sum
|
||||
|
||||
let titleSums = {}
|
||||
let lastTitle = ""
|
||||
|
||||
createddocument.rows.forEach(row => {
|
||||
if(row.mode === 'title'){
|
||||
titleSums[`${row.pos} - ${row.text}`] = 0
|
||||
lastTitle = `${row.pos} - ${row.text}`
|
||||
} else if(!['pagebreak','text'].includes(row.mode) && lastTitle !== ""){
|
||||
titleSums[lastTitle] = Number(titleSums[lastTitle]) + Number(Number(row.quantity) * Number(row.price) * (1 - Number(row.discountPercent) /100) )
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
let totalGross = Number(totalNet.toFixed(2)) + Number(total19.toFixed(2)) + Number(total7.toFixed(2))
|
||||
|
||||
let totalGrossAlreadyPaid = 0
|
||||
|
||||
createddocument.usedAdvanceInvoices.forEach(advanceInvoiceId => {
|
||||
let advanceInvoice = createddocuments.value.find(i => i.id === advanceInvoiceId)
|
||||
|
||||
let priceNet = advanceInvoice.rows.find(i => i.advanceInvoiceData).price
|
||||
|
||||
let partSum = priceNet * ((100 + advanceInvoice.rows.find(i => i.advanceInvoiceData).taxPercent) / 100)
|
||||
|
||||
totalGrossAlreadyPaid += partSum
|
||||
})
|
||||
|
||||
console.log(totalGrossAlreadyPaid)
|
||||
|
||||
let sumToPay = totalGross - totalGrossAlreadyPaid
|
||||
|
||||
return {
|
||||
titleSums: titleSums,
|
||||
totalNet: totalNet,
|
||||
total19: total19,
|
||||
total7: total7,
|
||||
totalGross: totalGross,
|
||||
totalGrossAlreadyPaid: totalGrossAlreadyPaid,
|
||||
totalSumToPay: sumToPay
|
||||
}
|
||||
}
|
||||
|
||||
return {getIncomingInvoiceSum, getCreatedDocumentSum, getCreatedDocumentSumDetailed}
|
||||
|
||||
}
|
||||
@@ -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