From da609f0de4b6e7d95c363ff0a5c6068b8230d775 Mon Sep 17 00:00:00 2001 From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com> Date: Sat, 13 Jun 2020 03:19:05 +0530 Subject: [PATCH] feat: add loan button (foreclosure) (#869) Fixes: #244 --- .../assign-loan-officer.component.ts | 4 +- .../foreclosure/foreclosure.component.html | 75 +++++++++++ .../foreclosure/foreclosure.component.scss | 0 .../foreclosure/foreclosure.component.spec.ts | 25 ++++ .../foreclosure/foreclosure.component.ts | 124 ++++++++++++++++++ .../loan-account-actions.component.html | 1 + .../loan-account-actions.component.ts | 6 +- src/app/loans/loans.module.ts | 2 + src/app/loans/loans.service.ts | 14 ++ 9 files changed, 247 insertions(+), 4 deletions(-) create mode 100644 src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.html create mode 100644 src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.scss create mode 100644 src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.spec.ts create mode 100644 src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.ts diff --git a/src/app/loans/loans-view/loan-account-actions/assign-loan-officer/assign-loan-officer.component.ts b/src/app/loans/loans-view/loan-account-actions/assign-loan-officer/assign-loan-officer.component.ts index 3572512c8..68e902299 100644 --- a/src/app/loans/loans-view/loan-account-actions/assign-loan-officer/assign-loan-officer.component.ts +++ b/src/app/loans/loans-view/loan-account-actions/assign-loan-officer/assign-loan-officer.component.ts @@ -56,10 +56,10 @@ export class AssignLoanOfficerComponent implements OnInit { } submit() { - const assignmentDatee = this.assignOfficerForm.value.assignmentDate; + const assignmentDate = this.assignOfficerForm.value.assignmentDate; const dateFormat = 'yyyy-MM-dd'; this.assignOfficerForm.patchValue({ - assignmentDate: this.datePipe.transform(assignmentDatee, dateFormat) + assignmentDate: this.datePipe.transform(assignmentDate, dateFormat) }); const assignForm = this.assignOfficerForm.value; assignForm.locale = 'en'; diff --git a/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.html b/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.html new file mode 100644 index 000000000..17a0e3525 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.html @@ -0,0 +1,75 @@ +
+ +
+ + + +
+ + + Transaction Date + + + + + Transaction Date is required + + + + + Principal + + + Loan Officer is required + + + + + Interest + + + Loan Officer is required + + + + + Fee Amount + + + Loan Officer is required + + + + + Penalty Amount + + + Loan Officer is required + + + + + Transaction Amount + + + Loan Officer is required + + + + + Note + + + +
+ + + + + + +
+ +
+ +
diff --git a/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.scss b/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.spec.ts b/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.spec.ts new file mode 100644 index 000000000..ccf34a122 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ForeclosureComponent } from './foreclosure.component'; + +describe('ForeclosureComponent', () => { + let component: ForeclosureComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ForeclosureComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ForeclosureComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.ts b/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.ts new file mode 100644 index 000000000..a37c5d016 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/foreclosure/foreclosure.component.ts @@ -0,0 +1,124 @@ +import { Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { LoansService } from 'app/loans/loans.service'; +import { ActivatedRoute, Router } from '@angular/router'; +import { DatePipe } from '@angular/common'; + +@Component({ + selector: 'mifosx-foreclosure', + templateUrl: './foreclosure.component.html', + styleUrls: ['./foreclosure.component.scss'] +}) +export class ForeclosureComponent implements OnInit { + + + loanId: any; + foreclosureForm: FormGroup; + /** Minimum Date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum Date allowed. */ + maxDate = new Date(); + foreclosuredata: any; + paymentTypes: any; + + + /** + * @param {FormBuilder} formBuilder Form Builder. + * @param {LoansService} systemService Loan Service. + * @param {ActivatedRoute} route Activated Route. + * @param {Router} router Router for navigation. + */ + constructor(private formBuilder: FormBuilder, + private loanService: LoansService, + private route: ActivatedRoute, + private router: Router, + private datePipe: DatePipe) { + this.loanId = this.route.parent.snapshot.params['loanId']; + } + + ngOnInit() { + this.createforeclosureForm(); + this.onChanges(); + } + + createforeclosureForm() { + this.foreclosureForm = this.formBuilder.group({ + 'transactionDate': [new Date(), Validators.required], + 'outstandingPrincipalPortion': [{value: '', disabled: true}, Validators.required], + 'outstandingInterestPortion': [{value: '', disabled: true}, Validators.required], + 'outstandingFeeChargesPortion': [{value: '', disabled: true}, Validators.required], + 'outstandingPenaltyChargesPortion': [{value: '', disabled: true}, Validators.required], + 'transactionAmount': [{value: '', disabled: true}, Validators.required], + 'interestAccruedAfterDeath': '', + 'note': '' + }); + } + + onChanges(): void { + this.foreclosureForm.get('transactionDate').valueChanges.subscribe(val => { + this.retrieveLoanForeclosureTemplate(val); + }); + + } + + retrieveLoanForeclosureTemplate(val: any) { + const dateFormat = 'dd MMMM yyyy'; + const transactionDateFormatted = this.datePipe.transform(val, dateFormat); + const data = { + command: 'foreclosure', + dateFormat: 'dd MMMM yyyy', + locale: 'en', + transactionDate: transactionDateFormatted + }; + this.loanService.getForeclosureData(this.loanId, data) + .subscribe((response: any) => { + this.foreclosuredata = response; + + this.foreclosureForm.patchValue({ + outstandingPrincipalPortion: this.foreclosuredata.principalPortion, + outstandingInterestPortion: this.foreclosuredata.interestPortion, + outstandingFeeChargesPortion: this.foreclosuredata.feeChargesPortion, + outstandingPenaltyChargesPortion: this.foreclosuredata.penaltyChargesPortion, + foreClosureChargesPortion: this.foreclosuredata.foreClosureChargesPortion + }); + if (this.foreclosuredata.unrecognizedIncomePortion) { + this.foreclosureForm.patchValue({ + interestAccruedAfterDeath: this.foreclosuredata.unrecognizedIncomePortion + }); + } + this.calculateTransactionAmount(); + this.paymentTypes = this.foreclosuredata.paymentTypeOptions; + }); + } + + calculateTransactionAmount() { + let transactionAmount = 0; + transactionAmount += parseFloat(this.foreclosuredata.principalPortion); + transactionAmount += parseFloat(this.foreclosuredata.interestPortion); + transactionAmount += parseFloat(this.foreclosuredata.feeChargesPortion); + transactionAmount += parseFloat(this.foreclosuredata.penaltyChargesPortion); + this.foreclosureForm.patchValue({ + transactionAmount: transactionAmount + }); + } + + submit() { + const transactionDate = this.foreclosureForm.value.transactionDate; + const dateFormat = 'yyyy-MM-dd'; + this.foreclosureForm.patchValue({ + transactionDate: this.datePipe.transform(transactionDate, dateFormat) + }); + const formData = { + transactionDate: this.foreclosureForm.value.transactionDate, + locale: 'en', + dateFormat: dateFormat, + note: this.foreclosureForm.value.note + }; + + this.loanService.loanForclosureData(this.loanId, formData) + .subscribe((response: any) => { + this.router.navigate([`../general`], { relativeTo: this.route }); + }); + } + +} 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 05ce3c613..c5255e17c 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 @@ -3,5 +3,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 f963edb1a..9e09ebe9d 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 @@ -15,10 +15,12 @@ export class LoanAccountActionsComponent { /** flag object to store possible actions and render appropriate UI to the user */ actions: { close: boolean, undo_approval: boolean, - assign_loan_officer: boolean } = { + assign_loan_officer: boolean, + foreclosure: boolean } = { close: false, undo_approval: false, - assign_loan_officer: false }; + assign_loan_officer: false, + foreclosure: false }; actionButtonData: any; actionName: any; diff --git a/src/app/loans/loans.module.ts b/src/app/loans/loans.module.ts index ff83fd8c9..2524f8db8 100644 --- a/src/app/loans/loans.module.ts +++ b/src/app/loans/loans.module.ts @@ -26,6 +26,7 @@ import { MultiRowComponent } from './loans-view/datatable-tab/multi-row/multi-ro import { SingleRowComponent } from './loans-view/datatable-tab/single-row/single-row.component'; import { UndoApprovalComponent } from './loans-view/loan-account-actions/undo-approval/undo-approval.component'; import { AssignLoanOfficerComponent } from './loans-view/loan-account-actions/assign-loan-officer/assign-loan-officer.component'; +import { ForeclosureComponent } from './loans-view/loan-account-actions/foreclosure/foreclosure.component'; /** * Loans Module @@ -52,6 +53,7 @@ import { AssignLoanOfficerComponent } from './loans-view/loan-account-actions/as SingleRowComponent, UndoApprovalComponent, AssignLoanOfficerComponent, + ForeclosureComponent, ], providers: [DatePipe], }) diff --git a/src/app/loans/loans.service.ts b/src/app/loans/loans.service.ts index b4a24128c..1bbfdc5f4 100644 --- a/src/app/loans/loans.service.ts +++ b/src/app/loans/loans.service.ts @@ -167,4 +167,18 @@ export class LoansService { return this.http.post(`/loans/${loanId}`, data, {params: httpParams}); } + getForeclosureData(loanId: any, foreclosuredata: any) { + const httpParams = new HttpParams().set('command', foreclosuredata.command) + .set('dateFormat', foreclosuredata.dateFormat) + .set('locale', foreclosuredata.locale) + .set('transactionDate', foreclosuredata.transactionDate); + return this.http.get(`/loans/${loanId}/transactions/template`, {params: httpParams}); + + } + + loanForclosureData(loanId: any, data: any) { + const httpParams = new HttpParams().set('command', 'foreclosure'); + return this.http.post(`/loans/${loanId}/transactions`, data, {params: httpParams}); + } + }