feat: add loan action (guarantors) (#1059)

- add view guarantor
 - add create guarantor
 - add view guarantor details
 - add delete guarantor
 - add recover from guarantor
 - add delete loan action

Fixes: #832, #246
This commit is contained in:
Muskan Khedia
2020-07-12 11:06:38 +05:30
committed by GitHub
parent e74fdcf27b
commit ff6ac7028e
30 changed files with 838 additions and 20 deletions
@@ -0,0 +1,100 @@
<div class="container">
<form [formGroup]="newGuarantorForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-checkbox labelPosition="before" formControlName="existingClient">
Existing Client
</mat-checkbox>
<ng-container *ngIf="!showClientDetailsForm">
<mat-form-field>
<mat-label>Name</mat-label>
<input matInput required formControlName="name" required>
<mat-error *ngIf="newGuarantorForm.controls.name.hasError('required')">
Name <strong>is required</strong>
</mat-error>
</mat-form-field>
</ng-container>
<mat-form-field>
<mat-label>Relationship</mat-label>
<mat-select formControlName="clientRelationshipTypeId">
<mat-option *ngFor="let relationType of relationTypes" [value]="relationType.id">
{{ relationType.name }}
</mat-option>
</mat-select>
</mat-form-field>
<ng-container *ngIf="showClientDetailsForm">
<mat-form-field>
<mat-label>First Name</mat-label>
<input matInput required formControlName="firstname" required>
<mat-error *ngIf="newGuarantorForm.controls.firstname.hasError('required')">
First Name <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Last Name</mat-label>
<input matInput required formControlName="lastname" required>
<mat-error *ngIf="newGuarantorForm.controls.lastname.hasError('required')">
Last Name <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Date Of Birth</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="dobDatePicker" formControlName="dob">
<mat-datepicker-toggle matSuffix [for]="dobDatePicker"></mat-datepicker-toggle>
<mat-datepicker #dobDatePicker></mat-datepicker>
</mat-form-field>
<mat-form-field>
<mat-label>Address Line 1</mat-label>
<input matInput formControlName="addressLine1">
</mat-form-field>
<mat-form-field>
<mat-label>Address Line 2</mat-label>
<input matInput formControlName="addressLine2">
</mat-form-field>
<mat-form-field>
<mat-label>City</mat-label>
<input matInput formControlName="city">
</mat-form-field>
<mat-form-field>
<mat-label>Zip</mat-label>
<input matInput formControlName="zip">
</mat-form-field>
<mat-form-field>
<mat-label>Mobile</mat-label>
<input type="number" matInput formControlName="mobileNumber">
</mat-form-field>
<mat-form-field>
<mat-label>Residence Phone #</mat-label>
<input type="number" matInput formControlName="housePhoneNumber">
</mat-form-field>
</ng-container>
</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]="!newGuarantorForm.valid"
*mifosxHasPermission="'CREATE_GUARANTOR'">Submit</button>
</mat-card-actions>
</mat-card-content>
</form>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateGuarantorComponent } from './create-guarantor.component';
describe('CreateGuarantorComponent', () => {
let component: CreateGuarantorComponent;
let fixture: ComponentFixture<CreateGuarantorComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateGuarantorComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreateGuarantorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,125 @@
/** Angular Imports */
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { LoansService } from 'app/loans/loans.service';
import { DatePipe } from '@angular/common';
/**
* Create Guarantor Action
*/
@Component({
selector: 'mifosx-create-guarantor',
templateUrl: './create-guarantor.component.html',
styleUrls: ['./create-guarantor.component.scss']
})
export class CreateGuarantorComponent implements OnInit {
@Input() dataObject: any;
/** New Guarantor Form */
newGuarantorForm: FormGroup;
/** Loan ID */
loanId: string;
/** Relation Types */
relationTypes: any;
/** Show Client Details Form */
showClientDetailsForm = false;
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/**
* @param {FormBuilder} formBuilder Form Builder.
* @param {LoansService} loanService Loan Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe.
*/
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.createNewGuarantorForm();
this.setNewGuarantorDetailsForm();
this.buildDependencies();
}
/** Create Guarantor Details Form */
createNewGuarantorForm() {
this.newGuarantorForm = this.formBuilder.group({
'existingClient': [''],
'name': ['', Validators.required],
'clientRelationshipTypeId': ['']
});
}
/** Sets Guarantor Details Form */
setNewGuarantorDetailsForm() {
this.relationTypes = this.dataObject.allowedClientRelationshipTypes;
this.newGuarantorForm.patchValue({
existingClient: true
});
}
/**
* Add guarantor detail fields to the UI.
*/
buildDependencies() {
this.newGuarantorForm.get('existingClient').valueChanges.subscribe(() => {
this.showClientDetailsForm = !this.showClientDetailsForm;
if (this.showClientDetailsForm) {
this.newGuarantorForm.addControl('firstname', new FormControl(''));
this.newGuarantorForm.addControl('lastname', new FormControl(''));
this.newGuarantorForm.addControl('dob', new FormControl(''));
this.newGuarantorForm.addControl('addressLine1', new FormControl(''));
this.newGuarantorForm.addControl('addressLine2', new FormControl(''));
this.newGuarantorForm.addControl('city', new FormControl(''));
this.newGuarantorForm.addControl('zip', new FormControl(''));
this.newGuarantorForm.addControl('mobileNumber', new FormControl(''));
this.newGuarantorForm.addControl('housePhoneNumber', new FormControl(''));
this.newGuarantorForm.removeControl('name');
} else {
this.newGuarantorForm.addControl('name', new FormControl(''));
this.newGuarantorForm.removeControl('firstname');
this.newGuarantorForm.removeControl('lastname');
this.newGuarantorForm.removeControl('dob');
this.newGuarantorForm.removeControl('addressLine1');
this.newGuarantorForm.removeControl('addressLine2');
this.newGuarantorForm.removeControl('city');
this.newGuarantorForm.removeControl('zip');
this.newGuarantorForm.removeControl('mobileNumber');
this.newGuarantorForm.removeControl('housePhoneNumber');
}
});
}
/** Submits the new guarantor details form */
submit() {
const prevdob: Date = this.newGuarantorForm.value.dob;
const guarantorTypeId: number = this.newGuarantorForm.value.existingClient ? this.dataObject.guarantorTypeOptions[0].id : this.dataObject.guarantorTypeOptions[2].id;
// TODO: Update once language and date settings are setup
const dateFormat = 'dd-MM-yyyy';
const locale = 'en';
const newGuarantorData = {
... this.newGuarantorForm.value,
dob: this.datePipe.transform(prevdob, dateFormat),
locale,
dateFormat,
guarantorTypeId
};
delete newGuarantorData.existingClient;
this.loanService.createNewGuarantor(this.loanId, newGuarantorData)
.subscribe((response: any) => {
this.router.navigate(['../general'], { relativeTo: this.route });
});
}
}