diff --git a/.gitignore b/.gitignore index 8e20071b..9d455059 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ api/application/logs/* api/application/syslogs/* api/application/request_logs/* api/application/pd_reports/* +api/application/views/pd_reports/* api/application/docs/* !api/application/logs/index.html !api/application/logs/.htaccess diff --git a/api/application/config/constants.php b/api/application/config/constants.php index 6f06b0a9..e30796b9 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -85,8 +85,9 @@ defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automat defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code // define login route name for token verification -//defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', '(listAllEntites/:any)'); // no errors +//defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', '(getPDReportHTML/:any)'); // no errors defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN', 'getPDOfficerCurrentLocation'); // no errors +defined('ROUTE_LOGIN_X') OR define('ROUTE_LOGIN_X', '(getPDReportHTML/:any)'); // no errors //defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN','getFullPDDetails'); // no errors /*********************AWS resources Constants*************************************************/ diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 26f0c9d4..adde5e77 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -87,6 +87,9 @@ $route['getCustomerSegment'] = 'Common_Masters_Controller/getCustomerSegment'; + + + //USER MANAGEMENT $route['getListOfUsers'] = 'User_Management_Controller/listAllUsers'; $route['saveNewUser'] = 'User_Management_Controller/saveNewUser'; @@ -197,7 +200,8 @@ $route['getPDAddress'] = 'PD_Controller/getPDAddress'; $route['updatePDAddress'] = 'PD_Controller/updatePDAddress'; $route['getPDCompleteDetails'] = 'PD_Controller/getPDCompleteDetails'; $route['getStateCityNamesAndPincode'] = 'PD_Controller/getStateCityNamesAndPincode'; - +$route['saveHTMLReport'] = 'PD_Controller/saveHTMLReport'; +$route['(getPDReportHTML/:any)'] = 'PD_Controller/getPDReportHTML'; // $route['savePDFormDetailsJSON'] = 'PD_Controller/savePDFormDetailsJSON'; // $route['getPDFormDetailsJSON'] = 'PD_Controller/getPDFormDetailsJSON'; @@ -221,5 +225,8 @@ $route['getDashBoardDetailsOfCity'] = 'Dash_Board_Controller/getDashBoardDetails $route['getDashBoardAlertDetails'] = 'Dash_Board_Controller/getDashBoardDetailsOfAlert'; $route['PD_MIS_report'] = 'Dash_Board_Controller/PD_MIS_report'; + +//$route['(getPDReportHTML/:any)'] = 'Welcome/getPDReportHTML'; + //miscellanous //$route['showBusinessScorecard'] = 'PD_Controller/'; diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index ae6da878..e423c5a7 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -703,7 +703,7 @@ class PD_Controller extends REST_Controller { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; - for ($i = 0; $i < 8; $i++) + for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } @@ -3915,7 +3915,9 @@ class PD_Controller extends REST_Controller { /********************************************************************************************* *********************************************************************************************/ - public function generatePDReport_post() + + //Generate Report AS PDF, currenly not in use. + public function generatePDReportPDF_post() { $records = $this->post('records'); $pdid = $records['pd_id']; @@ -3981,8 +3983,7 @@ class PD_Controller extends REST_Controller { $temp = $this->load->view('report_templates/JSONTOREPORT',$data,true); //Save Report as HTML Version with timestamp - $file_name = APPPATH.'pd_reports/'.$pdid.'_'.date('Y-m-d-h-m-s').'.html'; - file_put_contents($file_name,$temp,LOCK_EX); + //PDF Gen using DOM PDF $pdf_doc = $this->pdfgenerator->generate($temp, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait"); @@ -4058,6 +4059,109 @@ class PD_Controller extends REST_Controller { } } } + + + //Generate Report as HTML File + public function generatePDReport_post() + { + $records = $this->post('records'); + $pdid = $records['pd_id']; + $fk_createdby = $records['fk_createdby']; + $original_template = "RAW"; + $is_regenerate = 0; + if(isset($records['regenerate'])) + { + $is_regenerate = 1; + } + + $data['pd_master_details'] = $this->PD_Model->getPDMasterDetails($pdid); + $data['applicants_details'] = $this->PD_Model->getApplicantsDetails($pdid); + $data['pd_additional_requirements'] = $this->PD_Model->getPDAdditionalRequirements($pdid); + $data['score_questions_display'] = $this->PD_Model->getScoreableQuestionToDispaly($pdid); + $data['pd_score'] = $this->calculateScore($pdid); + $data['dsc_cards'] = $this->getDetailedScoreCardChart( $data['pd_score'] ); + $data['assessed_income_details'] = $this->getAssessedIncomeForPDReport($pdid); + $score_for_chart = $data['pd_score']['score_summary']['overall_score']['final_score'] ? round($data['pd_score']['score_summary']['overall_score']['final_score'],1) : 0; + //echo $score_for_chart; + + //GET phantom script from DB + $phantom_script = $this->PD_Model->selectCustomRecords(array('*'),array('script_name' => PHANTOMJSSCRIPT_LOCATION),SCRIPTS); + + $exact_script = $phantom_script[0]['script_content']; + //print_r($exact_script); + $exact_script = str_replace('{{place_score_here}}',$score_for_chart,$exact_script); + //print_r($exact_script);die(); + + + //GENERATE CHART PART + file_put_contents(APPPATH.'/views/js/phantomchart.js',$exact_script,LOCK_EX); + + $str = 'phantomjs '.APPPATH.'/views/js/phantomchart.js'; + exec($str,$ou); + exec('phantom.exit();'); + + //print_r($ou); + + $chart_img_path = APPPATH.'/views/report_templates/chart.png'; + $type = pathinfo($chart_img_path, PATHINFO_EXTENSION); + $chart_img_content = file_get_contents($chart_img_path); + $base64_pdscore_chart_url = 'data:image/' . $type . ';base64,' . base64_encode($chart_img_content); + $data['base64_pdscore_chart_url'] = $base64_pdscore_chart_url; + // echo $data['base64_pdscore_chart_url']; + //die(); + //END OF GENERATE CHART PART + + + + + //GET ALL PROCESSED JSON + for($i = 1;$i<=25;$i++) + { + $fields = array('processed_json'); + $where_condition_array = array('isactive' => 1,'fk_pd_id'=>$pdid,'fk_form_id' => $i); + $data['pd_processed_forms'][$i] = $this->PD_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILSJSON,array(),'','company_id','ASC'); + + $fields2 = array('*'); + $data['pd_images'][$i] = $this->PD_Model->getSignedPDDocsURL($pdid,$i); + } + + + $temp = $this->load->view('report_templates/JSONTOREPORT',$data,true); + //Save Report as HTML Version with timestamp + if (!is_dir(APPPATH.'views/pd_reports/'.$pdid)) { + $dust = mkdir(APPPATH.'views/pd_reports/'.$pdid, 0777, TRUE); + } + $pd_report_time = date('Y-m-d-h-m-s'); + $pd_report_store = APPPATH.'views/pd_reports/'.$pdid.'/'.$pd_report_time.'.html'; + $is_write_done = file_put_contents($pd_report_store,$t); + + if($is_write_done) + { + + $update = $this->PD_Model->updateRecords(array('pd_report_html_filename' => $pd_report_time),PDTRIGGER,array('pd_id' => $pdid)); + + $where_condition_array = array("pd_id" => $pdid); + $temp_array = array('is_original_report_created'=>1,'pd_report_html_filename' => $pd_report_time,'pd_report_generated_date' => date('Y-m-d h:m:s')); + + $id = $this->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array); + + $response_data['dataStatus'] = true; + $response_data['status'] = REST_Controller::HTTP_OK; + $response_data['msg'] = 'Report Generated Sucessfully..!'; + $this->response($response_data,REST_Controller::HTTP_OK); + + } + else + { + $response_data['dataStatus'] = true; + $response_data['status'] = REST_Controller::HTTP_NOT_MODIFIED; + $response_data['msg'] = 'Something went wrong..!'; + $this->response($response_data,REST_Controller::HTTP_OK); + + } + + } + @@ -4863,9 +4967,12 @@ class PD_Controller extends REST_Controller { public function codeigniterViewTest_post() { + + //echo MYUTIL::customIndianNumberFormat(145263.45896);die(); $records = $this->post('records'); $pdid = $records['pd_id']; + $is_regenerate = 0; if(isset($records['regenerate'])) { @@ -4939,9 +5046,26 @@ class PD_Controller extends REST_Controller { //die(); //echo "*******************************************"; $t = $this->load->view('report_templates/JSONTOREPORT',$data,true); - $file_name = APPPATH.'pd_reports/'.$pdid.'_'.date('Y-m-d-h-m-s').'.html'; - //file_put_contents($file_name,$t,LOCK_EX); - //echo $t; die(); + + //echo $t; + + if (!is_dir(APPPATH.'views/pd_reports/'.$pdid)) { + $dust = mkdir(APPPATH.'views/pd_reports/'.$pdid, 0777, TRUE); + } + $pd_report_time = date('Y-m-d-h-m-s'); + $pd_report_store = APPPATH.'views/pd_reports/'.$pdid.'/'.$pd_report_time.'.html'; + file_put_contents($pd_report_store,$t); + + $update = $this->PD_Model->updateRecords(array('pd_report_html_filename' => $pd_report_time),PDTRIGGER,array('pd_id' => $pdid)); + + if(count($update)) + { + $dat['dataStatus'] = true; + $dat['status'] = REST_Controller::HTTP_OK; + $dat['msg'] = 'Report Generated Sucessfully..!'; + $this->response($dat,REST_Controller::HTTP_OK); + } + //PDF Gen using DOM PDF $pdf_doc = $this->pdfgenerator->generate($t, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait"); //End of PDF Gen using DOM PDF @@ -6483,5 +6607,48 @@ class PD_Controller extends REST_Controller { } + public function saveHTMLReport_post() + { + + $records = $this->post('records'); + $pdid = $records['pdid']; + $content = $records['content']; + $pd_report_time = date('Y-m-d-h-m-s'); + $pd_report_store = APPPATH.'views/pd_reports/'.$pdid.'/'.$pd_report_time.'.html'; + file_put_contents($pd_report_store,$content); + + $update = $this->PD_Model->updateRecords(array('pd_report_html_filename' => $pd_report_time),PDTRIGGER,array('pd_id' => $pdid)); + + if(count($update)) + { + $dat['dataStatus'] = true; + $dat['status'] = REST_Controller::HTTP_OK; + $dat['msg'] = 'Report Generated Sucessfully..!'; + $this->response($dat,REST_Controller::HTTP_OK); + } + } + + public function getPDReportHTML_get() + { + $pdid = $this->uri->segment(2); + if(($pdid != null || $pdid != "") && (strlen($pdid) == 16) &&(is_string($pdid))) + { + $pd_data = $this->PD_Model->selectCustomRecords(array('pd_id','pd_report_html_filename'),array('random_string' => $pdid),PDTRIGGER); + if(count($pd_data)) + { + $view_name = 'pd_reports/'.$pd_data[0]['pd_id'].'/'.$pd_data[0]['pd_report_html_filename'].'.html'; + $this->load->view($view_name); + } + else + { + echo "
PD Location Address : '.$pd_address['address'].' ,'.$pd_address['city_master'].' ,'.$pd_address['state_master'].' - '.$pincode;
+ echo 'PD Location Address : '.$pd_address['address'].', '.$pd_address['city_master'].', '.$pd_address['state_master'].' - '.$pincode;
echo '
GPS Coordinates of location where PD Visit was done : '.$pd_master_details[0]['start_location'];
echo '
';
?>
@@ -663,20 +673,20 @@ defined('BASEPATH') OR exit('No direct script access allowed');
if($business_assets_details['business_assets_for_address'][0]['business_month'] != ""){ $yrs_being_run.= ' and '.$business_assets_details['business_assets_for_address'][0]['business_month'].' Months';}
echo '
';
- echo "The PD visit was done at ". $address_type. " of the loan applicants. ";
- echo "The ".$address_type." is ".$property_owner_type." and the business has been in operation from here for the last $yrs_being_run.";
- echo "
The ".$address_type." is located in ".$locality." and the estimated area of the office is ".$estimated_area." .";
- echo "
The PD location was ". $pd_address['pd_location_master'].". " . "As Per PD Offcier, the ".$address_type ." is situated in ".$comment_locality_master ." Locality.";
- echo "
The PD officer also made the following observations:" ;
- echo "