feat: add loan button (close action) (#855)

Fixes: #849
This commit is contained in:
Muskan Khedia
2020-06-09 10:27:33 +05:30
committed by GitHub
parent 347e84f366
commit a3f60783dc
17 changed files with 222 additions and 14 deletions
@@ -0,0 +1,5 @@
<div class="container">
<mat-card>
<mifosx-loans-account-close *ngIf="actions.close"></mifosx-loans-account-close>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
padding: 3%;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoanAccountActionsComponent } from './loan-account-actions.component';
describe('LoanAccountActionsComponent', () => {
let component: LoanAccountActionsComponent;
let fixture: ComponentFixture<LoanAccountActionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoanAccountActionsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoanAccountActionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,21 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
@Component({
selector: 'mifosx-loan-account-actions',
templateUrl: './loan-account-actions.component.html',
styleUrls: ['./loan-account-actions.component.scss']
})
export class LoanAccountActionsComponent {
/** flag object to store possible actions and render appropriate UI to the user */
actions: { close: boolean } = { close: false };
constructor(private router: Router,
private route: ActivatedRoute) {
this.route.params.subscribe(params => {
this.actions[params['action']] = true;
});
}
}
@@ -0,0 +1,35 @@
<div class="container">
<form [formGroup]="closeLoanForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Closed On</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="closedDatePicker" required formControlName="transactionDate">
<mat-datepicker-toggle matSuffix [for]="closedDatePicker"></mat-datepicker-toggle>
<mat-datepicker #closedDatePicker></mat-datepicker>
<mat-error *ngIf="closeLoanForm.controls.transactionDate.hasError('required')">
Closed 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]="['../general']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!closeLoanForm.valid">Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LoansAccountCloseComponent } from './loans-account-close.component';
describe('LoansAccountCloseComponent', () => {
let component: LoansAccountCloseComponent;
let fixture: ComponentFixture<LoansAccountCloseComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LoansAccountCloseComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoansAccountCloseComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,74 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { LoansService } from 'app/loans/loans.service';
import { DatePipe } from '@angular/common';
@Component({
selector: 'mifosx-loans-account-close',
templateUrl: './loans-account-close.component.html',
styleUrls: ['./loans-account-close.component.scss']
})
export class LoansAccountCloseComponent implements OnInit {
/** Close form. */
closeLoanForm: FormGroup;
/** Loan Id */
loanId: any;
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/**
* @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'];
}
/**
* Creates the close form.
*/
ngOnInit() {
this.createCloseForm();
}
/**
* Creates the create close form.
*/
createCloseForm() {
this.closeLoanForm = this.formBuilder.group({
'transactionDate': [new Date(), Validators.required],
'note': []
});
}
/**
* Submits the close form and creates a close,
* if successful redirects to view created close.
*/
submit() {
const transactionDate = this.closeLoanForm.value.transactionDate;
const dateFormat = 'yyyy-MM-dd';
this.closeLoanForm.patchValue({
transactionDate: this.datePipe.transform(transactionDate, dateFormat)
});
const closeForm = this.closeLoanForm.value;
closeForm.locale = 'en';
closeForm.dateFormat = dateFormat;
this.loanService.closeAccount(this.loanId, closeForm)
.subscribe((response: any) => {
this.router.navigate(['../general'], { relativeTo: this.route });
});
}
}