From f7f2100e6fd80c463e776367e627563d94b1339d Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Sat, 24 Sep 2022 17:47:21 +0530 Subject: [PATCH] FI PD photo : ps --- api/application/config/routes.php | 4 +- .../Template_Management_Controller.php | 231 ++++++++++++++---- api/application/models/PD_Model.php | 7 +- 3 files changed, 186 insertions(+), 56 deletions(-) diff --git a/api/application/config/routes.php b/api/application/config/routes.php index bba26e60..6e9f1f75 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -342,7 +342,9 @@ $route['getBuinessGroupForms'] = 'Template_Management_Controller/getBuinessGroup $route['getCompaniesListsForBusinessV2'] = 'PD_Controller/getCompaniesListsFromGeneralFormRawJSONV2'; // $route['getFIPDTemplate'] = 'Template_Management_Controller/getFIPDTemplate'; -$route['getFIPDFormsDetails'] = 'Template_Management_Controller/getFIPDFormsDetails'; +$route['getFIPDImgDetails'] = 'Template_Management_Controller/getFIPDPhotograph'; +$route['saveFIPDImg'] = 'Template_Management_Controller/saveFIPDPhotograph'; + $route['FIformWiseTemplate'] = 'Template_Management_Controller/FIformWiseTemplate'; $route['loadFiTemplate'] = 'Template_Management_Controller/loadFiTemplate'; diff --git a/api/application/controllers/Template_Management_Controller.php b/api/application/controllers/Template_Management_Controller.php index e0bb7e0c..db4d9877 100644 --- a/api/application/controllers/Template_Management_Controller.php +++ b/api/application/controllers/Template_Management_Controller.php @@ -19,6 +19,7 @@ class Template_Management_Controller extends REST_Controller { parent::__construct(); $this->load->model('PD_Model'); $this->load->model('Template_Management_Model'); + $this->external_path = $this->config->item('external_data_path'); } @@ -1690,64 +1691,186 @@ class Template_Management_Controller extends REST_Controller { } } - // public function getFIPDForms_get() - // { + public function saveFIPDPhotograph_post() + { - // $PDtype_id = $this->get('pd_type_id'); - // $FItype_id = $this->get('fi_id'); - // if($PDtype_id == 4){ - // if(!empty($FItype_id)){ - // // $field_investigation = array(array("field_investigation_id"=> 1,"field_investigation"=> "Office Visit (DI)"),array("field_investigation_id"=> 2,"field_investigation"=> "Office Visit (Sal)"),array("field_investigation_id"=> 3,"field_investigation"=> "Residence Visit")); - // if($FItype_id == 1){ + $records = $this->post('records'); + if ($records['pd_document_id'] != null && $records['pd_document_id'] != "") { + $where_condition_array = array('pd_document_id' => $records['pd_document_id']); + $to_update = array("pd_image_alias_name" => $records['pd_image_alias_name']); + $res['count'] = $this->PD_Model->updateRecords($to_update, PDDOCUMENTS, $where_condition_array); + $res['msg'] = "Updated"; + $data['uri'] = null; + }else if($records['pd_document_id'] == "") { + $res = $this->saveBase64Images($records); + } + if (!empty($res)) { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['uri'] = $res['records']; + $data['msg'] = $res['msg']; + $this->response($data, REST_Controller::HTTP_OK, true); + } else { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Something Went Wrong!'; + $this->response($data, REST_Controller::HTTP_OK); + } + } - // }else if($FItype_id == 2){ + public function saveBase64Images($data) + { + $pd_id = $data['pd_id']; + $form_id = $data['formid']; + log_message('ERROR', '###FI-PDIMAGE saveBase64Images function called' . $pd_id . ' - ' . $form_id); + $count = 0; + $result = array(); + $pks = array(); + $uri = null; + $pd_details = $this->PD_Model->getPDMasterDetails($pd_id); + //print_r($data);die(); + EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_id); + $this->location_for_watermark = $data['location']; + $temp_base64_string = $data['image']; + $is_show_report = isset($data['is_show_report']) ? $data['is_show_report'] : null; + + $output_file = $this->external_path . "/pd_reports/" . $pd_id . "/temp_base64_image.jpeg"; + $this->temp_path_for_watermark = $output_file; - // }else if($FItype_id == 3){ + //Generate Random File Name + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 5; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + $temp_file_name = $randomString . date('Y-m-d-H-i-s') . '.jpeg'; - // } + log_message('ERROR', '###FI-PDIMAGE writing started' . $pd_id . ' - ' . $form_id); + $ifp = fopen($output_file, 'wb'); + $temp_data = explode(',', $temp_base64_string); + fwrite($ifp, base64_decode($temp_data[1])); + fclose($ifp); + log_message('ERROR', '###FI-PDIMAGE writing done' . $pd_id . ' - ' . $form_id); - // } - // else{ - // $data['dataStatus'] = false; - // $data['status'] = REST_Controller::HTTP_NO_CONTENT; - // $data['msg'] = 'Field Investigation id is Not available'; - // $this->response($data,REST_Controller::HTTP_OK); - // } - // } - // else{ - // $data['dataStatus'] = false; - // $data['status'] = REST_Controller::HTTP_NO_CONTENT; - // $data['msg'] = 'Its not a FI PD Type'; - // $this->response($data,REST_Controller::HTTP_OK); - // } + log_message('ERROR', '###FI-PDIMAGE uploading to S3' . $pd_id . ' - ' . $form_id); + $tempdoc = $output_file; + $tempdocname = $temp_file_name; + $bucketname = LENDER_BUCKET_NAME_PREFIX . $pd_details[0]['fk_lender_id']; + $key = 'pd' . $pd_id . '/' . $tempdocname; + $sourcefile = $tempdoc; + + $bucket_data = array('bucket_name' => $bucketname, 'key' => $key, 'sourcefile' => $sourcefile); + + //this line make this bucket data values in obj level so can access in helpers and hook files + $this->bucket_data_for_watermark = $bucket_data; + $s3result = $this->aws_s3->uploadFileToS3Bucket($bucket_data); + + if (is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { + log_message('ERROR', '###FI-PDIMAGE stored in S3' . $pd_id . ' - ' . $form_id); + $record_data = array('fk_pd_id' => $pd_id, 'pd_document_title' => (isset($data['pd_document_title']) ? $data['pd_document_title'] : null), 'pd_document_name' => $tempdocname, 'fk_form_id' => $form_id, 'is_show_report' => $is_show_report, 'location' => isset($data['location']) ? $data['location'] : null, 'img_type' => (isset($data['img_type']) ? $data['img_type'] : null), 'image_key' => (isset($data['image_key']) ? $data['image_key'] : null), "pd_image_alias_name" => (isset($data['pd_image_alias_name']) ? $data['pd_image_alias_name'] : null)); + $id = $this->PD_Model->saveRecords($record_data, PDDOCUMENTS); + $uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucketname, $key, $time = '+1 week'); + $this->img_url_for_watermark = $uri; + } - // $fields = array('form_id'); - // $where_condition_array = array('fk_template_id'=>$template_id,'isactive'=>1); - // $result_array = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,TEMPLATEFORMS); - // //print_r($this->db->last_query()); - // $temp = array(); - // foreach($result_array as $r) - // { - // $formid = $r['form_id']; - // $temp = array_merge($temp,array($formid)); - // } - - // if(count($result_array)) - // { - // $data['dataStatus'] = true; - // $data['status'] = REST_Controller::HTTP_OK; - // $data['records'] = $temp; - // $this->response($data,REST_Controller::HTTP_OK); - // } - // else - // { - // $data['dataStatus'] = false; - // $data['status'] = REST_Controller::HTTP_NO_CONTENT; - // $data['msg'] = 'No Data Available'; - // $this->response($data,REST_Controller::HTTP_OK); - - // } - - - // } + + if ($id) { + log_message('ERROR', '###FI-PDIMAGE Saved Sucessfully ID '.$id); + //$logger->info('All Images Saved Sucessfully',array($pd_id,$form_id,$company_id)); + $result['status'] = true; + $result['id'] = $id; + $result['records'] = $uri; + $result['msg'] = "Images Saved Successfully"; + } else { + //$logger->info('Some Images Not Saved',array($pd_id,$form_id,$company_id)); + $result['status'] = true; + $result['msg'] = "Images Not Saved!"; + } + return $result; + } + + + public function FIPDPhotograph_get(){ + + $pd_id = $this->get('pd_id'); + $form_id = "34"; // FI photograph HardCoded. + if(!empty($pd_id)){ + $fields = array('json'); + $where_condition_array = array("fk_form_id"=>$form_id,"fk_pd_id"=>$pd_id,'isactive'=>1); + $form_table = $this->Template_Management_Model->selectCustomRecords($fields,$where_condition_array,PDFORMDETAILSJSON); + // $file = $this->external_path . '/pd_reports/tmp/1.txt'; // testing purpose; + if(count($form_table)>0){ + // if(1){ + $json = json_decode($form_table[0]['json'],true); + // $json = $this->getArr(); // testing purpose; + // print_r($json);die(); // testing purpose; + $pd_master = $this->PD_Model->selectCustomRecords(array('pd_id', 'random_string','fk_lender_id'), array('pd_id' => $pd_id ), PDTRIGGER); + $pd_docs = $this->PD_Model->selectCustomRecords(array('pd_document_id', 'fk_pd_id', 'fk_pd_detail_id', 'fk_form_id', 'co_applicant_id', 'img_type', 'image_key', 'pd_document_title', 'pd_document_name', 'pd_image_alias_name', 'createdon', 'fk_createdby', 'updatedon', 'fk_updatedby', 'company_id', 'is_show_report', 'is_name_editable', 'rental_count_id', 'location', 'isactive', 'retake_flag'), array('fk_pd_id' => $pd_id, 'fk_form_id' =>$form_id, 'pd_document_title != ""' =>null), PDDOCUMENTS); + + if(count($pd_docs)>0){ + $bucket_name = LENDER_BUCKET_NAME_PREFIX . $pd_master[0]['fk_lender_id']; + // $imgs = array('selfie_with_person_met' => array('is_multiple' => 0,'img_name' => 'Selfie of the person contacted'),'name_board_seen' => array('is_multiple' => 1,'img_name' => 'Business Name Board'),'stock_image' => array('is_multiple' => 1,'img_name' => 'Stock Images'),'workplace_interior_image' => array('is_multiple' => 1,'img_name' => 'Work Place Interior')); + foreach ($pd_docs as $key => $value) { + $picspath = 'pd' . $pd_master[0]['pd_id'] . '/' . $value['pd_document_name']; + $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name, $picspath, '+5 minutes'); + $pd_docs[$key]['doc_url'] = $singed_uri; + + } + // print_r($pd_docs);die(); // wroking fine + for($i=0; $iresponse($data, REST_Controller::HTTP_OK); + + } } \ No newline at end of file diff --git a/api/application/models/PD_Model.php b/api/application/models/PD_Model.php index cd529fa0..ad42cde0 100644 --- a/api/application/models/PD_Model.php +++ b/api/application/models/PD_Model.php @@ -1054,8 +1054,12 @@ class PD_Model extends SPARQ_Model { */ public function getPDMasterDetails($pdid,$random_string = null) { - + //$field_investigation = array(array("field_investigation_id"=> 1,"field_investigation"=> "Office Visit (DI)"),array("field_investigation_id"=> 2,"field_investigation"=> "Office Visit (Sal)"),array("field_investigation_id"=> 3,"field_investigation"=> "Residence Visit")); $this->db->SELECT('PDTRIGGER.pd_id, PDTRIGGER.pd_sno,PDTRIGGER.fk_lender_id,PDTRIGGER.sub_entity_id,SUBENTITY.short_name as sub_entity_short_name,PDTRIGGER.imgc_fin_institute,ENTITY.full_name as lender_full_name,ENTITY.short_name as lender_short_name,ENTITY.is_score_card_enabled,ENTITY.is_otp_enabled, PDTRIGGER.fk_entity_billing_id,ENTITYBILLING.billing_name,PDTRIGGER.lender_applicant_id, DATE_FORMAT(PDTRIGGER.pd_date_of_initiation, "%d/%m/%Y") as pd_date_of_initiation,PDTRIGGER.pd_date_of_initiation as pd_date_of_initiation_sqlformat, PDTRIGGER.fk_product_id,PRODUCTS.name as product_name,PRODUCTS.abbr as product_abbr, PRODUCTS.prod_catagory,PDTRIGGER.fk_subproduct_id,SUBPRODUCTS.name as subproduct_name,SUBPRODUCTS.abbr as subproduct_abbr, PDTRIGGER.fk_pd_type,PDTYPE.type_name as pd_type_name, PDTRIGGER.pd_status,PDTRIGGER.pd_specific_clarification, DATE_FORMAT(PDTRIGGER.createdon,"%d/%m/%Y %h:%i:%s %p") as createdon, PDTRIGGER.fk_createdby, DATE_FORMAT(PDTRIGGER.updatedon,"%d/%m/%Y %H:%i %p") as updatedon, PDTRIGGER.fk_updatedby,concat(USERPROFILE.first_name," ",IFNULL(USERPROFILE.last_name,"")) as createdby,concat(USERPROFILE1.first_name," ",IFNULL(USERPROFILE1.last_name,"")) as updatedby,DESIGNATION.designation as updatedby_designation,PDTRIGGER.fk_pd_allocation_type,,PDALLOCATIONTYPE.pd_allocation_type_name, PDTRIGGER.fk_pd_allocated_to,concat(USERPROFILE2.first_name," ",USERPROFILE2.last_name) as pd_allocated_to,PDTRIGGER.executive_id,concat(EXECUTIVE.first_name," ",EXECUTIVE.last_name) as executive_name,PDTRIGGER.central_pd_officer_id,concat(CENTRALOFFICER.first_name," ",CENTRALOFFICER.last_name) as centralofficer,PDTRIGGER.fk_pd_template_id,TEMPLATE.template_name, PDTRIGGER.fk_customer_segment,CUSTOMERSEGMENT.name as customer_segment_name,CUSTOMERSEGMENT.abbr as customer_segment_abbr, PDTRIGGER.pd_officier_final_judgement, PDTRIGGER.pd_agency_id,AGENCY.is_qc_enabled,AGENCY.full_name as agency_name,AGENCY.short_name as agency_short_name,PDTRIGGER.vendor_pdofficer,concat(VENDORPDOFFICER.first_name," ",VENDORPDOFFICER.last_name) as vendor_pdofficer_name,PDTRIGGER.loan_amount,PDTRIGGER.addressline1,PDTRIGGER.addressline2,PDTRIGGER.addressline3,PDTRIGGER.fk_city,CITY.name as city_name,PDTRIGGER.fk_state,STATE.name as state_name,PINCODE.pincode,PDTRIGGER.pincode as pincode_id,PDTRIGGER.lender_sales_person,concat(LENDERSALESPERSON.first_name," ",LENDERSALESPERSON.last_name) as lender_sales_person_name,LENDERSALESPERSON.mobile_no as lender_sales_contact_mobileno,LENDERSALESPERSON.email as lender_sales_person_email,PDTRIGGER.lender_credit_person,concat(LENDERCREDITPERSON.first_name," ",LENDERCREDITPERSON.last_name) as lender_credit_person_name,LENDERCREDITPERSON.mobile_no as lender_credit_person_contact_mobileno,LENDERCREDITPERSON.email as lender_credit_person_email,PDTRIGGER.pd_contact_person,PDTRIGGER.pd_contact_mobileno,DATE_FORMAT(PDTRIGGER.scheduled_on,"%d/%m/%Y %h:%i %p") as scheduled_on,PDTRIGGER.scheduled_on as scheduled_on_for_validation,DATE_FORMAT(PDTRIGGER.scheduled_on,"%dth %b %Y ") as scheduled_date_for_log,DATE_FORMAT(PDTRIGGER.scheduled_on,"%h:%i %p") as scheduled_time_for_log,DATE_FORMAT(PDTRIGGER.completed_on,"%d/%m/%Y %h:%i:%s %p") as completed_on,PDTRIGGER.remarks,PDTRIGGER.bounce_reason,PDTRIGGER.bounce_reason_others,BOUNCEMASTER.bounce_reason_name,PDTRIGGER.is_original_report_created,PDTRIGGER.pd_report_latest_version,PDAPPLICANTSDETAILS.applicant_name as main_applicant,PDTRIGGER.pd_branch_id,ENTITYLENDERBRANCH.branch_name,PDTRIGGER.qc_feedback,PDTRIGGER.qc_rating,PDTRIGGER.qc_remarks,PDTRIGGER.lender_rating,PDTRIGGER.lender_feedback,PDAPPLICANTSDETAILS.applicant_title_name,TITLES.name as title_name,PDTRIGGER.pd_contact_landline,PDTRIGGER.other_pincode,PDTRIGGER.is_otp_done,OTPREJECTION.rejection_reason,PDTRIGGER.otp_reject_other_reason,PDTRIGGER.encrypted_url,PDTRIGGER.is_child,PDTRIGGER.parent_pd_id,PDTRIGGER.fk_primary_address_id,PDTRIGGER.fk_address_id,PDTRIGGER.start_location,PDTRIGGER.satellite_image_base64_blob,DATE_FORMAT(PDTRIGGER.pd_report_generated_date,"%d/%m/%Y %h:%i:%s %p") as pd_report_generated_date,DATE_FORMAT(PDTRIGGER.pd_visit_date,"%d/%m/%Y %h:%i:%s %p") as pd_visit_date,PDTRIGGER.random_string,PDTRIGGER.pd_report_html_filename,PDTRIGGER.is_qc_edited,PDTRIGGER.is_zip_created,PDTRIGGER.pd_qc_note,ENTITY.is_sms_enabled,ENTITY.is_mail_enabled,ENTITY.is_app_notify_enabled,AGENCY.is_vendor_visit_disabled,PDTRIGGER.is_notify_enabled,ENTITYFININSTITUTION.institute_name as fin_institute_name,PDTRIGGER.is_img_pdf_created,PDTRIGGER.is_video_merged,PDTRIGGER.vendor_status,PDTRIGGER.vendor_scheduled_on as vendor_scheduled_on_validation,DATE_FORMAT(PDTRIGGER.vendor_scheduled_on,"%d/%m/%Y %h:%i %p") as vendor_scheduled_on,PDTRIGGER.complete_override_data,PDTRIGGER.excel_file_id,SMC_EXCEL_FILELIST.file_name,SMC_EXCEL_FILELIST.modified_fname,PDTRIGGER.mwise_sales_person,PDTRIGGER.is_field_visit_done,PDTRIGGER.cancel_pd_remark,if(SMC_EXCEL_FILELIST_RE_UPLOAD.fk_pd_id is not null,"1","0") as re_uploaded,SMC_EXCEL_FILELIST_RE_UPLOAD.modified_fname as re_uploaded_file_name,ROLES.role_id as pd_allocated_to_role_id,AGENCYLIST.agency_name as SMC_vendor_agency_name,AGENCYLIST.agency_abbr as SMC_vendor_agency_short_name,PDTRIGGER.gmeet_code,PDTRIGGER.gmeet_id,ENTITY.is_face_api_enabled,PDTRIGGER.fk_fi_type_id'); + $this->db->SELECT('CASE WHEN PDTRIGGER.fk_pd_type = "4" AND PDTRIGGER.fk_fi_type_id = "1" THEN "Office Visit (DI)" + WHEN PDTRIGGER.fk_pd_type = "4" AND PDTRIGGER.fk_fi_type_id = "2" THEN "Office Visit (Sal)" + WHEN PDTRIGGER.fk_pd_type = "4" AND PDTRIGGER.fk_fi_type_id = "3" THEN "Residence Visit" + ELSE null END as fi_type'); $this->db->FROM(PDTRIGGER.' as PDTRIGGER'); $this->db->JOIN(ENTITY.' as ENTITY','PDTRIGGER.fk_lender_id = ENTITY.entity_id ','LEFT'); $this->db->JOIN(ENTITY.' as SUBENTITY','PDTRIGGER.sub_entity_id = SUBENTITY.entity_id ','LEFT'); @@ -1359,6 +1363,7 @@ class PD_Model extends SPARQ_Model { $this->db->WHERE('PDFORMDETAILSJSON.isactive',1); $template_forms_count = 0; $template_forms_count = $this->db->GET()->result_array(); + //print_r($template_forms_count); //if($value['form_id'] == 19){ print_r($template_forms_count); }//die(); if(count($template_forms_count) && $template_forms_count[0]['count'] != 0) {