/** 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' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Create employee component.
 */ @ Component ( { selector : 'mifosx-create-employee' , templateUrl : './create-employee.component.html' , styleUrls : [ './create-employee.component.scss' ] } ) export class CreateEmployeeComponent implements OnInit { /** Minimum joining date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum joining date allowed. */ maxDate = new Date ( ) ; /** Employee form. */ employeeForm : FormGroup ; /** Office data. */ officeData : any ; param { FormBuilder } formBuilder param { OrganizationService } organizationService param { SettingsService } settingsService param { ActivatedRoute } route param { Router } router param { DatePipe } datePipe constructor ( private formBuilder , private organizationService , private settingsService , private route , private router , private datePipe ) { this . route . data . subscribe ( ( data ) => { this . officeData = data . offices ; } ) ; } /**
     * Creates the employee form.
     */ ngOnInit ( ) { this . createEmployeeForm ( ) ; } /**
     * Creates the employee form.
     */ createEmployeeForm ( ) { this . employeeForm = this . formBuilder . group ( { 'officeId' : [ '' , Validators . required ] , 'firstname' : [ '' , [ Validators . required , Validators . pattern ( '(^[A-z]).*' ) ] ] , 'lastname' : [ '' , [ Validators . required , Validators . pattern ( '(^[A-z]).*' ) ] ] , 'isLoanOfficer' : [ false ] , 'mobileNo' : [ '' ] , 'joiningDate' : [ '' , Validators . required ] , } ) ; } /**
     * Submits the employee form and creates employee,
     * if successful redirects to employees.
     */ submit ( ) { const prevJoiningDate = this . employeeForm . value . joiningDate ; const dateFormat = this . settingsService . dateFormat ; this . employeeForm . patchValue ( { joiningDate : this . datePipe . transform ( prevJoiningDate , dateFormat ) } ) ; const employee = this . employeeForm . value ; employee . locale = this . settingsService . language . code ; employee . dateFormat = dateFormat ; this . organizationService . createEmployee ( employee ) . subscribe ( ( response ) => { this . router . navigate ( [ '../' ] , { relativeTo : this . route } ) ; } ) ; } }