From 85ff00ea4f970b372659f4bf55b89d0509f3fbf1 Mon Sep 17 00:00:00 2001 From: sanjeev Date: Fri, 24 Dec 2021 12:18:49 +0530 Subject: [PATCH] Templateformv2 api changes : ps --- api/application/config/routes.php | 1 + .../Template_Management_Controller.php | 36 +++++++++++- api/application/models/Sales_PD_Model.php | 12 ++-- .../models/Template_Management_Model.php | 57 +++++++++++++------ 4 files changed, 81 insertions(+), 25 deletions(-) diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 70a6a694..fa33192b 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -336,4 +336,5 @@ $route['getTemplateMappingDetailsV2'] = 'Template_Management_Controller/getTempl $route['getTemplateFormsV2'] = 'Template_Management_Controller/getTemplateFormsV2'; $route['saveTemplateMappingDetailsV2'] = 'Template_Management_Controller/saveTemplateV2'; $route['saveAndUpdateTemplateFormsV2'] = 'Template_Management_Controller/saveTemplateFormsV2'; +$route['deleteTemplateV2'] = 'Template_Management_Controller/deleteTemplateV2'; // $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 7f78d315..627b43a8 100644 --- a/api/application/controllers/Template_Management_Controller.php +++ b/api/application/controllers/Template_Management_Controller.php @@ -924,7 +924,16 @@ class Template_Management_Controller extends REST_Controller { // 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); + $result_array = $this->Template_Management_Model->getTemplateMappingDetailsV2($records); + if(!empty($result_array)) + foreach($result_array as $inx => $arr) + { + if($arr['map_id'] != null || $arr['map_id'] != ""){ + $result_array[$inx]["forms"] = $this->Template_Management_Model->getTemplateFormsV2($arr['map_id']); + }else{ + $result_array[$inx]["forms"] = array(); + } + } if(count($result_array)) { $data['dataStatus'] = true; @@ -1085,5 +1094,30 @@ class Template_Management_Controller extends REST_Controller { } } + + //API 5 : to Delete Template Details Using map id and its json's + public function deleteDynamicTemplateV2_get(){ + $map_id = $this->get('map_id'); + if(isset($map_id) && !empty($map_id)){ + $flag = $this->Template_Management_Model->inactiveMappingDetailsandJSONV2($map_id); + if($flag) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'Successfully Deleted'; + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Noting to Delete'; + } + }else{ + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NOT_FOUND; + $data['msg'] = 'Map Id Not Found. Try Again!'; + } + $this->response($data,REST_Controller::HTTP_OK); + } } \ No newline at end of file diff --git a/api/application/models/Sales_PD_Model.php b/api/application/models/Sales_PD_Model.php index 22b349e2..23d96b5f 100644 --- a/api/application/models/Sales_PD_Model.php +++ b/api/application/models/Sales_PD_Model.php @@ -22,9 +22,9 @@ class Sales_PD_Model extends SPARQ_Model { } if(($pd_from_date != "" || $pd_from_date != null) && ($pd_to_date != "" || $pd_to_date != null)) { // $this->db->where('SALES_PD_DATA.createdon BETWEEN '. "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); - if($pd_status == "STARTED" ){ + if($pd_status[0] == "STARTED" ){ $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); - }else if($pd_status == "COMPLETED" ){ + }else if($pd_status[0] == "COMPLETED" ){ $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); }else{ $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d') BETWEEN ". "'$pd_from_date'". ' AND '. "'$pd_to_date'" ); @@ -33,9 +33,9 @@ class Sales_PD_Model extends SPARQ_Model { } else if($pd_from_date != "" && $pd_from_date != null) { // $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_from_date); - if($pd_status == "STARTED" ){ + if($pd_status[0] == "STARTED" ){ $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_from_date); - }else if($pd_status == "COMPLETED" ){ + }else if($pd_status[0] == "COMPLETED" ){ $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_from_date); }else{ $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_from_date); @@ -44,9 +44,9 @@ class Sales_PD_Model extends SPARQ_Model { } else if($pd_to_date != "" && $pd_to_date != null) { // $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_to_date); - if($pd_status == "STARTED" ){ + if($pd_status[0] == "STARTED" ){ $this->db->where("DATE_FORMAT(SALES_PD_DATA.createdon,'%Y-%m-%d')",$pd_to_date); - }else if($pd_status == "COMPLETED" ){ + }else if($pd_status[0] == "COMPLETED" ){ $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_to_date); }else{ $this->db->where("DATE_FORMAT(SALES_PD_DATA.completed_date,'%Y-%m-%d')",$pd_to_date); diff --git a/api/application/models/Template_Management_Model.php b/api/application/models/Template_Management_Model.php index 18937e41..6b869a91 100644 --- a/api/application/models/Template_Management_Model.php +++ b/api/application/models/Template_Management_Model.php @@ -279,33 +279,40 @@ class Template_Management_Model extends SPARQ_Model { } - public function getTemplateMappingDetailsV2($lender_id){ + public function getTemplateMappingDetailsV2($value){ $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); + if(!empty($value)) { + if(is_array($value)){ + if(isset($value['entity_id'])) + { + $this->db->WHERE('TEMPLATE_MAP_V2.entity_id',$value['entity_id']); + } + if(isset($value['product_id'])) + { + $this->db->WHERE('TEMPLATE_MAP_V2.product_id',$value['product_id']); + } + if(isset($value['customer_segment_id'])) + { + $this->db->WHERE('TEMPLATE_MAP_V2.customer_segment_id',$value['customer_segment_id']); + } + } + else { + $this->db->WHERE('TEMPLATE_MAP_V2.entity_id',$value); + } + } $result = $this->db->GET()->result_array(); return $result; } - public function getTemplateFormsV2($records){ - $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'])) - { - $this->db->WHERE('TEMPLATE_MAP_V2.entity_id',$records['entity_id']); - } - if(isset($records['product_id'])) - { - $this->db->WHERE('TEMPLATE_MAP_V2.product_id',$records['product_id']); - } - if(isset($records['customer_segment_id'])) - { - $this->db->WHERE('TEMPLATE_MAP_V2.customer_segment_id',$records['customer_segment_id']); - } + public function getTemplateFormsV2($value){ + $this->db->SELECT('TEMPLATE_JSON_V2.form_id,PDFORMS.pd_form_name,TEMPLATE_JSON_V2.json'); + $this->db->FROM(TEMPLATE_JSON_V2.' as TEMPLATE_JSON_V2'); + $this->db->JOIN(PDFORMS.' as PDFORMS','TEMPLATE_JSON_V2.form_id = PDFORMS.pd_form_id','LEFT'); + $this->db->WHERE('TEMPLATE_JSON_V2.map_id',$value); $result = $this->db->GET()->result_array(); return $result; } @@ -316,4 +323,18 @@ class Template_Management_Model extends SPARQ_Model { return $insert_id; } + public function inactiveMappingDetailsandJSONV2($id){ + $this->db->where('map_id',$id); + $this->db->set('isactive',0); + $this->db->update(TEMPLATE_MAP_V2); + $afftectedRows = $this->db->affected_rows(); + if(count($afftectedRows>0)){ + $this->db->where('map_id',$id); + $this->db->set('isactive',0); + $this->db->update(TEMPLATE_JSON_V2); + // $afftectedRows = $this->db->affected_rows(); + } + return count($afftectedRows)>0 ? true: false; + } + } \ No newline at end of file