diff --git a/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.html b/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.html index cb9d38d8..371c2fca 100755 --- a/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.html +++ b/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.html @@ -363,17 +363,84 @@ No - + + Select {{a.name}} - - + --> + +
+ + +

Working Capital Facilities availed

+
+ +
+
+ {{entityType.controls.name.value}} +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.scss b/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.scss index 297dbd29..692a798e 100755 --- a/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.scss +++ b/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.scss @@ -65,5 +65,7 @@ page-pd-question-financial-info { height: 28px; } - + .toggle{ + padding: 1.4rem; + } } diff --git a/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.ts b/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.ts index 448ea85c..d7866e6e 100755 --- a/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.ts +++ b/src/pages/pd-question/pd-question-business-group/pd-question-financial-info/pd-question-financial-info.ts @@ -3,7 +3,7 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular'; import {AwsServiceProvider} from '../../../../providers/aws-service/aws-service' import {ToastProvider} from '../../../../providers/common-provider/toast' import {QuestionCategoryProvider} from '../../../../providers/question-category/question-category' -import { FormGroup,Validators,FormBuilder, FormArray } from '@angular/forms' +import { FormGroup,Validators,FormBuilder, FormArray, FormControl } from '@angular/forms' import {ConstantsProvider} from '../../../../providers/constants/constants' import {CameraProvider} from '../../../../providers/common-provider/camera' import {LoadingProvider} from '../../../../providers/common-provider/loading' @@ -231,10 +231,11 @@ this.complete_status = this.pdDetails.pd_status == 'COMPLETED' ? true : false; unsold_stock_lies_in_days:[''], is_there_working_capital_available:[''], working_capital_facilities_availed:[''], - reason_for_working_capital_facilities_availed:[''], + // reason_for_working_capital_facilities_availed:[''], // same_as_financial_statements:[''], date_per_financial: this.fb.array([]), - estimated_value: this.fb.array([]) + estimated_value: this.fb.array([]), + select_working_capital_facilities_availed : this.fb.array([]) }); } createDate(date){ @@ -340,6 +341,8 @@ submitDetails(){ //financeDate.push(this.createDate('')) const estimate= this.financialForm.controls['estimated_value'] //estimate.push(this.createValue('')) + const workingCptlControl = this.financialForm.controls['select_working_capital_facilities_availed']; + let params:any={} params.parent_pdid=this.pdDetails.parent_pd_id params.pd_id=this.pdDetails.pd_id @@ -399,15 +402,149 @@ submitDetails(){ retrieveData.company_id=this.company_id retrieveData.fk_createdby=this.users retrieveData.formid=this.FormId + let avData = this.av.map(item => ({ name: item.name, id: item.id })) + let exist_av_data: any = []; + + if (retrieveData.select_working_capital_facilities_availed) { + exist_av_data = Object.keys(retrieveData.select_working_capital_facilities_availed).map(function (key) { + return retrieveData.select_working_capital_facilities_availed[key].id; + }); + } + + let actual_av = avData.map(item => item.id); + let check_exist_av = actual_av.map((id, index) => { + if (exist_av_data.indexOf(id) < 0) { + avData[index].exist_status = 0; + return avData[index]; + } + else { + avData[index].exist_status = 1; + return avData[index]; + } + }).filter(item => item != undefined); + + if (check_exist_av.length > 0) { + check_exist_av.forEach(val => { + workingCptlControl.push(this.workingCptl(val)); + + if (val.exist_status == 1 && val.id == 2) { + this.financialForm.addControl('bank_guarantee', new FormControl('')); + } + if (val.exist_status == 1 && val.id == 3) { + this.financialForm.addControl('cash_credit_limit', new FormControl('')); + } + if (val.exist_status == 1 && val.id == 4) { + this.financialForm.addControl('factoring', new FormControl('')); + } + if (val.exist_status == 1 && val.id == 5) { + this.financialForm.addControl('forfaiting', new FormControl('')); + } + if (val.exist_status == 1 && val.id == 6) { + this.financialForm.addControl('letter_of_credit', new FormControl('')); + } + if (val.exist_status == 1 && val.id == 7) { + this.financialForm.addControl('od_limit', new FormControl('')); + } + if (val.exist_status == 1 && val.id == 1) { + this.financialForm.addControl('other_reason_for_working_capital_facilities_availed', new FormControl('')); + this.financialForm.addControl('reason_for_working_capital_facilities_availed', new FormControl('')); + } + console.log(val); + }); + console.log('check_exist_businees_activity',check_exist_av); + retrieveData.select_working_capital_facilities_availed = check_exist_av; + } + this.financialForm.setValue(retrieveData) } else { + let avData = this.av.map(item => ({ name: item.name, id: item.id })) + let exist_av_data: any = []; + + let actual_av = avData.map(item => item.id); + let check_exist_av = actual_av.map((id, index) => { + if (exist_av_data.indexOf(id) < 0) { + avData[index].exist_status = 0; + return avData[index]; + } + else { + avData[index].exist_status = 1; + return avData[index]; + } + }).filter(item => item != undefined); + + if (check_exist_av.length > 0) { + check_exist_av.forEach(val => { + workingCptlControl.push(this.workingCptl(val)); + }); + } //financial_date.push(this.createDate()); //estimated_val.push(this.createValue('')); } }) } + workingCptl(details: any): FormGroup { + return this.fb.group({ + id: [details.id, Validators.compose([Validators.required])], + name: [details.name, Validators.compose([Validators.required])], + exist_status: [details.exist_status == 1 ? true : false] + }); + } + +changeWorkingCapitalFacilities(event: any) { + console.log('event',event); + if (event.value.exist_status == true && event.value.id == 2) { + console.log('event.value.exist_status == true && event.value.id == 2',event.value.exist_status,event.value.id) + + this.financialForm.removeControl('bank_guarantee'); + } + else if (event.value.exist_status == false && event.value.id == 2) { + console.log('event.value.exist_status == true && event.value.id == 2',event.value.exist_status,event.value.id) + this.financialForm.addControl('bank_guarantee', new FormControl('')); + } + if (event.value.exist_status == true && event.value.id == 3) { + this.financialForm.removeControl('cash_credit_limit'); + } + else if (event.value.exist_status == false && event.value.id == 3) { + this.financialForm.addControl('cash_credit_limit', new FormControl('')); + } + if (event.value.exist_status == true && event.value.id == 4) { + this.financialForm.removeControl('factoring'); + } + else if (event.value.exist_status == false && event.value.id == 4) { + this.financialForm.addControl('factoring', new FormControl('')); + } + if (event.value.exist_status == true && event.value.id == 5) { + this.financialForm.removeControl('forfaiting'); + } + else if (event.value.exist_status == false && event.value.id == 5) { + this.financialForm.addControl('forfaiting', new FormControl('')); + } + if (event.value.exist_status == true && event.value.id == 6) { + this.financialForm.removeControl('letter_of_credit'); + } + else if (event.value.exist_status == false && event.value.id == 6) { + this.financialForm.addControl('letter_of_credit', new FormControl('')); + } + if (event.value.exist_status == true && event.value.id == 7) { + this.financialForm.removeControl('od_limit'); + } + else if (event.value.exist_status == false && event.value.id == 7) { + this.financialForm.addControl('od_limit', new FormControl('')); + } + if (event.value.exist_status == true && event.value.id == 1) { + this.financialForm.removeControl('other_reason_for_working_capital_facilities_availed'); + this.financialForm.removeControl('reason_for_working_capital_facilities_availed'); + } + else if (event.value.exist_status == false && event.value.id == 1) { + this.financialForm.addControl('other_reason_for_working_capital_facilities_availed', new FormControl('')); + this.financialForm.addControl('reason_for_working_capital_facilities_availed', new FormControl('')); + } + +} + + /** * New Calculation for Finanical Statement **/