diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.html b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.html index 39b7b75f9..45b79a01f 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.html +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.html @@ -1,3 +1,123 @@ -

- neighbour-hood works! -

+
+ +

+
+
+
+ {{pageTitle}} +
+
+ + {{types.type_name}} + +
+
+ +
+
+ +
+

+ + + +
+ + + + + + Yes + No + + +
+
+ + + + + + Yes + No + + + +
+
+
+ +
+ + + + + + + + + Enter Valid Mobile Number. + + + + Enter Valid Landline Number. + + + + + + + + Select + + {{relationship.relation_with_business_name | titlecase}} + + + + + + +

Period of Relationship

+ + + + + + + + + + + + Select + + {{volume.name | titlecase}} + + + + +
+
+ +
+ +
+ + Remarks + + +
+
+ + +
+ +
+ + + + diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.scss b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.scss index e69de29bb..f18a47720 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.scss +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.scss @@ -0,0 +1,20 @@ +.paragraph_change { + color: #e00201 !important; + } + mat-form-field { + margin: 0 2%; + } + #period_paragraph { + margin: 0 2%; + } + + .example-radio-group { + display: flex; + flex-direction: row; + flex-wrap: wrap; + } + + .example-radio-button { + margin: 0 4%; + color: #000 !important + } \ No newline at end of file diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.ts b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.ts index 23f2a3a01..9919dd140 100644 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.ts +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/start-pd/forms/neighbour-hood/neighbour-hood.component.ts @@ -1,15 +1,270 @@ -import { Component, OnInit } from '@angular/core'; - +import { Component, OnInit, Input, Output, Inject } from '@angular/core'; +import { FormBuilder, FormGroup, Validators, FormControl, FormArray } from '@angular/forms'; +import { MatDialog, MatDialogRef, MAT_DIALOG_DATA , DialogPosition} from '@angular/material'; +import { NotifierService } from 'angular-notifier'; +import { PdTrigerService } from './../../../../../pd-service/pd-triger.service'; +import { parse } from 'url'; @Component({ selector: 'app-neighbour-hood', templateUrl: './neighbour-hood.component.html', styleUrls: ['./neighbour-hood.component.scss'] }) export class NeighbourHoodComponent implements OnInit { + pageTitle: string ="Neighbourhood / Reference Check"; + public _neighbourhoodForm: FormGroup; + pdid : string; + form_id:number; + private notifier: NotifierService; + check_type:any=[{'id':0,'type_name':'Neighbourhood'},{'id':1,'type_name':'Reference Check'}] + default_reference_details: any= {'reference_name':'','mobile':'','landline':'','location':'','relationship_with':'','year_relation_applicant':'','months_relation_applicant':'','business_volume_amount':'','business_volume_unit':''}; + default_neighbourhood_details: any= {'neighbourhood_name':'','do_know':'','how_long_do_know':'','is_applicant_owner':''}; - constructor() { } + busineesRelationshipList:any=[]; + volumeunitList:any=[]; + errorMessage:any; + constructor(notifier: NotifierService, private _pd: PdTrigerService ,private _fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: any,) { + this.pdid = this.data.pdmaster_details.pd_id; + this.notifier = notifier; + this.form_id = 19; + } ngOnInit() { + this.initFormDetails(); + + // call neghbourhhod / reference check changes + this._neighbourhoodForm.controls['check_type'].valueChanges.subscribe(value => { + const referencecheckControl = this._neighbourhoodForm.controls['referencecheck_list']; + const neighbourhoodControl = this._neighbourhoodForm.controls['neighbourhood_list']; + if(value==0){ + referencecheckControl.controls = []; + referencecheckControl.setValue([]); + if(neighbourhoodControl.value.length==0){ + neighbourhoodControl.push(this.createNeighbourhood(this.default_neighbourhood_details)); + } + } + else { + neighbourhoodControl.controls = []; + neighbourhoodControl.setValue([]); + if(referencecheckControl.value.length==0){ + referencecheckControl.push(this.createReerenceCheck(this.default_reference_details)); + } + + } + }); + } + // init form details + initFormDetails() { + this._neighbourhoodForm = this._fb.group({ + pdid:this.pdid, + formid:this.form_id, + check_type:0, + neighbourhood_list: this._fb.array([]), + referencecheck_list: this._fb.array([]), + neighbour_reference_remark:'' + }); + // load form data + this.loadFormData(); + this.getMasterDetails('RELATIONWITHBUSINESS',1); + this.getMasterDetails('FREQUENCY',2); + + } + + // load form data + loadFormData(){ + let params: any = {}; + params.pd_id = this.pdid; + params.pd_form_id = '19'; + let referencecheckControl = this._neighbourhoodForm.controls['referencecheck_list']; + referencecheckControl.controls = []; + const neighbourhoodControl = this._neighbourhoodForm.controls['neighbourhood_list']; + neighbourhoodControl.controls=[]; + this._pd.retriveForm(params).subscribe(data => { + if(data.dataStatus) { + let exist_ref_details = data.records.referencecheck_list ? Object.keys(data.records.referencecheck_list).map((item)=>data.records.referencecheck_list[item]) : []; + let exist_neighbourhood_details = data.records.neighbourhood_list ? Object.keys(data.records.neighbourhood_list).map((item)=>data.records.neighbourhood_list[item]) : []; + if(exist_neighbourhood_details.length>0 && data.records.check_type==0){ + exist_neighbourhood_details.forEach(element => { + neighbourhoodControl.push(this.createNeighbourhood(element)); + }); + } + else if(exist_ref_details.length>0 && data.records.check_type==1){ + exist_ref_details.forEach(element => { + referencecheckControl.push(this.createReerenceCheck(element)); + }); + } + + this._neighbourhoodForm.controls['neighbour_reference_remark'].setValue(data.records.neighbour_reference_remark ? data.records.neighbour_reference_remark : ''); + this._neighbourhoodForm.controls['check_type'].setValue(data.records.check_type==1 ? 1 : data.records.check_type==0 ? 0 : ''); + } + + else { + neighbourhoodControl.push(this.createNeighbourhood(this.default_neighbourhood_details)); + + } + + }, error => this.errorMessage = error); + } + + // get all master details + getMasterDetails(table:string,type:number){ + this._pd.getAllMasterDatas(table).subscribe( + data => { + if (data.status == 200) { + if(type==1){ + this.busineesRelationshipList=data.records.filter(item => item.isactive == 1); + } + if(type==2){ + this.volumeunitList=data.records.filter(item => item.isactive == 1); + } + + } + }, error => this.errorMessage = error); + } + + + + + // create reference check form array + createReerenceCheck(elementValue:any){ + return this._fb.group({ + reference_name: [elementValue.reference_name, Validators.required], + mobile: [elementValue.mobile,Validators.compose([Validators.required,Validators.minLength(10),Validators.maxLength(10)])], + landline: [elementValue.landline,Validators.compose([Validators.minLength(6),Validators.maxLength(8)])], + location:[elementValue.location,Validators.required], + relationship_with:[elementValue.relationship_with,Validators.required], + others: [elementValue.others], + year_relation_applicant:[elementValue.year_relation_applicant,Validators.required], + months_relation_applicant:[elementValue.months_relation_applicant,Validators.required], + business_volume_amount:[elementValue.business_volume_amount,Validators.required], + business_volume_unit:[elementValue.business_volume_unit, Validators.required], + }); + } + + // add more referencecheck details + + addReferencecheck(){ + const referenceControl = this._neighbourhoodForm.controls['referencecheck_list']; + referenceControl.push(this.createReerenceCheck(this.default_reference_details)); + } + + // remove referencecheck details + removeReferencecheck(renoveIndex) { + const remove_control = this._neighbourhoodForm.controls['referencecheck_list']; + remove_control.removeAt(renoveIndex) + } + + // create neighbourhood form array + createNeighbourhood(elementValue:any){ + return this._fb.group({ + neighbourhood_name: [elementValue.neighbourhood_name, Validators.required], + do_know: [elementValue.do_know,Validators.required], + how_long_do_know: [elementValue.how_long_do_know], + is_applicant_owner: [elementValue.is_applicant_owner], + }); + } + + // add more createNeighbourhood details + + addNeighbourhood(){ + const neighbourhoodControl = this._neighbourhoodForm.controls['neighbourhood_list']; + neighbourhoodControl.push(this.createNeighbourhood(this.default_neighbourhood_details)); + } + + // remove neighbour hood details + removeNeighbourhood(renoveIndex) { + const remove_control = this._neighbourhoodForm.controls['neighbourhood_list']; + remove_control.removeAt(renoveIndex) + } + + /** On Key Press Event For Mobile Number */ + keyPress(event: any) { + const pattern = /[0-9]/; + + let inputChar = String.fromCharCode(event.charCode); + if (event.keyCode != 8 && !pattern.test(inputChar)) { + event.preventDefault(); + } + } + + //save heighbourhood forms + saveNeighbourhood(formData:any){ + let resultMessage:string=''; + if (this._neighbourhoodForm.invalid) { + this.validateAllFormFields(this._neighbourhoodForm); + return; + } + else{ + let saveRecords:any = {} + let referencecheck_list:any=[]; + let neighbourhood_list:any=[]; + if(formData.check_type==0){ + formData.neighbourhood_list.forEach((element,key) => { + neighbourhood_list.push({ + "neighbourhood_name":element.neighbourhood_name, + "do_know":element.do_know, + "how_long_do_know":element.how_long_do_know, + "is_applicant_owner":element.is_applicant_owner, + }) + }); + saveRecords.neighbourhood_list=neighbourhood_list; + resultMessage='Neihbourhood Updated.!' + } + else{ + // this for referencecheck_list for selected + formData.referencecheck_list.forEach((element,key) => { + referencecheck_list.push({ + "reference_name":element.reference_name, + "mobile":element.mobile, + "landline":element.landline, + "location":element.location, + "relationship_with":element.relationship_with, + "others":element.others, + "year_relation_applicant":element.year_relation_applicant, + "months_relation_applicant":element.months_relation_applicant, + "business_volume_amount":element.business_volume_amount, + "business_volume_unit":element.business_volume_unit, + }) + }); + saveRecords.referencecheck_list=referencecheck_list; + resultMessage='Reference Check Updated.!' + } + + saveRecords.check_type=formData.check_type; + saveRecords.pdid=formData.pdid; + saveRecords.formid=formData.formid; + saveRecords.neighbour_reference_remark=formData.neighbour_reference_remark; + this._pd.savePDFormDetailsWithID(saveRecords).subscribe( + dataresult => { + if (dataresult.status == 200) { + this.notifier.notify('success', resultMessage); + + } + else { + this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + // this.errorMessage = "Some Thing Wents Wrong Try Again !"; + } + }, error => { + this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + }); + } + } + + // validate all form group and form array fields +validateAllFormFields(formGroup: any) { + Object.keys(formGroup.controls).forEach(field => { + const control = formGroup.get(field); + + if (control instanceof FormControl) { + control.markAsTouched({ onlySelf: true }); + } else if (control instanceof FormGroup) { + this.validateAllFormFields(control); + } else if (control instanceof FormArray) { + this.validateAllFormFields(control); + } + }); +} + + }