diff --git a/api/application/config/constants.php b/api/application/config/constants.php index d8994241..c345663d 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -130,6 +130,7 @@ else if(ENVIRONMENT == 'testing') defined('SALESPD_CUSTOMER_IMG_URL') OR define('SALESPD_CUSTOMER_IMG_URL','https://demo.pdgenie.com/customer/#/salespd_images/'); defined('CUSTOMER_IMG_URL') OR define('CUSTOMER_IMG_URL','https://demo.pdgenie.com/customer/#/pd-images/'); defined('PDF_ATTACHEMENT_URL') OR define('PDF_ATTACHEMENT_URL','https://apitest.pdgenie.com/sparqtest/api/short?dat='); + defined('GOOGLE_DISTANCE_MATRIX_API_KEY') OR define('GOOGLE_DISTANCE_MATRIX_API_KEY',getenv('GOOGLE_DISTANCE_MATRIX_API_KEY')); } else if(ENVIRONMENT == 'production') { @@ -144,6 +145,7 @@ else if(ENVIRONMENT == 'production') defined('SALESPD_CUSTOMER_IMG_URL') OR define('SALESPD_CUSTOMER_IMG_URL','https://pdgenie.com/customer/#/salespd_images/'); defined('CUSTOMER_IMG_URL') OR define('CUSTOMER_IMG_URL','https://pdgenie.com/customer/#/pd-images/'); defined('PDF_ATTACHEMENT_URL') OR define('PDF_ATTACHEMENT_URL','https://api.pdgenie.com/sparqprod/api/short?dat='); + defined('GOOGLE_DISTANCE_MATRIX_API_KEY') OR define('GOOGLE_DISTANCE_MATRIX_API_KEY',getenv('GOOGLE_DISTANCE_MATRIX_API_KEY')); } /*********************END of AWS resources Constants*************************************************/ diff --git a/api/application/controllers/Dash_Board_Controller.php b/api/application/controllers/Dash_Board_Controller.php index c43e1469..6aa59788 100644 --- a/api/application/controllers/Dash_Board_Controller.php +++ b/api/application/controllers/Dash_Board_Controller.php @@ -194,10 +194,13 @@ class Dash_Board_Controller extends REST_Controller { $title_arr = explode(",",$field_mapping[$a]['column_title']); } $array = json_decode(json_encode($res), true); - for($i=0;$iresponse($data,REST_Controller::HTTP_OK); } + } \ No newline at end of file diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index ba0f3b41..74de48f3 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -6266,8 +6266,14 @@ public function getPDFormDetailsJSON_post() // } // else // { - //echo 'NOR'; - $pd_type = $data['pd_master_details'][0]['fk_pd_type'] == 3 ? 3 : 1; + // echo 'NOR'; + // print_r($data['pd_master_details']);die(); + if($data['pd_master_details'][0]['lender_short_name'] == 'CSLFL'){ + $entity_geo_location = $this->PD_Model->getEntityAddr($data['pd_master_details'][0]['fk_lender_id']); + $pd_location = $data['pd_master_details'][0]['start_location']; + $data['distances'] = satellite_image::getdistancematrix($entity_geo_location,$pd_location); + } + $pd_type = $data['pd_master_details'][0]['fk_pd_type'] == 3 ? 3 : 1; $data['lender_disclaimer'] = $this->PD_Model->selectRecords(ENTITYDISCLAIMER,array('fk_entity_id' => ($data['pd_master_details'][0]['sub_entity_id'] ? $data['pd_master_details'][0]['sub_entity_id'] : $data['pd_master_details'][0]['fk_lender_id']),'fk_pd_type' => $pd_type)); //} //print_r($data['lender_disclaimer']);die(); @@ -6393,7 +6399,6 @@ public function getPDFormDetailsJSON_post() if(!count($add_on_pd)) { - if($data['pd_master_details'][0]['fk_pd_type'] == 1 ) { @@ -9774,7 +9779,7 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() $pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id,$random_string); // print_r($pd_master_details);die(); $result_data = (new video_grabber_helper)->grabAllVideo($pd_master_details[0]['pd_id'],$pd_master_details[0]['random_string'],$pd_master_details); - + exit(); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; @@ -11236,7 +11241,13 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() $records = array('file_id' => $pd_id,'addressline' => $addresses[0]['addressline1'],'city' => $addresses[0]['fk_city'],'state' => $addresses[0]['fk_state'],'pincode' => $addresses[0]['pincode']); $this->PD_Model->saveRecords($records,SMC_TEMP_ADDRESS); } - + + function distancematrix_get(){ + $pd_loc = $this->get('loc'); + $lender = $this->get('lender'); + $entity_loc = $this->PD_Model->getEntityAddr($lender); + $this->response(satellite_image::getdistancematrix($entity_loc,$pd_loc),REST_Controller::HTTP_OK,true); + } } diff --git a/api/application/helpers/satellite_image_helper.php b/api/application/helpers/satellite_image_helper.php index 68abf81e..a0140063 100644 --- a/api/application/helpers/satellite_image_helper.php +++ b/api/application/helpers/satellite_image_helper.php @@ -117,5 +117,31 @@ class satellite_image } } + + public static function getdistancematrix($from_addr,$to_addr){ + if((int)$from_addr != 0){ + // $apikey = GOOGLE_DISTANCE_MATRIX_API_KEY; + $apikey = "AIzaSyA1QV-A3t_3RwlozdlwgxlXnLNb_3WqxfY"; // now hardcoded + $url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=".$from_addr."&destinations=".$to_addr."&mode=driving&key=".$apikey; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_PROXYPORT, 3128); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + $response = curl_exec($ch); + curl_close($ch); + $response_a = json_decode($response, true); + if($response_a['rows'][0]['elements'][0]['status'] != "ZERO_RESULTS"){ + $dist = $response_a['rows'][0]['elements'][0]['distance']['text']; + $time = $response_a['rows'][0]['elements'][0]['duration']['text']; + return array('status'=>true,'distance' => $dist, 'time' => $time,'url'=>$url); + }else{ + return array('status'=>false,'distance' => '0 km', 'time' => '0 days','url'=>$url); + } + }else{ + return array('status'=>false,'distance' => '0 km', 'time' => '0 days','url'=>""); + } + } } ?> \ No newline at end of file diff --git a/api/application/models/PD_Model.php b/api/application/models/PD_Model.php index 55cd89f1..9fe550cc 100644 --- a/api/application/models/PD_Model.php +++ b/api/application/models/PD_Model.php @@ -2254,5 +2254,19 @@ class PD_Model extends SPARQ_Model { // print_r($this->db->last_query());exit(); } + function getEntityAddr($Eid){ + $this->db->select('geo_loc'); + $this->db->from(ENTITYBILLING.' as ENTITYBILLING'); + $this->db->where('fk_entity_id',$Eid); + $this->db->where('isactive',1); + $this->db->where('is_dist_cal_enable',1); + $query = $this->db->get(); + if ($query->num_rows() > 0) { + $result = $query->row()->geo_loc; + }else{ $result = 0; } + return $result; + } + // SELECT as full_address FROM sineedgedemo.m_entity_billing where fk_entity_id = 43 and isactive = 1 and is_dist_cal_enable = 1; + } \ No newline at end of file diff --git a/api/application/views/report_templates/JSONTOREPORT_CLIX.php b/api/application/views/report_templates/JSONTOREPORT_CLIX.php index 01a0a64d..43fc8882 100644 --- a/api/application/views/report_templates/JSONTOREPORT_CLIX.php +++ b/api/application/views/report_templates/JSONTOREPORT_CLIX.php @@ -1056,7 +1056,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_CLIX_SMARTPD.php b/api/application/views/report_templates/JSONTOREPORT_CLIX_SMARTPD.php index 413659da..1626e75b 100644 --- a/api/application/views/report_templates/JSONTOREPORT_CLIX_SMARTPD.php +++ b/api/application/views/report_templates/JSONTOREPORT_CLIX_SMARTPD.php @@ -1062,7 +1062,9 @@ font-weight: bolder;; echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_DI_AI.php b/api/application/views/report_templates/JSONTOREPORT_DI_AI.php index d2cfe867..6c0c60c1 100644 --- a/api/application/views/report_templates/JSONTOREPORT_DI_AI.php +++ b/api/application/views/report_templates/JSONTOREPORT_DI_AI.php @@ -1080,7 +1080,9 @@ if ( isset($pdf) ) { echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_DI_AI_ADDON.php b/api/application/views/report_templates/JSONTOREPORT_DI_AI_ADDON.php index 02ff3086..769625c3 100644 --- a/api/application/views/report_templates/JSONTOREPORT_DI_AI_ADDON.php +++ b/api/application/views/report_templates/JSONTOREPORT_DI_AI_ADDON.php @@ -1304,7 +1304,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_DI_AI_SMARTPD.php b/api/application/views/report_templates/JSONTOREPORT_DI_AI_SMARTPD.php index 69db546e..58f4d7b7 100644 --- a/api/application/views/report_templates/JSONTOREPORT_DI_AI_SMARTPD.php +++ b/api/application/views/report_templates/JSONTOREPORT_DI_AI_SMARTPD.php @@ -1073,7 +1073,9 @@ if ( isset($pdf) ) { echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_RI.php b/api/application/views/report_templates/JSONTOREPORT_RI.php index 16ae56ef..4b57582d 100644 --- a/api/application/views/report_templates/JSONTOREPORT_RI.php +++ b/api/application/views/report_templates/JSONTOREPORT_RI.php @@ -851,7 +851,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_RI_SMARTPD.php b/api/application/views/report_templates/JSONTOREPORT_RI_SMARTPD.php index 16ae56ef..4b57582d 100644 --- a/api/application/views/report_templates/JSONTOREPORT_RI_SMARTPD.php +++ b/api/application/views/report_templates/JSONTOREPORT_RI_SMARTPD.php @@ -851,7 +851,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_SAL.php b/api/application/views/report_templates/JSONTOREPORT_SAL.php index 9c233ae7..b00235dc 100644 --- a/api/application/views/report_templates/JSONTOREPORT_SAL.php +++ b/api/application/views/report_templates/JSONTOREPORT_SAL.php @@ -854,7 +854,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?> diff --git a/api/application/views/report_templates/JSONTOREPORT_SAL_SMARTPD.php b/api/application/views/report_templates/JSONTOREPORT_SAL_SMARTPD.php index 904fb21a..80791a1b 100644 --- a/api/application/views/report_templates/JSONTOREPORT_SAL_SMARTPD.php +++ b/api/application/views/report_templates/JSONTOREPORT_SAL_SMARTPD.php @@ -861,7 +861,9 @@ font-weight: bolder;; echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode.'.'; } - + if($pd_master_details[0]['lender_short_name'] == 'CSLFL'){ + echo '

Total distances of Entity location and PD Visit location : '.$distances['distance'].' and '. $distances['time']; + } echo '

GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location']; echo '

'; ?>