Fix customer balance calculation
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
William Buezas 2024-04-04 11:55:43 -03:00
parent 82f259be32
commit 1cff622898
1 changed files with 18 additions and 11 deletions

View File

@ -134,18 +134,26 @@ const getData = () => {
clientRisksRef.value?.fetch();
};
const onFetch = (data) => {
if (clientRisks.value?.length && data.length) {
data[0].balance = clientRisks.value[0]?.amount || 0;
const getCurrentBalance = () => {
const currentBalance = clientRisks.value.find((balance) => {
return balance.companyFk === companyId.value;
});
return currentBalance && currentBalance.amount;
};
data.reduce((prev, curr) => {
const netMovement = prev.debit - prev.credit;
curr.balance = prev.balance - netMovement;
return curr;
});
}
const onFetch = (balances) => {
balances.forEach((balance, index) => {
if (index === 0) {
balance.balance = getCurrentBalance();
} else {
let previousBalance = balances[index - 1];
balance.balance =
previousBalance.balance -
(previousBalance.debit - previousBalance.credit);
}
});
receiptsData.value = data;
receiptsData.value = balances;
};
const showNewPaymentDialog = () => {
@ -200,7 +208,6 @@ const sendEmailAction = () => {
<VnPaginate
auto-load
data-key="CustomerBalance"
order="id DESC"
url="Receipts/filter"
:user-params="userParams"
ref="receiptsRef"