/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { FormBuilder , FormGroup , Validators } from '@angular/forms' ; import { Router , ActivatedRoute } from '@angular/router' ; /** Custom Services */ import { AccountingService } from '../../accounting.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Create closure component.
 */ @ Component ( { selector : 'mifosx-create-closure' , templateUrl : './create-closure.component.html' , styleUrls : [ './create-closure.component.scss' ] } ) export class CreateClosureComponent implements OnInit { /** Minimum closing date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum closing date allowed. */ maxDate = new Date ( ) ; /** Accounting closure form. */ accountingClosureForm : FormGroup ; /** Office data. */ officeData : any ; param { FormBuilder } formBuilder param { AccountingService } accountingService param { SettingsService } settingsService param { ActivatedRoute } route param { Router } router constructor ( private formBuilder , private accountingService , private settingsService , private route , private router ) { this . route . data . subscribe ( ( data ) => { this . officeData = data . offices ; } ) ; } /**
     * Creates the accounting closure form.
     */ ngOnInit ( ) { this . createAccountingClosureForm ( ) ; } /**
     * Creates the accounting closure form.
     */ createAccountingClosureForm ( ) { this . accountingClosureForm = this . formBuilder . group ( { 'officeId' : [ '' , Validators . required ] , 'closingDate' : [ '' , Validators . required ] , 'comments' : [ '' ] } ) ; } /**
     * Submits the accounting closure form and creates accounting closure,
     * if successful redirects to view created closure.
     */ submit ( ) { const accountingClosure = this . accountingClosureForm . value ; accountingClosure . locale = this . settingsService . language . code ; accountingClosure . dateFormat = this . settingsService . dateFormat ; if ( accountingClosure . closingDate instanceof Date ) { let day = accountingClosure . closingDate . getDate ( ) ; let month = accountingClosure . closingDate . getMonth ( ) + 1 ; const year = accountingClosure . closingDate . getFullYear ( ) ; if ( day < 10 ) { day = `0${ day }` ; } if ( month < 10 ) { month = `0${ month }` ; } accountingClosure . closingDate = `${ year }-${ month }-${ day }` ; } this . accountingService . createAccountingClosure ( accountingClosure ) . subscribe ( ( response ) => { this . router . navigate ( [ '../view' , response . resourceId ] , { relativeTo : this . route } ) ; } ) ; } }