feat: client actions (withdraw) (#1077)

Fixes: #1076
This commit is contained in:
Karan Takalkar
2020-07-13 15:45:20 +05:30
committed by GitHub
parent 9a6791d713
commit cdb6a46de7
10 changed files with 172 additions and 5 deletions
@@ -3,3 +3,4 @@
<mifosx-view-survey *ngIf="actions['Survey']"></mifosx-view-survey>
<mifosx-reject-client *ngIf="actions['Reject']"></mifosx-reject-client>
<mifosx-activate-client *ngIf="actions['Activate']"></mifosx-activate-client>
<mifosx-withdraw-client *ngIf="actions['Withdraw']"></mifosx-withdraw-client>
@@ -18,11 +18,13 @@ export class ClientActionsComponent {
'Close': boolean
'Reject': boolean
'Survey': boolean
'Withdraw': boolean
} = {
'Assign Staff': false,
'Close': false,
'Reject': false,
'Survey': false
'Survey': false,
'Withdraw': false
};
/**
@@ -0,0 +1,46 @@
<div class="container">
<mat-card>
<form [formGroup]="withdrawClientForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Withdrawal Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="withdrawalDatePicker" required formControlName="withdrawalDate">
<mat-datepicker-toggle matSuffix [for]="withdrawalDatePicker"></mat-datepicker-toggle>
<mat-datepicker #withdrawalDatePicker></mat-datepicker>
<mat-error *ngIf="withdrawClientForm.controls.withdrawalDate.hasError('required')">
Withdrawal Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Withdrawal Reason</mat-label>
<mat-select formControlName="withdrawalReasonId">
<mat-option *ngFor="let reason of withdrawalData" [value]="reason.id">
{{ reason.description }}
</mat-option>
</mat-select>
<mat-error *ngIf="withdrawClientForm.controls.withdrawalReasonId.hasError('required')">
Withdrawal 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="primary" [disabled]="!withdrawClientForm.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 { WithdrawClientComponent } from './withdraw-client.component';
describe('WithdrawClientComponent', () => {
let component: WithdrawClientComponent;
let fixture: ComponentFixture<WithdrawClientComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ WithdrawClientComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(WithdrawClientComponent);
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';
/**
* Withdraw Client Component
*/
@Component({
selector: 'mifosx-withdraw-client',
templateUrl: './withdraw-client.component.html',
styleUrls: ['./withdraw-client.component.scss']
})
export class WithdrawClientComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Withdraw Client form. */
withdrawClientForm: FormGroup;
/** Client Data */
withdrawalData: 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.withdrawalData = data.clientActionData.narrations;
});
this.clientId = this.route.parent.snapshot.params['clientId'];
}
ngOnInit() {
this.createWithdrawClientForm();
}
/**
* Creates the withdraw client form.
*/
createWithdrawClientForm() {
this.withdrawClientForm = this.formBuilder.group({
'withdrawalDate': ['', Validators.required],
'withdrawalReasonId': ['', Validators.required]
});
}
/**
* Submits the form and withdraws the client.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevWithdrawalDate: Date = this.withdrawClientForm.value.withdrawalDate;
this.withdrawClientForm.patchValue({
withdrawalDate: this.datePipe.transform(prevWithdrawalDate, dateFormat),
});
const data = {
...this.withdrawClientForm.value,
dateFormat,
locale
};
this.clientsService.executeClientCommand(this.clientId, 'withdraw', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -42,9 +42,10 @@
<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>
<span *ngIf="clientViewData.status.value === 'Pending'"><button mat-menu-item (click)="doAction('Activate')">Activate</button></span>
<button mat-menu-item (click)="doAction('Close')">Close</button>
<button mat-menu-item (click)="doAction('Survey')"> Survey</button>
<span *ngIf="clientViewData.status.value === 'Pending'"><button mat-menu-item (click)="doAction('Activate')">Activate</button></span>
<span *ngIf="clientViewData.status.value === 'Pending'"><button mat-menu-item (click)="doAction('Withdraw')">Withdraw</button></span>
<span *ngIf="clientViewData.status.value === 'Pending'"><button mat-menu-item (click)="doAction('Reject')">Reject</button></span>
<span *ngIf="clientViewData.status.value === 'Pending'"><button mat-menu-item (click)="doAction('Delete')">Delete</button></span>
</mat-menu>
@@ -56,6 +56,7 @@ export class ClientsViewComponent implements OnInit {
case 'Survey':
case 'Reject':
case 'Activate':
case 'Withdraw':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
+3 -1
View File
@@ -32,6 +32,7 @@ import { CloseClientComponent } from './clients-view/client-actions/close-client
import { ViewSurveyComponent } from './clients-view/client-actions/view-survey/view-survey.component';
import { RejectClientComponent } from './clients-view/client-actions/reject-client/reject-client.component';
import { ActivateClientComponent } from './clients-view/client-actions/activate-client/activate-client.component';
import { WithdrawClientComponent } from './clients-view/client-actions/withdraw-client/withdraw-client.component';
/**
@@ -69,7 +70,8 @@ import { ActivateClientComponent } from './clients-view/client-actions/activate-
CloseClientComponent,
ViewSurveyComponent,
RejectClientComponent,
ActivateClientComponent
ActivateClientComponent,
WithdrawClientComponent
],
entryComponents: [
UploadDocumentDialogComponent,
@@ -30,12 +30,14 @@ export class ClientActionsResolver implements Resolve<Object> {
switch (actionName) {
case 'Assign Staff':
return this.clientsService.getClientDataAndTemplate(clientId);
case 'Close':
return this.clientsService.getClientCommandTemplate('close');
case 'Survey':
return this.clientsService.getSurveys(clientId);
case 'Close':
return this.clientsService.getClientCommandTemplate('close');
case 'Reject':
return this.clientsService.getClientCommandTemplate('reject');
case 'Withdraw':
return this.clientsService.getClientCommandTemplate('withdraw');
default:
return undefined;
}