From f81d9e8ddea9c845d071fdbd61980fdd374e23b2 Mon Sep 17 00:00:00 2001 From: "venbatechnologies@gmail.com" Date: Sat, 17 Nov 2018 12:50:02 +0530 Subject: [PATCH] Dashboard Chart Query Changes : ps --- api/application/config/routes.php | 3 +- .../controllers/Dash_Board_Controller.php | 26 +++++++++ api/application/models/Dash_Board_Model.php | 56 +++++++++++++++---- 3 files changed, 74 insertions(+), 11 deletions(-) diff --git a/api/application/config/routes.php b/api/application/config/routes.php index a227bc4e..cfa0baf9 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -156,7 +156,8 @@ $route['getPDFormDetails'] = 'PD_Controller/getPDFormDetails'; $route['savePDFormDetails'] = 'PD_Controller/savePDFormDetails'; //Dashboard and Reports Related routes -$route['getDashBoardMaster'] = 'Dash_Board_Controller/getDashBoardDetailsOfPDTypeAndPDStatusWithDayWeekMonth'; +//$route['getDashBoardMaster'] = 'Dash_Board_Controller/getDashBoardDetailsOfPDTypeAndPDStatusWithDayWeekMonth'; +$route['getDashBoardMaster'] = 'Dash_Board_Controller/getDashBoardDetails'; $route['getDashBoardLenderCity'] = 'Dash_Board_Controller/getDashBoardDetailsOfLenderAndCitywise'; $route['getDashBoardDetailsOfCity'] = 'Dash_Board_Controller/getDashBoardDetailsOfCitywise'; $route['getDashBoardAlertDetails'] = 'Dash_Board_Controller/getDashBoardDetailsOfAlert'; diff --git a/api/application/controllers/Dash_Board_Controller.php b/api/application/controllers/Dash_Board_Controller.php index e4e10373..2e7c0dff 100644 --- a/api/application/controllers/Dash_Board_Controller.php +++ b/api/application/controllers/Dash_Board_Controller.php @@ -30,6 +30,32 @@ class Dash_Board_Controller extends REST_Controller { $data['records'] = $res; $this->response($data,REST_Controller::HTTP_OK); } + + public function getDashBoardDetails_post() + { + $fdate = ''; + $tdate = ''; + $cityarr = ''; + $lenderarr = ''; + + if($this->post('fromdate')) { $fdate = $this->post('fromdate'); } + if($this->post('todate')){ $tdate = $this->post('todate'); } + if($this->post('cityarr')) { $cityarr = $this->post('cityarr'); } + if($this->post('lenderarr')) { $lenderarr = $this->post('lenderarr'); } + + // echo $from_date; + // echo $to_date; + // print_r($city_arr); + // print_r($lender_arr); + // die(); + $res = $this->Dash_Board_Model->getDetailsOfPDType($fdate,$tdate,$lenderarr,$cityarr); + + + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $res; + $this->response($data,REST_Controller::HTTP_OK); + } public function getDashBoardDetailsOfLenderAndCitywise_get() { diff --git a/api/application/models/Dash_Board_Model.php b/api/application/models/Dash_Board_Model.php index 53f7a95e..cdb4f2c8 100644 --- a/api/application/models/Dash_Board_Model.php +++ b/api/application/models/Dash_Board_Model.php @@ -11,19 +11,55 @@ class Dash_Board_Model extends SPARQ_Model { } - public function getDetailsOfPDTypeAndPDStatusWithDayWeekMonth() + // public function getDetailsOfPDTypeAndPDStatusWithDayWeekMonth() + // { + // $sql_query_current_day = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count FROM t_pd_triggered where date_format(createdon,'%Y-%m-%d') = date_format(CURDATE(),'%Y-%m-%d') group by fk_pd_type,pd_status;"; + // $result_data['current_day'] = $this->db->query($sql_query_current_day)->result_array(); + + // $sql_query_current_week = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count,WEEK(createdon),WEEK(CURDATE()) FROM t_pd_triggered where WEEK(createdon) = WEEK(CURDATE()) group by fk_pd_type,pd_status;"; + // $result_data['current_week'] = $this->db->query($sql_query_current_week)->result_array(); + + // $sql_query_current_month = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count FROM t_pd_triggered where MONTH(createdon) = MONTH(CURDATE()) group by fk_pd_type,pd_status;"; + // $result_data['current_month'] = $this->db->query($sql_query_current_month)->result_array(); + // return $result_data; + // } + + public function getDetailsOfPDType($fdate,$tdate,$cityarr,$lenderarr) { - $sql_query_current_day = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count FROM t_pd_triggered where date_format(createdon,'%Y-%m-%d') = date_format(CURDATE(),'%Y-%m-%d') group by fk_pd_type,pd_status;"; - $result_data['current_day'] = $this->db->query($sql_query_current_day)->result_array(); + if(($lenderarr != "" || $lenderarr != null)&& ($cityarr != "" || $cityarr != null) && ($fdate && $tdate != '')){ + $sql_query = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count FROM t_pd_triggered where MONTH(createdon) = MONTH(CURDATE()) group by fk_pd_type,pd_status;"; + } + else{ + $sql_query = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count FROM t_pd_triggered where "; - $sql_query_current_week = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count,WEEK(createdon),WEEK(CURDATE()) FROM t_pd_triggered where WEEK(createdon) = WEEK(CURDATE()) group by fk_pd_type,pd_status;"; - $result_data['current_week'] = $this->db->query($sql_query_current_week)->result_array(); - - $sql_query_current_month = "SELECT if(fk_pd_type = 1,'FULL',if(fk_pd_type = 2,'SMART',if(fk_pd_type = 3,'TELE','NULL'))) as PDTYPE,pd_status,count(*) as count FROM t_pd_triggered where MONTH(createdon) = MONTH(CURDATE()) group by fk_pd_type,pd_status;"; - $result_data['current_month'] = $this->db->query($sql_query_current_month)->result_array(); - return $result_data; + if($lenderarr != "") + { + $lenderarr = implode(",",$lenderarr); + $sql_query.="fk_lender_id IN (".$lenderarr.") and "; + + } + if($cityarr != "" || $cityarr != null) + { + $cityarr = implode(",",$cityarr); + $sql_query.="fk_city IN (".$cityarr.") and "; + + } + if($fdate != ""){ + + $from= date("Y-m-d",strtotime($fdate)); + $to=date("Y-m-d",strtotime($tdate)); + $sql_query.="date(t_pd_triggered.createdon) >= '".$from."' + and date(t_pd_triggered.createdon) <= '".$to."' and "; + + } + + $sql_query.= " 1 = 1 group by fk_pd_type,pd_status ;"; + } + + $result_data['current_month'] = $this->db->query($sql_query)->result_array(); + return $result_data; } - + public function getDetailsOfLenderAndCitywise() { $sql_query_current_day = "SELECT pd.fk_lender_id,entity.full_name,pd.fk_city,city.name as city_name,if(pd.fk_pd_type = 1,'FULL',if(pd.fk_pd_type = 2,'SMART',if(pd.fk_pd_type = 3,'TELE','OTHERS'))) as PDTYPE,pd.pd_status,count(*) as count FROM t_pd_triggered as pd