feat: add loan action button (waive-interest) (#861)

Fixes: #846
This commit is contained in:
Benura Abeywardena
2020-06-14 00:28:46 +05:30
committed by GitHub
parent 06fd5e793c
commit f0b728a0a0
8 changed files with 155 additions and 2 deletions
@@ -30,6 +30,8 @@ export class LoanActionButtonResolver implements Resolve<Object> {
return this.loansService.getLoanTemplate(loanId);
// } else if (loanActionButton === 'make-repayment') {
// return this.loansService.getLoanActionTemplate(loanId, 'repayment');
} else if (loanActionButton === 'waive-interest') {
return this.loansService.getLoanActionTemplate(loanId, 'waiveinterest');
} else {
return this.loansService.getLoanActionTemplate(loanId, 'prepayLoan');
}
@@ -6,5 +6,6 @@
<mifosx-foreclosure *ngIf="actions.foreclosure"></mifosx-foreclosure>
<mifosx-prepay-loan [dataObject]="actionButtonData" *ngIf="actions.prepay_loan"></mifosx-prepay-loan>
<mifosx-make-repayment [dataObject]="actionButtonData" *ngIf="actions.make_repayment"></mifosx-make-repayment>
<mifosx-waive-interest [dataObject]="actionButtonData" *ngIf="actions.waive_interest"></mifosx-waive-interest>
</mat-card>
</div>
@@ -18,13 +18,15 @@ export class LoanAccountActionsComponent {
assign_loan_officer: boolean,
foreclosure: boolean,
prepay_loan: boolean,
make_repayment: boolean } = {
make_repayment: boolean,
waive_interest: boolean } = {
close: false,
undo_approval: false,
assign_loan_officer: false,
foreclosure: false,
prepay_loan: false,
make_repayment: false };
make_repayment: false,
waive_interest: false };
actionButtonData: any;
actionName: any;
@@ -0,0 +1,43 @@
<div class="container">
<form [formGroup]="loanInterestForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Interest waived on</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="interestDatePicker" required formControlName="transactionDate">
<mat-datepicker-toggle matSuffix [for]="interestDatePicker"></mat-datepicker-toggle>
<mat-datepicker #interestDatePicker></mat-datepicker>
<mat-error *ngIf="loanInterestForm.controls.transactionDate.hasError('required')">
Interest Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Transaction amount</mat-label>
<input matInput required formControlName="transactionAmount">
<mat-error *ngIf="loanInterestForm.controls.transactionAmount.hasError('required')">
Transaction Amount is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Note</mat-label>
<textarea matInput formControlName="note"></textarea>
</mat-form-field>
</div>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!loanInterestForm.valid" *mifosxHasPermission="'WAIVEINTERESTPORTION_LOAN'">Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { WaiveInterestComponent } from './waive-interest.component';
describe('WaiveInterestComponent', () => {
let component: WaiveInterestComponent;
let fixture: ComponentFixture<WaiveInterestComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WaiveInterestComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WaiveInterestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,78 @@
/** Angular Imports. */
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services. */
import { LoansService } from 'app/loans/loans.service';
/**
* Waive Interest component.
*/
@Component({
selector: 'mifosx-waive-interest',
templateUrl: './waive-interest.component.html',
styleUrls: ['./waive-interest.component.scss']
})
export class WaiveInterestComponent implements OnInit {
@Input() dataObject: any;
/** Loan Interest form. */
loanInterestForm: FormGroup;
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/**
* Get data from `Resolver`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {Router} router Router.
* @param {DatePipe} datePipe DatePipe.
* @param {LoansService} loanService Loan Service.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private formBuilder: FormBuilder,
private router: Router,
private datePipe: DatePipe,
private loanService: LoansService,
private route: ActivatedRoute) { }
ngOnInit() {
this.setLoanInterestForm();
}
/**
* Set Loan Interest form.
*/
setLoanInterestForm() {
this.loanInterestForm = this.formBuilder.group({
'transactionAmount': [this.dataObject.amount, Validators.required],
'transactionDate': [this.dataObject.date && new Date(this.dataObject.date), Validators.required],
'note': ['']
});
}
/**
* Submits loan interest form.
*/
submit() {
const transactionDate = this.loanInterestForm.value.transactionDate;
const transactionAmount = this.loanInterestForm.value.transactionAmount;
const dateFormat = 'dd MMMM yyyy';
this.loanInterestForm.patchValue({
transactionDate: this.datePipe.transform(transactionDate, dateFormat),
transactionAmount: parseInt(transactionAmount, 10)
});
const loanId = this.route.parent.snapshot.params['loanId'];
const loanInterestForm = this.loanInterestForm.value;
loanInterestForm.locale = 'en';
loanInterestForm.dateFormat = dateFormat;
this.loanService.submitLoanActionButton(loanId, loanInterestForm, 'waiveinterest').subscribe((response: any) => {
this.router.navigate(['../general'], {relativeTo: this.route});
});
}
}
+2
View File
@@ -29,6 +29,7 @@ import { AssignLoanOfficerComponent } from './loans-view/loan-account-actions/as
import { ForeclosureComponent } from './loans-view/loan-account-actions/foreclosure/foreclosure.component';
import { PrepayLoanComponent } from './loans-view/loan-account-actions/prepay-loan/prepay-loan.component';
import { MakeRepaymentComponent } from './loans-view/loan-account-actions/make-repayment/make-repayment.component';
import { WaiveInterestComponent } from './loans-view/loan-account-actions/waive-interest/waive-interest.component';
/**
* Loans Module
@@ -58,6 +59,7 @@ import { MakeRepaymentComponent } from './loans-view/loan-account-actions/make-r
ForeclosureComponent,
PrepayLoanComponent,
MakeRepaymentComponent,
WaiveInterestComponent,
],
providers: [DatePipe],
})