feat: client actions (transfer) (#1081)

Fixes: #1080
This commit is contained in:
Karan Takalkar
2020-07-13 19:02:11 +05:30
committed by GitHub
parent 5541e1fe8d
commit 8dc254f491
11 changed files with 182 additions and 2 deletions
@@ -5,3 +5,4 @@
<mifosx-activate-client *ngIf="actions['Activate']"></mifosx-activate-client>
<mifosx-withdraw-client *ngIf="actions['Withdraw']"></mifosx-withdraw-client>
<mifosx-update-client-savings-account *ngIf="actions['Update Default Savings']"></mifosx-update-client-savings-account>
<mifosx-transfer-client *ngIf="actions['Transfer Client']"></mifosx-transfer-client>
@@ -20,13 +20,15 @@ export class ClientActionsComponent {
'Survey': boolean
'Withdraw': boolean
'Update Default Savings': boolean
'Transfer Client': boolean
} = {
'Assign Staff': false,
'Close': false,
'Reject': false,
'Survey': false,
'Withdraw': false,
'Update Default Savings': false
'Update Default Savings': false,
'Transfer Client': false
};
/**
@@ -0,0 +1,51 @@
<div class="container">
<mat-card>
<form [formGroup]="transferClientForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Office</mat-label>
<mat-select required formControlName="destinationOfficeId">
<mat-option *ngFor="let office of officeData" [value]="office.id">
{{ office.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="transferClientForm.controls.destinationOfficeId.hasError('required')">
Office is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Transfer Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="transferDatePicker" required formControlName="transferDate">
<mat-datepicker-toggle matSuffix [for]="transferDatePicker"></mat-datepicker-toggle>
<mat-datepicker #transferDatePicker></mat-datepicker>
<mat-error *ngIf="transferClientForm.controls.transferDate.hasError('required')">
Transfer Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Note</mat-label>
<textarea matInput formControlName="note"></textarea>
</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]="!transferClientForm.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 { TransferClientComponent } from './transfer-client.component';
describe('TransferClientComponent', () => {
let component: TransferClientComponent;
let fixture: ComponentFixture<TransferClientComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TransferClientComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TransferClientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,85 @@
/** 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';
/**
* Transfer Client Component
*/
@Component({
selector: 'mifosx-transfer-client',
templateUrl: './transfer-client.component.html',
styleUrls: ['./transfer-client.component.scss']
})
export class TransferClientComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Transfer Client form. */
transferClientForm: FormGroup;
/** Client Data */
officeData: 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.officeData = data.clientActionData;
});
this.clientId = this.route.parent.snapshot.params['clientId'];
}
ngOnInit() {
this.createTransferClientForm();
}
/**
* Creates the transfer client form.
*/
createTransferClientForm() {
this.transferClientForm = this.formBuilder.group({
'destinationOfficeId': ['', Validators.required],
'transferDate': ['', Validators.required],
'note': ['']
});
}
/**
* Submits the form and transfers the client.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevClosedDate: Date = this.transferClientForm.value.transferDate;
this.transferClientForm.patchValue({
transferDate: this.datePipe.transform(prevClosedDate, dateFormat),
});
const data = {
...this.transferClientForm.value,
dateFormat,
locale
};
this.clientsService.executeClientCommand(this.clientId, 'proposeTransfer', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -45,6 +45,7 @@
<button mat-menu-item (click)="doAction('Close')">Close</button>
<button mat-menu-item (click)="doAction('Survey')"> Survey</button>
<button mat-menu-item (click)="doAction('Update Default Savings')"> Update Default Savings </button>
<button mat-menu-item (click)="doAction('Transfer Client')"> Transfer Client </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>
@@ -58,6 +58,7 @@ export class ClientsViewComponent implements OnInit {
case 'Activate':
case 'Withdraw':
case 'Update Default Savings':
case 'Transfer Client':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
+3 -1
View File
@@ -35,6 +35,7 @@ import { ActivateClientComponent } from './clients-view/client-actions/activate-
import { WithdrawClientComponent } from './clients-view/client-actions/withdraw-client/withdraw-client.component';
import { TakeSurveyComponent } from './clients-view/client-actions/view-survey/take-survey/take-survey.component';
import { UpdateClientSavingsAccountComponent } from './clients-view/client-actions/update-client-savings-account/update-client-savings-account.component';
import { TransferClientComponent } from './clients-view/client-actions/transfer-client/transfer-client.component';
/**
@@ -75,7 +76,8 @@ import { UpdateClientSavingsAccountComponent } from './clients-view/client-actio
ActivateClientComponent,
WithdrawClientComponent,
TakeSurveyComponent,
UpdateClientSavingsAccountComponent
UpdateClientSavingsAccountComponent,
TransferClientComponent
],
entryComponents: [
UploadDocumentDialogComponent,
+7
View File
@@ -220,6 +220,13 @@ export class ClientsService {
return this.http.get(`/clients/template`, { params: httpParams });
}
/**
* @returns {Observable<any>} Offices data
*/
getOffices(): Observable<any> {
return this.http.get('/offices');
}
/**
* returns the list of survey data of the particular Client
* @param clientId
@@ -39,6 +39,8 @@ export class ClientActionsResolver implements Resolve<Object> {
return this.clientsService.getClientCommandTemplate('reject');
case 'Withdraw':
return this.clientsService.getClientCommandTemplate('withdraw');
case 'Transfer Client':
return this.clientsService.getOffices();
default:
return undefined;
}