diff --git a/src/app/loans/common-resolvers/loan-action-button.resolver.ts b/src/app/loans/common-resolvers/loan-action-button.resolver.ts index 21d5c6615..92c7d048a 100644 --- a/src/app/loans/common-resolvers/loan-action-button.resolver.ts +++ b/src/app/loans/common-resolvers/loan-action-button.resolver.ts @@ -38,6 +38,8 @@ export class LoanActionButtonResolver implements Resolve { return this.loansService.getLoanActionTemplate(loanId, 'close'); } else if (loanActionButton === 'close-as-rescheduled') { return this.loansService.getLoanActionTemplate(loanId, 'close-rescheduled'); + } else if (loanActionButton === 'reschedule') { + return this.loansService.rescheduleLoanTemplate(); } else { return this.loansService.getLoanActionTemplate(loanId, 'prepayLoan'); } 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 9f9877ded..1b5c7aa9c 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 @@ -9,5 +9,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 d34bdcdfc..a0b279450 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 @@ -21,7 +21,8 @@ export class LoanAccountActionsComponent { prepay_loan: boolean, make_repayment: boolean, waive_interest: boolean, - close_as_rescheduled: boolean } = { + close_as_rescheduled: boolean, + reschedule: boolean } = { close: false, undo_approval: false, write_off: false, @@ -30,7 +31,9 @@ export class LoanAccountActionsComponent { prepay_loan: false, make_repayment: false, waive_interest: false, - close_as_rescheduled: false }; + close_as_rescheduled: false, + reschedule: false }; + actionButtonData: any; actionName: any; diff --git a/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.html b/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.html new file mode 100644 index 000000000..711f62abf --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.html @@ -0,0 +1,99 @@ +
+ +
+ + + +
+ + + Reschedule from Installment On + + + + + Reschedule Date is required + + + + + Reason for Rescheduling + + + {{ rescheduleReasonCode.name }} + + + + Reason for Rescheduling is required + + + + + Submitted On + + + + + Submitted On Date is required + + + + + Comments + + + + Change Repayment Date + + + + Installment Rescheduled to + + + + + + + Introduce Mid-term grace periods + + + + Principal Grace Periods + + + + + Interest Grace Periods + + + + + Extend Repayment Period + + + + Number Of new Repayments + + + + + Adjust interest rates for remainder of loan + + + New Interest Rate + + + + +
+ + + + + + +
+ +
+ +
diff --git a/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.scss b/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.spec.ts b/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.spec.ts new file mode 100644 index 000000000..61a533603 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LoanRescheduleComponent } from './loan-reschedule.component'; + +describe('LoanRescheduleComponent', () => { + let component: LoanRescheduleComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LoanRescheduleComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LoanRescheduleComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts b/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts new file mode 100644 index 000000000..f767b67cb --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component.ts @@ -0,0 +1,88 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { LoansService } from 'app/loans/loans.service'; +import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { DatePipe } from '@angular/common'; +import { subscribeOn } from 'rxjs/operators'; + +@Component({ + selector: 'mifosx-loan-reschedule', + templateUrl: './loan-reschedule.component.html', + styleUrls: ['./loan-reschedule.component.scss'] +}) +export class LoanRescheduleComponent implements OnInit { + + @Input() dataObject: any; + loanId: any; + rescheduleLoanForm: FormGroup; + + /** Minimum Date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum Date allowed. */ + maxDate = new Date(); + codes: any; + + changeRepaymentDate = new FormControl(false); + introduceGracePeriods = new FormControl(false); + extendRepaymentPeriod = new FormControl(false); + adjustinterestrates = new FormControl(false); + + /** + * @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.codes = this.dataObject.rescheduleReasons; + this.setRescheduleLoanForm(); + } + + setRescheduleLoanForm() { + this.rescheduleLoanForm = this.formBuilder.group({ + 'rescheduleFromDate': [new Date(), Validators.required], + 'rescheduleReasonId': ['', Validators.required], + 'submittedOnDate': [new Date(), Validators.required], + 'rescheduleReasonComment': [''], + 'adjustedDueDate': [''], + 'graceOnPrincipal': [''], + 'graceOnInterest': [''], + 'extraTerms': [''], + 'newInterestRate': [''] + }); + + } + + submit() { + const rescheduleFromDate = this.rescheduleLoanForm.value.rescheduleFromDate; + const adjustedDueDate = this.rescheduleLoanForm.value.adjustedDueDate; + const submittedOnDate = this.rescheduleLoanForm.value.submittedOnDate; + const dateFormat = 'dd MMMM yyyy'; + + this.rescheduleLoanForm.patchValue({ + rescheduleFromDate: this.datePipe.transform(rescheduleFromDate, dateFormat), + adjustedDueDate: this.datePipe.transform(adjustedDueDate, dateFormat), + submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat) + }); + const rescheduleForm = this.rescheduleLoanForm.value; + rescheduleForm.locale = 'en'; + rescheduleForm.dateFormat = dateFormat; + rescheduleForm.loanId = this.loanId; + this.loanService.submitRescheduleData(rescheduleForm).subscribe((response: any) => { + + // TODO: needs to be updated + // mentioned in Community App: + // location.path('/loans/' + scope.loanId + '/viewreschedulerequest/'+ data.resourceId); + this.router.navigate(['../general'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/loans/loans.module.ts b/src/app/loans/loans.module.ts index 5e0a3555a..651f2f8fb 100644 --- a/src/app/loans/loans.module.ts +++ b/src/app/loans/loans.module.ts @@ -34,6 +34,7 @@ import { FloatingInterestRatesComponent } from './loans-view/floating-interest-r import { WriteOffPageComponent } from './loans-view/loan-account-actions/write-off-page/write-off-page.component'; import { LoanTrancheDetailsComponent } from './loans-view/loan-tranche-details/loan-tranche-details.component'; import { CloseAsRescheduledComponent } from './loans-view/loan-account-actions/close-as-rescheduled/close-as-rescheduled.component'; +import { LoanRescheduleComponent } from './loans-view/loan-account-actions/loan-reschedule/loan-reschedule.component'; /** * Loans Module @@ -68,6 +69,7 @@ import { CloseAsRescheduledComponent } from './loans-view/loan-account-actions/c WriteOffPageComponent, LoanTrancheDetailsComponent, CloseAsRescheduledComponent, + LoanRescheduleComponent, ], providers: [DatePipe], }) diff --git a/src/app/loans/loans.service.ts b/src/app/loans/loans.service.ts index 86479df05..8f4d2983d 100644 --- a/src/app/loans/loans.service.ts +++ b/src/app/loans/loans.service.ts @@ -188,4 +188,14 @@ export class LoansService { return this.http.post(`/loans/${loanId}/transactions`, data, {params: httpParams}); } + rescheduleLoanTemplate() { + return this.http.get('/rescheduleloans/template'); + } + + submitRescheduleData(data: any) { + // https://staging.mifos.io/fineract-provider/api/v1/rescheduleloans?command=reschedule + const httpParams = new HttpParams().set('command', 'reschedule'); + return this.http.post('/rescheduleloans', data, {params: httpParams}); + } + }