@@ -31,6 +31,7 @@ import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/
|
||||
import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component';
|
||||
import { HolidaysComponent } from './holidays/holidays.component';
|
||||
import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.component';
|
||||
import { CreateTellerComponent } from './tellers/create-teller/create-teller.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
|
||||
@@ -205,6 +206,14 @@ const routes: Routes = [
|
||||
tellers: TellersResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'create',
|
||||
component: CreateTellerComponent,
|
||||
data: { title: extract('Create Teller'), breadcrumb: 'Create' },
|
||||
resolve: {
|
||||
offices: OfficesResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: ViewTellerComponent,
|
||||
|
||||
@@ -30,6 +30,7 @@ import { EditOfficeComponent } from './offices/edit-office/edit-office.component
|
||||
import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component';
|
||||
import { HolidaysComponent } from './holidays/holidays.component';
|
||||
import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.component';
|
||||
import { CreateTellerComponent } from './tellers/create-teller/create-teller.component';
|
||||
|
||||
/**
|
||||
* Organization Module
|
||||
@@ -65,7 +66,8 @@ import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.c
|
||||
CreateAdhocQueryComponent,
|
||||
HolidaysComponent,
|
||||
EditOfficeComponent,
|
||||
EditEmployeeComponent
|
||||
EditEmployeeComponent,
|
||||
CreateTellerComponent
|
||||
]
|
||||
})
|
||||
export class OrganizationModule { }
|
||||
|
||||
@@ -159,6 +159,14 @@ export class OrganizationService {
|
||||
return this.http.delete(`/tellers/${tellerId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} teller Teller to be created.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
createTeller(teller: any): Observable<any> {
|
||||
return this.http.post('/tellers', teller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Payment Types data
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="tellerForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Teller Name</mat-label>
|
||||
<input matInput required formControlName="name">
|
||||
<mat-error *ngIf="tellerForm.controls.name.hasError('required')">
|
||||
Teller Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="tellerForm.controls.name.hasError('pattern')">
|
||||
Teller Name <strong>cannot</strong> begin with a special character or number
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Office</mat-label>
|
||||
<mat-select required formControlName="officeId">
|
||||
<mat-option *ngFor="let office of officeData" [value]="office.id">
|
||||
{{ office.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="tellerForm.controls.officeId.hasError('required')">
|
||||
Office is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Description</mat-label>
|
||||
<textarea matInput formControlName="description"></textarea>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Start Date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="startDatePicker" required formControlName="startDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="startDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #startDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="tellerForm.controls.startDate.hasError('required')">
|
||||
Start Date is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>End Date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="endDatePicker" formControlName="endDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="endDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #endDatePicker></mat-datepicker>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Status</mat-label>
|
||||
<mat-select required formControlName="status">
|
||||
<mat-option *ngFor="let tellerStatus of tellerStatusesData" [value]="tellerStatus.id">
|
||||
{{ tellerStatus.value }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="tellerForm.controls.status.hasError('required')">
|
||||
Status 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]="!tellerForm.valid">Submit</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 { CreateTellerComponent } from './create-teller.component';
|
||||
|
||||
describe('CreateTellerComponent', () => {
|
||||
let component: CreateTellerComponent;
|
||||
let fixture: ComponentFixture<CreateTellerComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CreateTellerComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateTellerComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { OrganizationService } from '../../organization.service';
|
||||
|
||||
/**
|
||||
* Create teller component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-create-teller',
|
||||
templateUrl: './create-teller.component.html',
|
||||
styleUrls: ['./create-teller.component.scss']
|
||||
})
|
||||
export class CreateTellerComponent implements OnInit {
|
||||
|
||||
/** Minimum date allowed. */
|
||||
minDate = new Date(2000, 0, 1);
|
||||
/** Maximum date allowed. */
|
||||
maxDate = new Date();
|
||||
/** Teller form. */
|
||||
tellerForm: FormGroup;
|
||||
/** Office data. */
|
||||
officeData: any;
|
||||
/** TellerStatuses data. */
|
||||
tellerStatusesData: any;
|
||||
|
||||
/**
|
||||
* Retrieves the offices data from `resolve`.
|
||||
* @param {FormBuilder} formBuilder Form Builder.
|
||||
* @param {OrganizationService} organizationService Organization Service.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
* @param {DatePipe} datePipe Date Pipe to format date.
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private organizationService: OrganizationService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private datePipe: DatePipe) {
|
||||
this.route.data.subscribe((data: { offices: any }) => {
|
||||
this.officeData = data.offices;
|
||||
});
|
||||
this.tellerStatusesData = [{'id': 300, 'code': '300', 'value': 'Active'},
|
||||
{'id': 400, 'code': '400', 'value': 'Inactive'}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the teller form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createTellerForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the teller form.
|
||||
*/
|
||||
createTellerForm() {
|
||||
this.tellerForm = this.formBuilder.group({
|
||||
'officeId': ['', Validators.required],
|
||||
'name': ['', [Validators.required, Validators.pattern('(^[A-z]).*')]],
|
||||
'description': [''],
|
||||
'startDate': ['', Validators.required],
|
||||
'endDate': [''],
|
||||
'status': ['', Validators.required],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the teller form and creates teller,
|
||||
* if successful redirects to tellers.
|
||||
*/
|
||||
submit() {
|
||||
const prevStartDate: Date = this.tellerForm.value.startDate;
|
||||
const prevEndDate: Date = this.tellerForm.value.endDate;
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = 'yyyy-MM-dd';
|
||||
this.tellerForm.patchValue({
|
||||
startDate: this.datePipe.transform(prevStartDate, dateFormat),
|
||||
endDate: this.datePipe.transform(prevEndDate, dateFormat)
|
||||
});
|
||||
const teller = this.tellerForm.value;
|
||||
teller.locale = 'en';
|
||||
teller.dateFormat = dateFormat;
|
||||
this.organizationService.createTeller(teller).subscribe((response: any) => {
|
||||
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
|
||||
<button mat-raised-button color="primary">
|
||||
<button mat-raised-button color="primary" [routerLink]="['create']">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Create Teller
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user