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 });
});
}
}
@@ -92,6 +92,7 @@ import { AdhocQueryAndTemplateResolver } from './adhoc-query/common-resolvers/ad
import { BulkImportResolver } from './bulk-import/bulk-import.resolver';
import { SmsCampaignTemplateResolver } from './sms-campaigns/common-resolvers/sms-campaign-template.resolver';
import { EntityDataTableChecksTemplateResolver } from './entity-data-table-checks/enitity-data-table-checks-template.resolver';
import { BulkLoanReassignmnetComponent } from './bulk-loan-reassignmnet/bulk-loan-reassignmnet.component';
/** Organization Routes */
const routes: Routes = [
@@ -491,6 +492,14 @@ const routes: Routes = [
passwordPreferencesTemplate: PasswordPreferencesTemplateResolver
}
},
{
path: 'bulkloan',
component: BulkLoanReassignmnetComponent,
data: { title: extract('Bulk Loan Reassignment'), breadcrumb: 'Bulk Loan Reasssignment' },
resolve: {
offices: OfficesResolver
}
},
{
path: 'entity-data-table-checks',
data: { title: extract('Entity Data Table Checks'), breadcrumb: 'Entity Data Table Checks' },
@@ -631,7 +640,8 @@ const routes: Routes = [
HolidayTemplateResolver,
BulkImportResolver,
HolidayResolver,
EntityDataTableChecksTemplateResolver
EntityDataTableChecksTemplateResolver,
LoanProvisioningCriteriasResolver
]
})
export class OrganizationRoutingModule { }
@@ -97,7 +97,7 @@
<p matLine>Funds are associated with loans</p>
</mat-list-item>
<mat-list-item>
<mat-list-item [routerLink]="['bulkloan']">
<mat-icon matListIcon>
<fa-icon icon="money-bill-alt" size="sm"></fa-icon>
</mat-icon>
@@ -63,6 +63,7 @@ import { EditCampaignComponent } from './sms-campaigns/edit-campaign/edit-campai
import { EditSmsCampaignStepComponent } from './sms-campaigns/sms-campaign-stepper/edit-sms-campaign-step/edit-sms-campaign-step.component';
import { EditBusinessRuleParametersComponent } from './sms-campaigns/sms-campaign-stepper/edit-sms-campaign-step/edit-business-rule-parameters/edit-business-rule-parameters.component';
import { CreateEnityDataTableChecksComponent } from './entity-data-table-checks/create-enity-data-table-checks/create-enity-data-table-checks.component';
import { BulkLoanReassignmnetComponent } from './bulk-loan-reassignmnet/bulk-loan-reassignmnet.component';
/**
* Organization Module
@@ -132,6 +133,7 @@ import { CreateEnityDataTableChecksComponent } from './entity-data-table-checks/
EditSmsCampaignStepComponent,
EditBusinessRuleParametersComponent,
CreateEnityDataTableChecksComponent,
BulkLoanReassignmnetComponent,
]
})
export class OrganizationModule { }
@@ -56,6 +56,37 @@ export class OrganizationService {
return this.http.get('/offices');
}
/**
* Get Office Template.
* @param {string} officeId Office Id of the office selected.
* @returns {Observable<any>} Office Template.
*/
getOfficeTemplate(officeId: string): Observable<any> {
const httpParams = new HttpParams().set('officeId', officeId.toString());
return this.http.get(`/loans/loanreassignment/template`, { params: httpParams });
}
/**
* Get Officer Template.
* @param officerId Officer Id.
* @param officeId Office Id.
*/
getOfficerTemplate(officerId: string, officeId: string): Observable<any> {
const httpParams = new HttpParams()
.set('fromLoanOfficerId', officerId.toString())
.set('officeId', officerId.toString());
return this.http.get('/loans/loanreassignment/template', { params: httpParams });
}
/**
* Bulk Loan Reassignment.
* @param loanData Load Data to be created.
* @returns {Observable<any>}
*/
createLoanReassignment(loanData: any): Observable<any> {
return this.http.post('/loans/loanreassignment', loanData);
}
/**
* @param {string} officeId Office ID of Office.
* @param {boolean} template