/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { DatePipe } from '@angular/common' ; import { ActivatedRoute , Router } from '@angular/router' ; /** Custom Services */ import { GroupsService } from 'app/groups/groups.service' ; import { SettingsService } from 'app/settings/settings.service' ; /**
 * Close Group Component
 */ @ Component ( { selector : 'mifosx-close-group' , templateUrl : './close-group.component.html' , styleUrls : [ './close-group.component.scss' ] } ) export class CloseGroupComponent implements OnInit { /** Minimum date allowed. */ minDate = new Date ( 2000 , 0 , 1 ) ; /** Maximum date allowed. */ maxDate = new Date ( ) ; /** Close Group form. */ closeGroupForm : FormGroup ; /** Group Closure Data */ closureData : any ; /** Group Id */ groupId : any ; param { FormBuilder } formBuilder param { GroupsService } groupsService param { DatePipe } datePipe param { ActivatedRoute } route param { Router } router param { SettingsService } settingsService constructor ( private formBuilder , private groupsService , private datePipe , private route , private router , private settingsService ) { this . route . data . subscribe ( ( data ) => { this . closureData = data . groupActionData . closureReasons ; } ) ; this . groupId = this . route . parent . snapshot . params [ 'groupId' ] ; } ngOnInit ( ) { this . createCloseGroupForm ( ) ; } /**
     * Creates the close group form.
     */ createCloseGroupForm ( ) { this . closeGroupForm = this . formBuilder . group ( { 'closureDate' : [ '' , Validators . required ] , 'closureReasonId' : [ '' , Validators . required ] } ) ; } /**
     * Submits the form and closes the group.
     */ submit ( ) { const locale = this . settingsService . language . code ; const dateFormat = this . settingsService . dateFormat ; const prevClosedDate = this . closeGroupForm . value . closureDate ; this . closeGroupForm . patchValue ( { closureDate : this . datePipe . transform ( prevClosedDate , dateFormat ) , } ) ; const data = { ... this . closeGroupForm . value , dateFormat , locale } ; this . groupsService . executeGroupCommand ( this . groupId , 'close' , data ) . subscribe ( ( ) => { this . router . navigate ( [ '../../' ] , { relativeTo : this . route } ) ; } ) ; } }