diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.html b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.html index 866e9d4c6..10d70f253 100755 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.html +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.html @@ -31,54 +31,67 @@
-
+
{{relation.controls.applicant_name.value | titlecase}} - - - - - - - Select - - {{comrelShip.name | titlecase}} - - - - - - - Select - - - {{rel | titlecase}} - - - - - - - - Select - - {{relShip.name | titlecase}} - - - -
- - +
+
+
+ + + Select + + + {{rel | titlecase}} + + + + + + Select + + {{relShip.name | titlecase}} + + + + + +
+
+
+ + + + + + Select + + {{comrelShip.name | titlecase}} + + + + + +
+
- - +
+ + +
diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.ts b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.ts index 4981b675a..6e38f395d 100755 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.ts +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/general-info/general-info.component.ts @@ -112,16 +112,54 @@ export class GeneralInfoComponent implements OnInit { } if(exist_applicant_relation.length > 0){ - exist_applicant_relation.forEach(val => { - relationControl.push(this.createApplicantRelation(val)); + exist_applicant_relation.forEach((val,key) => { + let control: any = this._generalForm.get('applicant_relation') as FormArray; + control.push(this.createApplicantRelation(val)); + control = control.controls[key].get('multiple_relation') as FormArray; + val.multiple_relation.forEach((firstInnerelement,firstInnerKey) => { + control.push(this.createMultipleRelation(firstInnerelement)); + let innerControl = this._generalForm.get('applicant_relation') as FormArray; + innerControl = innerControl.controls[key].get('multiple_relation') as FormArray; + innerControl = innerControl.controls[firstInnerKey].get('multiple_company_relation') as FormArray; + firstInnerelement.multiple_company_relation.forEach((secondInnerValue,secondInnerKey) => { + innerControl.push(this.createMultipleCompanyRelation(secondInnerValue)) + }); + + }); //push related to details - this.fetch_related_details.push(val.applicant_name); + this.fetch_related_details.push(val.applicant_name); }); } }, error => this.errorMessage = error); } + // check and uncheck function + checkboxChange(event, index, item) { + if(item.exist_status.value){ + let relationControl: any = this._generalForm.controls['applicant_relation']; + let applicant_details: any= {'pd_co_applicant_id':item.pd_co_applicant_id.value,'applicant_name':item.applicant_name.value,'applicant_relation_to':'','relation':'','company_name':item.company_name.value,'company_relation':''}; + relationControl.push(this.createApplicantRelation(applicant_details)); + relationControl = relationControl.controls[relationControl.controls.length-1].get('multiple_relation'); + relationControl.push(this.createMultipleRelation(applicant_details)) + relationControl = relationControl.controls[relationControl.controls.length-1].get('multiple_company_relation'); + relationControl.push(this.createMultipleCompanyRelation(applicant_details)) + // to push selected persons names + this.fetch_related_details.push(item.applicant_name.value); + + } + else { + if(item.pd_co_applicant_id.value!=0){ + let relationControl = this._generalForm.controls['applicant_relation']; + let pos_id = relationControl.value.map(e=> e.pd_co_applicant_id).indexOf(item.pd_co_applicant_id.value); + relationControl.removeAt(pos_id); + // remove related to details + let pos_name=this.fetch_related_details.indexOf(item.applicant_name.value); + this.fetch_related_details.splice(pos_name, 1); + } + } + } + // create applicant form array createApplicant(elementValue:any){ return this._fb.group({ @@ -137,34 +175,59 @@ export class GeneralInfoComponent implements OnInit { return this._fb.group({ pd_co_applicant_id: [elementValue.pd_co_applicant_id], applicant_name: [elementValue.applicant_name], - company_name: [elementValue.company_name,elementValue.company_name ? Validators.required : Validators.nullValidator], - company_relationship: [elementValue.company_relationship], - applicant_relation_to: [elementValue.applicant_relation_to, Validators.required], - relationship: [elementValue.relationship], + multiple_relation: this._fb.array([]), }); } - - // checkand un check function - checkboxChange(event, index, item) { - if(item.exist_status.value){ - let relationControl = this._generalForm.controls['applicant_relation']; - let applicant_details: any= {'pd_co_applicant_id':item.pd_co_applicant_id.value,'applicant_name':item.applicant_name.value,'applicant_relation_to':'','relation':'','company_name':item.company_name.value,'company_relation':''}; - relationControl.push(this.createApplicantRelation(applicant_details)); - // push related to details - this.fetch_related_details.push(item.applicant_name.value); - - } - else { - if(item.pd_co_applicant_id.value!=0){ - let relationControl = this._generalForm.controls['applicant_relation']; - let pos_id = relationControl.value.map(e=> e.pd_co_applicant_id).indexOf(item.pd_co_applicant_id.value); - relationControl.removeAt(pos_id); - // remove related to details - let pos_name=this.fetch_related_details.indexOf(item.applicant_name.value); - this.fetch_related_details.splice(pos_name, 1); - } + // create multiple relation details + createMultipleRelation(elementValue: any) { + return this._fb.group({ + applicant_relation_to: [elementValue.applicant_relation_to, Validators.required], + relationship: [elementValue.relationship], + multiple_company_relation : this._fb.array([]), + }); + } + + // add more relation + addMoreRelation(rindex,mindex) { + let control: any = this._generalForm.get('applicant_relation') as FormArray; + control = control.controls[rindex].get('multiple_relation') as FormArray; + let setValues: any = {applicant_relation_to :'',relationship:''} + control.push(this.createMultipleRelation(setValues)) + let setCompanyValue = {company_name :'',company_relationship:''}; + control = control.controls[control.controls.length-1].get('multiple_company_relation'); + control.push(this.createMultipleCompanyRelation(setCompanyValue)) + } + + // remove relation + removeRelation(rindex,mindex) { + let control: any = this._generalForm.get('applicant_relation') as FormArray; + control = control.controls[rindex].get('multiple_relation') as FormArray; + control.removeAt(mindex); + } + + // create multiple company relation + createMultipleCompanyRelation(elementValue: any) { + return this._fb.group({ + company_name: [elementValue.company_name,elementValue.company_name ? Validators.required : Validators.nullValidator], + company_relationship: [elementValue.company_relationship], + }); + } + // add more company relation + addMoreCompanyRelation(rindex,mindex,cindex) { + let control: any = this._generalForm.get('applicant_relation') as FormArray; + control = control.controls[rindex].get('multiple_relation') as FormArray; + control = control.controls[mindex].get('multiple_company_relation') as FormArray; + let setValues: any = {company_name :'',company_relationship:''} + control.push(this.createMultipleCompanyRelation(setValues)) + } + + // remove company relation + removeCompanyRelation(rindex,mindex,cindex) { + let control: any = this._generalForm.get('applicant_relation') as FormArray; + control = control.controls[rindex].get('multiple_relation') as FormArray; + control = control.controls[mindex].get('multiple_company_relation') as FormArray; + control.removeAt(cindex); } - } // add more applicant details addOtherApplicant() { @@ -176,10 +239,14 @@ export class GeneralInfoComponent implements OnInit { dialogRef.afterClosed() .subscribe(dataresult => { if(dataresult.data.length>0){ - let relationControl = this._generalForm.controls['applicant_relation']; dataresult.data.forEach(element => { - let applicant_details: any= {'pd_co_applicant_id':element.pd_co_applicant_id,'applicant_name':element.applicant_name,'applicant_relation_to':'','relation':'','company_name':element.company_name,'company_relation':''}; + let relationControl = this._generalForm.controls['applicant_relation']; + let applicant_details: any= {'pd_co_applicant_id':element.pd_co_applicant_id,'applicant_name':element.applicant_name,'applicant_relation_to':'','relation':'','company_name':element.company_name,'company_relation':''}; relationControl.push(this.createApplicantRelation(applicant_details)); + relationControl = relationControl.controls[relationControl.controls.length-1].get('multiple_relation'); + relationControl.push(this.createMultipleRelation(applicant_details)) + relationControl = relationControl.controls[relationControl.controls.length-1].get('multiple_company_relation'); + relationControl.push(this.createMultipleCompanyRelation(applicant_details)) // push related to details this.fetch_related_details.push(element.applicant_name); }); @@ -192,7 +259,6 @@ export class GeneralInfoComponent implements OnInit { // remove other details removeOthers(index, item: any){ - console.log(item) if(item.pd_co_applicant_id==0){ let relationControl = this._generalForm.controls['applicant_relation']; relationControl.removeAt(index); @@ -226,22 +292,22 @@ export class GeneralInfoComponent implements OnInit { } }); // this is for selected applicant relation - formData.applicant_relation.forEach((element,key) => { - applicantRelationList.push({ - "pd_co_applicant_id":element.pd_co_applicant_id, - "applicant_name":element.applicant_name, - "company_name":element.company_name, - "company_relationship":element.company_relationship, - "applicant_relation_to":element.applicant_relation_to, - "relationship":element.relationship, - }) - }); + // formData.applicant_relation.forEach((element,key) => { + // applicantRelationList.push({ + // "pd_co_applicant_id":element.pd_co_applicant_id, + // "applicant_name":element.applicant_name, + // "company_name":element.company_name, + // "company_relationship":element.company_relationship, + // "applicant_relation_to":element.applicant_relation_to, + // "relationship":element.relationship, + // }) + // }); saveRecords.pdid=formData.pdid; saveRecords.formid=formData.formid; saveRecords.general_remark=formData.general_remark; saveRecords.selected_applicant=applicantList; - saveRecords.applicant_relation=applicantRelationList; + saveRecords.applicant_relation=formData.applicant_relation; this._pd.savePDFormDetailsWithID(saveRecords).subscribe( dataresult => { if (dataresult.status == 200) {