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 ab6647557..a0e8c6aa4 100644 --- a/src/app/loans/common-resolvers/loan-action-button.resolver.ts +++ b/src/app/loans/common-resolvers/loan-action-button.resolver.ts @@ -32,6 +32,8 @@ export class LoanActionButtonResolver implements Resolve { // return this.loansService.getLoanActionTemplate(loanId, 'repayment'); } else if (loanActionButton === 'waive-interest') { return this.loansService.getLoanActionTemplate(loanId, 'waiveinterest'); + } else if (loanActionButton === 'write-off') { + return this.loansService.getLoanActionTemplate(loanId, 'writeoff'); } 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 316ed790e..1f941173d 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 @@ -7,5 +7,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 0c428a94f..be3138ec3 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,6 +15,7 @@ export class LoanAccountActionsComponent { /** flag object to store possible actions and render appropriate UI to the user */ actions: { close: boolean, undo_approval: boolean, + write_off: boolean, assign_loan_officer: boolean, foreclosure: boolean, prepay_loan: boolean, @@ -22,6 +23,7 @@ export class LoanAccountActionsComponent { waive_interest: boolean } = { close: false, undo_approval: false, + write_off: false, assign_loan_officer: false, foreclosure: false, prepay_loan: false, diff --git a/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.html b/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.html new file mode 100644 index 000000000..0cdb7102e --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.html @@ -0,0 +1,40 @@ +
+ + + +
+ +
+ + + Write off on + + + + + Write Off Date is required + + + + + Amount + + + + + Note + + + +
+ +
+ + + + + + +
+ +
diff --git a/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.scss b/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.spec.ts b/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.spec.ts new file mode 100644 index 000000000..acc7576ae --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { WriteOffPageComponent } from './write-off-page.component'; + +describe('WriteOffPageComponent', () => { + let component: WriteOffPageComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ WriteOffPageComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(WriteOffPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.ts b/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.ts new file mode 100644 index 000000000..6791c7d64 --- /dev/null +++ b/src/app/loans/loans-view/loan-account-actions/write-off-page/write-off-page.component.ts @@ -0,0 +1,72 @@ +/** Angular Imports. */ +import { Component, OnInit, Input } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { DatePipe } from '@angular/common'; + +/** Custom Services. */ +import { LoansService } from 'app/loans/loans.service'; +/** + * Write Off component. + */ +@Component({ + selector: 'mifosx-write-off-page', + templateUrl: './write-off-page.component.html', + styleUrls: ['./write-off-page.component.scss'] +}) +export class WriteOffPageComponent implements OnInit { + + @Input() dataObject: any; + + /** Write Off form. */ + writeOffForm: FormGroup; + + /** + * Get data from `Resolver`. + * @param {FormBuilder} formBuilder Form Builder. + * @param {ActivatedRoute} route Activated Route. + * @param {LoansService} loanService Loan Service. + * @param {DatePipe} datePipe Date Pipe. + * @param {Router} router Router. + */ + constructor(private formBuilder: FormBuilder, + private route: ActivatedRoute, + private loanService: LoansService, + private datePipe: DatePipe, + private router: Router) { } + + ngOnInit() { + this.setWriteOffForm(); + } + + /** + * Set Write Off form. + */ + setWriteOffForm() { + this.writeOffForm = this.formBuilder.group({ + 'transactionDate': [this.dataObject.date && new Date(this.dataObject.date), Validators.required], + 'amount': [{value: this.dataObject.amount, disabled: true}], + 'note': [''] + }); + } + + /** + * Submits write off form. + */ + submit() { + const transactionDate = this.writeOffForm.value.transactionDate; + const dateFormat = 'dd MMMM yyyy'; + this.writeOffForm.patchValue({ + transactionDate: this.datePipe.transform(transactionDate, dateFormat) + }); + const loanId = this.route.parent.snapshot.params['loanId']; + const writeOffForm = this.writeOffForm.value; + delete writeOffForm.amount; + writeOffForm.locale = 'en'; + writeOffForm.dateFormat = dateFormat; + this.loanService.submitLoanActionButton(loanId, writeOffForm, 'writeoff').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 8cd3a7a69..4b70c956e 100644 --- a/src/app/loans/loans.module.ts +++ b/src/app/loans/loans.module.ts @@ -31,6 +31,7 @@ import { PrepayLoanComponent } from './loans-view/loan-account-actions/prepay-lo 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'; import { FloatingInterestRatesComponent } from './loans-view/floating-interest-rates/floating-interest-rates.component'; +import { WriteOffPageComponent } from './loans-view/loan-account-actions/write-off-page/write-off-page.component'; /** * Loans Module @@ -62,6 +63,7 @@ import { FloatingInterestRatesComponent } from './loans-view/floating-interest-r MakeRepaymentComponent, WaiveInterestComponent, FloatingInterestRatesComponent, + WriteOffPageComponent, ], providers: [DatePipe], })