diff --git a/src/pages/Customer/Card/CustomerBalance.vue b/src/pages/Customer/Card/CustomerBalance.vue index 54023c26b..f7d22a345 100644 --- a/src/pages/Customer/Card/CustomerBalance.vue +++ b/src/pages/Customer/Card/CustomerBalance.vue @@ -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 = () => {