refactor: Loans Module (#1150)

Fixes: #1149
This commit is contained in:
Muskan Khedia
2020-07-22 20:32:55 +05:30
committed by GitHub
parent f618bb3cda
commit 55280eae2a
65 changed files with 622 additions and 470 deletions
@@ -5,32 +5,67 @@
<div fxLayout="column">
<mat-checkbox labelPosition="before" formControlName="existingClient">
Existing Client
</mat-checkbox>
<mat-checkbox labelPosition="before" formControlName="existingClient">
Existing Client
</mat-checkbox>
<ng-container *ngIf="!showClientDetailsForm">
<mat-form-field>
<mat-form-field fxFlex="30%">
<mat-label>Name</mat-label>
<input matInput required formControlName="name" required>
<input matInput formControlName="name" [matAutocomplete]="clientsAutocomplete">
<mat-error *ngIf="newGuarantorForm.controls.name.hasError('required')">
Name <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-autocomplete autoActiveFirstOption #clientsAutocomplete="matAutocomplete" [displayWith]="displayClient"
(optionSelected)='clientSelected($event.option.value)'>
<mat-option *ngFor="let client of clientsData" [value]="client">
{{ client.displayName }}
</mat-option>
</mat-autocomplete>
<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="accountOptions.length > 0">
<mat-form-field>
<mat-label>Account</mat-label>
<mat-select formControlName="savingsId">
<mat-option *ngFor="let accountOption of accountOptions" [value]="accountOption.id">
{{ accountOption.productName }} - {{ accountOption.accountNo }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field>
<mat-label>Amount</mat-label>
<input type="number" matInput required formControlName="amount" required>
</mat-form-field>
</ng-container>
</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>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>
<mat-form-field>
<mat-label>First Name</mat-label>
<input matInput required formControlName="firstname" required>
@@ -89,7 +124,7 @@
</div>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../general']">Cancel</button>
<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>
@@ -97,4 +132,25 @@
</mat-card-content>
</form>
</div>
<ng-container *ngIf="!(newGuarantorForm.controls.name === undefined)">
<div class="mat-table">
<div class="mat-header-row">
<div class="mat-header-cell">Client Details</div>
</div>
<div class="mat-row">
<div class="mat-cell">Name</div>
<div class="mat-cell">{{newGuarantorForm.controls.name.value.displayName}}</div>
</div>
<div class="mat-row">
<div class="mat-cell">Id</div>
<div class="mat-cell">{{newGuarantorForm.controls.name.value.id}}</div>
</div>
<div class="mat-row">
<div class="mat-cell">Office</div>
<div class="mat-cell">{{newGuarantorForm.controls.name.value.officeName}}</div>
</div>
</div>
</ng-container>
</div>
@@ -0,0 +1,31 @@
.container {
.mat-table {
display: block;
font-family: Tahoma, Verdana;
width: 100%;
}
.mat-row,
.mat-header-row {
display: flex;
border-bottom-width: 1px;
border-bottom-style: solid;
align-items: center;
min-height: 48px;
padding: 0 24px;
}
.mat-cell,
.mat-header-cell {
flex: 1;
overflow: hidden;
word-wrap: break-word;
}
h3 {
padding-left: 0;
margin-bottom: 0;
}
}
@@ -1,11 +1,12 @@
/** Angular Imports */
import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit, Input, AfterViewInit } 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';
import { ClientsService } from 'app/clients/clients.service';
/**
* Create Guarantor Action
@@ -15,7 +16,7 @@ import { DatePipe } from '@angular/common';
templateUrl: './create-guarantor.component.html',
styleUrls: ['./create-guarantor.component.scss']
})
export class CreateGuarantorComponent implements OnInit {
export class CreateGuarantorComponent implements OnInit, AfterViewInit {
@Input() dataObject: any;
/** New Guarantor Form */
@@ -30,6 +31,10 @@ export class CreateGuarantorComponent implements OnInit {
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Client data. */
clientsData: any = [];
/** Account Options */
accountOptions: any = [];
/**
* @param {FormBuilder} formBuilder Form Builder.
@@ -42,7 +47,8 @@ export class CreateGuarantorComponent implements OnInit {
private loanService: LoansService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
private datePipe: DatePipe,
private clientsService: ClientsService) {
this.loanId = this.route.parent.snapshot.params['loanId'];
}
@@ -57,7 +63,9 @@ export class CreateGuarantorComponent implements OnInit {
this.newGuarantorForm = this.formBuilder.group({
'existingClient': [''],
'name': ['', Validators.required],
'clientRelationshipTypeId': ['']
'clientRelationshipTypeId': [''],
'savingsId': [''],
'amount': ['']
});
}
@@ -86,8 +94,12 @@ export class CreateGuarantorComponent implements OnInit {
this.newGuarantorForm.addControl('mobileNumber', new FormControl(''));
this.newGuarantorForm.addControl('housePhoneNumber', new FormControl(''));
this.newGuarantorForm.removeControl('name');
this.newGuarantorForm.removeControl('savingsId');
this.newGuarantorForm.removeControl('amount');
} else {
this.newGuarantorForm.addControl('name', new FormControl(''));
this.newGuarantorForm.addControl('savingsId', new FormControl(''));
this.newGuarantorForm.addControl('amount', new FormControl(''));
this.newGuarantorForm.removeControl('firstname');
this.newGuarantorForm.removeControl('lastname');
this.newGuarantorForm.removeControl('dob');
@@ -101,6 +113,39 @@ export class CreateGuarantorComponent implements OnInit {
});
}
/**
* Subscribes to Clients search filter:
*/
ngAfterViewInit() {
if (this.newGuarantorForm.value.existingClient) {
this.newGuarantorForm.get('name').valueChanges.subscribe((value: string) => {
if (value.length >= 2) {
this.clientsService.getFilteredClients('displayName', 'ASC', true, value)
.subscribe((data: any) => {
this.clientsData = data.pageItems;
});
}
});
}
}
clientSelected(clientDetails: any){
console.log(clientDetails);
this.accountOptions = [];
this.loanService.guarantorAccountResource(this.loanId, clientDetails.id).subscribe((response: any) => {
this.accountOptions = response.accountLinkingOptions;
})
}
/**
* Displays Client name in form control input.
* @param {any} client Client data.
* @returns {string} Client name if valid otherwise undefined.
*/
displayClient(client: any): string | undefined {
return client ? client.displayName : undefined;
}
/** Submits the new guarantor details form */
submit() {
const prevdob: Date = this.newGuarantorForm.value.dob;
@@ -108,17 +153,25 @@ export class CreateGuarantorComponent implements OnInit {
// TODO: Update once language and date settings are setup
const dateFormat = 'dd-MM-yyyy';
const locale = 'en';
const newGuarantorData = {
let newGuarantorData = {
... this.newGuarantorForm.value,
dob: this.datePipe.transform(prevdob, dateFormat),
locale,
dateFormat,
guarantorTypeId
};
if(this.newGuarantorForm.value.existingClient) {
newGuarantorData['entityId'] = this.newGuarantorForm.controls.name.value.id;
} else {
newGuarantorData['dob'] = this.datePipe.transform(prevdob, dateFormat),
newGuarantorData['dateFormat'] = dateFormat
}
delete newGuarantorData.existingClient;
delete newGuarantorData.name;
this.loanService.createNewGuarantor(this.loanId, newGuarantorData)
.subscribe((response: any) => {
this.router.navigate(['../general'], { relativeTo: this.route });
this.router.navigate(['../../general'], { relativeTo: this.route });
});
}