Files
cbsnexora/src/app/shares/shares-account-view/transactions-tab/transactions-tab.component.ts
T

101 lines
2.9 KiB
TypeScript

/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/** Angular Imports */
import { Component, OnInit, inject } from '@angular/core';
import {
MatTableDataSource,
MatTable,
MatColumnDef,
MatHeaderCellDef,
MatHeaderCell,
MatCellDef,
MatCell,
MatHeaderRowDef,
MatHeaderRow,
MatRowDef,
MatRow
} from '@angular/material/table';
import { ActivatedRoute } from '@angular/router';
import { DateFormatPipe } from '../../../pipes/date-format.pipe';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
import { isSettledShareTransaction } from 'app/shares/share-transactions.util';
/**
* Transactions Tab Component.
*/
@Component({
selector: 'mifosx-transactions-tab',
templateUrl: './transactions-tab.component.html',
styleUrls: ['./transactions-tab.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
MatTable,
MatColumnDef,
MatHeaderCellDef,
MatHeaderCell,
MatCellDef,
MatCell,
MatHeaderRowDef,
MatHeaderRow,
MatRowDef,
MatRow,
DateFormatPipe
]
})
export class TransactionsTabComponent implements OnInit {
private route = inject(ActivatedRoute);
/** Shares Account Data */
shareAccountData: any;
/** Transactions Data */
transactionsData: any;
/** Data source for transactions table. */
dataSource: MatTableDataSource<any>;
/** Columns to be displayed in transactions table — a share account's passbook: every
* purchase/redeem entry plus the running share balance and, for a withdrawal, the Board
* Resolution Number / Date of Meeting that authorised it. */
displayedColumns: string[] = [
'transactionDate',
'transactionType',
'totalShares',
'purchasedOrRedeemedPrice',
'chargeAmount',
'amountRecievedOrReturned',
'runningBalance',
'resolutionMeeting'
];
/**
* Retrieves shares account data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor() {
this.route.parent.data.subscribe((data: { sharesAccountData: any }) => {
this.shareAccountData = data.sharesAccountData;
this.transactionsData = this.shareAccountData.purchasedShares
.filter(isSettledShareTransaction)
.slice()
.sort((a: any, b: any) => new Date(a.purchasedDate).getTime() - new Date(b.purchasedDate).getTime());
let runningBalance = 0;
this.transactionsData.forEach((transaction: any) => {
const shares = Number(transaction.numberOfShares) || 0;
runningBalance += transaction.type.value === 'Redeem' ? -shares : shares;
transaction.runningBalance = runningBalance;
});
// Passbook reads newest-first.
this.transactionsData.reverse();
});
}
ngOnInit() {
this.dataSource = new MatTableDataSource(this.transactionsData);
}
}