feat: add loan action (reject) (#844)

Fixes: #830
This commit is contained in:
Benura Abeywardena
2020-07-12 15:43:46 +05:30
committed by GitHub
parent b2afabc8d0
commit d56f950b53
8 changed files with 145 additions and 1 deletions
+1
View File
@@ -22,6 +22,7 @@ import { FloatingInterestRatesComponent } from './loans-view/floating-interest-r
import { LoanTrancheDetailsComponent } from './loans-view/loan-tranche-details/loan-tranche-details.component';
import { LoanCollateralTabComponent } from './loans-view/loan-collateral-tab/loan-collateral-tab.component';
import { CreateLoansAccountComponent } from './create-loans-account/create-loans-account.component';
import { RejectLoanComponent } from './loans-view/loan-account-actions/reject-loan/reject-loan.component';
/** Custom Resolvers */
import { LoanChargeTemplateResolver } from './common-resolvers/loan-charge-template.resolver';
@@ -14,5 +14,6 @@
<mifosx-view-guarantors [dataObject]="actionButtonData" *ngIf="actions.view_guarantors"></mifosx-view-guarantors>
<mifosx-create-guarantor [dataObject]="actionButtonData" *ngIf="actions.create_guarantor"></mifosx-create-guarantor>
<mifosx-disburse-loan-account [dataObject]="actionButtonData" *ngIf="actions.disburse_to_savings"></mifosx-disburse-loan-account>
<mifosx-reject-loan *ngIf="actions.reject"></mifosx-reject-loan>
</mat-card>
</div>
@@ -19,6 +19,7 @@ export class LoanAccountActionsComponent {
assign_loan_officer: boolean,
foreclosure: boolean,
prepay_loan: boolean,
reject: boolean,
disburse_to_savings: boolean,
make_repayment: boolean,
waive_interest: boolean,
@@ -33,6 +34,7 @@ export class LoanAccountActionsComponent {
assign_loan_officer: false,
foreclosure: false,
prepay_loan: false,
reject: false,
disburse_to_savings: false,
make_repayment: false,
waive_interest: false,
@@ -0,0 +1,35 @@
<div class="container">
<form [formGroup]="rejectLoanForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Rejected On</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="rejectedDatePicker" required formControlName="rejectedOnDate">
<mat-datepicker-toggle matSuffix [for]="rejectedDatePicker"></mat-datepicker-toggle>
<mat-datepicker #rejectedDatePicker></mat-datepicker>
<mat-error *ngIf="rejectLoanForm.controls.rejectedOnDate.hasError('required')">
Rejected Date <strong>is 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]="!rejectLoanForm.valid" *mifosxHasPermission="'REJECT_LOAN'" >Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RejectLoanComponent } from './reject-loan.component';
describe('RejectLoanComponent', () => {
let component: RejectLoanComponent;
let fixture: ComponentFixture<RejectLoanComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RejectLoanComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RejectLoanComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,75 @@
/** Angular Imports. */
import { Component, OnInit } 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';
/**
* Reject Loan component.
*/
@Component({
selector: 'mifosx-reject-loan',
templateUrl: './reject-loan.component.html',
styleUrls: ['./reject-loan.component.scss']
})
export class RejectLoanComponent implements OnInit {
/** Loan Id. */
loanId: any;
/** Reject Loan form. */
rejectLoanForm: FormGroup;
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/**
* Retrieve data from `Resolver`.
* @param formBuilder Form Builder.
* @param router Router.
* @param route Activated Route.
* @param datePipe Date Pipe.
*/
constructor(private formBuilder: FormBuilder,
private router: Router,
private route: ActivatedRoute,
private loanService: LoansService,
private datePipe: DatePipe ) {
this.loanId = this.route.parent.snapshot.params['loanId'];
}
ngOnInit() {
this.setRejectLoanForm();
}
/**
* Set Reject Loan form.
*/
setRejectLoanForm() {
this.rejectLoanForm = this.formBuilder.group({
'rejectedOnDate': [new Date(), Validators.required],
'note': ['']
});
}
/**
* Submit Reject Loan form.
*/
submit() {
const rejectedOnDate = this.rejectLoanForm.value.rejectedOnDate;
const dateFormat = 'yyyy-MM-dd';
this.rejectLoanForm.patchValue({
rejectedOnDate: this.datePipe.transform(rejectedOnDate, dateFormat)
});
const rejectForm = this.rejectLoanForm.value;
rejectForm.locale = 'en';
rejectForm.dateFormat = dateFormat;
this.loanService.loanActionButtons(this.loanId, 'reject', rejectForm).subscribe((response: any) => {
this.router.navigate(['../general'], { relativeTo: this.route });
});
}
}
+3 -1
View File
@@ -50,6 +50,7 @@ import { LoansAccountViewGuarantorDetailsDialogComponent } from './custom-dialog
import { LoansAccountAddCollateralDialogComponent } from './custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component';
import { LoansConfirmationDialogBoxComponent } from './custom-dialog/loans-confirmation-dialog-box/loans-confirmation-dialog-box.component';
import { DisburseLoanAccountComponent } from './loans-view/loan-account-actions/disburse-loan-account/disburse-loan-account.component';
import { RejectLoanComponent } from './loans-view/loan-account-actions/reject-loan/reject-loan.component';
/**
* Loans Module
@@ -97,7 +98,8 @@ import { DisburseLoanAccountComponent } from './loans-view/loan-account-actions/
CreateGuarantorComponent,
LoansAccountViewGuarantorDetailsDialogComponent,
LoansConfirmationDialogBoxComponent,
DisburseLoanAccountComponent
DisburseLoanAccountComponent,
RejectLoanComponent
],
entryComponents: [
LoansAccountAddCollateralDialogComponent,