From d56f950b538c1f88a3a684eb8aa73d38585afd12 Mon Sep 17 00:00:00 2001 From: Benura Abeywardena <43112139+BLasan@users.noreply.github.com> Date: Sun, 12 Jul 2020 15:43:46 +0530 Subject: [PATCH] feat: add loan action (reject) (#844) Fixes: #830 --- src/app/loans/loans-routing.module.ts | 1 + .../loan-account-actions.component.html | 1 + .../loan-account-actions.component.ts | 2 + .../reject-loan/reject-loan.component.html | 35 +++++++++ .../reject-loan/reject-loan.component.scss | 3 + .../reject-loan/reject-loan.component.spec.ts | 25 +++++++ .../reject-loan/reject-loan.component.ts | 75 +++++++++++++++++++ src/app/loans/loans.module.ts | 4 +- 8 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.html create mode 100644 src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.scss create mode 100644 src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.spec.ts create mode 100644 src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.ts diff --git a/src/app/loans/loans-routing.module.ts b/src/app/loans/loans-routing.module.ts index 3e3cdea36..4a8fc2705 100644 --- a/src/app/loans/loans-routing.module.ts +++ b/src/app/loans/loans-routing.module.ts @@ -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'; diff --git a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html index 5240d8bea..6d74ac9ad 100644 --- a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html +++ b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.html @@ -14,5 +14,6 @@ + diff --git a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts index f81b7a335..0d23ab46d 100644 --- a/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts +++ b/src/app/loans/loans-view/loan-account-actions/loan-account-actions.component.ts @@ -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, diff --git a/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.html b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.html new file mode 100644 index 000000000..b80fb0b54 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.html @@ -0,0 +1,35 @@ +
+ +
+ + + +
+ + + Rejected On + + + + + Rejected Date is required + + + + + Note + + + +
+ + + + + + +
+ +
+ +
diff --git a/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.scss b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.scss new file mode 100644 index 000000000..1915ad6d3 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.spec.ts b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.spec.ts new file mode 100644 index 000000000..970724df1 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ RejectLoanComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(RejectLoanComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.ts b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.ts new file mode 100644 index 000000000..f86edd1d5 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/reject-loan/reject-loan.component.ts @@ -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 }); + }); + } + +} diff --git a/src/app/loans/loans.module.ts b/src/app/loans/loans.module.ts index db7bceb11..adadbf402 100644 --- a/src/app/loans/loans.module.ts +++ b/src/app/loans/loans.module.ts @@ -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,