diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 4b7caf8f..70a6a694 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -332,6 +332,8 @@ $route['getSMCVendorList'] = 'SMC_Credit_PD_Controller/getCityWiseAgency'; $route['getSMCVendorPDOfficersList'] = 'SMC_Credit_PD_Controller/getSMCVendorPDOfficersList'; //Template V2 (Dynamical) +$route['getTemplateMappingDetailsV2'] = 'Template_Management_Controller/getTemplateV2'; $route['getTemplateFormsV2'] = 'Template_Management_Controller/getTemplateFormsV2'; +$route['saveTemplateMappingDetailsV2'] = 'Template_Management_Controller/saveTemplateV2'; $route['saveAndUpdateTemplateFormsV2'] = 'Template_Management_Controller/saveTemplateFormsV2'; // $route['updateTemplateFormsV2'] = 'Template_Management_Controller/updateTemplateFormsV2'; \ No newline at end of file diff --git a/api/application/controllers/Template_Management_Controller.php b/api/application/controllers/Template_Management_Controller.php index 74fd23fe..7f78d315 100644 --- a/api/application/controllers/Template_Management_Controller.php +++ b/api/application/controllers/Template_Management_Controller.php @@ -896,7 +896,32 @@ class Template_Management_Controller extends REST_Controller { } //Module : Template V2.0 (Dynamic Form Template). - //Get Form Template Details V2.0 : ps 20/12/2021 + // API 1 Master Listing + public function getTemplateV2_get(){ + $lender_id = $this->get('entity_id'); + if(isset($lender_id) && !empty($lender_id)){ + $result_array = $this->Template_Management_Model->getTemplateMappingDetailsV2($lender_id); + if(count($result_array)>0) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $result_array; + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Data Available'; + } + }else{ + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Lender Id Not Found. Try Again!'; + } + $this->response($data,REST_Controller::HTTP_OK); + } + + // API 2 Get Template with Form Details V2.0 : ps 20/12/2021 public function getTemplateFormsV2_post(){ $records = $this->post("records"); $result_array = $this->Template_Management_Model->getTemplateFormsV2($records); @@ -925,43 +950,88 @@ class Template_Management_Controller extends REST_Controller { // "json": "{ \"section_id\":\"5\", \"section_name\":\"Address details\", \"onsubmit\":null, \"questions\":[ { \"question\":\"Address at which PD was initiated\", \"question_key\":\"initiated_address\", \"type\":\"7\", \"disable\":false, \"field_width\":\"100\", \"title\":\"Address Details\", \"answers\":true, \"api_properties\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"State\", \"question_key\":\"State_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"STATE\" }, \"fields\":[ \"state_id\", \"name\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"City\", \"question_key\":\"City_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfStatesAndCities\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"state_id\" }, \"fields\":[ \"city_id\", \"city_name\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Pincode\", \"question_key\":\"Pincode_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfStatesAndCities\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"pincode\" }, \"fields\":[ \"pincode\", \"pincode_id\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Is this the address where PD is done ?\", \"question_key\":\"is_pd_done_on_initiated_address\", \"type\":\"2\", \"disable\":false, \"field_width\":\"100\", \"onchange_properties\": [{ \"purpose\":\"FORM_CTRL\", \"form_controls\":[ { \"insert_index\":\"is_pd_done_on_initiated_address\", \"expression\":\"(String('is_pd_done_on_initiated_address') == String('No'))\", \"value_keys\":[ \"is_pd_done_on_initiated_address\" ], \"questions\":[ { \"question\":\"Reason for change in PD visit address\", \"question_key\":\"end_use\", \"type\":\"1\", \"field_width\":\"100\", \"api_properties\":null, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ ] }, { \"question\":\"Pincode\", \"question_key\":\"Pincode_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"COMMENTSONLOCALITY\" }, \"fields\":[ \"comments_on_locality_id\", \"rating\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"City\", \"question_key\":\"City_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"COMMENTSONLOCALITY\" }, \"fields\":[ \"comments_on_locality_id\", \"rating\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"State\", \"question_key\":\"State_list\", \"type\":\"3\", \"disable\":false, \"field_width\":\"25\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"STATE\" }, \"fields\":[ \"state_id\", \"name\" ] }, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Enter actual PD address\", \"question_key\":\"actual_pd_address\", \"type\":\"1\", \"field_width\":\"100\", \"api_properties\":null, \"answers\":null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ ] } ] } ] }], \"api_properties\":null, \"answers\":[ { \"answer_id\":\"Yes\", \"answer\":\"Yes\" }, { \"answer_id\":\"No\", \"answer\":\"No\" } ], \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Address Type\", \"question_key\":\"Address_Type\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"ADDRESSTYPE\" }, \"fields\":[ \"address_type_id\", \"address_type\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Locality\", \"question_key\":\"Locality\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"LOCALITY\" }, \"fields\":[ \"locality_id\", \"locality_name\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Approach to PD location*\", \"question_key\":\"Approach_to_PD_location\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"PDLOCATIONAPPROACH\" }, \"fields\":[ \"pd_location_approach_id\", \"description\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Comment on Locality\", \"question_key\":\"Comment_on_Locality\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"COMMENTSONLOCALITY\" }, \"fields\":[ \"comments_on_locality_id\", \"rating\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] }, { \"question\":\"Unit of Measurement\", \"question_key\":\"Unit_of_Measurement\", \"type\":\"3\", \"disable\":false, \"field_width\":\"45\", \"api_properties\":{ \"api\":\"getListOfMaster\", \"api_method\":\"POST\", \"params\":{ \"master_name\":\"UOM\" }, \"fields\":[ \"uom_id\", \"name\" ] }, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] },{ \"question\":\"Estimate area of the Residence\", \"question_key\":\"Estimate_area_of_the_Residence\", \"type\":\"1\", \"disable\":false, \"field_width\":\"45\", \"api_properties\": null, \"answers\": null, \"onchange_properties\":null, \"is_repeatable\":null, \"validations\":[ { \"name\":\"required\", \"isactive\":\"1\", \"validator\":\"Validators.required\", \"message\":\"Field Required\", \"value\":null } ] } ] }", // "form_id": "5" - public function saveTemplateFormsV2_post(){ - $records = $this->post("records"); - $json = json_encode($records['json'],true); - $fields = array('id'); - $where_condition_array = array('entity_id'=>$records['entity_id'],'product_id'=>$records['product_id'],'customer_segment_id'=>$records['customer_segment_id'],"isactive"=>1); - $mapping_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_MAP_V2); - // print_r($mapping_table);die(); - if(count($mapping_table)>0){ - $map_id = $mapping_table[0]['id']; - //in-active existing Entries here using Map ID and Form ID means - $fields = array('id'); - $where_condition_array = array('map_id'=>$map_id,"form_id"=>$records['form_id'],"isactive"=>1); - $json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2); - if(count($json_table)>0){ - $this->db->where('id',$json_table[0]['id']); - $this->db->set('isactive',0); - $this->db->update(TEMPLATE_JSON_V2); - } - // insert json here. - $fields = array('isactive' => 1,'form_id' => $records['form_id'],'json' => $json,'map_id'=>$map_id); - $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); - } - else{ - // insert map & its json here. - $fields = array('entity_id'=>$records['entity_id'],'product_id'=>$records['product_id'],'customer_segment_id'=>$records['customer_segment_id'],"isactive"=>1); - $map_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_MAP_V2); - if($map_pk_id){ - $fields = array('isactive' => 1,'form_id' => $records['form_id'],'json' => $json,'map_id'=>$map_pk_id); - $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); - } - } + // public function saveTemplateFormsV2_post(){ + // $records = $this->post("records"); + // $json = json_encode($records['json'],true); + // $fields = array('id'); + // $where_condition_array = array('entity_id'=>$records['entity_id'],'product_id'=>$records['product_id'],'customer_segment_id'=>$records['customer_segment_id'],"isactive"=>1); + // $mapping_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_MAP_V2); + // // print_r($mapping_table);die(); + // if(count($mapping_table)>0){ + // $map_id = $mapping_table[0]['id']; + // //in-active existing Entries here using Map ID and Form ID means + // $fields = array('id'); + // $where_condition_array = array('map_id'=>$map_id,"form_id"=>$records['form_id'],"isactive"=>1); + // $json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2); + // if(count($json_table)>0){ + // $this->db->where('id',$json_table[0]['id']); + // $this->db->set('isactive',0); + // $this->db->update(TEMPLATE_JSON_V2); + // } + // // insert json here. + // $fields = array('isactive' => 1,'form_id' => $records['form_id'],'json' => $json,'map_id'=>$map_id); + // $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); + // } + // else{ + // // insert map & its json here. + // $fields = array('entity_id'=>$records['entity_id'],'product_id'=>$records['product_id'],'customer_segment_id'=>$records['customer_segment_id'],"isactive"=>1); + // $map_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_MAP_V2); + // if($map_pk_id){ + // $fields = array('isactive' => 1,'form_id' => $records['form_id'],'json' => $json,'map_id'=>$map_pk_id); + // $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); + // } + // } - if($json_pk_id) + // if($json_pk_id) + // { + // $data['dataStatus'] = true; + // $data['status'] = REST_Controller::HTTP_OK; + // $data['records'] = "Sucessfully Inserted"; + // $this->response($data,REST_Controller::HTTP_OK); + // } + // else + // { + // $data['dataStatus'] = false; + // $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; + // $data['msg'] = 'Something Went Wrong! Try again Later'; + // $this->response($data,REST_Controller::HTTP_OK); + // } + + // } + + // API 3 : to save and Update the Mapping Details and return the Pkid + public function saveTemplateV2_post(){ + $records = $this->post("records"); + // print_r($records);die(); + if( (!isset($records['entity_id'])) && (!isset($records['product_id'])) && (!isset($records['customer_segment_id'])) ) + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Key Missing! Try again Later'; + $this->response($data,REST_Controller::HTTP_OK); + }else{ + $fields = array('id'); + $where_condition_array = $records; + $where_condition_array['isactive'] = 1; + $map_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_MAP_V2); + if(count($map_table)>0){ + // $this->db->where('id',$map_table[0]['id']); + // $this->db->set('isactive',0); + // $this->db->update(TEMPLATE_MAP_V2); + $map_pk_id = (int)$map_table[0]['id']; + $msg = "Entry Alredy Available For Given Params"; + }else{ + $map_pk_id = $this->Template_Management_Model->saveTemplateMapping($records,TEMPLATE_MAP_V2); + $msg = "Sucessfully Inserted"; + } + + + if($map_pk_id) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; - $data['records'] = "Sucessfully Inserted"; + $data['map_id'] = $map_pk_id; + $data['msg'] = $msg; $this->response($data,REST_Controller::HTTP_OK); } else @@ -971,12 +1041,49 @@ class Template_Management_Controller extends REST_Controller { $data['msg'] = 'Something Went Wrong! Try again Later'; $this->response($data,REST_Controller::HTTP_OK); } - + } } - //Update Form Template Details V2.0 : ps 20/12/2021 - public function updateTemplateFormsV2_post(){ - + // API 4 : to save and Update the Mapping Details and return the Pkid + public function saveTemplateFormsV2_post(){ + $records = $this->post("records"); + if(!isset($records['json']) || !isset($records['form_id']) || !isset($records['map_id'])) + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Key Missing! Try again Later'; + $this->response($data,REST_Controller::HTTP_OK); + }else{ + $map_id = $records['map_id']; + $form_id = $records['form_id']; + $fields = array('id'); + $where_condition_array = array('map_id'=>$map_id,"form_id"=>$form_id,"isactive"=>1); + $json_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATE_JSON_V2); + if(count($json_table)>0){ + $this->db->where('id',$json_table[0]['id']); + $this->db->set('isactive',0); + $this->db->update(TEMPLATE_JSON_V2); + } + $json = json_encode($records['json'],true); + $fields = array('form_id' => $form_id,'json' => $json,'map_id'=>$map_id); + $json_pk_id = $this->Template_Management_Model->saveTemplateMapping($fields,TEMPLATE_JSON_V2); + if($json_pk_id) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['json_id'] = $json_pk_id; + $data['msg'] = "Sucessfully Inserted"; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; + $data['msg'] = 'Something Went Wrong! Try again Later'; + $this->response($data,REST_Controller::HTTP_OK); + } + } + } } \ No newline at end of file diff --git a/api/application/models/Template_Management_Model.php b/api/application/models/Template_Management_Model.php index d8997fb5..18937e41 100644 --- a/api/application/models/Template_Management_Model.php +++ b/api/application/models/Template_Management_Model.php @@ -279,8 +279,19 @@ class Template_Management_Model extends SPARQ_Model { } + public function getTemplateMappingDetailsV2($lender_id){ + $this->db->SELECT('TEMPLATE_MAP_V2.id as map_id, TEMPLATE_MAP_V2.entity_id, ENTITY.full_name, ENTITY.short_name, TEMPLATE_MAP_V2.product_id,PRODUCTS.name as product_name,PRODUCTS.abbr as product_abbr, TEMPLATE_MAP_V2.customer_segment_id,CUSTOMERSEGMENT.name as customer_segment_name,CUSTOMERSEGMENT.abbr as customer_segment_abbr'); + $this->db->FROM(TEMPLATE_MAP_V2.' as TEMPLATE_MAP_V2'); + $this->db->JOIN(ENTITY.' as ENTITY','TEMPLATE_MAP_V2.entity_id = ENTITY.entity_id','LEFT'); + $this->db->JOIN(PRODUCTS.' as PRODUCTS','TEMPLATE_MAP_V2.product_id = PRODUCTS.product_id','LEFT'); + $this->db->JOIN(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT','TEMPLATE_MAP_V2.customer_segment_id = CUSTOMERSEGMENT.customer_segment_id','LEFT'); + $this->db->WHERE('TEMPLATE_MAP_V2.entity_id',$lender_id); + $result = $this->db->GET()->result_array(); + return $result; + } + public function getTemplateFormsV2($records){ - $this->db->SELECT('TEMPLATE_MAP_V2.id, TEMPLATE_MAP_V2.entity_id, TEMPLATE_MAP_V2.product_id, TEMPLATE_MAP_V2.customer_segment_id, TEMPLATE_MAP_V2.isactive,TEMPLATE_JSON_V2.form_id,TEMPLATE_JSON_V2.json'); + $this->db->SELECT('TEMPLATE_MAP_V2.id as map_id, TEMPLATE_MAP_V2.entity_id, TEMPLATE_MAP_V2.product_id, TEMPLATE_MAP_V2.customer_segment_id,TEMPLATE_JSON_V2.form_id,TEMPLATE_JSON_V2.json'); $this->db->FROM(TEMPLATE_MAP_V2.' as TEMPLATE_MAP_V2'); $this->db->JOIN(TEMPLATE_JSON_V2.' as TEMPLATE_JSON_V2','TEMPLATE_MAP_V2.id = TEMPLATE_JSON_V2.map_id','LEFT'); if(isset($records['entity_id'])) @@ -305,27 +316,4 @@ class Template_Management_Model extends SPARQ_Model { return $insert_id; } - - - - public function updateTemplateFormsV2($records){ - // $this->db->SELECT('TEMPLATE_JSON_V2.id, TEMPLATE_JSON_V2.entity_id, TEMPLATE_JSON_V2.product_id, TEMPLATE_JSON_V2.customer_segment_id, TEMPLATE_JSON_V2.isactive,TEMPLATE_MAP_V2.json, TEMPLATE_MAP_V2.form_id'); - // $this->db->FROM(TEMPLATE_JSON_V2.' as TEMPLATE_JSON_V2'); - // $this->db->JOIN(TEMPLATE_MAP_V2.' as TEMPLATE_MAP_V2','TEMPLATE_MAP_V2.map_id = TEMPLATE_JSON_V2.id','LEFT'); - // if(isset($records['entity_id'])) - // { - // $this->db->WHERE('TEMPLATE_JSON_V2.entity_id',$records['entity_id']); - // } - // if(isset($records['product_id'])) - // { - // $this->db->WHERE('TEMPLATE_JSON_V2.product_id',$records['product_id']); - // } - // if(isset($records['customer_segment_id'])) - // { - // $this->db->WHERE('TEMPLATE_JSON_V2.customer_segment_id',$records['customer_segment_id']); - // } - // $result = $this->db->GET()->result_array(); - // return $result; - } - } \ No newline at end of file