/** Angular Imports. */ import { Component , OnInit , Input } from '@angular/core' ; import { FormBuilder , Validators , FormGroup , FormControl } from '@angular/forms' ; import { ActivatedRoute , Router } from '@angular/router' ; import { DatePipe } from '@angular/common' ; /** Custom Service. */ import { LoansService } from 'app/loans/loans.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Disburse To Savings component.
 */ @ Component ( { selector : 'mifosx-disburse-loan-account' , templateUrl : './disburse-loan-account.component.html' , styleUrls : [ './disburse-loan-account.component.scss' ] } ) export class DisburseLoanAccountComponent implements OnInit { @ Input ( ) dataObject : any ; /** Minimum Date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum Date allowed. */ maxDate = new Date ( ) ; /** Disbursement Loan form. */ disbursementForm : FormGroup ; param { FormBuilder } formBuilder param { ActivatedRoute } route param { Router } router param { DatePipe } datePipe param { LoansService } loanService param { SettingsService } settingsService constructor ( private formBuilder , private route , private router , private datePipe , private loanService , private settingsService ) { } ngOnInit ( ) { this . setDisbursementToSavingsForm ( ) ; } /**
     * Set Disbursement Loan form.
     */ setDisbursementToSavingsForm ( ) { this . disbursementForm = this . formBuilder . group ( { 'actualDisbursementDate' : [ new Date ( ) , Validators . required ] , 'transactionAmount' : [ this . dataObject . amount , Validators . required ] , 'note' : [ '' , Validators . required ] } ) ; if ( this . dataObject . fixedEmiAmount !== null || this . dataObject . fixedEmiAmount !== undefined ) { this . disbursementForm . addControl ( 'fixedEmiAmount' , new FormControl ( this . dataObject . fixedEmiAmount , [ Validators . required ] ) ) ; } } /**
     * Submit Disburse Form.
     */ submit ( ) { const actualDisbursementDate = this . disbursementForm . value . actualDisbursementDate ; const dateFormat = this . settingsService . dateFormat ; this . disbursementForm . patchValue ( { actualDisbursementDate : this . datePipe . transform ( actualDisbursementDate , dateFormat ) } ) ; const loanId = this . route . parent . snapshot . params [ 'loanId' ] ; const disbursementForm = this . disbursementForm . value ; disbursementForm . locale = this . settingsService . language . code ; disbursementForm . dateFormat = dateFormat ; this . loanService . loanActionButtons ( loanId , 'disbursetosavings' , disbursementForm ) . subscribe ( ( response ) => { this . router . navigate ( [ '../../general' ] , { relativeTo : this . route } ) ; } ) ; } }