/** Angular Imports */ import { Component , OnInit , Input } from '@angular/core' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { DatePipe } from '@angular/common' ; import { ActivatedRoute , Router } from '@angular/router' ; /** Custom Services */ import { SavingsService } from 'app/savings/savings.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Savings Account Assign Staff Component
 */ @ Component ( { selector : 'mifosx-savings-account-assign-staff' , templateUrl : './savings-account-assign-staff.component.html' , styleUrls : [ './savings-account-assign-staff.component.scss' ] } ) export class SavingsAccountAssignStaffComponent implements OnInit { /** Minimum date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum date allowed. */ maxDate = new Date ( ) ; /** Savings Account Assign Staff form. */ savingsAssignStaffForm : FormGroup ; /** Savings Account Id */ accountId : any ; /** Field Officer Data */ fieldOfficerData : any ; /** Savings Account Data */ savingsAccountData : any ; param { FormBuilder } formBuilder param { SavingsService } savingsService param { DatePipe } datePipe param { ActivatedRoute } route param { Router } router param { SettingsService } settingsService constructor ( private formBuilder , private savingsService , private datePipe , private route , private router , private settingsService ) { this . accountId = this . route . parent . snapshot . params [ 'savingAccountId' ] ; this . route . data . subscribe ( ( data ) => { this . savingsAccountData = data . savingsAccountActionData ; } ) ; } /**
     * Creates the savings account assign staff form.
     */ ngOnInit ( ) { this . fieldOfficerData = this . savingsAccountData . fieldOfficerOptions ; this . createSavingsAssignStaffForm ( ) ; } /**
     * Creates the savings account assign staff form.
     */ createSavingsAssignStaffForm ( ) { this . savingsAssignStaffForm = this . formBuilder . group ( { 'toSavingsOfficerId' : [ '' ] , 'assignmentDate' : [ '' , Validators . required ] } ) ; } /**
     * Submits the form and assigns staff the saving account,
     * if successful redirects to the saving account.
     */ submit ( ) { const locale = this . settingsService . language . code ; const dateFormat = this . settingsService . dateFormat ; const prevAssignmentDate = this . savingsAssignStaffForm . value . assignmentDate ; this . savingsAssignStaffForm . patchValue ( { assignmentDate : this . datePipe . transform ( prevAssignmentDate , dateFormat ) , } ) ; const data = { ... this . savingsAssignStaffForm . value , fromSavingsOfficerId : '' , dateFormat , locale } ; this . savingsService . executeSavingsAccountCommand ( this . accountId , 'assignSavingsOfficer' , data ) . subscribe ( ( ) => { this . router . navigate ( [ '../../' ] , { relativeTo : this . route } ) ; } ) ; } }