charges add module add in the saving account and current account

This commit is contained in:
Nitesh Yadav
2026-05-18 10:11:41 +05:30
parent c74cbb7ef2
commit 6753ab1d56
23 changed files with 661 additions and 202 deletions
@@ -113,7 +113,7 @@
</ng-container>
<ng-container matColumnDef="balance">
<th mat-header-cell class="r-amount" *matHeaderCellDef>{{ 'labels.inputs.Balance' | translate }}</th>
<th mat-header-cell class="r-amount" *matHeaderCellDef>{{ 'labels.inputs.Balance' | translate }} ↑</th>
<td
mat-cell
class="r-amount"
@@ -124,7 +124,9 @@ export class TransactionsTabComponent implements OnInit {
*/
constructor() {
this.route.parent.parent.data.subscribe((data: { savingsAccountData: any }) => {
this.transactionsData = data.savingsAccountData.transactions;
this.transactionsData = this.recalculateRunningBalances(
this.sortAscending(data.savingsAccountData.transactions || [])
);
this.status = data.savingsAccountData.status.value;
this.currency = data.savingsAccountData.currency || null;
});
@@ -260,6 +262,32 @@ export class TransactionsTabComponent implements OnInit {
});
}
private recalculateRunningBalances(transactions: SavingsAccountTransaction[]): SavingsAccountTransaction[] {
let balance = 0;
return transactions.map((txn) => {
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 toTime = (d: any) =>
Array.isArray(d) && d.length >= 3 ? new Date(d[0], d[1] - 1, d[2]).getTime() : new Date(d).getTime();
const diff = toTime(a.date) - toTime(b.date);
if (diff !== 0) return diff;
return (a.id as number) - (b.id as number);
});
}
private reload() {
const clientId = this.route.parent.parent.snapshot.params['clientId'];
const url: string = this.router.url;