add pd dropdown autofill added

This commit is contained in:
sriram-at-840620226347 2020-01-23 15:16:52 +05:30
parent d5502ca3eb
commit 7716564fc3
3 changed files with 173 additions and 29 deletions

View File

@ -102,6 +102,11 @@ export class AddPdComponent implements OnInit, OnDestroy {
console.log(selectLender);
this.selectedLender(selectLender)
this._PDtriggerForm.controls['fk_product_id'].setValue(res['records'].default_product);
this._PDtriggerForm.controls['fk_customer_segment'].setValue(res['records'].default_customer_segment);
this._PDtriggerForm.controls['fk_pd_type'].setValue(res['records'].default_pd_type);
this.getSubproductList(res['records'].default_product)
}
else{
this.notifier.notify("success","Something went wrong Reopen the window and Try again");
@ -185,20 +190,20 @@ export class AddPdComponent implements OnInit, OnDestroy {
this._PDtriggerForm.controls['fk_customer_segment'].setValue('');
this._PDtriggerForm.controls['loan_amount'].setValue('');
if(this.lenderShortName == "IIB"){ //FOR INDUSLAND BANK
// console.log("entered");
this._PDtriggerForm.controls['fk_product_id'].setValue("3")
this._PDtriggerForm.controls['fk_pd_type'].setValue("1");
this.getSubproductList("3")
}
else if(this.lenderShortName == 'HHFL'){
this.getSubproductList("1")
this._PDtriggerForm.controls['fk_product_id'].setValue('1');
this._PDtriggerForm.controls['fk_subproduct_id'].setValue('1');
this._PDtriggerForm.controls['fk_customer_segment'].setValue('5');
this._PDtriggerForm.controls['fk_pd_type'].setValue('1');
this._PDtriggerForm.controls['loan_amount'].setValue(0);
}
// if(this.lenderShortName == "IIB"){ //FOR INDUSLAND BANK
// // console.log("entered");
// this._PDtriggerForm.controls['fk_product_id'].setValue("3")
// this._PDtriggerForm.controls['fk_pd_type'].setValue("1");
// this.getSubproductList("3")
// }
// else if(this.lenderShortName == 'HHFL'){
// this.getSubproductList("1")
// this._PDtriggerForm.controls['fk_product_id'].setValue('1');
// this._PDtriggerForm.controls['fk_subproduct_id'].setValue('1');
// this._PDtriggerForm.controls['fk_customer_segment'].setValue('5');
// this._PDtriggerForm.controls['fk_pd_type'].setValue('1');
// this._PDtriggerForm.controls['loan_amount'].setValue(0);
// }
// console.log("len",lender)
}
@ -298,11 +303,11 @@ export class AddPdComponent implements OnInit, OnDestroy {
break;
}
if(this.lenderShortName == 'CLIX' && productabbr != ''){
this._PDtriggerForm.controls['fk_pd_type'].setValue('1');
this._PDtriggerForm.controls['fk_customer_segment'].setValue('5');
this._PDtriggerForm.controls['loan_amount'].setValue(0);
}
// if(this.lenderShortName == 'CLIX' && productabbr != ''){
// this._PDtriggerForm.controls['fk_pd_type'].setValue('1');
// this._PDtriggerForm.controls['fk_customer_segment'].setValue('5');
// this._PDtriggerForm.controls['loan_amount'].setValue(0);
// }
}

View File

@ -1,26 +1,45 @@
<form [formGroup]="_otherPreferenceForm">
<div fxLayout="row wrap" fxLayout.xs="column" fxLayoutGap="2%" fxLayoutAlign="center center" style="margin-top:8px;">
<mat-form-field fxFlex="40%" appearance="outline">
<mat-form-field fxFlex="60%" appearance="outline">
<mat-label>Products</mat-label>
<mat-select formControlName="products" multiple>
<mat-option (click)="selectAll('products')" [value]="0">Select All</mat-option>
<mat-option *ngFor="let option of productList" [value]="option.product_id">{{option.product_name}}</mat-option>
<mat-option (click)="selectAll('products')" [value]="0">Select All <span style="float: right;">Default</span></mat-option>
<span *ngFor="let option of productList; let p_i=index">
<mat-option [value]="option.product_id">{{option.product_name}}
</mat-option>
<ng-container formArrayName="products_default">
<!-- <span *ngFor="let prod_toggle of _otherPreferenceForm.controls.products_default['controls']; let i=index" > -->
<mat-slide-toggle [disabled]="checkDisableToggle(_otherPreferenceForm.getRawValue().products,option.product_id)" [formControlName]="p_i" (change)="default_toggle($event,option.product_id,p_i,1)" style="float: right;margin-top: -40px;margin-right: 18px;"></mat-slide-toggle>
<!-- </span> -->
</ng-container>
</span>
</mat-select>
<!-- <mat-error *ngIf="getForm.product.hasError('required')" class="mat-text-warn">Product is Required.!</mat-error> -->
</mat-form-field>
<!-- {{_otherPreferenceForm.value.products}} -->
<mat-form-field fxFlex="40%" appearance="outline">
<mat-label>Customer Segments</mat-label>
<mat-select formControlName="customer_segments" multiple>
<mat-option (click)="selectAll('customer_segments')" [value]="0">Select All</mat-option>
<mat-option *ngFor="let option of customerSegmentList" [value]="option.customer_segment_id">{{option.customer_segment}}</mat-option>
<span *ngFor="let option of customerSegmentList; let p_i=index">
<mat-option [value]="option.customer_segment_id">{{option.customer_segment}}</mat-option>
<ng-container formArrayName="customer_segments_default">
<mat-slide-toggle [disabled]="checkDisableToggle(_otherPreferenceForm.value.customer_segments,option.customer_segment_id)" [formControlName]="p_i" (change)="default_toggle($event,option.customer_segment_id,p_i,2)" style="float: right;margin-top: -40px;margin-right: 18px;"></mat-slide-toggle>
</ng-container>
</span>
</mat-select>
<!-- <mat-error *ngIf="getForm.product.hasError('required')" class="mat-text-warn">Product is Required.!</mat-error> -->
</mat-form-field>
<mat-form-field fxFlex="30%" appearance="outline">
<mat-form-field fxFlex="40%" appearance="outline">
<mat-label>PD Types</mat-label>
<mat-select formControlName="pd_types" multiple>
<mat-option (click)="selectAll('pd_types')" [value]="0">Select All</mat-option>
<mat-option *ngFor="let option of pdTypeList" [value]="option.pd_type_id">{{option.type_name}}</mat-option>
<span *ngFor="let option of pdTypeList; let p_i=index">
<mat-option [value]="option.pd_type_id">{{option.type_name}}</mat-option>
<ng-container formArrayName="pd_types_default">
<mat-slide-toggle [disabled]="checkDisableToggle(_otherPreferenceForm.value.pd_types,option.pd_type_id)" [formControlName]="p_i" (change)="default_toggle($event,option.pd_type_id,p_i,3)" style="float: right;margin-top: -40px;margin-right: 18px;"></mat-slide-toggle>
</ng-container>
</span>
</mat-select>
<!-- <mat-error *ngIf="getForm.product.hasError('required')" class="mat-text-warn">Product is Required.!</mat-error> -->
</mat-form-field>

View File

@ -1,8 +1,9 @@
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';
import { FormGroup, FormBuilder, FormArray, FormControl } from '@angular/forms';
import { EntityService } from 'app/settings/service/entity/entity.service';
import { NotifierService } from 'angular-notifier';
import { AwsService } from 'app/AwsService/aws.service';
import { MatSlideToggleChange } from '@angular/material';
@Component({
selector: 'app-entity-other-preference',
@ -21,24 +22,56 @@ export class EntityOtherPreferenceComponent implements OnInit {
constructor(private entityService:EntityService,private _fb:FormBuilder,notifier:NotifierService,private awsService:AwsService) {
this.notifier=notifier
this.users=this.awsService.getlocale()
this.getDropdownValues()
}
ngOnInit() {
this.getDropdownValues()
this._otherPreferenceForm=this._fb.group({
products:[''],
customer_segments:[''],
pd_types:[''],
fk_entity_id:[this.entityId],
fk_createdby:[this.users],
fk_updatedby:[this.users]
fk_updatedby:[this.users],
products_default:this._fb.array([]),
customer_segments_default:this._fb.array([]),
pd_types_default:this._fb.array([])
})
setTimeout(() => {
this.getvalueFromApi()
});
}
getvalueFromApi(){
this.entityService.getEntityOtherPreferences(this.entityId).subscribe(res=>{
if(res['dataStatus']){
this._otherPreferenceForm.patchValue(res['records'])
this.productList.forEach((element,index) => {
if(element.product_id == res['records'].products_default){
let event={checked:true}
this.default_toggle(event,element.product_id,index,1)
}
});
this.customerSegmentList.forEach((element,index) => {
if(element.customer_segment_id == res['records'].customer_segments_default){
let event={checked:true}
this.default_toggle(event,element.customer_segment_id,index,2)
}
});
this.pdTypeList.forEach((element,index) => {
if(element.pd_type_id == res['records'].pd_types_default){
let event={checked:true}
this.default_toggle(event,element.pd_type_id,index,3)
}
});
delete res['records'].products_default
delete res['records'].customer_segments_default
delete res['records'].pd_types_default
console.log(this._otherPreferenceForm.value);
setTimeout(() => {
this._otherPreferenceForm.patchValue(res['records'])
});
}
})
}
@ -46,16 +79,22 @@ export class EntityOtherPreferenceComponent implements OnInit {
this.entityService.getListOfProducts().subscribe(res=>{
if(res['dataStatus']){
this.productList=res['records']
this.initslidetoggle(1)
console.log(this._otherPreferenceForm.value);
}
})
this.entityService.getListOfCustomerSegments().subscribe(res=>{
if(res['dataStatus']){
this.customerSegmentList=res['records']
this.initslidetoggle(2)
console.log(this._otherPreferenceForm.value);
}
})
this.entityService.getListOfPDAllocationTypes().subscribe(res=>{
if(res['dataStatus']){
this.pdTypeList=res['records'].pd_type
this.initslidetoggle(3)
console.log(this._otherPreferenceForm.value);
}
})
@ -77,6 +116,8 @@ export class EntityOtherPreferenceComponent implements OnInit {
}
}
else{
let array_name = option+'_default'
this.changeToogletoFalse(array_name)
this._otherPreferenceForm.controls[option].patchValue('')
this.selectedAll[option]=false
}
@ -87,6 +128,25 @@ export class EntityOtherPreferenceComponent implements OnInit {
console.log(this._otherPreferenceForm.value)
let records=this._otherPreferenceForm.value
records.fk_updatedby=this.users
records.products_default = records.products_default.filter(prod_filter =>prod_filter != false)
if(records.products_default.length > 0){
records.products_default=records.products_default[0]
}else{
records.products_default= null
}
records.customer_segments_default = records.customer_segments_default.filter(prod_filter =>prod_filter != false)
if(records.customer_segments_default.length > 0){
records.customer_segments_default=records.customer_segments_default[0]
}else{
records.customer_segments_default= null
}
records.pd_types_default = records.pd_types_default.filter(prod_filter =>prod_filter != false)
if(records.pd_types_default.length > 0){
records.pd_types_default=records.pd_types_default[0]
}else{
records.pd_types_default= null
}
console.log('records',records);
this.entityService.saveEntityOtherPreferences(records).subscribe(res=>{
if(res['dataStatus']){
this.notifier.notify("success","Saved Successfully..!");
@ -97,5 +157,65 @@ export class EntityOtherPreferenceComponent implements OnInit {
})
}
default_toggle(event,prod_id,index,flag){
console.log(event.checked,prod_id,this._otherPreferenceForm.value.products_default,index)
if(flag == 1){
if(event.checked){
this.changeToogletoFalse('products_default')
const control=this._otherPreferenceForm.controls['products_default']['controls'][index]
control.setValue(prod_id)
console.log("set true",this._otherPreferenceForm.value.products_default)
}
}
if(flag == 2){
if(event.checked){
this.changeToogletoFalse('customer_segments_default')
const control=this._otherPreferenceForm.controls['customer_segments_default']['controls'][index]
control.setValue(prod_id)
console.log("set true",this._otherPreferenceForm.value.customer_segments_default)
}
}
if(flag == 3){
if(event.checked){
this.changeToogletoFalse('pd_types_default')
const control=this._otherPreferenceForm.controls['pd_types_default']['controls'][index]
control.setValue(prod_id)
console.log("set true",this._otherPreferenceForm.value.pd_types_default)
}
}
}
changeToogletoFalse(array_name){
const control=this._otherPreferenceForm.controls[array_name]['controls']
console.log(control)
control.forEach((val,index)=>{
control[index].setValue(false)
})
console.log("set False",this._otherPreferenceForm.value[array_name])
}
initslidetoggle(flag){
if(flag == 1){
const formArray = this._otherPreferenceForm.get('products_default') as FormArray;
this.productList.forEach(x => formArray.push(new FormControl(false)));
}
if(flag == 2){
const formArray = this._otherPreferenceForm.get('customer_segments_default') as FormArray;
this.customerSegmentList.forEach(x => formArray.push(new FormControl(false)));
}
if(flag == 3){
const formArray = this._otherPreferenceForm.get('pd_types_default') as FormArray;
this.pdTypeList.forEach(x => formArray.push(new FormControl(false)));
}
}
checkDisableToggle(select_value, curr_id){
// console.log("bvvvv",select_value,select_value.length > 0)
if(select_value.length > 0){
return select_value.filter(val=>val == curr_id).length == 0
}
else{
return true
}
}
}