191 lines
5.6 KiB
TypeScript
191 lines
5.6 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, ViewChild, inject } from '@angular/core';
|
|
import { UntypedFormControl, ReactiveFormsModule } from '@angular/forms';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { MatSort } from '@angular/material/sort';
|
|
import {
|
|
MatTableDataSource,
|
|
MatTable,
|
|
MatColumnDef,
|
|
MatHeaderCellDef,
|
|
MatHeaderCell,
|
|
MatCellDef,
|
|
MatCell,
|
|
MatHeaderRowDef,
|
|
MatHeaderRow,
|
|
MatRowDef,
|
|
MatRow
|
|
} from '@angular/material/table';
|
|
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
|
|
import { SavingsAccountTransaction } from 'app/savings/models/savings-account-transaction.model';
|
|
import { NgClass } from '@angular/common';
|
|
import { MatCheckbox } from '@angular/material/checkbox';
|
|
import { MatIconButton } from '@angular/material/button';
|
|
import { MatMenuTrigger, MatMenu, MatMenuItem } from '@angular/material/menu';
|
|
import { MatIcon } from '@angular/material/icon';
|
|
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
|
import { DateFormatPipe } from '../../../../pipes/date-format.pipe';
|
|
import { FormatNumberPipe } from '../../../../pipes/format-number.pipe';
|
|
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
|
|
|
/**
|
|
* Transactions Tab Component.
|
|
*/
|
|
@Component({
|
|
selector: 'mifosx-transactions-tab',
|
|
templateUrl: './transactions-tab.component.html',
|
|
styleUrls: ['./transactions-tab.component.scss'],
|
|
imports: [
|
|
...STANDALONE_SHARED_IMPORTS,
|
|
MatCheckbox,
|
|
MatTable,
|
|
MatColumnDef,
|
|
MatHeaderCellDef,
|
|
MatHeaderCell,
|
|
MatCellDef,
|
|
MatCell,
|
|
NgClass,
|
|
MatIconButton,
|
|
MatMenuTrigger,
|
|
MatIcon,
|
|
MatMenu,
|
|
MatMenuItem,
|
|
FaIconComponent,
|
|
MatHeaderRowDef,
|
|
MatHeaderRow,
|
|
MatRowDef,
|
|
MatRow,
|
|
DateFormatPipe,
|
|
FormatNumberPipe
|
|
]
|
|
})
|
|
export class TransactionsTabComponent implements OnInit {
|
|
private route = inject(ActivatedRoute);
|
|
private router = inject(Router);
|
|
|
|
/** Recurring Deposits Account Status */
|
|
status: any;
|
|
/** Transactions Data */
|
|
transactionsData: any;
|
|
/** Form control to handle accural parameter */
|
|
hideAccrualsParam: UntypedFormControl;
|
|
hideReversedParam: UntypedFormControl;
|
|
/** Columns to be displayed in transactions table. */
|
|
displayedColumns: string[] = [
|
|
'row',
|
|
'id',
|
|
'transactionDate',
|
|
'transactionType',
|
|
'debit',
|
|
'credit',
|
|
'balance',
|
|
'actions'
|
|
];
|
|
/** Data source for transactions table. */
|
|
dataSource: MatTableDataSource<any>;
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
|
|
/**
|
|
* Retrieves recurring deposits account data from `resolve`.
|
|
* @param {ActivatedRoute} route Activated Route.
|
|
*/
|
|
constructor() {
|
|
this.route.parent.data.subscribe((data: { recurringDepositsAccountData: any }) => {
|
|
this.transactionsData = data.recurringDepositsAccountData.transactions;
|
|
this.status = data.recurringDepositsAccountData.status.value;
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.dataSource = new MatTableDataSource(this.transactionsData);
|
|
this.hideAccrualsParam = new UntypedFormControl(false);
|
|
this.hideReversedParam = new UntypedFormControl(false);
|
|
}
|
|
|
|
/**
|
|
* Checks if transaction is debit.
|
|
* @param {any} transactionType Transaction Type
|
|
*/
|
|
isDebit(transactionType: any) {
|
|
return (
|
|
transactionType.withdrawal === true ||
|
|
transactionType.feeDeduction === true ||
|
|
transactionType.overdraftInterest === true ||
|
|
transactionType.withholdTax === true
|
|
);
|
|
}
|
|
|
|
hideAccruals() {
|
|
this.filterTransactions(this.hideReversedParam.value, !this.hideAccrualsParam.value);
|
|
}
|
|
|
|
hideReversed() {
|
|
this.filterTransactions(!this.hideReversedParam.value, this.hideAccrualsParam.value);
|
|
}
|
|
|
|
filterTransactions(hideReversed: boolean, hideAccrual: boolean): void {
|
|
let transactions: SavingsAccountTransaction[] = this.transactionsData;
|
|
|
|
if (hideAccrual || hideReversed) {
|
|
transactions = this.transactionsData.filter((t: SavingsAccountTransaction) => {
|
|
return !(hideReversed && t.reversed) && !(hideAccrual && t.transactionType.accrual);
|
|
});
|
|
}
|
|
this.dataSource = new MatTableDataSource(transactions);
|
|
this.dataSource.paginator = this.paginator;
|
|
this.dataSource.sort = this.sort;
|
|
}
|
|
|
|
savingsTransactionColor(transaction: SavingsAccountTransaction): string {
|
|
if (transaction.reversed) {
|
|
return 'strike';
|
|
} else if (transaction.transfer) {
|
|
return 'transfer';
|
|
} else if (transaction.transactionType.accrual) {
|
|
return 'accrual';
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Checks transaction status.
|
|
*/
|
|
checkStatus() {
|
|
if (
|
|
this.status === 'Active' ||
|
|
this.status === 'Closed' ||
|
|
this.status === 'Transfer in progress' ||
|
|
this.status === 'Transfer on hold' ||
|
|
this.status === 'Premature Closed' ||
|
|
this.status === 'Matured'
|
|
) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Show Transactions Details
|
|
* @param transactionsData Transactions Data
|
|
*/
|
|
showTransactions(transactionsData: SavingsAccountTransaction) {
|
|
if (transactionsData.transfer) {
|
|
this.router.navigate([`../transfer-funds/account-transfers/${transactionsData.transfer.id}`], {
|
|
relativeTo: this.route
|
|
});
|
|
} else {
|
|
this.router.navigate([transactionsData.id], { relativeTo: this.route });
|
|
}
|
|
}
|
|
}
|