/** 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' ; /**
 * Create financial activity mapping component.
 */ @ Component ( { selector : 'mifosx-create-financial-activity-mapping' , templateUrl : './create-financial-activity-mapping.component.html' , styleUrls : [ './create-financial-activity-mapping.component.scss' ] } ) export class CreateFinancialActivityMappingComponent implements OnInit { /** Financial activity mapping form. */ financialActivityMappingForm : FormGroup ; /** GL Account options. */ glAccountOptions : any ; /** GL Account data. */ glAccountData : any ; /** Financial activity data. */ financialActivityData : any ; param { FormBuilder } formBuilder param { AccountingService } accountingService param { ActivatedRoute } route param { Router } router constructor ( private formBuilder , private accountingService , private route , private router ) { this . route . data . subscribe ( ( data ) => { this . glAccountOptions = data . financialActivityAccountsTemplate . glAccountOptions ; this . financialActivityData = data . financialActivityAccountsTemplate . financialActivityOptions ; } ) ; } /**
     * Creates the financial activity mapping form and sets the gl account data.
     */ ngOnInit ( ) { this . createFinancialActivityMappingForm ( ) ; this . setGlAccountData ( ) ; } /**
     * Creates the financial activity mapping form.
     */ createFinancialActivityMappingForm ( ) { this . financialActivityMappingForm = this . formBuilder . group ( { 'financialActivityId' : [ '' , Validators . required ] , 'glAccountId' : [ '' , Validators . required ] } ) ; } /**
     * Sets the gl account data on the basis of selected financial activity.
     */ setGlAccountData ( ) { this . financialActivityMappingForm . get ( 'financialActivityId' ) . valueChanges . subscribe ( financialActivityId => { switch ( financialActivityId ) { case 100 : case 101 : case 102 : case 103 : this . glAccountData = this . glAccountOptions . assetAccountOptions ; break ; case 200 : case 201 : this . glAccountData = this . glAccountOptions . liabilityAccountOptions ; break ; case 300 : this . glAccountData = this . glAccountOptions . equityAccountOptions ; break ; } } ) ; } /**
     * Submits the financial activity mapping form and creates financial activity account,
     * if successful redirects to view created account.
     */ submit ( ) { this . accountingService . createFinancialActivityAccount ( this . financialActivityMappingForm . value ) . subscribe ( ( response ) => { this . router . navigate ( [ '../view' , response . resourceId ] , { relativeTo : this . route } ) ; } ) ; } }