/** Angular Imports. */ import { Component , OnInit } from '@angular/core' ; import { FormGroup , FormBuilder , Validators , FormControl } from '@angular/forms' ; import { ActivatedRoute , Router } from '@angular/router' ; import { DatePipe } from '@angular/common' ; /** Custom Services. */ import { OrganizationService } from '../organization.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Bulk Loan Reassignment component.
 */ @ Component ( { selector : 'mifosx-bulk-loan-reassignmnet' , templateUrl : './bulk-loan-reassignmnet.component.html' , styleUrls : [ './bulk-loan-reassignmnet.component.scss' ] } ) export class BulkLoanReassignmnetComponent implements OnInit { /** Bulk Loan form. */ bulkLoanForm : FormGroup ; /** Office data. */ offices : any ; /** To Loan Officers. */ toLoanOfficers : any [ ] ; /** From Loan Offices. */ fromLoanOfficers : any [ ] ; /** Office Template. */ officeTemplate : any ; /** Officer Template. */ officerTemplate : any ; /** Loans. */ loans : any [ ] = new Array ( ) ; /** Minimum Date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum Date allowed. */ maxDate = new Date ( ) ; param { FormBuilder } formBuilder param { ActivatedRoute } route param { OrganizationService } organizationSevice param { SettingsService } settingsService param { Router } router constructor ( private formBuilder , private route , private organizationSevice , private settingsService , private datePipe , private router ) { this . route . data . subscribe ( ( data ) => { this . offices = data . offices ; } ) ; } ngOnInit ( ) { this . setBulkLoanForm ( ) ; } /**
     * Set Bulk Loan Form.
     */ setBulkLoanForm ( ) { this . bulkLoanForm = this . formBuilder . group ( { 'assignmentDate' : [ new Date ( ) , Validators . required ] , 'toLoanOfficerId' : [ '' , Validators . required ] } ) ; } param officeId getOffice ( officeId ) { this . organizationSevice . getOfficeTemplate ( officeId ) . subscribe ( ( response ) => { this . officeTemplate = response ; this . fromLoanOfficers = this . officeTemplate . loanOfficerOptions ; this . bulkLoanForm . addControl ( 'fromLoanOfficerId' , new FormControl ( '' , Validators . required ) ) ; } ) ; } param officerId getFromOfficers ( officerId ) { this . toLoanOfficers = this . fromLoanOfficers . filter ( ( officer ) => officer . id !== officerId ) ; console . log ( this . toLoanOfficers ) ; this . organizationSevice . getOfficerTemplate ( officerId , this . officeTemplate . id ) . subscribe ( ( response ) => { this . officerTemplate = response ; } ) ; } param event param loanId getLoans ( event , loanId ) { const isChecked = event . checked ; if ( isChecked ) { this . loans . push ( loanId ) ; } else { const index = this . loans . indexOf ( loanId , 0 ) ; this . loans . splice ( index , 1 ) ; } } /**
     * Submits bulk loan reassignment form.
     */ submit ( ) { const dateFormat = this . settingsService . dateFormat ; const assignmentDate = this . bulkLoanForm . value . assignmentDate ; this . bulkLoanForm . patchValue ( { assignmentDate : this . datePipe . transform ( assignmentDate , dateFormat ) } ) ; const bulkForm = this . bulkLoanForm . value ; bulkForm . locale = this . settingsService . language . code ; bulkForm . dateFormat = dateFormat ; bulkForm . loans = this . loans ; this . organizationSevice . createLoanReassignment ( bulkForm ) . subscribe ( ( response ) => { this . router . navigate ( [ '../' ] , { relativeTo : this . route } ) ; } ) ; } }