Skip to content

Commit 9d6cf15

Browse files
Jose Alberto Hernandezalberto-art3ch
authored andcommitted
Loan Interest Pauses management to Edit or Delete
1 parent b729898 commit 9d6cf15

File tree

8 files changed

+137
-11
lines changed

8 files changed

+137
-11
lines changed

src/app/loans/loans-view/loan-account-actions/add-interest-pause/add-interest-pause.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<div class="container mat-elevation-z8">
22
<mat-card>
3+
<div class="m-b-20" fxLayout="column" *ngIf="maturityDate">
4+
<span class="m-r-10">{{'Maturity Date' | translateKey:'inputs'}} : {{ maturityDate | dateFormat}}</span>
5+
</div>
36
<form [formGroup]="interestPauseLoanForm" (ngSubmit)="submit()">
47
<mat-card-content>
58
<div fxLayout="column">

src/app/loans/loans-view/loan-account-actions/add-interest-pause/add-interest-pause.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class AddInterestPauseComponent implements OnInit {
2424
/** Maximum Date allowed. */
2525
maxDate = new Date();
2626
startDate = new Date();
27+
maturityDate: Date | null = null;
2728
/** Interest Pause Loan Form */
2829
interestPauseLoanForm: UntypedFormGroup;
2930

@@ -49,11 +50,10 @@ export class AddInterestPauseComponent implements OnInit {
4950
* and initialize with the required values
5051
*/
5152
ngOnInit() {
53+
this.maturityDate = new Date(this.dataObject.timeline.expectedMaturityDate);
5254
this.maxDate = new Date(this.dataObject.timeline.expectedMaturityDate);
5355
this.startDate = new Date(this.settingsService.businessDate);
54-
if (this.startDate < this.maxDate) {
55-
this.maxDate = this.startDate;
56-
} else {
56+
if (this.startDate > this.maxDate) {
5757
this.startDate = this.maxDate;
5858
}
5959
this.createInterestPauseLoanForm();

src/app/loans/loans-view/loan-accounts-button-config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ export class LoansAccountButtonConfiguration {
159159
switch (status) {
160160
case 'Active':
161161
this.optionArray = [
162-
{
163-
name: 'Add Interest Pause',
164-
taskPermissionName: 'CREATE_INTEREST_PAUSE',
165-
},
166162
{
167163
name: 'Waive Interest',
168164
taskPermissionName: 'WAIVEINTERESTPORTION_LOAN',

src/app/loans/loans-view/loan-term-variations-tab/loan-term-variations-tab.component.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h3>{{ 'labels.heading.Term Variations' | translate }}</h3>
2323
<tr mat-row *matRowDef="let row; columns: loanDTermVariationsColumns;"></tr>
2424
</table>
2525

26-
<h3 class="m-t-20">{{ 'labels.heading.Interest Pauses' | translate }}</h3>
26+
<h3 class="m-t-20" *ngIf="interestPausesData?.length > 0">{{ 'labels.heading.Interest Pauses' | translate }}</h3>
2727
<table mat-table class="m-t-20" [dataSource]="interestPausesData" *ngIf="interestPausesData?.length > 0">
2828
<ng-container matColumnDef="row">
2929
<th mat-header-cell *matHeaderCellDef>#</th>
@@ -45,6 +45,22 @@ <h3 class="m-t-20">{{ 'labels.heading.Interest Pauses' | translate }}</h3>
4545
<td mat-cell *matCellDef="let item">{{ item.days | formatNumber }}</td>
4646
</ng-container>
4747

48+
<ng-container matColumnDef="actions">
49+
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Actions' | translate }}</th>
50+
<td mat-cell *matCellDef="let item">
51+
<button class="button" mat-icon-button color="primary"
52+
matTooltip="{{ 'tooltips.Edit' | translate }}" matTooltipPosition="right"
53+
(click)="manageRequest(item, 'Edit')">
54+
<fa-icon icon="edit" size="lg"></fa-icon>
55+
</button>
56+
<button class="button" mat-icon-button color="warn"
57+
matTooltip="{{ 'tooltips.Delete' | translate }}" matTooltipPosition="left"
58+
(click)="manageRequest(item, 'Delete')">
59+
<fa-icon icon="trash" size="lg"></fa-icon>
60+
</button>
61+
</td>
62+
</ng-container>
63+
4864
<tr mat-header-row *matHeaderRowDef="interestPausesColumns"></tr>
4965
<tr mat-row *matRowDef="let row; columns: interestPausesColumns"></tr>
5066
</table>

src/app/loans/loans-view/loan-term-variations-tab/loan-term-variations-tab.component.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
table {
22
width: 100%;
3+
4+
.action-button {
5+
min-width: 26px;
6+
padding: 0 0 3px;
7+
margin: 0 2%;
8+
line-height: 25px;
9+
}
310
}
411

512
.container {

src/app/loans/loans-view/loan-term-variations-tab/loan-term-variations-tab.component.ts

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { Component } from '@angular/core';
2-
import { ActivatedRoute } from '@angular/router';
2+
import { MatDialog } from '@angular/material/dialog';
3+
import { ActivatedRoute, Router } from '@angular/router';
34
import { Dates } from 'app/core/utils/dates';
5+
import { LoansService } from 'app/loans/loans.service';
6+
import { SettingsService } from 'app/settings/settings.service';
7+
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
8+
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
9+
import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicker-base';
10+
import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base';
11+
import { AnyKindOfDictionary } from 'cypress/types/lodash';
412

513
@Component({
614
selector: 'mifosx-loan-term-variations-tab',
@@ -14,13 +22,22 @@ export class LoanTermVariationsTabComponent {
1422
loanDTermVariationsColumns: string[] = ['termType', 'applicableFrom', 'value', 'specificToInstallment'];
1523
/** Interest Pauses Data */
1624
interestPausesData: any[] = [];
17-
interestPausesColumns: string[] = ['row', 'startDate', 'endDate', 'days'];
25+
interestPausesColumns: string[] = ['row', 'startDate', 'endDate', 'days', 'actions'];
26+
27+
loanId: number;
28+
clientId: AnyKindOfDictionary;
1829

1930
constructor(private route: ActivatedRoute,
20-
private dates: Dates
31+
private router: Router,
32+
private dates: Dates,
33+
private settingsService: SettingsService,
34+
private loansService: LoansService,
35+
private dialog: MatDialog
2136
) {
2237
this.interestPausesData = [];
38+
this.clientId = this.route.parent.parent.snapshot.paramMap.get('clientId');
2339
this.route.data.subscribe((data: { loanDetailsData: any, interestPausesData: any }) => {
40+
this.loanId = data.loanDetailsData.id;
2441
this.loanTermVariationsData = data.loanDetailsData.loanTermVariations;
2542
this.interestPausesData = [];
2643
data.interestPausesData?.forEach((item: any) => {
@@ -29,4 +46,76 @@ export class LoanTermVariationsTabComponent {
2946
});
3047
});
3148
}
49+
50+
manageRequest(variation: any, action: string) {
51+
if (action === 'Delete') {
52+
this.deleteInterestPause(variation);
53+
} else if (action === 'Edit') {
54+
this.updateInterestPause(variation);
55+
}
56+
}
57+
58+
deleteInterestPause(variation: any) {
59+
const deleteStandingInstructionDialogRef = this.dialog.open(DeleteDialogComponent, {
60+
data: { deleteContext: `interest pause from ${variation.startDate} to ${variation.endDate}` }
61+
});
62+
deleteStandingInstructionDialogRef.afterClosed().subscribe((response: any) => {
63+
if (response.delete) {
64+
this.loansService.deleteInterestPause(this.loanId, variation.id).subscribe((response: any) => {
65+
this.reload();
66+
});
67+
}
68+
});
69+
}
70+
71+
updateInterestPause(variation: any) {
72+
const startDate: Date = this.dates.parseDate(variation.startDate);
73+
const endDate: Date = this.dates.parseDate(variation.endDate);
74+
const formfields: FormfieldBase[] = [
75+
new DatepickerBase({
76+
controlName: 'startDate',
77+
label: 'Start Date',
78+
value: startDate,
79+
maxDate: this.settingsService.maxFutureDate,
80+
required: true
81+
}),
82+
new DatepickerBase({
83+
controlName: 'endDate',
84+
label: 'End Date',
85+
value: endDate,
86+
maxDate: this.settingsService.maxFutureDate,
87+
required: true
88+
}),
89+
];
90+
91+
const data = {
92+
title: 'Edit Interest Pause id: ' + variation.id,
93+
formfields: formfields,
94+
layout: { addButtonText: 'Submit' }
95+
};
96+
const editDialogRef = this.dialog.open(FormDialogComponent, { data, width: '50rem' });
97+
editDialogRef.afterClosed().subscribe((response: any) => {
98+
if (response.data) {
99+
if (response.data.value.startDate <= response.data.value.endDate) {
100+
const locale = this.settingsService.language.code;
101+
const dateFormat = this.settingsService.dateFormat;
102+
const payload = {
103+
startDate: this.dates.formatDate(response.data.value.startDate, dateFormat),
104+
endDate: this.dates.formatDate(response.data.value.endDate, dateFormat),
105+
locale,
106+
dateFormat
107+
}
108+
this.loansService.updateInterestPause(this.loanId, variation.id, payload).subscribe((response: any) => {
109+
this.reload();
110+
});
111+
}
112+
}
113+
});
114+
}
115+
116+
private reload() {
117+
const url: string = this.router.url;
118+
this.router.navigateByUrl(`/clients/${this.clientId}/loans-accounts`, { skipLocationChange: true })
119+
.then(() => this.router.navigate([url]));
120+
}
32121
}

src/app/loans/loans-view/loans-view.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ export class LoansViewComponent implements OnInit {
151151
taskPermissionName: 'DISBURSALLASTUNDO_LOAN'
152152
});
153153
}
154+
if (this.recalculateInterest) {
155+
this.buttonConfig.addButton({
156+
name: 'Add Interest Pause',
157+
icon: 'calendar',
158+
taskPermissionName: 'CREATE_INTEREST_PAUSE'
159+
});
160+
}
154161
// loan officer not assigned to loan, below logic
155162
// helps to display otherwise not
156163
if (!this.loanDetailsData.loanOfficerName) {

src/app/loans/loans.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ export class LoansService {
285285
return this.http.get(`/loans/${loanId}/interest-pauses`);
286286
}
287287

288+
updateInterestPause(loanId: number, variationId: number, data?: any): Observable<any> {
289+
return this.http.put(`/loans/${loanId}/interest-pauses/${variationId}`, data);
290+
}
291+
292+
deleteInterestPause(loanId: number, variationId: number): Observable<any> {
293+
return this.http.delete(`/loans/${loanId}/interest-pauses/${variationId}`);
294+
}
295+
288296
/**
289297
* @param {string|number} loanId Loan Id.
290298
* @param {any} foreclosuredata ForeClosure Data

0 commit comments

Comments
 (0)