diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.html b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.html index 0df28f78d..dbeb3d242 100755 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.html +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.html @@ -3,7 +3,8 @@

- {{main_applicant}} ({{lender_applicant_id}}), {{customer_segment_abbr}} - + {{main_applicant}} ({{lender_applicant_id}}), {{customer_segment_abbr}} - {{subproduct_abbr}}
{{pageTitle}}
@@ -19,210 +20,297 @@ -
-
- -
-
- -

Address Details {{i+1}}

-
- -
-
+ + +

Address Details

+
+ +
+
+
+
+
+
+
- - - Address Required - -
+ + + + Address Required + +
-
- - - Select - {{SL.name}} - - +
+ + + Select + {{SL.name}} + + - - - Select - {{CL.city_name}} - - + + + Select + {{CL.city_name}} + + - - - Select - {{PL.pincode}} - - + + + Select + {{PL.pincode}} + + - - - Pincode Required - + + + + + +
+
+
+
-
- - Is This Address PD is being done ? ( {{item.get('pd_is_done_on_initiated_address').value===true ? 'Yes' : 'No'}} ) - -
-
+
+
+ + Is this the address where PD is done ? ( + {{addressForm.controls['is_pd_done_on_initiated_address'].value===true ? 'Yes' : 'No'}} + ) + +
+
+
+ + +
+
+
+
+
+
-
- - - Alternative Address Required + + + Alternative Address Required -
- -
+
+ +
- + Select - {{SL.name}} + {{SL.name}} - + - + Select - {{CL.city_name}} + {{CL.city_name}} + - + - + Select - {{PL.pincode}} + {{PL.pincode}} + - - - - Pincode Required - -
-
- - - Reason Required + + + + +
+ +
+ + + + + Reason Required + +
- -
- - - Select - {{m_addressType.address_type}} - - - Address Type Required - - - - - Address Type Required - -
+
+
+
-
- - - Select - {{m_locality.locality_name}} - - - Locality Required - +
+
+ + + Select + + {{m_addressType.address_type}} + + + + Address Type Required - - - - - Locality Required - + - + + + Locality Required + + + -
+
+ +
+ + + Select + {{data.description}} + + + + Approach to PD Location Required + + + + + Select + {{data.rating}} + + + + Comment on Locality Required + +
+ +
+ + + + + + + Select + + {{uom.name}} + + + + + + + UOM Required + +
+
-
- - - Select - {{data.description}} - - - Approach to PD Location Required - - - - Select - {{data.rating}} - - - Comment on Locality Required - -
- - -
- - - - - - - Select - {{uom.name}} - - - - - - UOM Required - - -
- - -
- - - -
+
- -
-
+
+
+ - -
-
-
-
-
-
-
{{doc.document_name}} -
- + +
+
+
+
+
+
+
{{doc.document_name}} +
+ +
-
-
-
-
-
-
- - picture_as_pdf - {{doc.document_title}} - -
+
+
+
+
+
+ + picture_as_pdf + {{doc.document_title}} + +
+
-
- -

No Files

-
-
+ +

No Files

+
+ @@ -294,8 +390,8 @@
-
diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.ts b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.ts index 9b67278d2..43ba314a1 100755 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.ts +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/address/address.component.ts @@ -38,15 +38,9 @@ export class AddressComponent implements OnInit { parent_pdid: string; pdid: number; form_id: number; - // pdAddress: string; - // pdState: any; - // pdCity: any; - // pdPincode: any; - // pdOtherPincode: any; CustSegAbbr: any; - loadDataStatus: boolean = true; - placeholderName: any = []; + placeholderName: any = ''; /**Array declaration Of Dropdown */ locationdata: any = []; @@ -57,8 +51,8 @@ export class AddressComponent implements OnInit { pincodeData: any = []; cityData: any = []; uomData: any = []; - alertnativeCityData:any=[]; - alertnativePincodeData:any=[]; + alertnativeCityData: any = []; + alertnativePincodeData: any = []; addressesList: any = []; documentsAndFilesList: any = []; @@ -68,17 +62,6 @@ export class AddressComponent implements OnInit { private notifier: NotifierService; public addressForm: FormGroup; - // public address: AbstractControl; - // public addressType: AbstractControl; - // public state: AbstractControl; - // public city: AbstractControl; - // public pincode: AbstractControl; - // public locality: AbstractControl; - // public pdLocation: AbstractControl; - // public commentLocality: AbstractControl; - // public estArea: AbstractControl; - // public uom: AbstractControl; - /**Constructor of the class */ constructor(private el: ElementRef, notifier: NotifierService, private fb: FormBuilder, @@ -86,9 +69,10 @@ export class AddressComponent implements OnInit { private router: Router, private _pd: PdTrigerService, private dialogRef: MatDialogRef, - private titlecasePipe:TitleCasePipe, + private titlecasePipe: TitleCasePipe, private dialog: MatDialog, private imageRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public pd_all_details: any) { // console.log('pd_all_details',pd_all_details); this.parent_pdid = this.pd_all_details.pdmaster_details.parent_pd_id; @@ -118,187 +102,83 @@ export class AddressComponent implements OnInit { this.getMasterDetails('STATE', 6); let params: any = {}; - params.parent_pdid=this.parent_pdid; + params.parent_pdid = this.parent_pdid; params.pd_id = this.pdid; params.pd_form_id = '5'; - - this._pd.retriveForm(params).subscribe(data => { - const control = this.addressForm.controls['addresses']; - if (data.status == 200) { - // console.log('data.records',data.records); - // console.log('data.records.addresses',data.records.addresses); - if (data.records.addresses.length == 0) { - control.push(this.createAddresses(null)); - // this.loadPDAddressesDetails(); - } else { - data.records.addresses.forEach((datas, index) => { - let obj = { - 'address': this.transformName(datas.address), - 'address_type': datas.address_type.toString(), - 'address_type_others': datas.address_type_others, - 'state': datas.state, - 'city': datas.city, - 'citySearch':'', - 'stateSearch':'', - 'pinSearch':'', - 'pincode': datas.pincode, - 'pincode_others': datas.pincode_others, - 'locality': datas.locality, - 'locality_others': datas.locality_others, - 'pd_is_done_on_initiated_address':datas.pd_is_done_on_initiated_address !== null ? datas.pd_is_done_on_initiated_address : true, - // 'locality_mixuse': datas.locality_mixuse, - 'pd_location': datas.pd_location, - 'comment_locality': datas.comment_locality, - 'estimated_area': datas.estimated_area, - 'uom': datas.uom, - 'uom_others': datas.uom_others - } - this.getCityAndPincodeDetails(datas.state,index,1); - this.getOtherPincode(datas.pincode, index); - // this.alternativeAddress(datas.pd_is_done_on_initiated_address,index,2); - let selectedAddressType = this.addressData.filter(element => element.address_type_id == datas.address_type)[0]; - if(selectedAddressType){ - this.selectedAddressType(selectedAddressType.address_type, index); - } - if (datas.address_type == 1) { - this.selectedAddressType(datas.address_type_others, index); - } - - control.push(this.createAddresses(obj)); - - if(datas.pd_is_done_on_initiated_address === false){ - this.getCityAndPincodeDetails(datas.alternative_state,index,2); - console.log('datas.pd_is_done_on_initiated_address',datas.pd_is_done_on_initiated_address,index); - let ChildCtrl : any = control.controls[index]; - ChildCtrl.addControl('alternative_address', new FormControl(datas.alternative_address, Validators.required)); - ChildCtrl.addControl('alternative_state', new FormControl(datas.alternative_state)); - ChildCtrl.addControl('alternative_city', new FormControl(datas.alternative_city)); - ChildCtrl.addControl('alternative_pincode', new FormControl(datas.alternative_pincode)); - ChildCtrl.addControl('alternative_pincode_others', new FormControl(datas.alternative_pincode_others, Validators.required)); - // data.alternative_pincode == 1 - // ? ChildCtrl.addControl('alternative_pincode_others', new FormControl(data.alternative_pincode_others)) - // : ChildCtrl.removeControl('alternative_pincode_others'); - ChildCtrl.addControl('reason_for_alternative_address', new FormControl(datas.reason_for_alternative_address, Validators.required)); - } - }); - } - - - // this.addressForm.controls.address.setValue(data.records.address); - // this.addressForm.controls.state.setValue(data.records.state); - - // if (data.records.state != '') { - // this.getCityAndPincodeDetails(data.records.state); - // this.addressForm.controls.city.setValue(data.records.city); - // this.addressForm.controls.pincode.setValue(data.records.pincode); - // if (data.records.pincode == 1) { - // this.addressForm.controls.pincode_others.setValue(data.records.pincode_others); - // this.addressForm.controls.pincode_others.setValidators([Validators.required]); - // this.addressForm.controls.pincode_others.updateValueAndValidity(); - // } - // } - - // this.addressForm.controls.pd_location.setValue(data.records.pd_location); - // this.addressForm.controls.address_type.setValue(data.records.address_type); - - // let selectedAddressType = this.addressData.filter(element => element.address_type_id == data.records.address_type)[0]; - // this.selectedAddressType(selectedAddressType.address_type); - - // if (data.records.address_type == 1) { - // this.addressForm.controls.address_type_others.setValue(data.records.address_type_others); - // this.addressForm.controls.address_type_others.setValidators([Validators.required]); - // this.addressForm.controls.address_type_others.updateValueAndValidity(); - // this.selectedAddressType(data.records.address_type_others); - // } - - // this.addressForm.controls.comment_locality.setValue(data.records.comment_locality); - - // this.addressForm.controls.locality.setValue(data.records.locality); - - // if (data.records.locality == 1) { - // this.addressForm.controls.locality_others.setValue(data.records.locality_others); - // this.addressForm.controls.locality_others.setValidators([Validators.required]); - // this.addressForm.controls.locality_others.updateValueAndValidity(); - // } - // if (data.records.locality == 5) { - // this.addressForm.controls.locality_mixuse.setValue(data.records.locality_mixuse); - // this.addressForm.controls.locality_mixuse.setValidators([Validators.required]) - // this.addressForm.controls.locality_mixuse.updateValueAndValidity(); - // } - - // this.addressForm.controls.estimated_area.setValue(data.records.estimated_area); - // this.addressForm.controls.uom.setValue(data.records.uom); - // if (data.records.uom == 1) { - // this.addressForm.controls.uom_others.setValue(data.records.uom_others); - // this.addressForm.controls.uom_others.setValidators([Validators.required]) - // this.addressForm.controls.uom_others.updateValueAndValidity(); - // } - - this.addressForm.controls.address_form_remark.setValue(data.records.address_form_remark); - } - else { - this.loadPDAddressesDetails(); - } - // else { - // control.push(this.createAddresses(null)); - // } - }); - - this._pd.retriveFile(this.pdid,'5',null).subscribe(data => { - if (data.status == 200) { - if(data.records.length>0){ - data.records.forEach((val, index) => { - let splitted = val.pd_document_name.split("."); - let DocumentsAndFiles = { - 'document_name': val.pd_document_name, - 'document_title': val.pd_document_title, - 'document': val.doc_url, - 'document_type' : splitted[1] == 'pdf'?'pdf':'image' - } - this.documentsAndFilesList.push(DocumentsAndFiles); - }); - } - } - else{ - this.documentsAndFilesList = []; - } - }); + this.setAddressFromDatas(params); } loadPDAddressesDetails() { const control = this.addressForm.controls['addresses']; + this._pd.getAddressesDetails(this.pdid).subscribe( data => { if (data.status == 200) { - this.addressesList = data.records.filter(item => item.assigned_pd==this.pdid && item.isactive == 1); + this.addressesList = data.records.filter(item => item.assigned_pd == this.pdid && item.isactive == 1); if (this.addressesList.length > 0) { - this.addressesList.forEach((val, index) => { + this.addressesList.forEach((datas, index) => { + if (datas.address_type_others == "" || datas.address_type_others == null){ delete datas.address_type_others;} + if (datas.citySearch == "" || datas.citySearch == null){delete datas.citySearch;} + if (datas.locality_others == "" || datas.locality_others == null){delete datas.locality_others;} + if (datas.pinSearch == "" || datas.pinSearch == null){delete datas.pinSearch;} + if (datas.pincode_others == "" || datas.pincode_others == null){delete datas.pincode_others;} + if (datas.stateSearch == "" || datas.stateSearch == null){delete datas.stateSearch;} + if (datas.uom_others == "" || datas.uom_others == null){delete datas.uom_others;} + let obj = { - 'address': this.transformName(val.addressline1), - 'address_type': '', - 'address_type_others': '', - 'state': val.fk_state, - 'city': val.fk_city, - 'citySearch':'', - 'stateSearch':'', - 'pinSearch':'', - 'pincode': val.pincode_id, - 'pincode_others': val.other_pincode, - 'pd_is_done_on_initiated_address':true, - 'locality': '', - 'locality_others': '', - // 'locality_mixuse': '', - 'pd_location': '', - 'comment_locality': '', - 'estimated_area': '', - 'uom': '', - 'uom_others': '' + 'address': this.transformName(datas.addressline1), + 'state': datas.fk_state, + 'city': datas.fk_city, + 'pincode': datas.pincode_id, + 'pincode_others': datas.pincode_id == 1 ? datas.other_pincode :'', } - this.getCityAndPincodeDetails(val.fk_state,index,1); - this.getOtherPincode(val.pincode_id, index); + this.getCityAndPincodeDetails(datas.fk_state, index, 1); control.push(this.createAddresses(obj)); + // if(datas.pincode == 1) { + // let ChildCtrl: any = control.controls[index]; + // ChildCtrl.controls['pincode_others'].setValue(datas.pincode_others); + // ChildCtrl.controls['pincode_others'].updateValueAndValidity(); + // } + + + this.addressForm.controls.pd_location.setValue(datas.pd_location ? datas.pd_location : ''); + this.addressForm.controls.address_type.setValue(datas.address_type ? datas.address_type : ''); + if (datas.address_type) { + let selectedAddressType = this.addressData.filter(element => element.address_type_id == datas.address_type)[0]; + this.selectedAddressType(selectedAddressType.address_type); + this.setOthers(datas.address_type, '', 3); + if (datas.address_type == 1) { + this.addressForm.controls.address_type_others.setValue(datas.address_type_others); + this.selectedAddressType(datas.address_type_others); + } + } + + + this.addressForm.controls.comment_locality.setValue(datas.comment_locality ? datas.comment_locality : ''); + this.addressForm.controls.locality.setValue(datas.locality ? datas.locality : ''); + + if (datas.locality) { + + this.setOthers(datas.locality, '', 4); + + if (datas.locality == 1) { + this.addressForm.controls.locality_others.setValue(datas.locality_others); + } + } + + + this.addressForm.controls.estimated_area.setValue(datas.estimated_area ? datas.estimated_area : ''); + this.addressForm.controls.uom.setValue(datas.uom); + if (datas.uom) { + this.setOthers(datas.uom, '', 5); + if (data.records.uom == 1) { + this.addressForm.controls.uom_others.setValue(datas.uom_others); + } + } }); } + let initiated_address_check =data.records.hasOwnProperty('is_pd_done_on_initiated_address') ? data.records.is_pd_done_on_initiated_address : true ; + this.addressForm.controls.is_pd_done_on_initiated_address.setValue(initiated_address_check); this.addressForm.controls.address_form_remark.setValue(''); // else{ // control.push(this.createAddresses(null)); @@ -309,99 +189,72 @@ export class AddressComponent implements OnInit { // } }); } - // getM_Address_Type() { - // this._pd.getAllMasterDatas('ADDRESSTYPE').subscribe( - // data => { - // this.addressData = data.records.filter(data => data.isactive == 1); - // if(this.CustSegAbbr == 'SENP' || this.CustSegAbbr == 'SEP'){ - // let index1 = this.addressData.map(data => data.address_type).indexOf("Residence"); - // this.addressData.splice(index1, 1); - // let index2 = this.addressData.map(data => data.address_type).indexOf("Residence cum Office"); - // this.addressData.splice(index2, 1); - // } - // }) - // } + /** Address Form ELements */ public initAddressForm(): void { this.addressForm = this.fb.group({ addresses: this.fb.array([]), + is_pd_done_on_initiated_address: [true], + address_type: ['', Validators.compose([Validators.required])], + locality: ['', Validators.compose([Validators.required])], + locality_mixuse: [''], + pd_location: ['', Validators.compose([Validators.required])], + comment_locality: ['', Validators.compose([Validators.required])], + estimated_area: [''], + uom: [''], address_form_remark: [''] }); - // this.address = this.addressForm.controls['address']; - // this.state = this.addressForm.controls['state']; - // this.city = this.addressForm.controls['city']; - // this.pincode = this.addressForm.controls['pincode']; - // this.addressType = this.addressForm.controls['address_type']; - // this.locality = this.addressForm.controls['locality']; - // this.pdLocation = this.addressForm.controls['pd_location']; - // this.commentLocality = this.addressForm.controls['comment_locality']; - // this.estArea = this.addressForm.controls['estimated_area']; - // this.uom = this.addressForm.controls['uom']; } - // pdf(url){ - // this._pd.downloadPDF(url).subscribe(res => { - // const fileURL = URL.createObjectURL(res); - // window.open(fileURL, '_blank'); - // }); - // // this._pd.downloadPDF(url).subscribe(res => { - // // const fileURL = URL.createObjectURL(res); - // window.open(url, '_blank'); - // // }); - // } - pdf(fileURL){ + pdf(fileURL) { window.open(fileURL); } - /** FOR Adress */ + /** FOR Form Field For Address Array */ createAddresses(AddressDetails): FormGroup { - console.log(AddressDetails); if (AddressDetails != null) { - console.log(AddressDetails); return this.fb.group({ address: [this.transformName(AddressDetails.address), Validators.compose([Validators.required])], - address_type: [AddressDetails.address_type || '', Validators.compose([Validators.required])], - address_type_others: [AddressDetails.address_type_others], state: [AddressDetails.state], city: [AddressDetails.city], - citySearch:[''], - stateSearch:[''], - pinSearch:[''], pincode: [AddressDetails.pincode],/** ,Validators.compose([Validators.minLength(6),Validators.maxLength(6)]) */ pincode_others: [AddressDetails.pincode_others, Validators.compose([Validators.minLength(6), Validators.maxLength(6)])], - pd_is_done_on_initiated_address:[AddressDetails.pd_is_done_on_initiated_address], - locality: [AddressDetails.locality, Validators.compose([Validators.required])], - locality_others: [AddressDetails.locality_others], - // locality_mixuse: [AddressDetails.locality_mixuse], - pd_location: [AddressDetails.pd_location, Validators.compose([Validators.required])], - comment_locality: [AddressDetails.comment_locality, Validators.compose([Validators.required])], - estimated_area: [AddressDetails.estimated_area], - uom: [AddressDetails.uom], - uom_others: [AddressDetails.uom_others] }); } else { return this.fb.group({ address: ['', Validators.compose([Validators.required])], - address_type: ['', Validators.compose([Validators.required])], - address_type_others: [''], state: [''], city: [''], - citySearch:[''], - stateSearch:[''], - pinSearch:[''], pincode: [''], pincode_others: ['', Validators.compose([Validators.minLength(6), Validators.maxLength(6)])], - pd_is_done_on_initiated_address:[true], - locality: ['', Validators.compose([Validators.required])], - locality_others: [''], - // locality_mixuse: [''], - pd_location: ['', Validators.compose([Validators.required])], - comment_locality: ['', Validators.compose([Validators.required])], - estimated_area: [''], - uom: [''], - uom_others: [''] + }); + } + } + + /** FOR Form Field For Alternative Address Array */ + createAlternativeAddresses(AddressDetails): FormGroup { + if (AddressDetails != null) { + console.log('not null'); + return this.fb.group({ + alternative_address: [this.transformName(AddressDetails.alternative_address), Validators.compose([Validators.required])], + alternative_state: [AddressDetails.alternative_state], + alternative_city: [AddressDetails.alternative_city], + alternative_pincode: [AddressDetails.alternative_pincode], + alternative_pincode_others: [AddressDetails.alternative_pincode_others, Validators.compose([Validators.minLength(6), Validators.maxLength(6)])], + reason_for_alternative_address: [AddressDetails.reason_for_alternative_address, Validators.compose([Validators.required])], + }); + } + else if (AddressDetails == null) { + console.log('null'); + return this.fb.group({ + alternative_address: ['', Validators.compose([Validators.required])], + alternative_state: [''], + alternative_city: [''], + alternative_pincode: [''], + alternative_pincode_others:['', Validators.compose([Validators.minLength(6), Validators.maxLength(6)])], + reason_for_alternative_address: ['', Validators.compose([Validators.required])], }); } } @@ -445,105 +298,127 @@ export class AddressComponent implements OnInit { /** To Get City And Pincode Data For Address Form * Param 'stateID' -> selected StateId */ - getCityAndPincodeDetails(stateID: string, index,flag) { - - this._pd.getStateWiseCities(stateID).subscribe(data => { - if (data.status == 200) { - if(flag==1){ - this.cityData[index] = data.records.cities; - this.pincodeData[index] = data.records.pincode; - }else if(flag == 2){ - this.alertnativeCityData[index] = data.records.cities; - this.alertnativePincodeData[index] = data.records.pincode; - } + getCityAndPincodeDetails(stateID: string, index, flag) { + + this._pd.getStateWiseCities(stateID).subscribe(data => { + if (data.status == 200) { + if (flag == 1) { + this.cityData = data.records.cities; + this.pincodeData = data.records.pincode; + } else if (flag == 2) { + this.alertnativeCityData = data.records.cities; + this.alertnativePincodeData = data.records.pincode; } - }); + } + }); } - getOtherPincode(e, i) { this.otherPincodeFlag[i] = e == 1 ? true : false; } - transformName(vals){ return this.titlecasePipe.transform(vals); } + // getOtherPincode(e, i) { this.otherPincodeFlag[i] = e == 1 ? true : false; } + transformName(vals) { return this.titlecasePipe.transform(vals); } - alternativeAddress(e,i,flag){ - const control = this.addressForm.controls['addresses']; - let ChildCtrl : any = control.controls[i]; + // Add and Remove The Alternative-Address Form-Array + alternativeAddress(e) { + + if (e === false) { + // console.log('alternativeAddress',e); + this.addressForm.addControl('alternative_addresses', this.fb.array([])); + const alternative_address_control = this.addressForm.controls['alternative_addresses']; + alternative_address_control.push(this.createAlternativeAddresses(null)); + } + else if (e === true) { + // console.log('alternativeAddress',e); + this.addressForm.removeControl('alternative_addresses'); + } + } - if(e==false){ - if(flag==1){ - ChildCtrl.addControl('alternative_address', new FormControl('', Validators.required)); - ChildCtrl.addControl('alternative_state', new FormControl('')); - ChildCtrl.addControl('alternative_city', new FormControl('')); - ChildCtrl.addControl('alternative_pincode', new FormControl('')); - ChildCtrl.addControl('alternative_pincode_others', new FormControl('', Validators.required)); - ChildCtrl.addControl('reason_for_alternative_address', new FormControl('', Validators.required)); - } - } - else{ - ChildCtrl.removeControl('alternative_address'); - ChildCtrl.removeControl('alternative_state'); - ChildCtrl.removeControl('alternative_city'); - ChildCtrl.removeControl('alternative_pincode'); - ChildCtrl.removeControl('alternative_pincode_others'); - ChildCtrl.removeControl('reason_for_alternative_address'); - } - } + // Add and Remove The SpecifyOthers Field + setOthers(e, i, flag) { + switch (flag) { + case 1: + const control = this.addressForm.controls['addresses']; + let ChildCtrl: any = control.controls[i]; + e == 1 ? ChildCtrl.addControl('pincode_others', new FormControl('', Validators.required)) : ChildCtrl.removeControl('pincode_others'); + break; + case 2: + const alternative_address_control = this.addressForm.controls['alternative_addresses']; + let AltChildCtrl: any = alternative_address_control.controls[i]; + e == 1 ? AltChildCtrl.addControl('alternative_pincode_others', new FormControl('', Validators.required)) : AltChildCtrl.removeControl('alternative_pincode_others'); + break; + case 3: + e == 1 ? this.addressForm.addControl('address_type_others', new FormControl('', Validators.required)) : this.addressForm.removeControl('address_type_others'); + break; + case 4: + e == 1 ? this.addressForm.addControl('locality_others', new FormControl('', Validators.required)) : this.addressForm.removeControl('locality_others'); + break; + case 5: + e == 1 ? this.addressForm.addControl('uom_others', new FormControl('', Validators.required)) : this.addressForm.removeControl('uom_others'); + break; + } + } /** TO Save Address Forms Details*/ - onSubmit() { - - const control = this.addressForm.controls['addresses']; - let CtrlLength = control.controls.length; - if (CtrlLength > 0) { - let cnt = 0; - while(cnt < CtrlLength){ + onSubmitOLD() { - let ChildCtrl : any = control.controls[cnt] - console.log('ChildCtrl.controls.address.value',ChildCtrl.controls.address.value); - ChildCtrl.controls.address.value = this.transformName(ChildCtrl.controls.address.value); - console.log('ChildCtrl.controls.address.value',ChildCtrl.controls.address.value); - if(ChildCtrl.controls.address_type.value == 1){ - ChildCtrl.controls['address_type_others'].setValidators([Validators.required]);} - else{ - ChildCtrl.controls['address_type_others'].clearValidators(); - ChildCtrl.controls['address_type_others'].setValue(''); - } - ChildCtrl.controls['address_type_others'].updateValueAndValidity(); + const control = this.addressForm.controls['addresses']; + let CtrlLength = control.controls.length; + if (CtrlLength > 0) { + let cnt = 0; + while (cnt < CtrlLength) { - if(ChildCtrl.controls.locality.value == 1){ - ChildCtrl.controls['locality_others'].setValidators([Validators.required]);} - else{ ChildCtrl.controls['locality_others'].clearValidators(); - ChildCtrl.controls['locality_others'].setValue(''); - } - ChildCtrl.controls['locality_others'].updateValueAndValidity(); + let ChildCtrl: any = control.controls[cnt] - if(ChildCtrl.controls.pincode.value == 1){ - ChildCtrl.controls['pincode_others'].setValidators([Validators.required]);} - else{ ChildCtrl.controls['pincode_others'].clearValidators(); - ChildCtrl.controls['pincode_others'].setValue(''); - } - ChildCtrl.controls['pincode_others'].updateValueAndValidity(); + ChildCtrl.controls.address.value = this.transformName(ChildCtrl.controls.address.value); - if(ChildCtrl.controls.alternative_pincode){ - if(ChildCtrl.controls.alternative_pincode.value != 1){ - ChildCtrl.removeControl('alternative_pincode_others'); + if (ChildCtrl.controls.address_type.value == 1) { + ChildCtrl.controls['address_type_others'].setValidators([Validators.required]); + } + else { + ChildCtrl.controls['address_type_others'].clearValidators(); + ChildCtrl.controls['address_type_others'].setValue(''); + } + ChildCtrl.controls['address_type_others'].updateValueAndValidity(); + + if (ChildCtrl.controls.locality.value == 1) { + ChildCtrl.controls['locality_others'].setValidators([Validators.required]); + } + else { + ChildCtrl.controls['locality_others'].clearValidators(); + ChildCtrl.controls['locality_others'].setValue(''); + } + ChildCtrl.controls['locality_others'].updateValueAndValidity(); + + if (ChildCtrl.controls.pincode.value == 1) { + ChildCtrl.controls['pincode_others'].setValidators([Validators.required]); + } + else { + ChildCtrl.controls['pincode_others'].clearValidators(); + ChildCtrl.controls['pincode_others'].setValue(''); + } + ChildCtrl.controls['pincode_others'].updateValueAndValidity(); + + if (ChildCtrl.controls.alternative_pincode) { + if (ChildCtrl.controls.alternative_pincode.value != 1) { + ChildCtrl.removeControl('alternative_pincode_others'); + } + } + + // data.controls.locality.value == 5 + // ? this.addressForm.controls['locality_mixuse'].setValidators([Validators.required]) + // : this.addressForm.controls['locality_mixuse'].clearValidators(); + // this.addressForm.controls['locality_mixuse'].updateValueAndValidity(); + + if (ChildCtrl.controls.uom.value == 1) { + ChildCtrl.controls['uom_others'].setValidators([Validators.required]); + } + else { + ChildCtrl.controls['uom_others'].clearValidators(); + ChildCtrl.controls['uom_others'].setValue(''); + } + ChildCtrl.controls['uom_others'].updateValueAndValidity(); + cnt++; } } - // data.controls.locality.value == 5 - // ? this.addressForm.controls['locality_mixuse'].setValidators([Validators.required]) - // : this.addressForm.controls['locality_mixuse'].clearValidators(); - // this.addressForm.controls['locality_mixuse'].updateValueAndValidity(); - - if(ChildCtrl.controls.uom.value == 1){ - ChildCtrl.controls['uom_others'].setValidators([Validators.required]);} - else{ - ChildCtrl.controls['uom_others'].clearValidators(); - ChildCtrl.controls['uom_others'].setValue(''); - } - ChildCtrl.controls['uom_others'].updateValueAndValidity(); - cnt++; - } - } - if (!this.addressForm.valid) { this.validateAllFormFields(this.addressForm); this.notifier.notify('warning', 'Please Fill All Mandatory Fields.!'); @@ -563,7 +438,7 @@ export class AddressComponent implements OnInit { this.addressForm.controls.addresses.value records.address_form_remark = this.addressForm.controls.address_form_remark.value; records.pdid = this.pdid; - records.parent_pdid= this.parent_pdid; + records.parent_pdid = this.parent_pdid; records.formid = '5'; // records.fk_createdby = '250'; @@ -585,13 +460,111 @@ export class AddressComponent implements OnInit { this.notifier.notify('warning', 'Something Wents Wrong Try Again.!' + '-' + error.error_text + ' occur'); this.disableAfterSubmit = false; }); + + } + onSubmit() { + + if (!this.addressForm.valid) { + this.validateAllFormFields(this.addressForm); + this.notifier.notify('warning', 'Please Fill All Mandatory Fields.!'); + this.disableAfterSubmit = false; + return; + } + // else if (this.addressForm.value.address_form_remark == '') { + // this.notifier.notify('warning', 'Fill Remark!'); + // this.disableAfterSubmit = false; + // return; + // } + else { + // console.log('this.addressForm.controls.addresses.value;', this.addressForm.value); + + let records: any = {}; + + records.addresses = this.addressForm.controls.addresses.value; + records.is_pd_done_on_initiated_address = this.addressForm.controls.is_pd_done_on_initiated_address.value + + if (this.addressForm.controls.is_pd_done_on_initiated_address.value == true) { + if(records.addresses[0].pincode != 1){ + delete records.addresses[0].pincode_others + } + records.addresses[0].address_type = this.addressForm.controls.address_type.value; + if (this.addressForm.controls.address_type.value == 1) { + records.addresses[0].address_type_others = this.addressForm.controls.address_type_others.value; + } + records.addresses[0].locality = this.addressForm.controls.locality.value; + if (this.addressForm.controls.locality.value == 1) { + records.addresses[0].locality_others = this.addressForm.controls.locality_others.value; + } + records.addresses[0].locality_mixuse = this.addressForm.controls.locality_mixuse.value; + records.addresses[0].pd_location = this.addressForm.controls.pd_location.value; + records.addresses[0].comment_locality = this.addressForm.controls.comment_locality.value; + records.addresses[0].estimated_area = this.addressForm.controls.estimated_area.value; + records.addresses[0].uom = this.addressForm.controls.uom.value; + records.addresses[0].citySearch = ''; + records.addresses[0].pinSearch = ''; + records.addresses[0].stateSearch = ''; + if (this.addressForm.controls.uom.value == 1) { + records.addresses[0].uom_others = this.addressForm.controls.uom_others.value; + } + } + else if (this.addressForm.controls.is_pd_done_on_initiated_address.value == false) { + records.alternative_addresses = this.addressForm.controls.alternative_addresses.value; + records.alternative_addresses[0].address_type = this.addressForm.controls.address_type.value; + if(records.addresses[0].alternative_pincode != 1){ + delete records.addresses[0].alternative_pincode_others + } + if (this.addressForm.controls.address_type.value == 1) { + records.alternative_addresses[0].address_type_others = this.addressForm.controls.address_type_others.value; + } + records.alternative_addresses[0].locality = this.addressForm.controls.locality.value; + if (this.addressForm.controls.locality.value == 1) { + records.alternative_addresses[0].locality_others = this.addressForm.controls.locality_others.value; + } + records.alternative_addresses[0].locality_mixuse = this.addressForm.controls.locality_mixuse.value; + records.alternative_addresses[0].pd_location = this.addressForm.controls.pd_location.value; + records.alternative_addresses[0].comment_locality = this.addressForm.controls.comment_locality.value; + records.alternative_addresses[0].estimated_area = this.addressForm.controls.estimated_area.value; + records.alternative_addresses[0].uom = this.addressForm.controls.uom.value; + records.alternative_addresses[0].citySearch = ''; + records.alternative_addresses[0].pinSearch = ''; + records.alternative_addresses[0].stateSearch = ''; + if (this.addressForm.controls.uom.value == 1) { + records.alternative_addresses[0].uom_others = this.addressForm.controls.uom_others.value; + } + } + records.address_form_remark = this.addressForm.controls.address_form_remark.value; + records.pdid = this.pdid; + records.parent_pdid = this.parent_pdid; + records.formid = '5'; + + // console.log('Final records', records); + + this.disableAfterSubmit = true; + + this._pd.saveForm(records).subscribe(data => { + if (data.status == 200) { + this.notifier.notify('success', 'Saved Successfully.'); + setTimeout(() => { + this.dialogRef.close(); + this.disableAfterSubmit = false; + }, 3000); + } + else { + this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + this.disableAfterSubmit = false; + } + }, error => { + this.notifier.notify('warning', 'Something Wents Wrong Try Again.!' + '-' + error.error_text + ' occur'); + this.disableAfterSubmit = false; + }); + } + } /** For PlaceHolder * selected AddressType is concate with label */ - selectedAddressType(e: any, i) { - - this.placeholderName[i] = 'Estimated area of the ' + e; + selectedAddressType(e: any) { + this.placeholderName = 'Estimated area of the ' + e; } @@ -601,13 +574,13 @@ export class AddressComponent implements OnInit { const control = formGroup.get(field); if (control instanceof FormControl) { control.markAsTouched({ onlySelf: true }); - } else if (control instanceof FormGroup) { + } else if (control instanceof FormGroup) { this.validateAllFormFields(control); - } else if (control instanceof FormArray) { + } else if (control instanceof FormArray) { this.validateAllFormFields(control); } }); - } + } /** For DOCS Tab */ public viewerOptions: any = { @@ -630,44 +603,186 @@ export class AddressComponent implements OnInit { } }; - imageCrop(pic){ + imageCrop(pic) { // let arr = { 'pic_name':pic_name,'pic':pic,'from_id':this.form_id} const imageRef = this.dialog.open(ImageCropComponent, { - data: pic, + data: pic, }); imageRef.afterClosed() - .subscribe(dataresult => { - console.log(dataresult); + .subscribe(dataresult => { + console.log(dataresult); + }); + } + + setAddressFromDatas(params){ + this._pd.retriveForm(params).subscribe(data => { + + const control = this.addressForm.controls['addresses']; + if (data.status == 200) { + let initiated_address_check =data.records.hasOwnProperty('is_pd_done_on_initiated_address') ? data.records.is_pd_done_on_initiated_address : true ; + this.addressForm.controls.is_pd_done_on_initiated_address.setValue(initiated_address_check); + if (data.records.addresses.length == 0) { + control.push(this.createAddresses(null)); + } else { + data.records.addresses.forEach((datas, index) => { + let obj = { + 'address': this.transformName(datas.address), + 'state': datas.state, + 'city': datas.city, + 'pincode': datas.pincode, + 'pincode_others': datas.pincode ? datas.pincode_others : '' + } + this.getCityAndPincodeDetails(datas.state, index, 1); + control.push(this.createAddresses(obj)); + + if (datas.address_type_others == "" || datas.address_type_others == null){ + delete datas.address_type_others; + } + + if (datas.citySearch == "" || datas.citySearch == null){ + delete datas.citySearch; + } + + if (datas.locality_others == "" || datas.locality_others == null){ + delete datas.locality_others; + } + if (datas.pinSearch == "" || datas.pinSearch == null){ + delete datas.pinSearch; + } + if (datas.pincode_others == "" || datas.pincode_others == null){ + delete datas.pincode_others; + } + if (datas.stateSearch == "" || datas.stateSearch == null){ + delete datas.stateSearch; + } + if (datas.uom_others == "" || datas.uom_others == null){ + delete datas.uom_others; + } + + if (initiated_address_check === true) { + + this.addressForm.controls.pd_location.setValue(datas.pd_location ? datas.pd_location : ''); + this.addressForm.controls.address_type.setValue(datas.address_type ? datas.address_type : ''); + + let selectedAddressType = this.addressData.filter(element => element.address_type_id == datas.address_type)[0]; + this.selectedAddressType(selectedAddressType.address_type); + this.setOthers(datas.address_type, '', 3); + + if (datas.address_type == 1) { + this.addressForm.controls.address_type_others.setValue(datas.address_type_others); + this.selectedAddressType(datas.address_type_others); + } + + this.addressForm.controls.comment_locality.setValue(datas.comment_locality ? datas.comment_locality : ''); + this.addressForm.controls.locality.setValue(datas.locality ? datas.locality : ''); + + this.setOthers(datas.locality, '', 4); + + if (datas.locality == 1) { + this.addressForm.controls.locality_others.setValue(datas.locality_others); + } + + this.addressForm.controls.estimated_area.setValue(datas.estimated_area ? datas.estimated_area : ''); + this.addressForm.controls.uom.setValue(datas.uom); + + this.setOthers(datas.uom, '', 5); + if (data.records.uom == 1) { + this.addressForm.controls.uom_others.setValue(datas.uom_others); + } + } + }); + } + + if (initiated_address_check == false) { + + this.addressForm.addControl('alternative_addresses', this.fb.array([])); + const alternative_address_control = this.addressForm.controls['alternative_addresses']; + if (data.records.alternative_addresses.length > 0) { + + data.records.alternative_addresses.forEach((datas, index) => { + + if (datas.citySearch == "" || datas.citySearch == null){ + delete datas.citySearch; + } + if (datas.pinSearch == "" || datas.pinSearch == null){ + delete datas.pinSearch; + } + if (datas.stateSearch == "" || datas.stateSearch == null){ + delete datas.stateSearch; + } + + let obj = { + 'alternative_address': this.transformName(datas.alternative_address), + 'alternative_state': datas.alternative_state, + 'alternative_city': datas.alternative_city, + 'alternative_pincode': datas.alternative_pincode, + 'alternative_pincode_others': datas.alternative_pincode == 1 ? datas.alternative_pincode_others : '', + 'reason_for_alternative_address': datas.reason_for_alternative_address, + } + this.getCityAndPincodeDetails(datas.alternative_state, index, 2); + alternative_address_control.push(this.createAlternativeAddresses(obj)); + + this.addressForm.controls.pd_location.setValue(datas.pd_location); + this.addressForm.controls.address_type.setValue(datas.address_type); + + let selectedAddressType = this.addressData.filter(element => element.address_type_id == datas.address_type)[0]; + this.selectedAddressType(selectedAddressType.address_type); + + this.setOthers(datas.address_type, '', 3); + + if (datas.address_type == 1) { + this.addressForm.controls.address_type_others.setValue(datas.address_type_others); + this.selectedAddressType(datas.address_type_others); + } + + this.addressForm.controls.comment_locality.setValue(datas.comment_locality); + + this.addressForm.controls.locality.setValue(datas.locality); + this.setOthers(datas.locality, '', 4); + + if (datas.locality == 1) { + this.addressForm.controls.locality_others.setValue(datas.locality_others); + } + + this.addressForm.controls.estimated_area.setValue(datas.estimated_area); + this.addressForm.controls.uom.setValue(datas.uom); + this.setOthers(datas.uom, '', 5); + if (data.records.uom == 1) { + this.addressForm.controls.uom_others.setValue(datas.uom_others); + } + + }); + } + } + this.addressForm.controls.address_form_remark.setValue(data.records.address_form_remark); + } + else { + this.loadPDAddressesDetails(); + } + // else { + // control.push(this.createAddresses(null)); + // } + }); + + this._pd.retriveFile(this.pdid, '5', null).subscribe(data => { + if (data.status == 200) { + if (data.records.length > 0) { + data.records.forEach((val, index) => { + let splitted = val.pd_document_name.split("."); + let DocumentsAndFiles = { + 'document_name': val.pd_document_name, + 'document_title': val.pd_document_title, + 'document': val.doc_url, + 'document_type': splitted[1] == 'pdf' ? 'pdf' : 'image' + } + this.documentsAndFilesList.push(DocumentsAndFiles); + }); + } + } + else { + this.documentsAndFilesList = []; + } }); } - // addMoreIndividuals() { - // const imageRef = this.dialog.open(OtherApplicantDetailsComponent, { - // data: '', - // width: '40%', - // disableClose: true - // }); - // imageRef.afterClosed() - // .subscribe(dataresult => { - // if (dataresult.data.length > 0) { - // dataresult.data.forEach((element, index) => { - - // let individualsControl = this._generalForm.controls['individuals']; - // element.pd_co_applicant_id = this.count; - // this.count = this.count + 1; - // element.individuals_order_id = individualsControl.controls.length + 1; - // element.is_new = true; - // element.is_active = true; - // element.is_main_applicant = false; - // individualsControl.push(this.createIndividulas(element)); - // let relationControl = this._generalForm.controls['persons_with_relationships']; - // let applicant_details: any = { 'pd_co_applicant_id': element.pd_co_applicant_id, 'applicant_name': this.titleCase.transform(element.applicant_name), 'relationship': '', 'relation_to': '', 'individuals_order_id': element.individuals_order_id, 'is_active': element.is_active }; - // relationControl.push(this.createPersonsWithRelationships(applicant_details,individualsControl.controls.length-1)); - // }); - - // } - // }); - - // } - } \ No newline at end of file