charges add module add in the saving account and current account
This commit is contained in:
@@ -84,7 +84,7 @@ export class PassbookTabComponent implements OnInit, OnDestroy {
|
||||
this.accountBalance = account.summary?.accountBalance || 0;
|
||||
this.availableBalance = account.summary?.availableBalance || 0;
|
||||
this.activatedOnDate = account.timeline?.activatedOnDate || null;
|
||||
this.allTransactions = account.transactions || [];
|
||||
this.allTransactions = this.recalculateRunningBalances(this.sortAscending(account.transactions || []));
|
||||
this.filteredTransactions = [...this.allTransactions];
|
||||
});
|
||||
|
||||
@@ -179,6 +179,33 @@ export class PassbookTabComponent implements OnInit, OnDestroy {
|
||||
printWindow.close();
|
||||
}
|
||||
|
||||
private recalculateRunningBalances(transactions: SavingsAccountTransaction[]): SavingsAccountTransaction[] {
|
||||
let balance = 0;
|
||||
return transactions.map((txn) => {
|
||||
// Accruals and on-hold entries don't affect actual account balance
|
||||
const affectsBalance =
|
||||
!txn.transactionType.accrual && !txn.transactionType.amountHold && !txn.transactionType.amountRelease;
|
||||
|
||||
if (affectsBalance) {
|
||||
if (this.isDebit(txn.transactionType)) {
|
||||
balance -= txn.amount;
|
||||
} else {
|
||||
balance += txn.amount;
|
||||
}
|
||||
}
|
||||
return { ...txn, runningBalance: parseFloat(balance.toFixed(2)) };
|
||||
});
|
||||
}
|
||||
|
||||
private sortAscending(transactions: SavingsAccountTransaction[]): SavingsAccountTransaction[] {
|
||||
return [...transactions].sort((a, b) => {
|
||||
const dateA = this.getTransactionDateAsTime(a.date);
|
||||
const dateB = this.getTransactionDateAsTime(b.date);
|
||||
if (dateA !== dateB) return dateA - dateB;
|
||||
return (a.id as number) - (b.id as number);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.destroy$.next();
|
||||
this.destroy$.complete();
|
||||
|
||||
Reference in New Issue
Block a user