feat: client actions (close) (#1069)

Fixes: #1068
This commit is contained in:
Karan Takalkar
2020-07-13 11:55:03 +05:30
committed by GitHub
parent af32d481bf
commit 9d827c8500
11 changed files with 174 additions and 1 deletions
@@ -1 +1,3 @@
<mifosx-client-assign-staff *ngIf="actions['Assign Staff']"></mifosx-client-assign-staff>
<mifosx-close-client *ngIf="actions['Close']"></mifosx-close-client>
@@ -15,8 +15,10 @@ export class ClientActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Assign Staff': boolean
'Close': boolean
} = {
'Assign Staff': false,
'Close': false
};
/**
@@ -0,0 +1,46 @@
<div class="container">
<mat-card>
<form [formGroup]="closeClientForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Closed On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="closureDatePicker" required formControlName="closureDate">
<mat-datepicker-toggle matSuffix [for]="closureDatePicker"></mat-datepicker-toggle>
<mat-datepicker #closureDatePicker></mat-datepicker>
<mat-error *ngIf="closeClientForm.controls.closureDate.hasError('required')">
Closed On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Closure Reason</mat-label>
<mat-select formControlName="closureReasonId">
<mat-option *ngFor="let reason of closureData" [value]="reason.id">
{{ reason.description }}
</mat-option>
</mat-select>
<mat-error *ngIf="closeClientForm.controls.closureReasonId.hasError('required')">
Closure Reason is <strong>required</strong>
</mat-error>
</mat-form-field>
</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="warn" [disabled]="!closeClientForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CloseClientComponent } from './close-client.component';
describe('CloseClientComponent', () => {
let component: CloseClientComponent;
let fixture: ComponentFixture<CloseClientComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CloseClientComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CloseClientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,84 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { ClientsService } from 'app/clients/clients.service';
/**
* Close Client Component
*/
@Component({
selector: 'mifosx-close-client',
templateUrl: './close-client.component.html',
styleUrls: ['./close-client.component.scss']
})
export class CloseClientComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Close Share Account form. */
closeClientForm: FormGroup;
/** Client Data */
closureData: any;
/** Client Id */
clientId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {ClientsService} clientsService Clients Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private clientsService: ClientsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { clientActionData: any }) => {
this.closureData = data.clientActionData.narrations;
});
this.clientId = this.route.parent.snapshot.params['clientId'];
}
ngOnInit() {
this.createCloseClientForm();
}
/**
* Creates the close client form.
*/
createCloseClientForm() {
this.closeClientForm = this.formBuilder.group({
'closureDate': ['', Validators.required],
'closureReasonId': ['', Validators.required]
});
}
/**
* Submits the form and closes the client.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevClosedDate: Date = this.closeClientForm.value.closureDate;
this.closeClientForm.patchValue({
closureDate: this.datePipe.transform(prevClosedDate, dateFormat),
});
const data = {
...this.closeClientForm.value,
dateFormat,
locale
};
this.clientsService.executeClientCommand(this.clientId, 'close', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -42,6 +42,7 @@
<button mat-menu-item [routerLink]="['fixed-deposits-accounts', 'create-fixed-deposit-account']">New Fixed Deposits Account</button>
<span *ngIf="!clientViewData.staffId"><button mat-menu-item (click)="doAction('Assign Staff')">Assign Staff</button></span>
<span *ngIf="clientViewData.staffId"><button mat-menu-item (click)="doAction('Unassign Staff')">Unassign Staff</button></span>
<button mat-menu-item (click)="doAction('Close')">Close</button>
</mat-menu>
</mat-card-actions>
</mat-card-header>
@@ -51,6 +51,7 @@ export class ClientsViewComponent implements OnInit {
doAction(name: string) {
switch (name) {
case 'Assign Staff':
case 'Close':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
+3 -1
View File
@@ -28,6 +28,7 @@ import { ChargesOverviewComponent } from './clients-view/charges-overview/charge
import { ClientActionsComponent } from './clients-view/client-actions/client-actions.component';
import { ClientAssignStaffComponent } from './clients-view/client-actions/client-assign-staff/client-assign-staff.component';
import { UnassignStaffDialogComponent } from './clients-view/custom-dialogs/unassign-staff-dialog/unassign-staff-dialog.component';
import { CloseClientComponent } from './clients-view/client-actions/close-client/close-client.component';
/**
@@ -61,7 +62,8 @@ import { UnassignStaffDialogComponent } from './clients-view/custom-dialogs/unas
ChargesOverviewComponent,
ClientActionsComponent,
ClientAssignStaffComponent,
UnassignStaffDialogComponent
UnassignStaffDialogComponent,
CloseClientComponent
],
entryComponents: [
UploadDocumentDialogComponent,
+5
View File
@@ -218,4 +218,9 @@ export class ClientsService {
return this.http.post(`/clients/${clientId}`, data, { params: httpParams });
}
getClientCommandTemplate(command: string): Observable<any> {
const httpParams = new HttpParams().set('commandParam', command);
return this.http.get(`/clients/template`, { params: httpParams });
}
}
@@ -30,6 +30,8 @@ export class ClientActionsResolver implements Resolve<Object> {
switch (actionName) {
case 'Assign Staff':
return this.clientsService.getClientDataAndTemplate(clientId);
case 'Close':
return this.clientsService.getClientCommandTemplate('close');
default:
return undefined;
}