/** 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 { SharesService } from 'app/shares/shares.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Apply Shares Component
 */ @ Component ( { selector : 'mifosx-apply-shares' , templateUrl : './apply-shares.component.html' , styleUrls : [ './apply-shares.component.scss' ] } ) export class ApplySharesComponent implements OnInit { /** Shares account data. */ sharesAccountData : any ; /** Minimum date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum date allowed. */ maxDate = new Date ( ) ; /** Apply Share Account form. */ applySharesForm : FormGroup ; /** Shares Account Id */ accountId : any ; param { FormBuilder } formBuilder param { SharesService } sharesService param { DatePipe } datePipe param { ActivatedRoute } route param { Router } router param { SettingsService } settingsService constructor ( private formBuilder , private sharesService , private datePipe , private route , private router , private settingsService ) { this . accountId = this . route . parent . snapshot . params [ 'shareAccountId' ] ; this . route . data . subscribe ( ( data ) => { this . sharesAccountData = data . shareAccountActionData ; } ) ; } /**
     * Creates the apply shares form.
     * Fetching data from service as action buttons malfunction
     * in clients view upon using a common resolver.
     */ ngOnInit ( ) { this . createApplySharesAccountForm ( ) ; this . applySharesForm . get ( 'unitPrice' ) . patchValue ( this . sharesAccountData . currentMarketPrice || '' ) ; } /**
     * Creates the apply shares form.
     */ createApplySharesAccountForm ( ) { this . applySharesForm = this . formBuilder . group ( { 'requestedDate' : [ '' , Validators . required ] , 'requestedShares' : [ '' , Validators . required ] , 'unitPrice' : [ { value : '' , disabled : true } ] } ) ; } /**
     * Submits the form and applies additional shares to the share account,
     * if successful redirects to the share account.
     */ submit ( ) { const locale = this . settingsService . language . code ; const dateFormat = this . settingsService . dateFormat ; const prevRequestedDate = this . applySharesForm . value . requestedDate ; this . applySharesForm . patchValue ( { requestedDate : this . datePipe . transform ( prevRequestedDate , dateFormat ) , } ) ; const data = { ... this . applySharesForm . value , unitPrice : this . applySharesForm . get ( 'unitPrice' ) . value , dateFormat , locale } ; this . sharesService . executeSharesAccountCommand ( this . accountId , 'applyadditionalshares' , data ) . subscribe ( ( ) => { this . router . navigate ( [ '../../' ] , { relativeTo : this . route } ) ; } ) ; } }