Support for Charge-off and Undo charge-off to Loan account (#1748)
Co-authored-by: Jose Alberto Hernandez <alberto@blue-daemon.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
d294885f00
commit
b2aa39cb67
@@ -4,6 +4,11 @@ import { FormControl } from '@angular/forms';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { LoansService } from 'app/loans/loans.service';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-transactions-tab',
|
||||
@@ -32,7 +37,11 @@ export class TransactionsTabComponent implements OnInit {
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
private dateUtils: Dates,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private loansService: LoansService,
|
||||
private settingsService: SettingsService) {
|
||||
this.route.parent.parent.data.subscribe((data: { loanDetailsData: any }) => {
|
||||
this.transactions = data.loanDetailsData.transactions;
|
||||
this.tempTransaction = data.loanDetailsData.transactions;
|
||||
@@ -42,6 +51,14 @@ export class TransactionsTabComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.hideAccrualsParam = new FormControl(false);
|
||||
this.setLoanTransactions(this.transactions);
|
||||
}
|
||||
|
||||
setLoanTransactions(transactions: any) {
|
||||
this.transactions = transactions;
|
||||
this.transactions.forEach((element: any) => {
|
||||
element.date = this.dateUtils.parseDate(element.date);
|
||||
});
|
||||
this.dataSource = new MatTableDataSource(this.transactions);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
@@ -99,16 +116,26 @@ export class TransactionsTabComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
loanTransactionColor(loanTransaction: any): string {
|
||||
if (loanTransaction.manuallyReversed) {
|
||||
allowUndoTransaction(transaction: any) {
|
||||
if (transaction.manuallyReversed) {
|
||||
return false;
|
||||
}
|
||||
return ([27].includes(transaction.type.id));
|
||||
}
|
||||
|
||||
loanTransactionColor(transaction: any): string {
|
||||
if (transaction.manuallyReversed) {
|
||||
return 'strike';
|
||||
}
|
||||
if (loanTransaction.transactionRelations && loanTransaction.transactionRelations.length > 0) {
|
||||
if (transaction.transactionRelations && transaction.transactionRelations.length > 0) {
|
||||
return 'linked';
|
||||
}
|
||||
if (this.isAccrual(loanTransaction.type)) {
|
||||
if (this.isAccrual(transaction.type)) {
|
||||
return 'accrual';
|
||||
}
|
||||
if (this.isChargeOff(transaction.type)) {
|
||||
return 'chargeoff';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -120,8 +147,59 @@ export class TransactionsTabComponent implements OnInit {
|
||||
$event.stopPropagation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the propagation to view pages.
|
||||
* @param $event Mouse Event
|
||||
*/
|
||||
undoTransaction(transaction: any, $event: MouseEvent) {
|
||||
$event.stopPropagation();
|
||||
const locale = this.settingsService.language.code;
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const loanId = this.route.parent.parent.snapshot.params['loanId'];
|
||||
let command = 'undo';
|
||||
let operationDate = transaction.date;
|
||||
let payload = {};
|
||||
if (this.isChargeOff(transaction.type)) {
|
||||
command = 'undo-charge-off';
|
||||
operationDate = this.settingsService.businessDate;
|
||||
}
|
||||
payload = {
|
||||
transactionDate: this.dateUtils.formatDate(operationDate && new Date(operationDate), dateFormat),
|
||||
transactionAmount: 0,
|
||||
dateFormat,
|
||||
locale
|
||||
};
|
||||
|
||||
const undoTransactionAccountDialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
||||
data: { heading: 'Undo Transaction', dialogContext: `Are you sure you want undo the transaction type ${transaction.type.value} with id ${transaction.id}` }
|
||||
});
|
||||
undoTransactionAccountDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
|
||||
if (response.confirm) {
|
||||
let transactionId = transaction.id;
|
||||
if (this.isChargeOff(transaction.type)) {
|
||||
transactionId = null;
|
||||
}
|
||||
this.loansService.executeLoansAccountTransactionsCommand(loanId, command, payload, transactionId).subscribe((responseCmd: any) => {
|
||||
transaction.manuallyReversed = true;
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private isAccrual(transactionType: any): boolean {
|
||||
return (transactionType.accrual || transactionType.code === 'loanTransactionType.overdueCharge');
|
||||
}
|
||||
|
||||
private isChargeOff(transactionType: any): boolean {
|
||||
return (transactionType.chargeoff || transactionType.code === 'loanTransactionType.chargeOff');
|
||||
}
|
||||
|
||||
private reload() {
|
||||
const clientId = this.route.parent.parent.snapshot.params['clientId'];
|
||||
const loanId = this.route.parent.parent.snapshot.params['loanId'];
|
||||
const url: string = this.router.url;
|
||||
this.router.navigateByUrl(`/clients/${clientId}/loans-accounts`, { skipLocationChange: true })
|
||||
.then(() => this.router.navigate([url]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user