/** 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 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 ; 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 ; } ) ; 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 = this . tellerForm . value . startDate ; const prevEndDate = this . tellerForm . value . endDate ; const dateFormat = this . settingsService . dateFormat ; this . tellerForm . patchValue ( { startDate : this . datePipe . transform ( prevStartDate , dateFormat ) , endDate : this . datePipe . transform ( prevEndDate , dateFormat ) } ) ; const teller = this . tellerForm . value ; teller . locale = this . settingsService . language . code ; teller . dateFormat = dateFormat ; this . organizationService . createTeller ( teller ) . subscribe ( ( response ) => { this . router . navigate ( [ '../' , response . resourceId ] , { relativeTo : this . route } ) ; } ) ; } }