/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { Router , ActivatedRoute } from '@angular/router' ; /** Custom Services */ import { AccountingService } from '../accounting.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Periodic accruals component.
 */ @ Component ( { selector : 'mifosx-periodic-accruals' , templateUrl : './periodic-accruals.component.html' , styleUrls : [ './periodic-accruals.component.scss' ] } ) export class PeriodicAccrualsComponent implements OnInit { /** Minimum accrue date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum accrue date allowed. */ maxDate = new Date ( ) ; /** Periodic accruals form. */ periodicAccrualsForm : FormGroup ; 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 ) { } /**
     * Creates periodic accruals form.
     */ ngOnInit ( ) { this . createPeriodicAccrualsForm ( ) ; } /**
     * Creates periodic accruals form.
     */ createPeriodicAccrualsForm ( ) { this . periodicAccrualsForm = this . formBuilder . group ( { 'tillDate' : [ '' , Validators . required ] } ) ; } /**
     * Submits the periodic accruals form and executes periodic accruals,
     * if successful redirects to accounting.
     */ submit ( ) { const periodicAccruals = this . periodicAccrualsForm . value ; periodicAccruals . locale = this . settingsService . language . code ; periodicAccruals . dateFormat = this . settingsService . dateFormat ; if ( periodicAccruals . tillDate instanceof Date ) { let day = periodicAccruals . tillDate . getDate ( ) ; let month = periodicAccruals . tillDate . getMonth ( ) + 1 ; const year = periodicAccruals . tillDate . getFullYear ( ) ; if ( day < 10 ) { day = `0${ day }` ; } if ( month < 10 ) { month = `0${ month }` ; } periodicAccruals . tillDate = `${ year }-${ month }-${ day }` ; } this . accountingService . executePeriodicAccruals ( periodicAccruals ) . subscribe ( ( ) => { this . router . navigate ( [ '../' ] , { relativeTo : this . route } ) ; } ) ; } }