diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 18e306aa..caf8937d 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -377,7 +377,8 @@ $route['faceMarkImage'] = 'PD_Controller/toMakeFaceBoundingBox'; $route['saveFlyhiPD'] = 'Flyhi_Controller/saveFlyhiPD'; $route['listFlyhiPD'] = 'Flyhi_Controller/listFlyhiPD'; -$route['listFlyhiSalesPD'] = 'Flyhi_Controller/listFlyhiPD'; $route['getFlyhiPD'] = 'Flyhi_Controller/getFlyhiPD'; +$route['loadFlyhiPDTemplate'] = 'Flyhi_Controller/loadFlyhiPDTemplate'; +$route['(downloadFlyhiPDReport/:any)'] = 'Flyhi_Controller/getFlyhiPDReport'; diff --git a/api/application/controllers/Flyhi_Controller.php b/api/application/controllers/Flyhi_Controller.php index 29ff1ad6..a27fa0fa 100644 --- a/api/application/controllers/Flyhi_Controller.php +++ b/api/application/controllers/Flyhi_Controller.php @@ -11,6 +11,12 @@ class Flyhi_Controller extends REST_Controller { parent::__construct(); $this->load->model('Flyhi_Model','Flyhi_Model'); $this->load->model('Sales_PD_Model','Sales_PD_Model'); + $this->load->library('AWS_S3'); + $this->load->library('pdfgenerator'); + $this->load->helper('satellite_image'); + $this->load->helper('camunda'); + + } public function listFlyhiPD_get(){ @@ -268,7 +274,7 @@ class Flyhi_Controller extends REST_Controller { $section_data = array(); if(isset($Flyhi_pdid) || $Flyhi_pdid != "" || $Flyhi_pdid != null) { - $section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $Flyhi_pdid,'isactive' => 1,'section_id' => 1),SALESPD_SECTION_DATA); + $section_data = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $Flyhi_pdid,'isactive' => 1,'section_id' => 1),SALESPD_SECTION_DATA); } if($section_data) { @@ -285,4 +291,290 @@ class Flyhi_Controller extends REST_Controller { $this->response($data,REST_Controller::HTTP_OK); } } + + public function loadFlyhiPDTemplate_post() + { + $records = $this->post('records'); + $lender_id = $records['lender_id']; + $sales_pd_type = $records['sales_pd_type']; + $product = $records['product_id']; + $pd_type = 2; + if(isset($records['pd_type'])){ $pd_type = $records['pd_type'];} + $template = $this->Flyhi_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'pd_type' => $pd_type,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE); + if(is_array($template) && count($template)) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $template[0]; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Tempate Found!'; + $this->response($data,REST_Controller::HTTP_OK); + + } + } + + public function getFlyhiPDReport_get() + { + $pd_id = $this->uri->segment(2); + $this->prepareFlyhiPDReport($pd_id); + } + + function prepareFlyhiPDReport($pd_id,$api = true) + { + log_message('ERROR','####PREPARE Flyhi PD REPORT CALLED'.$pd_id); + $columns = array('SALES_PD_DATA.*','ENTITY.short_name','USERPROFILE.smc_emp_code'); + $table = SALES_PD_DATA.' as SALES_PD_DATA'; + $joins = array( + array('table' => ENTITY. ' as ENTITY', + 'condition' =>'SALES_PD_DATA.lender_id = ENTITY.entity_id', + 'jointype' => 'INNER'), + array('table' => USERPROFILE. ' as USERPROFILE', + 'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid', + 'jointype' => 'LEFT') + ); + + $where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $pd_id); + $sales_pd_data = $this->Sales_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); + $pd_type = ""; + if($sales_pd_data[0]['sales_pd_type'] == 3){$pd_type = "Office FI PD-"; }else if($sales_pd_data[0]['sales_pd_type'] == 4){$pd_type = "Residence FI PD-";} + + if($sales_pd_data) + { + ini_set('max_execution_time', 0); + $bucket_name = LENDER_BUCKET_NAME_PREFIX.$sales_pd_data[0]['lender_id']; + // 1st Type Key name. (name,abbr and date). + $pdf_name = strtolower(trim($sales_pd_data[0]['applicant_name'])); + $pdf_name .= '-'.$pd_type; + $pdf_name .= '-'.(date('dmY',strtotime($sales_pd_data[0]['completed_date']))); + $key = 'sales_pd/'.$pd_id.'/'.$pdf_name.'.pdf'; + //$this->Sales_PD_Model->updateRecords(array('pd_report_filename' => 'PD_Report-'.$pdf_name),SALES_PD_DATA,array('sales_pd_id' => $pd_id)); + + if(!file_exists($this->external_path.'/sales_pd/'.$pd_id)) + { + mkdir($this->external_path.'/sales_pd/'.$pd_id,0777); + } + + if(!$sales_pd_data[0]['is_pdf'] || $sales_pd_data[0]['is_edited']) + { + + $all_section_data = $this->Sales_PD_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $pd_id,'isactive' => 1),SALESPD_SECTION_DATA,array(),'','section_id','ASC'); + // print_r(json_decode($all_section_data[0]['section_data'],true));die(); + $view_data['master'] = $sales_pd_data; + $common_fields = array('pdid'=>$sales_pd_data[0]['sales_pd_id'], + 'caseno'=>$sales_pd_data[0]['sales_pd_sno']); + foreach ($all_section_data as $sec_key => $section) + { + // print_r($section['section_id']);die(); + // log_message('ERROR','####PREPARE SALESPD REPORT CALLED'.$pd_id); + $view_data['section'.$section['section_id'] ] = $this->processSalesPDJSON($section);//die(); + $section_fields['section'.$section['section_id'] ] = $this->processSalesPDJSON($section); + } + $view_data['geo_location'] = $sales_pd_data[0]['geo_location']; + // die(); + //$view_name = $sales_pd_data[0]['short_name'].'_'.$sales_pd_data[0]['abbr']; + $view_name = $sales_pd_data[0]['short_name']; + $html_content = $this->load->view('sale_pd_templates/'.$view_name,$view_data,true); + // echo $html_content;die(); + $pdf_doc = $this->pdfgenerator->generate($html_content, $filename='version', $stream=false, $paper = 'A4', $orientation = "portrait"); + //End of PDF Gen using DOM PDF + $output_file = $this->external_path ."/sales_pd/" . $pd_id . "/temp.pdf"; + $bytes = file_put_contents($output_file, $pdf_doc); + //echo $bytes; + //die(); + $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$key,'sourcefile'=>$this->external_path.'/sales_pd/'.$pd_id.'/temp.pdf'); + log_message('ERROR','####FLYHIPD REPORT UPLOAD TO S3'.$pd_id); + $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); + + if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) + { + + $this->Sales_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SALES_PD_DATA,array('sales_pd_id' => $pd_id)); + if($api) + { + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + $headers = @get_headers($_uri); + if($headers && strpos( $headers[0], '200')) { + // $singed_uri = $_uri; + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $_uri; + }else { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Report URI Not Found'; + } + + $this->response($data,REST_Controller::HTTP_OK); + } + } + } + else + { + if($api) + { + ## NEW KEY BECAUSE TITLE-RENAME + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + $headers = @get_headers($_uri); + if($headers && strpos( $headers[0], '200')) { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $_uri; + }else { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Report URI Not Found'; + } + + $this->response($data,REST_Controller::HTTP_OK); + } + } + } + } + + function processSalesPDJSON($section_array) + { + // + //print_r($section_array);die(); + //echo '###'.$section_array['section_id'].'####'; + if($section_array['section_id'] == 6) + { + // print_r(json_decode($section_array['section_data'],true)); + // die(); + } + if($section_array['section_id']) + { + //print_r($section_array);//die(); + $questions = json_decode($section_array['section_data'],true); + return $this->processSalesPDQuestions($questions['questions'],$section_array['section_id']); + + } + // die(); + // $general_section_dta = array(); + // foreach ($section_array as $sec_key => $section) + // { + + //} + } + + function processSalesPDQuestions($questions,$section_id) + { + //print_r($questions);die(); + $temp_array = array(); + foreach ($questions as $ques_key => $question) + { + //if($question['section_id']){} + if($question['is_repeatable'] == null && ($question['type'] == 1 || $question['type'] == 2 || $question['type'] == 3 || $question['type'] == 4 || $question['type'] == 6 || $question['type'] == 7 || $question['type'] == 8))//text,radio,SDD,MDD,camera,txt area, searchable dd + { + + $temp_array[ $question['question_key'] ] = isset($question['answer_value']) ? $question['answer_value'] : null; + if($question['question_key'] == 'state' || $question['question_key'] == 'city' || $question['question_key'] == 'pincode' || $question['question_key'] == 'loan_purpose' || $question['question_key'] == 'constitution' || $question['question_key'] == 'about_locality' || $question['question_key'] == 'equipment_list' || $question['question_key'] == 'vendor_list' || $question['question_key'] == 'person_met_designation') + { + //if($question['type'] == 4) { print_r($question['answer_value']); } + $temp_array[ $question['question_key'] ] = $this->getMasterData($question['answer_value'],$question['answers']); + // if($question['type'] == 4) { print_r($temp_array[ $question['question_key'] ]); } + } + if(isset($question['subfield_key'])) + { + + $temp_array[ $question['question_key'] ] .= $question['subfield_value'].','; + + } +// echo 'FIRST';print_r($temp_array[ $question['question_key'] ]); + if(substr_count($temp_array[ $question['question_key'] ], ',')) + { + $temp_array[ $question['question_key'] ] = substr_replace($temp_array[ $question['question_key'] ],'', strrpos($temp_array[ $question['question_key'] ],','),1); + } + //echo 'SECOND'; print_r($temp_array[ $question['question_key'] ]); + if(substr_count($temp_array[ $question['question_key'] ], ',')) + { + + $temp_array[ $question['question_key'] ] = substr_replace($temp_array[ $question['question_key'] ],' and ', strrpos($temp_array[ $question['question_key'] ],','),1); + + } + } + else if($question['is_repeatable'] == 1 ) + { + //print_r($question['questions_group']);die(); + if($section_id != 9) + { + foreach ($question['questions_group'] as $group_key => $group_value) + { + //print_r($group_value['questions']);//die(); + $group_temp = array(); + foreach ($group_value['questions'] as $q_key => $q_value) + { + //print_r($q_value);die(); + //echo $group_key; + $group_temp[ $q_value['question_key'] ] = $q_value['answer_value']; + + if(isset($q_value['subfield_key'])){ $group_temp[ $q_value['question_key'] ] = $q_value['subfield_value']; } + //print_r($group_temp); + } + //print_r($group_temp); + $temp_array[ $group_key ] = $group_temp; + + } + } + else + { +//echo "SDKJHKSJ**"; + $group_temp = array(); + foreach ($question['questions_group'] as $group_key => $group_value) + { + + $temp_array[ $group_value['questions'][0]['question_key'] ][] = isset($group_value['questions'][0]['subfield_key']) ? $group_value['questions'][0]['subfield_value'] : $group_value['questions'][0]['answer_value']; + + } + } + } + } + // //print_r($temp_array);die(); + // if($section_id == 2) + // { + // //print_r(json_decode($section_array['section_data'],true)); die(); + // die(); + // } + return $temp_array; + } + + function getMasterData($id,$array) + { + + // print_r($id);echo '***'; + if(!is_array($id)) + { + foreach($array as $value) + { + if($id == $value['answer_id']) + { + return ($value['answer']); + break; + } + } + } + else + { + $final_string = ''; + + foreach($id as $value) + { + //echo $value.'****'.strcasecmp($value,'Others').'#'; + foreach($array as $mas_value) + { + if( !strcasecmp($value,$mas_value['answer_id']) && (!substr_count($mas_value['answer'],'Others')) ) + { + $final_string .= $mas_value['answer'] . ','; + } + } + } + // print_r($final_string);//die(); + return $final_string; + } + + } }// Class Ends diff --git a/api/application/views/sale_pd_templates/FHFSL.php b/api/application/views/sale_pd_templates/FHFSL.php new file mode 100644 index 00000000..f390c9ff --- /dev/null +++ b/api/application/views/sale_pd_templates/FHFSL.php @@ -0,0 +1,345 @@ +↑'; + $downarrow = ''; + $dash = ' '; + // $product_name = $master[0]['abbr']; + $product_name = ""; + $rupee_symbol = ""; + $title = ""; + if($master[0]['sales_pd_type'] == 3){$title = "Office FI PD "; }else if($master[0]['sales_pd_type'] == 4){$title = "Residence FI PD ";} + $smc_emp_code = $master[0]['smc_emp_code']; +?> + + + + + + + + + + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Personal Discussion by FlyHI Team -
Lender Name
Branch
Application ID
Lender sales Person
Lender credit Person
Product Name
Loan Amount Applied for (Rs)
Verification Type
CityStatePIN
Residence Ownership
Years at current Residence
Same as current residence address
Permanent Address
CityStatePIN
Number of earning family member
Number of Dependents
Occupation of the loan applicant
Employer/Business Name
Employer/Business Address
Address
CityStatePIN
Constitution of Employer /Business applicant
Years at Current employment/Business
Total Work Experience
Net Monthly Salary/ Net Income
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Additional Questions
Name of Student
Relationship with Applicant
Educational Institute Name
Educational Institute Address
CityStatePIN
Class /Section/ Course Name
Educational Institute Fee
Duration of the course
Loan Amount Applied for (Rs)Total Fund Requirement (Rs)
Loan Tenure (Months)Loan Purpose (End-Use)
+ + + + + \ No newline at end of file