forked from verdnatura/salix-front
Fix customer balance calculation
This commit is contained in:
parent
82f259be32
commit
1cff622898
|
@ -134,18 +134,26 @@ const getData = () => {
|
||||||
clientRisksRef.value?.fetch();
|
clientRisksRef.value?.fetch();
|
||||||
};
|
};
|
||||||
|
|
||||||
const onFetch = (data) => {
|
const getCurrentBalance = () => {
|
||||||
if (clientRisks.value?.length && data.length) {
|
const currentBalance = clientRisks.value.find((balance) => {
|
||||||
data[0].balance = clientRisks.value[0]?.amount || 0;
|
return balance.companyFk === companyId.value;
|
||||||
|
});
|
||||||
|
return currentBalance && currentBalance.amount;
|
||||||
|
};
|
||||||
|
|
||||||
data.reduce((prev, curr) => {
|
const onFetch = (balances) => {
|
||||||
const netMovement = prev.debit - prev.credit;
|
balances.forEach((balance, index) => {
|
||||||
curr.balance = prev.balance - netMovement;
|
if (index === 0) {
|
||||||
return curr;
|
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 = () => {
|
const showNewPaymentDialog = () => {
|
||||||
|
@ -200,7 +208,6 @@ const sendEmailAction = () => {
|
||||||
<VnPaginate
|
<VnPaginate
|
||||||
auto-load
|
auto-load
|
||||||
data-key="CustomerBalance"
|
data-key="CustomerBalance"
|
||||||
order="id DESC"
|
|
||||||
url="Receipts/filter"
|
url="Receipts/filter"
|
||||||
:user-params="userParams"
|
:user-params="userParams"
|
||||||
ref="receiptsRef"
|
ref="receiptsRef"
|
||||||
|
|
Loading…
Reference in New Issue