From 014d3776d47ded28bf37a7927670189bf7a86f74 Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Tue, 14 Jan 2020 17:42:57 +0530 Subject: [PATCH] SALES PD & SATELLITE SCRIPT CHANGED --- api/application/controllers/PD_Controller.php | 19 ++++++- .../controllers/Sales_PD_Controller.php | 15 ++++-- api/application/helpers/pdalerts_helper.php | 5 +- .../helpers/satellite_image_helper.php | 51 +++++++++++-------- .../report_templates/JSONTOREPORT_DI_AI.php | 2 +- .../views/sale_pd_templates/MWISE.php | 2 +- 6 files changed, 63 insertions(+), 31 deletions(-) diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 162e0e49..e4b1706d 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -4436,9 +4436,24 @@ public function getPDFormDetailsJSON_post() //if(isset($overall_summary_report['sales_calculated_by_monthwise']['netprofit'])){ $temp_netmargin_array = array_merge($temp_netmargin_array,array($overall_summary_report['sales_calculated_by_monthwise']['netprofit'])); } if(isset($overall_summary_report['sales_calculated_by_itemwise']['netprofit'])){ $temp_netmargin_array = array_merge($temp_netmargin_array,array($overall_summary_report['sales_calculated_by_itemwise']['netprofit'])); } - $overall_summary_report['consolidated_report']['consolidated_sales_revenue'] = round(array_sum($temp_sales_array) / count($temp_sales_array)); + if(count($temp_sales_array)) + { + $overall_summary_report['consolidated_report']['consolidated_sales_revenue'] = round(array_sum($temp_sales_array) / count($temp_sales_array)); + } + else + { + $overall_summary_report['consolidated_report']['consolidated_sales_revenue'] = 0.0; + } - $overall_summary_report['consolidated_report']['consolidated_nerprofit'] = round(array_sum($temp_netmargin_array) / count($temp_netmargin_array)); + + if(count($temp_netmargin_array)) + { + $overall_summary_report['consolidated_report']['consolidated_nerprofit'] = round(array_sum($temp_netmargin_array) / count($temp_netmargin_array)); + } + else + { + $overall_summary_report['consolidated_report']['consolidated_nerprofit'] = 0.0; + } if($overall_summary_report['consolidated_report']['consolidated_nerprofit'] != 0 && $overall_summary_report['consolidated_report']['consolidated_sales_revenue'] != 0) { diff --git a/api/application/controllers/Sales_PD_Controller.php b/api/application/controllers/Sales_PD_Controller.php index 0e0a511e..0fdbc6e2 100644 --- a/api/application/controllers/Sales_PD_Controller.php +++ b/api/application/controllers/Sales_PD_Controller.php @@ -188,8 +188,7 @@ class Sales_PD_Controller extends REST_Controller { { - //$json_data = (json_decode($sales_pd_data[0]['pd_json'],true)); - satellite_image::getSatelliteImage($sales_pd_id,2); + $all_section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $sales_pd_id,'isactive' => 1),SALESPD_SECTION_DATA); // print_r($this->db->last_query());die(); $view_data['master'] = $sales_pd_data; @@ -451,9 +450,12 @@ class Sales_PD_Controller extends REST_Controller { $update_fields = array('geo_location' => $records['location']); $this->Sales_PD_Model->updateRecords($update_fields,SALES_PD_DATA,array('sales_pd_id' => $records['fk_sales_pd_id'])); + satellite_image::getSatelliteImage($records['fk_sales_pd_id'],2); + //disable previous selfie img $update_fields2 = array('isactive' => 0); $this->Sales_PD_Model->updateRecords($update_fields2,SALEPD_DOCS,array('img_name' => 'selfie_with_person_met','fk_sales_pd_id' => $records['fk_sales_pd_id'])); + } $id = $this->Sales_PD_Model->saveRecords($records,SALEPD_DOCS); @@ -561,9 +563,11 @@ class Sales_PD_Controller extends REST_Controller { { $records['status'] = 'COMPLETED'; $records['completed_date'] = date('Y-m-d h:i:s'); + $id = $this->Sales_PD_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); - satellite_image::getSatelliteImage($records['sales_pd_id'],2); + $this->prepareSalesPDReport($records['sales_pd_id'],false); + sleep(5); //trigger mail function PDALERTS::sendSalesPDMail($this,$records['sales_pd_id']); } @@ -797,7 +801,10 @@ class Sales_PD_Controller extends REST_Controller { public function testAPISalesPD_post() { - PDALERTS::sendSalesPDMail($this,14);die(); + //PDALERTS::sendSalesPDMail($this,32);die(); + satellite_image::getSatelliteImage(32,2);//die(); + // $url = "https://maps.googleapis.com/maps/api/staticmap?center=12.9788141,80.1871334&zoom=14&markers=color:red|12.9788141,80.1871334&size=800x300&maptype=roadmap&key=AIzaSyA3lYDYxwtn5vLSl45SOKbtK7G6cEyXGr0"; + // file_put_contents('test.jpg', file_get_contents($url)); } public function salesPDMisReport_post() diff --git a/api/application/helpers/pdalerts_helper.php b/api/application/helpers/pdalerts_helper.php index 94229ff4..d601e852 100644 --- a/api/application/helpers/pdalerts_helper.php +++ b/api/application/helpers/pdalerts_helper.php @@ -206,7 +206,10 @@ class PDALERTS self::sendMail($CI,'komalmittal@sinemanagement.com',$msg,$core_details); - self::sendMail($CI,'sinepd@sinemanagement.com',$msg,$core_details); + if($core_details[0]['pd_status'] != 'TRIGGERED') + { + self::sendMail($CI,'sinepd@sinemanagement.com',$msg,$core_details); + } } diff --git a/api/application/helpers/satellite_image_helper.php b/api/application/helpers/satellite_image_helper.php index bc89fd34..8610a315 100644 --- a/api/application/helpers/satellite_image_helper.php +++ b/api/application/helpers/satellite_image_helper.php @@ -18,41 +18,48 @@ class satellite_image { mkdir($path_to_check,0777); } - + $google_map_static_api_key = GOOGLE_STATIC_MAP_API_KEY; if($pd_type == 1) { $pdmas = $CI->PD_Model->getPDMasterDetails($pdid); $geo_location = $pdmas[0]['start_location']; + + + // $satellite_script_from_db = $CI->$model_to_load->selectCustomRecords(array('*'),array('script_name' => SATELLITE_IMAGE_LOCATION),SCRIPTS); + // $satellite_script = $satellite_script_from_db[0]['script_content']; + + + + + //Replacing Place holders + + + // $satellite_script = str_replace('{{APPPATH}}',$path_to_check,$satellite_script); + // $satellite_script = str_replace('{{ADDRESS}}',$geo_location,$satellite_script); + // $satellite_script = str_replace('{{GEOLOCATION}}',$geo_location,$satellite_script); + // $satellite_script = str_replace('{{API_KEY}}',$google_map_static_api_key,$satellite_script); + // //echo $satellite_script;die(); + + // file_put_contents(APPPATH.'/views/js/phantomsatellite.js',$satellite_script); + + // //call& execute phantom script + // $str = 'phantomjs '.APPPATH.'/views/js/phantomsatellite.js'; + // exec($str,$ou); + // exec('phantom.exit();'); } else if($pd_type == 2) { $pdmas = $CI->Sales_PD_Model->selectCustomRecords(array('geo_location'),array('sales_pd_id' => $pdid),SALES_PD_DATA); $geo_location = $pdmas[0]['geo_location']; + } + $url = "https://maps.googleapis.com/maps/api/staticmap?center=".$geo_location."&zoom=14&markers=color:red|".$geo_location."&size=800x300&maptype=roadmap&key=".$google_map_static_api_key; + //echo $url; + $ou = file_put_contents($path_to_check.'/satellite.png', file_get_contents($url)); + $satellite_script = $url; - $satellite_script_from_db = $CI->$model_to_load->selectCustomRecords(array('*'),array('script_name' => SATELLITE_IMAGE_LOCATION),SCRIPTS); - $satellite_script = $satellite_script_from_db[0]['script_content']; - - $google_map_static_api_key = GOOGLE_STATIC_MAP_API_KEY; - - - //Replacing Place holders - - - $satellite_script = str_replace('{{APPPATH}}',$path_to_check,$satellite_script); - $satellite_script = str_replace('{{ADDRESS}}',$geo_location,$satellite_script); - $satellite_script = str_replace('{{GEOLOCATION}}',$geo_location,$satellite_script); - $satellite_script = str_replace('{{API_KEY}}',$google_map_static_api_key,$satellite_script); - //echo $satellite_script;die(); - - file_put_contents(APPPATH.'/views/js/phantomsatellite.js',$satellite_script); - - //call& execute phantom script - $str = 'phantomjs '.APPPATH.'/views/js/phantomsatellite.js'; - exec($str,$ou); - exec('phantom.exit();'); // //convert as base 64 image. diff --git a/api/application/views/report_templates/JSONTOREPORT_DI_AI.php b/api/application/views/report_templates/JSONTOREPORT_DI_AI.php index bcd7670e..6c35bc35 100644 --- a/api/application/views/report_templates/JSONTOREPORT_DI_AI.php +++ b/api/application/views/report_templates/JSONTOREPORT_DI_AI.php @@ -1122,7 +1122,7 @@ if ( isset($pdf) ) { echo '

'; echo 'The PD visit was done at '. $address_type. 'Address Form - Type of Address of the loan applicants. '; echo 'The '.$address_type.'Address Form - Type of Address is '.$property_owner_type.'Business Assest Form - Owner of the Property and the business has been in operation from here for the last '.$yrs_being_run.'Business Assest Form - Business running Yrs in this premise .'; - echo '

The '.$address_type.'Address Form - Type of Address is located in '.$locality.'Address Form - Locality of Address and the estimated area of the '.$address_type.'Address Form - Type of Address is '.$estimated_area.'Address Form - Estimated Area .'; + echo '

The '.$address_type.'Address Form - Type of Address is located in '.$locality.'Address Form - Locality of Address '.($estimated_area != 0? 'and the estimated area of the '.$address_type.'Address Form - Type of Address is '.$estimated_area.'Address Form - Estimated Area .' : ''); echo '

The PD location was '. $pd_address['pd_location_master'].'Address Form - Approach to PD location . ' . 'As Per PD Officer, the '.$address_type .'Address Form - Type of Address is situated in '.$comment_locality_master .'Address Form - Comment on locality Locality.'; echo '

The PD officer also made the following observations:' ; echo '