MEQ Product changes in Sales PD Module

This commit is contained in:
venbatechnologies@gmail.com 2020-12-10 19:17:50 +05:30
parent ddc5c79116
commit 377f4c6607
6 changed files with 1888 additions and 31 deletions

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
<mat-label>{{parent_ques.get('question').value}}</mat-label>
<input matInput [type]="parent_ques.get('field_type').value == 'num' || parent_ques.get('field_type').value == 'numtoword' ? 'number' : parent_ques.get('field_type').value == 'string' ? 'text' : parent_ques.get('field_type').value" formControlName="answer_value"
[placeholder]="parent_ques.get('place_holder').value"
[placeholder]="parent_ques.value.hasOwnProperty('place_holder') ? parent_ques.get('place_holder').value : ''"
autocomplete="off" (change)="onChangeProperty($event,parent_ques,'','',p_i)"
>
<!-- [placeholder]="parent_ques.get('field_type').value == 'num' || parent_ques.get('field_type').value == 'numtoword' ? 'Entert the Number' : 'Enter the Text'" -->
@ -120,7 +120,7 @@
<mat-form-field style="width: 100%" *ngIf="parent_ques.get('type').value == '8'">
<mat-label>{{parent_ques.get('question').value}}</mat-label>
<mat-select formControlName="answer_value" (selectionChange)="onChangeProperty($event,parent_ques,'','',p_i)">
<mat-select formControlName="answer_value" (selectionChange)="onChangeProperty($event,parent_ques,'','',p_i)" [multiple] = "parent_ques.value.hasOwnProperty('is_multiple') && parent_ques.get('is_multiple').value == '1'">
<mat-option>
<ngx-mat-select-search formControlName="select_search"
[placeholderLabel]="'Search'"
@ -128,7 +128,7 @@
<ion-icon name="md-close" ngxMatSelectSearchClear></ion-icon>
</ngx-mat-select-search>
</mat-option>
<mat-option>--</mat-option>
<mat-option *ngIf="parent_ques.get('is_multiple').value != '1'">--</mat-option>
<mat-option *ngFor="let val of fileredSearchValue.length > 0 ? fileredSearchValue[p_i] : parent_ques.get('answers').value" [value]="val.hasOwnProperty('answer_id') ? val.answer_id : val.answer">{{val.answer}}</mat-option>
</mat-select>
@ -235,7 +235,7 @@
<mat-form-field style="width: 100%" *ngIf="single_ques.get('type').value == '8'">
<mat-label>{{parent_ques.get('question').value}}</mat-label>
<mat-select formControlName="answer_value" (selectionChange)="onChangeProperty($event,parent_ques,p_i)">
<mat-select formControlName="answer_value" (selectionChange)="onChangeProperty($event,parent_ques,p_i)" [multiple] = "parent_ques.value.hasOwnProperty('is_multiple') && parent_ques.get('is_multiple').value == '1'">
<mat-option>
<ngx-mat-select-search formControlName="select_search"
[placeholderLabel]="'Search'"
@ -243,7 +243,7 @@
<ion-icon name="md-close" ngxMatSelectSearchClear></ion-icon>
</ngx-mat-select-search>
</mat-option>
<mat-option>--</mat-option>
<mat-option *ngIf="parent_ques.get('is_multiple').value != '1'">--</mat-option>
<mat-option *ngFor="let val of fileredSearchValue.length > 0 ? fileredSearchValue[p_i] : parent_ques.get('answers').value" [value]="val.hasOwnProperty('answer_id') ? val.answer_id : val.answer">{{val.answer}}</mat-option>
</mat-select>

View File

@ -824,10 +824,11 @@ this.proceedonChangeProperty(modified)
if(control_value_obj.answer_value == ''){
control_value_obj.answer_value =0
}
expression_value=expression_value.replace(res,control_value_obj.answer_value)
// expression_value=expression_value.replace(res,control_value_obj.answer_value)
expression_value = expression_value.split(res).join(control_value_obj.answer_value)
}
})
let calc_exp=eval(expression_value)
if(calc_exp != false){
@ -1021,6 +1022,7 @@ this.proceedonChangeProperty(modified)
// ]
// console.log(this.local_ques_JSON);
if(this.local_ques_JSON.hasOwnProperty('onsubmit') && this.local_ques_JSON.onsubmit != null){
this.salesPDProvider.getData_fromLocal('sales_pd_id_PRIMARYKEY').then((sales_pd_id)=>{
for(let i=0; i<this.local_ques_JSON.onsubmit.length ; i++){
// this.quesAnsForm.value.questions.forEach(parent_ques=>{
let parent_ques
@ -1034,7 +1036,7 @@ this.proceedonChangeProperty(modified)
return_val.length = 0
let val=this.calculation(parent_ques,submitProperty)
let val=this.calculation(parent_ques,submitProperty,sales_pd_id)
if(val != true && val != 100){
this.toastProvider.lenderappmessage(submitProperty.msg)
@ -1045,6 +1047,16 @@ this.proceedonChangeProperty(modified)
return_val.push(true) ;
}
}
else if(parent_ques.question_key == submitProperty.key_name) {
let val=this.calculation(parent_ques,submitProperty,sales_pd_id)
if(val != true) {
this.toastProvider.lenderappmessage(submitProperty.msg)
return_val.push(false) ;
}
else{
return_val.push(true) ;
}
}
else{
send_val =true
}
@ -1056,6 +1068,7 @@ this.proceedonChangeProperty(modified)
break;
}
}
})
console.log(return_val)
if(return_val.length > 0){
if(return_val.filter(res=>res == false).length > 0){
@ -1068,27 +1081,30 @@ this.proceedonChangeProperty(modified)
}
return send_val
}
calculation(control,submitProperty){
// console.log("control",control)
// let exp=`
// (function () {let sum_val=null
// let ques_key=[]
// control.questions_group.forEach(ques_obj=>{
// ques_obj.questions.map(ques=>{
// // console.log(ques)
// if(ques.question_key == 'share_holding'){
// ques_key.push(ques)
// }
// })
// })
// if(ques_key.length > 0){
// console.log(ques_key)
// sum_val= ques_key.map(val=>val.answer_value).reduce((tot,val)=>{
// console.log(">>>>",tot,val)
// return parseInt(tot)+parseInt(val)
// })
// }
// return sum_val == 100}());`
calculation(control,submitProperty,sales_pd_id?){
function addorUpdateLocalStorage(key,value) {
let storageKey = 'PD_FORM_VALUES-'+sales_pd_id
let existing_value:any = localStorage.getItem(storageKey)
if(existing_value ) {
existing_value = JSON.parse(existing_value);
if(Object.keys(existing_value).length > 0) {
existing_value[key] = value
}
// existing_value.push(value)
}
else {
existing_value = {}
existing_value[key] =value
}
localStorage.setItem(storageKey,JSON.stringify(existing_value))
}
console.log("control",control)
// let exp=`
// (function () {if(control.question_key == 'constitution'){addorUpdateLocalStorage('constitution',control.answer_value);}return true}());`
//for image total check
// let exp=`
@ -1112,10 +1128,29 @@ this.proceedonChangeProperty(modified)
let val= eval(submitProperty.expression);
// let val = eval(exp);
console.log(val)
return val
}
// addorUpdateLocalStorage(key,value) {
// this.salesPDProvider.getData_fromLocal('sales_pd_id_PRIMARYKEY').then((sales_pd_id)=>{
// let storageKey = 'PD_FORM_VALUES-'+sales_pd_id
// let existing_value:any = localStorage.getItem(storageKey)
// if(existing_value ) {
// existing_value = JSON.parse(existing_value);
// if(Object.keys(existing_value).length > 0) {
// existing_value[key] = value
// }
// // existing_value.push(value)
// }
// else {
// existing_value[key] =value
// }
// localStorage.setItem(storageKey,JSON.stringify(existing_value))
// })
// }
searchFun(control,index){
console.log(control,index);

View File

@ -6,6 +6,7 @@ import { ToastProvider } from '../../../../providers/common-provider/toast';
import { OfflineManagerProvider } from '../../providers/offline-manager/offline-manager';
import { ConstantsProvider } from '../../../../providers/constants/constants';
import { SocialSharing } from '@ionic-native/social-sharing';
import { Observable, Observer } from 'rxjs';
/**
* Generated class for the SectionListPage page.
*
@ -29,6 +30,7 @@ export class SectionListPage {
customer_link:string=''
sales_pd_type: string;
customer_link_with_text: string;
config_expression: any;
constructor(public navCtrl: NavController, public navParams: NavParams,private SalesPDService:SalesPdProvider,private toastProvider:ToastProvider,
private offlineManager:OfflineManagerProvider,private constantProvider:ConstantsProvider,
private socialSharing:SocialSharing) {
@ -50,10 +52,142 @@ export class SectionListPage {
this.getSectionStats()
},50)
}
checkTemplateConfig() {
if(this.raw_data && this.raw_data.hasOwnProperty('config') && this.raw_data.config && this.sales_pd_id != null && this.sales_pd_id) {
this.raw_data.config.forEach(singleConfig=>{
if(singleConfig.purpose == 'LOCAL_OR_API_FORM_VALUES') {
this.getLocalFormValues(singleConfig)
}
})
}
}
getLocalFormValues(temp_config) {
if(temp_config.hasOwnProperty('value_keys') && temp_config.value_keys != null ) {
let storageKey ='PD_FORM_VALUES-'+this.sales_pd_id
let currFormDatas:any = localStorage.getItem(storageKey)
if(currFormDatas) {
currFormDatas = JSON.parse(currFormDatas)
}
else {
currFormDatas = {}
}
this.config_expression = `(function () {console.log("c",'constitution'.toLowerCase() == 'trust');if('constitution'.toLowerCase() == 'trust' || 'constitution'.toLowerCase() == 'society'){ removeSection('3') } else { addSection('3')}return true}());`
temp_config.value_keys.forEach((obj,index)=>{
console.log(currFormDatas[obj.key_names[0]])
// FOR VERIFY SECTION VALUE STORED
if(!currFormDatas || !currFormDatas[obj.key_names[0]]) {
return this.getSectionDatas(obj.section_id,obj.key_names).subscribe(val=>{
console.log(val);
// this.SalesPDService.addorUpdateLocalStorage()
currFormDatas = {...currFormDatas,...val}
this.updateToLocalStorage(storageKey,currFormDatas)
this.proceedConfigCheck(temp_config,currFormDatas,index)
})
}
else {
this.proceedConfigCheck(temp_config,currFormDatas,index)
}
})
}
return
}
proceedConfigCheck(config,datas,index,section_template = this.section_template,raw_section_template = this.raw_data.sections) {
console.log("At last",datas)
// debugger;
config.value_keys[index].key_names.forEach(val=>{
console.log(val)
this.config_expression = this.config_expression.split(val).join(datas[val])
})
if(config.value_keys.length-1 == index) {
console.log("last obj",this.config_expression)
let exp = eval(this.config_expression)
}
// let raw_template = this.section_template
function addSection(section_id){
console.log("add",section_id);
if(section_template.filter(vv=>vv.section_id == section_id).length == 0) {
let curr_obj_index = raw_section_template.findIndex(vv=>vv.section_id == section_id)
let index_to_insert
if(section_id == 0) {
index_to_insert = 0
}
else {
index_to_insert = section_template.findIndex(vv=>vv.section_id == section_id-1)
}
if(curr_obj_index != -1 && index_to_insert != -1) {
console.log(index_to_insert)
section_template.splice(index_to_insert+1,0,raw_section_template[curr_obj_index])
}
}
}
function removeSection(section_id){
console.log("Remove",section_id,section_template)
section_template = section_template.filter(vv=>vv.section_id != section_id)
console.log(section_template)
}
this.section_template = section_template
// expression_value.split(res).join(control_value_obj.answer_value)
}
updateToLocalStorage(storageKey,values) {
let storageValue:any = localStorage.getItem(storageKey)
if(storageValue) {
storageValue = JSON.parse(storageValue)
storageValue = {...storageValue,...values}
}
else {
storageValue = values
}
localStorage.setItem(storageKey,JSON.stringify(storageValue))
}
getSectionDatas(section_id,keys_acquired) {
return new Observable((observer: Observer<any>) => {
let params={sales_pd_id:this.sales_pd_id,section_id:section_id}
return this.SalesPDService.getSalesPDSectionData(params).subscribe(response=>{
let obj
if(response['dataStatus']){
let original_result_data=response['records'][0].section_data
original_result_data = JSON.parse(original_result_data);
obj = this.updateKeyValues(keys_acquired,original_result_data.questions)
}
else{
obj = this.updateKeyValues(keys_acquired,null)
}
observer.next(obj);
observer.complete();
})
})
}
updateKeyValues(keys_acquired ,data_from_api) {
let return_value = {}
if(keys_acquired.length > 0) {
keys_acquired.forEach(key_name=>{
if(data_from_api != null) {
console.log("api",data_from_api);
let value = data_from_api.filter(vv=>vv.question_key == key_name)[0]
if(!value || !value.hasOwnProperty('answer_value')) {
value = null
}
else {
value = value.answer_value
}
return_value[key_name] = value
}
else{
return_value[key_name]= null
}
})
return return_value
}
}
getSectionStats() {
this.SalesPDService.getData_fromLocal('sales_pd_id_PRIMARYKEY').then((key_value)=>{
if(key_value && key_value != null && key_value != '' && key_value != undefined){
this.sales_pd_id=key_value
this.checkTemplateConfig()
if(!this.sales_pd_id.includes('local')) {
this.SalesPDService.getData_fromLocal('sales_rand_string').then((rand_string_sales)=>{
if(rand_string_sales) {

View File

@ -179,6 +179,7 @@ export class QuesServiceProvider {
"onchange_properties":[data.onchange_properties],
"answers":[answers_from_client.length != 0 ? answers_from_client: data.answers],
"is_repeatable":[data.is_repeatable || null],
"is_multiple":[data.is_multiple || 0],
"group_title":[data.group_title || null]
})
}
@ -301,6 +302,29 @@ export class QuesServiceProvider {
curr_control.controls[curr_index].addControl('is_image_status',new FormControl(false))
}
if(data.hasOwnProperty('question_enable') && data.question_enable != null && data.question_enable) {
let expression= data.question_enable;
console.log("Check started",expression,expression.includes('PD_FORM_VALUES'));
if(expression.includes('PD_FORM_VALUES')) {
this.salesPDProvider.getData_fromLocal('sales_pd_id_PRIMARYKEY').then(sales_pd_id => {
if(sales_pd_id) {
let PD_FORM_VALUES = localStorage.getItem('PD_FORM_VALUES-'+sales_pd_id)
if(PD_FORM_VALUES) {
PD_FORM_VALUES = JSON.parse(PD_FORM_VALUES)
// expression = expression.split('PD_FORM_VALUES').join(local_pd_form_values)
console.log("ex",expression)
let result = eval(expression)
console.log(result);
if(!result) {
curr_control.removeAt(curr_index);
}
}
}
})
}
// expression = expression.split(res).join(control_value_obj.answer_value)
}
//FOR SETTING THE VALIDATORS
this.settingArrayofValidators(data,curr_control.controls[curr_index],curr_index)
}

View File

@ -11,6 +11,7 @@ import { IonicStorageProvider } from '../../../../providers/ionic-storage/ionic-
import { OfflineManagerProvider } from '../offline-manager/offline-manager';
import { PdtriggerProvider } from '../../../../providers/pdtrigger/pdtrigger';
import { ApiServiceProvider } from '../../../credit_pd/providers/api-service/api-service';
import { Platform } from 'ionic-angular';
// import {environment} from '../../../../providers/constants/constants'
/*
@ -28,7 +29,8 @@ available_sections:any;
original_rawData:any;
current_section:any;
constructor(public http: HttpClient,private constantProvider:ConstantsProvider,private storage:Storage,private aws:AwsServiceProvider,private cameraService:CameraProvider,
private networkProvider:NetworkDetectionProvider,private ionicStorageProvider:IonicStorageProvider,private offlineManagerProvider:OfflineManagerProvider,private creditPDService:ApiServiceProvider) {
private networkProvider:NetworkDetectionProvider,private ionicStorageProvider:IonicStorageProvider,private offlineManagerProvider:OfflineManagerProvider,private creditPDService:ApiServiceProvider,
private platform:Platform) {
console.log('Hello SalesPdProvider Provider');
this.apiUrl=this.constantProvider.environment().url
}
@ -38,7 +40,15 @@ current_section:any;
let params = {records:{lender_id:users.fk_entity_id,product_id:product_id,sales_pd_type:sales_pd_type}}
return Observable.create((observer:any)=>{
if(this.networkProvider.getCurrentNetworkStatus() == ConnectionStatus.online) {
return this.http.post(this.apiUrl+'loadSalesPDTemplate',{records:{lender_id:users.fk_entity_id,product_id:product_id,sales_pd_type:sales_pd_type}}).subscribe(result=>{
console.log(this.platform.is('cordova'))
let api_properties = {method:'post', api_name:this.apiUrl+'loadSalesPDTemplate',params : params}
if(!this.platform.is('cordova')) {
// api_properties = {method:'get', api_name:`assets/data/sales_pd_templates/${product_id}.json`,params : params
}
return this.http[api_properties.method](api_properties.api_name,api_properties.params).subscribe(result=>{
if(!this.platform.is('cordova') && !result.hasOwnProperty('dataStatus')) {
result = {dataStatus:true,status:200,records:{template:JSON.stringify(result)}}
}
if(result['dataStatus']) {
return this.ionicStorageProvider.checkAndInsertApiDataLocally(result,params,'loadSalesPDTemplate',true).then(res=>{
observer.next(result)