address form field changes : ps

This commit is contained in:
venbatechnologies@gmail.com 2019-06-19 15:00:13 +05:30
parent 513b12797c
commit cc46c619a8
7 changed files with 132 additions and 17 deletions

View File

@ -12,7 +12,7 @@
</mat-expansion-panel-header>
<mat-list class="m-gap p-gap">
<div [formGroup]="searchForm">
<mat-form-field style="width:25%">
<mat-form-field style="width:20%">
<mat-select multiple formControlName="pd_type" placeholder="PD Type">
<mat-option *ngFor="let type of PDType" [value]="type.pd_type_id">{{type.type_name}}</mat-option>
</mat-select>
@ -21,7 +21,7 @@
<mat-select multiple formControlName="pd_status" placeholder="PD Status">
<mat-option *ngFor="let status of pdStatus" [value]="status.pd_status_name">{{status.pd_status_name}}</mat-option>
</mat-select>
</mat-form-field>
</mat-form-field> &nbsp; &nbsp;
<mat-form-field style="width:20%">
<input matInput [matDatepicker]="picker" (blur)="checkDate($event)" [max]="todaydate" formControlName="pd_from_date" placeholder="Choose a From date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
@ -71,7 +71,7 @@
</mat-expansion-panel>
<br/>
<mat-table [dataSource]="dataSourceTab1" matSort *ngIf="PdListData.length > 0 else noRecord">
<mat-table [dataSource]="dataSourceTab1" matSort *ngIf="PdListData.length > 0">
<ng-container matColumnDef="PDType">

View File

@ -24,6 +24,7 @@ export class CompletedPdComponent implements OnInit, OnChanges {
errorMessage:any[]=[];
tabStatus:string="COMPLETED";
pipe = new DatePipe('en-US');
todaydate:Date = new Date();
private notifier: NotifierService;
public dataLengthTab4: number;
public dataSourceTab4 = new MatTableDataSource();

View File

@ -22,6 +22,7 @@ export class InprogressPdComponent implements OnInit, OnChanges {
errorMessage:any[]=[];
tabStatus:string="INPROGRESS";
pipe = new DatePipe('en-US');
todaydate:Date = new Date();
private notifier: NotifierService;
public dataLengthTab2: number;
public dataSourceTab2 = new MatTableDataSource();

View File

@ -24,7 +24,7 @@ export class QcCompletedPdComponent implements OnInit, OnChanges {
errorMessage: any[] = [];
tabStatus: string = "QC_COMPLETED";
pipe = new DatePipe('en-US');
todaydate:Date = new Date();
public dataLengthTab5: number;
public dataSourceTab5 = new MatTableDataSource();
tempStore = new MatTableDataSource();

View File

@ -23,6 +23,7 @@ export class ScheduledPdComponent implements OnInit, OnChanges {
tabStatus:string="SCHEDULED";
pipe = new DatePipe('en-US');
searchForm:FormGroup;
todaydate:Date = new Date();
public dataLengthTab3: number;
public dataSourceTab3 = new MatTableDataSource();
private notifier: NotifierService;

View File

@ -32,7 +32,7 @@
<div fxFlex="100">
<!-- oninput="this.value = this.value.toUpperCase()" -->
<mat-form-field style="width: 96%">
<input matInput placeholder="Address" formControlName="address"
<input matInput placeholder="Address at which PD was initiated" formControlName="address"
[value]="item.get('address').value | titlecase"
required
autocomplete="off">
@ -43,7 +43,7 @@
<div fxFlex="100" fxLayout="nowrap">
<mat-form-field style="width: 32%">
<mat-select placeholder="State" formControlName="state"
(selectionChange)="getcityList($event.target.value,i)">
(selectionChange)="getCityAndPincodeDetails($event.value,i,1)">
<mat-option>Select</mat-option>
<mat-option *ngFor="let SL of stateData" [value]="SL.state_id">{{SL.name}}</mat-option>
</mat-select>
@ -67,11 +67,63 @@
<input matInput autocomplete="off" placeholder="Specify Pincode *"
formControlName="pincode_others" OnlyNumber type="text">
<mat-error *ngIf="item.controls['pincode_others'].hasError('required')">Pincode Required</mat-error>
</mat-form-field>
</div>
<div fxFlex="100" align="left" style="margin: 0 0 2% 2%;">
<mat-checkbox color="primary" formControlName="pd_is_done_on_initiated_address" (change)="alternativeAddress($event.checked,i,1)">
Is This Address PD is being done ? <strong>( {{item.get('pd_is_done_on_initiated_address').value===true ? 'Yes' : 'No'}} )</strong>
</mat-checkbox>
<br>
</div>
<div fxFlex="100" *ngIf="item.get('pd_is_done_on_initiated_address').value===false">
<!-- oninput="this.value = this.value.toUpperCase()" -->
<mat-form-field style="width: 96%">
<input matInput placeholder="Is this the address where PD is done?" formControlName="alternative_address"
[value]="item.get('alternative_address').value | titlecase" required autocomplete="off">
<mat-error *ngIf="item.controls['alternative_address'].hasError('required')">Alternative Address Required</mat-error>
</mat-form-field>
</div>
<div fxFlex="100" fxLayout="nowrap" *ngIf="item.get('pd_is_done_on_initiated_address').value===false">
<mat-form-field style="width: 32%">
<mat-select placeholder="State" formControlName="alternative_state"
(selectionChange)="getCityAndPincodeDetails($event.value,i,2)">
<mat-option>Select</mat-option>
<mat-option *ngFor="let SL of stateData" [value]="SL.state_id">{{SL.name}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field style="width: 32%">
<mat-select placeholder="City" formControlName="alternative_city">
<mat-option> Select </mat-option>
<mat-option *ngFor="let CL of alertnativeCityData[i]" [value]="CL.city_id">{{CL.city_name}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field style="width: 24%">
<mat-select placeholder="Pincode" formControlName="alternative_pincode">
<mat-option>Select</mat-option>
<mat-option *ngFor="let PL of alertnativePincodeData[i]" [value]="PL.pincode_id">{{PL.pincode}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field style="width: 24%" *ngIf="item.get('alternative_pincode').value == 1">
<input matInput autocomplete="off" placeholder="Specify Pincode *" required
formControlName="alternative_pincode_others" OnlyNumber type="text">
<mat-error *ngIf="item.controls['alternative_pincode_others'].hasError('required')">Pincode Required</mat-error>
</mat-form-field>
</div>
<div fxFlex="100" *ngIf="item.get('pd_is_done_on_initiated_address').value===false">
<mat-form-field style="width: 96%">
<input matInput placeholder="Reason for change in PD visit address ?" formControlName="reason_for_alternative_address" required autocomplete="off">
<mat-error *ngIf="item.controls['reason_for_alternative_address'].hasError('required')">Reason Required</mat-error>
</mat-form-field>
</div>
<div fxFlex="100">
<mat-form-field style="width: 46%;">
<mat-select placeholder="Address Type" formControlName="address_type"

View File

@ -57,6 +57,8 @@ export class AddressComponent implements OnInit {
pincodeData: any = [];
cityData: any = [];
uomData: any = [];
alertnativeCityData:any=[];
alertnativePincodeData:any=[];
addressesList: any = [];
documentsAndFilesList: any = [];
@ -143,6 +145,7 @@ export class AddressComponent implements OnInit {
'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,
@ -150,8 +153,9 @@ export class AddressComponent implements OnInit {
'uom': datas.uom,
'uom_others': datas.uom_others
}
this.getCityAndPincodeDetails(datas.state, index);
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);
@ -159,7 +163,23 @@ export class AddressComponent implements OnInit {
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));
}
});
}
@ -264,6 +284,7 @@ export class AddressComponent implements OnInit {
'pinSearch':'',
'pincode': val.pincode_id,
'pincode_others': val.other_pincode,
'pd_is_done_on_initiated_address':true,
'locality': '',
'locality_others': '',
// 'locality_mixuse': '',
@ -273,7 +294,7 @@ export class AddressComponent implements OnInit {
'uom': '',
'uom_others': ''
}
this.getCityAndPincodeDetails(val.fk_state, index);
this.getCityAndPincodeDetails(val.fk_state,index,1);
this.getOtherPincode(val.pincode_id, index);
control.push(this.createAddresses(obj));
});
@ -335,7 +356,9 @@ export class AddressComponent implements OnInit {
/** FOR Adress */
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])],
@ -347,6 +370,7 @@ export class AddressComponent implements OnInit {
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],
@ -356,7 +380,6 @@ export class AddressComponent implements OnInit {
uom: [AddressDetails.uom],
uom_others: [AddressDetails.uom_others]
});
}
else {
return this.fb.group({
@ -370,6 +393,7 @@ export class AddressComponent implements OnInit {
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: [''],
@ -421,11 +445,17 @@ export class AddressComponent implements OnInit {
/** To Get City And Pincode Data For Address Form
* Param 'stateID' -> selected StateId
*/
getCityAndPincodeDetails(stateID: string, index) {
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;
}
}
});
}
@ -433,6 +463,30 @@ export class AddressComponent implements OnInit {
getOtherPincode(e, i) { this.otherPincodeFlag[i] = e == 1 ? true : false; }
transformName(vals){ return this.titlecasePipe.transform(vals); }
alternativeAddress(e,i,flag){
const control = <FormArray>this.addressForm.controls['addresses'];
let ChildCtrl : any = control.controls[i];
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');
}
}
/** TO Save Address Forms Details*/
onSubmit() {
@ -468,6 +522,12 @@ export class AddressComponent implements OnInit {
}
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();