From 58019d0122c86c9f69c0ebe34b459b113220bef8 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Wed, 20 Jul 2022 17:29:57 +0530 Subject: [PATCH] SMC photo pdf and Zip : ps --- api/application/config/routes.php | 3 + .../controllers/Flyhi_Controller.php | 6 +- .../controllers/SMC_Credit_PD_Controller.php | 38 ++ .../helpers/smc_creditpd_helper.php | 131 +++++ .../views/report_templates/PDSMCIMG_PDF.php | 550 ++++++++++++++++++ 5 files changed, 725 insertions(+), 3 deletions(-) create mode 100644 api/application/views/report_templates/PDSMCIMG_PDF.php diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 52216863..0c3ce829 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -393,3 +393,6 @@ $route['filterFlyPDList']='Flyhi_Controller/filterFlyPDList'; $route['getDigiLockerDocs']='Flyhi_Controller/getDigiLockerDocs'; // $route['getDigiLockerDocs2']='Flyhi_Controller/getDigiLockerDos'; $route['downloadDigiLockerDocs']='Flyhi_Controller/downloadDigiLockerDocs'; + +$route['archivePDSMCImages'] = 'SMC_Credit_PD_Controller/archivePDImages'; +$route['smcPhotoPDFDownload'] = 'SMC_Credit_PD_Controller/imgPDFDownload'; diff --git a/api/application/controllers/Flyhi_Controller.php b/api/application/controllers/Flyhi_Controller.php index 848ec41d..d718f08b 100644 --- a/api/application/controllers/Flyhi_Controller.php +++ b/api/application/controllers/Flyhi_Controller.php @@ -2233,8 +2233,8 @@ class Flyhi_Controller extends REST_Controller { log_message('ERROR','### 5.1th User Choosen Files form data '.json_encode($form_data)); log_message('ERROR','### 5.2th User Choosen Files reindexed_array '.json_encode($reindexed_array)); log_message('ERROR','### 5.3th User Choosen Files reindexed_array count '.count($reindexed_array)); - log_message('ERROR','### 5.4th User Choosen Files digilocker_doc_name count '.count($digilocker_doc_name)); - log_message('ERROR','### 5.5th User Choosen Files digilocker_doc_name '.json_encode($digilocker_doc_name)); + log_message('ERROR','### 5.4th User Choosen Files digilocker_doc_name '.json_encode($digilocker_doc_name)); + log_message('ERROR','### 5.5th User Choosen Files digilocker_doc_name count '.count($digilocker_doc_name)); if(count($form_data)>0){ for($i=0;$i $pd_id,'img_type' => 2,'pd_document_title'=>$tempdocname,'pd_document_name'=>$digilocker_doc_name); + $record_data = array('fk_pd_id' => $pd_id,'img_type' => 2,'pd_document_title'=>$tempdocname,'pd_document_name'=>$digilocker_doc_name[$i]); $this->Flyhi_Model->saveRecords($record_data,PDDOCUMENTS); } log_message('ERROR',"### 8 : Choosen Files reponse :".json_encode($reponse)); diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php index bd362038..5a1dd017 100644 --- a/api/application/controllers/SMC_Credit_PD_Controller.php +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -1948,6 +1948,44 @@ public function filterSalesPDList_post() { $this->response($data,REST_Controller::HTTP_OK); } + public function archivePDImages_post() + { + $records = $this->post('records'); + $pdid = $records['pd_id']; + $random_string = $records['random_string']; + $regenerate = isset($records['regenerate']) ? $records['regenerate'] : 0; + + $this->load->helper('smc_creditpd'); + $res_data = smc_creditpd::covertSMCImgs2ZIP($pdid,$random_string,array(),$regenerate); + + $response_data['dataStatus'] = true; + $response_data['status'] = REST_Controller::HTTP_OK; + $response_data['records'] = $res_data; + $this->response($response_data,REST_Controller::HTTP_OK); + + + + } + + + public function imgPDFDownload_post() + { + $records = $this->post('records'); + $this->load->helper('smc_creditpd'); + + $pdid = $records['pd_id']; + $random_string = $records['random_string']; + $regenerate = isset($records['regenerate']) ? $records['regenerate'] : 0; + + $res_data = smc_creditpd::covertSMCImgs2PDF($pdid,$random_string,array(),$regenerate); + + + $response_data['dataStatus'] = true; + $response_data['status'] = REST_Controller::HTTP_OK; + $response_data['records'] = $res_data; + $this->response($response_data,REST_Controller::HTTP_OK); + + } } \ No newline at end of file diff --git a/api/application/helpers/smc_creditpd_helper.php b/api/application/helpers/smc_creditpd_helper.php index ccf662f8..26968d14 100644 --- a/api/application/helpers/smc_creditpd_helper.php +++ b/api/application/helpers/smc_creditpd_helper.php @@ -583,6 +583,137 @@ class smc_creditpd // print_r($json); return $json; } + public static function covertSMCImgs2ZIP($pdid,$random_string,$pd_master_details = array(),$regenerate = 0) + { + $CI =&get_instance(); + $CI->load->model('PD_Model'); + if(!count($pd_master_details)) + { + $pd_master_details = $CI->PD_Model->getPDMasterDetails($pdid,$random_string,$pd_master_details); + } + if(!file_exists($CI->external_path.'/pd_reports/'.$pdid)) + { + mkdir($CI->external_path.'/pd_reports/'.$pdid,0777); + } + + $bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id']; + $main_applicant_name = $pd_master_details[0]['main_applicant']; + //get zip url from s3 if any + + $key = 'pd'.$pdid.'/'.$main_applicant_name.'_'.$pdid.'_'.'pd_images.zip'; + + //$singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + if($pd_master_details[0]['is_zip_created'] && ($regenerate == 0)) + { + return $singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + + // $response_data['dataStatus'] = true; + // $response_data['status'] = REST_Controller::HTTP_OK; + // $response_data['records'] = $singed_uri; + // $CI->response($response_data,REST_Controller::HTTP_OK); 9344876517 + } else + { + + $all_pd_images = $CI->PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $pdid,'isactive' => 1 , 'img_name !=' => 'satellite'),SMC_CREDIT_PD_DOCS); + + // $all_form_names = array('pd_form_id'=>19,'pd_form_name'=>"photograph"); + // $form_name[19] = "photograph"; + + //Generate zip file + + $CI->load->library('zip'); + + $CI->zip->add_dir('pdimages'); + + foreach($all_pd_images as $image) + { + + $temp_dir_name = 'Common'; + $doc_name = str_replace(':', '-', $image['img_name']); + $src_local_file = XLPATH.'/tmp/'.$doc_name.'.png'; + $ifp = fopen( $src_local_file, 'wb' ); + $img = explode( ',', $image['img'] ); + fwrite( $ifp, base64_decode( $img[ 1 ] ) ); + fclose( $ifp ); + $MyFile = file_get_contents($src_local_file); + $CI->zip->add_data('pdimages/'.$doc_name.'.png',$MyFile); + unlink($src_local_file); + } + + $temp_path = $main_applicant_name.'_'.$pdid.'_'.'pd_images.zip'; + + $CI->zip->archive($CI->external_path.'/pd_reports/'.$pdid.'/'.$temp_path); + + $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>($CI->external_path.'/pd_reports/'.$pdid.'/'.$temp_path)); + + $s3result= $CI->aws_s3->uploadFileToS3Bucket($bucket_data); + //print_r($s3result); + if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) + { + //$result_array[0]['content'] + $where_condition_array = array("pd_id" => $pdid); + $temp_array['is_zip_created'] = 1; + $id = $CI->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array); + unlink($CI->external_path.'/pd_reports/'.$pdid.'/'.$temp_path); + } + return $singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + } + + } + public static function covertSMCImgs2PDF($pdid,$random_string,$pd_master_details = array(),$regenerate = 0) + { + //echo 'this is from daiu'; + $CI =&get_instance(); + $CI->load->model('PD_Model'); + $CI->load->library('pdfgenerator'); + + if(!count($pd_master_details)) + { + $pd_master_details = $CI->PD_Model->getPDMasterDetails($pdid,$random_string); + } + set_time_limit(60); + $bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['fk_lender_id']; + $main_applicant_name = $pd_master_details[0]['main_applicant']; + + //get zip url from s3 if any + + $key = 'pd'.$pdid.'/'.$main_applicant_name.'_'.$pdid.'_'.'pd_images.pdf'; + + //$singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+30 minutes'); + if($pd_master_details[0]['is_img_pdf_created'] && ($regenerate == 0)) + { + return $singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+7 days'); + } + else + { + $all_pd_images = $CI->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $pdid,'isactive' => 1,'img_name!=' => 'satellite'),SMC_CREDIT_PD_DOCS); + // $all_pd_images = $CI->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $pdid,'isactive' => 1),SMC_CREDIT_PD_DOCS); + + $data_to_view['all_pd_images'] = $all_pd_images; + $img_pdf_data = $CI->load->view('report_templates/PDSMCIMG_PDF',$data_to_view,true); + //print_r($img_pdf_data);die(); + $pdf_doc = $CI->pdfgenerator->generate($img_pdf_data, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait"); + //End of PDF Gen using DOM PDF + $output_file2 = $CI->external_path ."/pd_reports/" . $pdid . "/pd_images_pdf.pdf"; + $ti = file_put_contents($output_file2, $pdf_doc); + //echo $ti;die(); + + $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>($output_file2)); + + $s3result= $CI->aws_s3->uploadFileToS3Bucket($bucket_data); + //print_r($s3result); + if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) + { + //$result_array[0]['content'] + $where_condition_array = array("pd_id" => $pdid); + $temp_array['is_img_pdf_created'] = 1; + $id = $CI->PD_Model->updateRecords($temp_array,PDTRIGGER,$where_condition_array); + unlink($output_file2); + } + + return $singed_uri = $CI->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname,$key,'+7 days'); + + }} } ?> \ No newline at end of file diff --git a/api/application/views/report_templates/PDSMCIMG_PDF.php b/api/application/views/report_templates/PDSMCIMG_PDF.php new file mode 100644 index 00000000..758d72e1 --- /dev/null +++ b/api/application/views/report_templates/PDSMCIMG_PDF.php @@ -0,0 +1,550 @@ + + + + + + + + + + + + + + +
+
+ Powered by PDGenie +
+
+ +
+
+
+ + '; + echo '

PD Photograph`s :

'; + echo '
'; + echo ''; + $add_factor = 0; + for($img_row = 0; $img_row < $img_row_count; $img_row++) + { + //if($img_row > 0) { break; } + echo ''; + $from = $img_row == 0 ? $img_row : ($img_row+$add_factor); + $to = ($from + 2); + $add_factor = $add_factor + 2; + for($photo_iter = $from; $photo_iter <= $to;$photo_iter++) + { + + if(isset($all_pd_images[$photo_iter])) + { + echo ''; + // unset($all_pd_images[$photo_iter]); + } + + } + //echo "


"; + echo ''; + } + //echo ''; + echo '
'; + echo ''; + echo '
'; + } + // + ?> + + + + + + + \ No newline at end of file