feat: add bulk loan reassignment component (#792)

Fixes: #754
This commit is contained in:
Benura Abeywardena
2020-08-02 11:51:56 +05:30
committed by GitHub
parent 6a47a69007
commit 780fc000cb
8 changed files with 358 additions and 2 deletions
@@ -0,0 +1,159 @@
<div class="container">
<mat-card>
<form [formGroup]="bulkLoanForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
<mat-form-field fxFlex="48%">
<mat-label>Office</mat-label>
<mat-select required (selectionChange)="getOffice($event.value)">
<mat-option *ngFor="let office of offices" [value]="office.id">
{{ office.name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
<mat-form-field fxFlex="48%">
<mat-label>Assignment Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="assignmentDatePicker" required formControlName="assignmentDate">
<mat-datepicker-toggle matSuffix [for]="assignmentDatePicker"></mat-datepicker-toggle>
<mat-datepicker #assignmentDatePicker></mat-datepicker>
<mat-error *ngIf="bulkLoanForm.controls.assignmentDate.hasError('required')">
Assignment Date <strong>is required</strong>
</mat-error>
</mat-form-field>
</div>
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
<mat-form-field fxFlex="48%" *ngIf="fromLoanOfficers !== undefined">
<mat-label>From loan officer</mat-label>
<mat-select required formControlName="fromLoanOfficerId" (selectionChange)="getFromOfficers($event.value)">
<mat-option *ngFor="let fromOfficers of fromLoanOfficers" [value]="fromOfficers.id">
{{ fromOfficers.displayName }}
</mat-option>
</mat-select>
<mat-error *ngIf="bulkLoanForm.controls.fromLoanOfficerId.hasError('required')">
From Loan Officer is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
<mat-form-field fxFlex="48%">
<mat-label>To loan officer</mat-label>
<mat-select required formControlName="toLoanOfficerId">
<mat-option *ngFor="let toOfficers of toLoanOfficers" [value]="toOfficers.id">
{{ toOfficers.displayName }}
</mat-option>
</mat-select>
<mat-error *ngIf="bulkLoanForm.controls.toLoanOfficerId.hasError('required')">
To Loan Officer is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
<table *ngIf="officerTemplate !== undefined" fxFlex="48%">
<thead>
<th> Clients </th>
</thead>
<tbody>
<tr *ngFor="let clients of officerTemplate.accountSummaryCollection.clients">
<table>
<tr>
<td> <strong> {{ clients.displayName }} </strong></td>
</tr>
<tr *ngFor="let loans of clients.loans">
<td>
<mat-checkbox (change)="getLoans($event,loans.id)">{{ loans.productName}}({{ loans.accountNo }})</mat-checkbox>
</td>
</tr>
</table>
</tr>
</tbody>
</table>
<table *ngIf="officerTemplate !== undefined" fxFlex="48%">
<thead>
<th> Groups </th>
</thead>
<tbody>
<tr *ngFor="let groups of officerTemplate.accountSummaryCollection.groups">
<table>
<tr>
<td> <strong> {{ groups.displayName }} </strong></td>
</tr>
<tr *ngFor="let loans of groups.loans">
<td>
<mat-checkbox>{{ loans.productName}}({{ loans.accountNo }})</mat-checkbox>
</td>
</tr>
</table>
</tr>
</tbody>
</table>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!bulkLoanForm.valid">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
table {
border: none;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BulkLoanReassignmnetComponent } from './bulk-loan-reassignmnet.component';
describe('BulkLoanReassignmnetComponent', () => {
let component: BulkLoanReassignmnetComponent;
let fixture: ComponentFixture<BulkLoanReassignmnetComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ BulkLoanReassignmnetComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(BulkLoanReassignmnetComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,126 @@
/** Angular Imports. */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services. */
import { OrganizationService } from '../organization.service';
/**
* Bulk Loan Reassignment component.
*/
@Component({
selector: 'mifosx-bulk-loan-reassignmnet',
templateUrl: './bulk-loan-reassignmnet.component.html',
styleUrls: ['./bulk-loan-reassignmnet.component.scss']
})
export class BulkLoanReassignmnetComponent implements OnInit {
/** Bulk Loan form. */
bulkLoanForm: FormGroup;
/** Office data. */
offices: any;
/** To Loan Officers. */
toLoanOfficers: any[];
/** From Loan Offices. */
fromLoanOfficers: any[];
/** Office Template. */
officeTemplate: any;
/** Officer Template. */
officerTemplate: any;
/** Loans. */
loans: any[] = new Array();
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/**
* Get Office data from `resolver`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private organizationSevice: OrganizationService,
private datePipe: DatePipe,
private router: Router) {
this.route.data.subscribe((data: { offices: any} ) => {
this.offices = data.offices;
});
}
ngOnInit() {
this.setBulkLoanForm();
}
/**
* Set Bulk Loan Form.
*/
setBulkLoanForm() {
this.bulkLoanForm = this.formBuilder.group({
'assignmentDate': [new Date(), Validators.required],
'toLoanOfficerId': ['', Validators.required]
});
}
/**
* Get Office template.
* @param officeId Office Id.
*/
getOffice(officeId: string) {
this.organizationSevice.getOfficeTemplate(officeId).subscribe((response: any) => {
this.officeTemplate = response;
this.fromLoanOfficers = this.officeTemplate.loanOfficerOptions;
this.bulkLoanForm.addControl('fromLoanOfficerId', new FormControl('', Validators.required));
});
}
/**
* Get From Officers.
* @param officerId Office Id.
*/
getFromOfficers(officerId: any) {
this.toLoanOfficers = this.fromLoanOfficers.filter((officer: any) => officer.id !== officerId );
console.log(this.toLoanOfficers);
this.organizationSevice.getOfficerTemplate(officerId, this.officeTemplate.id).subscribe((response: any) => {
this.officerTemplate = response;
});
}
/**
* Get all loans.
* @param event Mat Checkbox Event.
* @param loanId Loan Id.
*/
getLoans(event: any, loanId: any) {
const isChecked = event.checked;
if (isChecked) {
this.loans.push(loanId);
} else {
const index = this.loans.indexOf(loanId, 0);
this.loans.splice(index, 1);
}
}
/**
* Submits bulk loan reassignment form.
*/
submit() {
const dateFormat = 'yyyy-MM-dd';
const assignmentDate = this.bulkLoanForm.value.assignmentDate;
this.bulkLoanForm.patchValue({
assignmentDate: this.datePipe.transform(assignmentDate, dateFormat)
});
const bulkForm = this.bulkLoanForm.value;
bulkForm.locale = 'en';
bulkForm.dateFormat = dateFormat;
bulkForm.loans = this.loans;
this.organizationSevice.createLoanReassignment(bulkForm).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}