load->model('Flyhi_Model','Flyhi_Model'); $this->load->library('AWS_S3'); $this->load->library('AWS_COGNITO'); $this->load->library('AWS_SNS'); $this->load->library('pdfgenerator'); $this->load->helper('satellite_image'); $this->load->helper('camunda'); $this->external_path = $this->config->item('external_data_path'); $this->load->helper('MYUTIL'); $this->load->helper('faceapi'); $this->load->library('phpmailer_library'); } public function filterFlyPDList_post() { $records = $this->post('records'); $pd_status= $records['pd_status']; $pd_from_date = $records['pd_from_date']; $pd_to_date = $records['pd_to_date']; $pd_lender = (ENVIRONMENT == 'production' ? 19 : 49); $pd_products = isset($records['pd_products']) ? $records['pd_products'] : (ENVIRONMENT == 'production' ? 27 : 26) ; $pd_applicant_name = strtolower($records['pd_applicant_name']); $sales_pd_officer_id = isset($records['sales_pd_officer_id']) ? $records['sales_pd_officer_id'] : null ; $sales_pd_type = isset($records['sales_pd_type']) ? $records['sales_pd_type'] : null ; $result_data=$this->Flyhi_Model->getFlyPDListwithFilters($pd_status,$pd_from_date,$pd_to_date,$pd_products,$pd_lender,$pd_applicant_name,$sales_pd_officer_id,$sales_pd_type); if(count($result_data)){ $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Records Found'; $this->response($data,REST_Controller::HTTP_OK); } } public function getMasterForFlyhiPD_get(){ $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); $FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26); $default_product = $FHFSL_product; $default_lender = $FHFSL_lender; $lender_fields = array('entity_id','full_name','short_name'); $lender_where_condition_array = array('isactive' => 1,'entity_id' => $FHFSL_lender); $result_data = $this->Flyhi_Model->selectCustomRecords($lender_fields,$lender_where_condition_array,ENTITY,array(),'','full_name'); if(count($result_data)) { foreach($result_data as $key => $value) { $fields = array('*'); $where_condition_array = array('isactive' => 1,'fk_entity_id' => $value['entity_id']); $result_data[$key]['billing_address'] = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,ENTITYBILLING); $branch_fields = array('entity_lender_branch_id', 'branch_name'); $branch_where_condition_array = array('fk_entity_id' => $value['entity_id'],'isactive'=>1); $result_data[$key]['branches'] = $this->Flyhi_Model->selectCustomRecords($branch_fields,$branch_where_condition_array,ENTITYLENDERBRANCH); } } $product = $this->Flyhi_Model->selectCustomRecords(array('product_id','name as product_name','abbr as product_abbr','prod_catagory'),array('product_id' => $FHFSL_product),PRODUCTS); $product = count($product)>0 ? $product : 'product was not found?. Create Product in Lender profile'; $columns = array('USERPROFILE.userid','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as user_name','USERPROFILE.fk_entity_id','USERPROFILE.fk_city','USERPROFILEROLES.user_role','USERPROFILE.fk_entity_type_id','ROLES.role_name','if( POSITION("credit" IN ROLES.role_name),"CREDIT","SALES") as role_type'); $table = USERPROFILE.' as USERPROFILE'; $joins = array(array('table' => USERPROFILEROLES. ' as USERPROFILEROLES', 'condition' =>'USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive =1', 'jointype' => 'INNER'), array('table' => ROLES.' as ROLES', 'condition' =>'ROLES.role_id = USERPROFILEROLES.user_role', 'jointype' => 'INNER')); $order_by = 'USERPROFILE.userid'; $or_where = array(); $lender_contact_persons = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,array('USERPROFILE.fk_entity_id' => $FHFSL_lender),$order_by,'DESC','',$or_where); $lender_contact_persons = count($lender_contact_persons)>0 ? $lender_contact_persons : 'Credit Person Lender Profile was not found?. Create Credit Person Lender profile'; // isset($records['pd_branch_id']) ? $records['pd_branch_id'] : null $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = array('lender'=> $result_data,'products' =>$product,'lender_contact_persons'=>$lender_contact_persons,'default_lender' =>$FHFSL_lender,'default_product' =>$FHFSL_product); $this->response($data,REST_Controller::HTTP_OK); } public function lenderMasterForFlyhiPD_get(){ $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); $default_lender = $FHFSL_lender; $lender_fields = array('entity_id','full_name','short_name'); $lender_where_condition_array = array('isactive' => 1,'entity_id' => $FHFSL_lender); $result_data = $this->Flyhi_Model->selectCustomRecords($lender_fields,$lender_where_condition_array,ENTITY,array(),'','full_name'); $result_data = count($result_data)>0 ? $result_data : 'Lender was not found'; $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result_data; $this->response($data,REST_Controller::HTTP_OK); } public function productMasterForFlyhiPD_get(){ $FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26); $default_product = $FHFSL_product; $product = $this->Flyhi_Model->selectCustomRecords(array('product_id','name as product_name','abbr as product_abbr','prod_catagory'),array('product_id' => $FHFSL_product),PRODUCTS); $product = count($product)>0 ? $product : 'product was not found'; $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $product; $this->response($data,REST_Controller::HTTP_OK); } public function branchMasterForFlyhiPD_get(){ $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); $branches = array(); $lender_fields = array('entity_id','full_name','short_name'); $lender_where_condition_array = array('isactive' => 1,'entity_id' => $FHFSL_lender); $result_data = $this->Flyhi_Model->selectCustomRecords($lender_fields,$lender_where_condition_array,ENTITY,array(),'','full_name'); if(count($result_data)) { foreach($result_data as $key => $value) { $branch_fields = array('entity_lender_branch_id', 'branch_name'); $branch_where_condition_array = array('fk_entity_id' => $value['entity_id'],'isactive'=>1); $result_data[$key]['branches'] = $this->Flyhi_Model->selectCustomRecords($branch_fields,$branch_where_condition_array,ENTITYLENDERBRANCH); $branches = $this->Flyhi_Model->selectCustomRecords($branch_fields,$branch_where_condition_array,ENTITYLENDERBRANCH); } } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = count($branches)>0?$branches:"Branches Not Found"; $this->response($data,REST_Controller::HTTP_OK); } public function lenderCreditPersonForFlyhiPD_get(){ $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); $FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26); $columns = array('USERPROFILE.userid','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as user_name','USERPROFILE.fk_entity_id','USERPROFILE.fk_city','USERPROFILEROLES.user_role','USERPROFILE.fk_entity_type_id','ROLES.role_name','if( POSITION("credit" IN ROLES.role_name),"CREDIT","SALES") as role_type'); $table = USERPROFILE.' as USERPROFILE'; $joins = array(array('table' => USERPROFILEROLES. ' as USERPROFILEROLES', 'condition' =>'USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive =1', 'jointype' => 'INNER'), array('table' => ROLES.' as ROLES', 'condition' =>'ROLES.role_id = USERPROFILEROLES.user_role', 'jointype' => 'INNER')); $order_by = 'USERPROFILE.userid'; $where_condition_array['USERPROFILE.fk_entity_id'] = $FHFSL_lender; $key_date="ROLES.role_name LIKE '%credit%'"; $condition_value=null; $where_condition_array[$key_date] = $condition_value; $or_where = array(); $lender_contact_persons = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where); $lender_contact_persons = count($lender_contact_persons)>0 ? $lender_contact_persons : 'Credit Person Lender Profile was not found?. Create Credit Person Lender profile'; // isset($records['pd_branch_id']) ? $records['pd_branch_id'] : null $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $lender_contact_persons; $this->response($data,REST_Controller::HTTP_OK); } public function lenderSalesPersonForFlyhiPD_get(){ $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); $FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26); $columns = array('USERPROFILE.userid','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as user_name','USERPROFILE.fk_entity_id','USERPROFILE.fk_city','USERPROFILEROLES.user_role','USERPROFILE.fk_entity_type_id','ROLES.role_name','if( POSITION("credit" IN ROLES.role_name),"CREDIT","SALES") as role_type'); $table = USERPROFILE.' as USERPROFILE'; $joins = array(array('table' => USERPROFILEROLES. ' as USERPROFILEROLES', 'condition' =>'USERPROFILEROLES.fk_userid = USERPROFILE.userid and USERPROFILEROLES.isactive =1', 'jointype' => 'INNER'), array('table' => ROLES.' as ROLES', 'condition' =>'ROLES.role_id = USERPROFILEROLES.user_role', 'jointype' => 'INNER')); $order_by = 'USERPROFILE.userid'; $or_where = array(); $where_condition_array['USERPROFILE.fk_entity_id'] = $FHFSL_lender; $key_date="ROLES.role_name LIKE '%sale%'"; $condition_value=null; $where_condition_array[$key_date] = $condition_value; $lender_contact_persons = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where); $lender_contact_persons = count($lender_contact_persons)>0 ? $lender_contact_persons : 'Sales Person Lender Profile was not found?. Create Sales Person Lender profile'; // isset($records['pd_branch_id']) ? $records['pd_branch_id'] : null $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $lender_contact_persons; $this->response($data,REST_Controller::HTTP_OK); } public function listFlyhiPD_get(){ $user_id = $this->uri->segment(1); $columns = array('SALES_PD_DATA.sales_pd_id','SALES_PD_DATA.sales_pd_sno','SALES_PD_DATA.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name','SALES_PD_DATA.applicant_id','SALES_PD_DATA.lender_id','SALES_PD_DATA.is_pdf','SALES_PD_DATA.is_edited','ENTITY.full_name','ENTITY.short_name','SALES_PD_DATA.status','SALES_PD_DATA.sales_pd_type','SALES_PD_DATA.rand_string','SALES_PD_DATA.isactive','SALES_PD_DATA.city_id','CITY.name as city_name', 'SALES_PD_DATA.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', 'SALES_PD_DATA.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', 'SALES_PD_DATA.pd_branch_id','ENTITYLENDERBRANCH.branch_name','SALES_PD_DATA.loan_amount', '(CASE WHEN SALES_PD_DATA.sales_pd_type = 3 THEN "Workplace verification" WHEN SALES_PD_DATA.sales_pd_type = 4 THEN "Residence verification" ELSE "-" END) AS sales_pd_type_master', '(CASE WHEN SALES_PD_DATA.status = "STARTED" THEN SALES_PD_DATA.createdon WHEN SALES_PD_DATA.status = "COMPLETED" THEN SALES_PD_DATA.completed_date ELSE NULL END) AS createdon'); $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' => PRODUCTS. ' as PRODUCT', // 'condition' =>'SALES_PD_DATA.product_id = PRODUCT.product_id', // 'jointype' => 'INNER'), array('table' => CITY. ' as CITY', 'condition' =>'SALES_PD_DATA.city_id = CITY.city_id', 'jointype' => 'LEFT'), array('table' => USERPROFILE. ' as USERPROFILE', 'condition' =>'SALES_PD_DATA.createdby = USERPROFILE.userid', 'jointype' => 'LEFT'), array('table' => USERPROFILE. ' as LENDERSALESPERSON', 'condition' =>'SALES_PD_DATA.lender_sales_person = LENDERSALESPERSON.userid', 'jointype' => 'LEFT'), array('table' => USERPROFILE. ' as LENDERCREDITPERSON', 'condition' =>'SALES_PD_DATA.lender_credit_person = LENDERCREDITPERSON.userid', 'jointype' => 'LEFT'), array('table' => ENTITYLENDERBRANCH. ' as ENTITYLENDERBRANCH', 'condition' =>'SALES_PD_DATA.pd_branch_id = ENTITYLENDERBRANCH.entity_lender_branch_id', 'jointype' => 'LEFT') ); $or_where = array(); $where_condition_array['SALES_PD_DATA.isactive'] = 1; // FILTERING THE LAST 10 DAYS RECORDS $key_date='SALES_PD_DATA.createdon BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW()'; $condition_value=null; $where_condition_array[$key_date] = $condition_value; // ----END OF FILTERING THE LAST 10 DAYS RECORDS--- $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); if($user_id && is_numeric($user_id)) { $where_condition_array['SALES_PD_DATA.createdby'] = $user_id; } $where_condition_array['SALES_PD_DATA.sales_pd_type in (3,4)'] = null; $order_by = 'SALES_PD_DATA.sales_pd_id'; $Flyhi_pd_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC','',$or_where); // print_r($this->db->last_query());die(); if(count($Flyhi_pd_data)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $Flyhi_pd_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'FlyHI PD Data Not Found! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function saveFlyhiPDOLD_post() { $records = $this->post('records'); $is_entry_done = null; $flyhi_pd_id = null; $section_data = json_encode($records); $fk_createdby = isset($records['fk_createdby']) ? $records['fk_createdby'] : ""; $applicant_id = null; $applicant_name = null; $city = null; $lender_id = null; $loan_amount = null; $pd_branch_id = null; $lender_sales_person = null; $lender_credit_person = null; $product_id = null; // $product_short_name = $this->Flyhi_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS); log_message('ERROR','####FLYHI-PD SAVE CALLED'); $section_names = array('1' => 'General Section','9' => 'Photography'); // $section_names = array('1' => 'General Section'); if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null) { /************ASSIGN Random URL******************/ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } $records['rand_string'] = $randomString; log_message('ERROR','####INSERT NEW FLYHIPD'); if($records['questions']) { foreach ($records['questions'] as $g_key => $g_value) { if(isset($g_value['question_key']) && $g_value['question_key'] === 'loan_application_id') { $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_name') { $lender_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'loan_amount') { $loan_amount = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'branch') { $pd_branch_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_sales_person') { $lender_sales_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_credit_person') { $lender_credit_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'product_name') { $product_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'verification_type') { if(isset($g_value['onchange_properties'])) { foreach ($g_value['onchange_properties'] as $h_key => $h_value) { foreach ($h_value['form_controls'] as $i_key => $i_value) { foreach ($i_value['questions'] as $j_key => $j_value) { if($g_value['answer_value'] == 'Residence verification' && $j_value['question_key'] == 'residence_city'){ $city = $j_value['answer_value']; $flyhi_pd_type = 4; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'officer_city'){ $city = $j_value['answer_value']; $flyhi_pd_type = 3; } } } } } } } } $count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $lender_id,'isactive' => 1),SALES_PD_DATA); $lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lender_id),ENTITY); $FLYHI_PD['applicant_name'] = $applicant_name; $FLYHI_PD['applicant_id'] = $applicant_id; $FLYHI_PD['city_id']=$city; $FLYHI_PD['loan_amount'] = $loan_amount; $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; $FLYHI_PD['pd_branch_id'] = $pd_branch_id; $FLYHI_PD['lender_id'] = $lender_id; $FLYHI_PD['createdby'] = $fk_createdby; $FLYHI_PD['rand_string'] = $randomString; $FLYHI_PD['sales_pd_type'] = $flyhi_pd_type; $FLYHI_PD['product_id'] = $product_id ? $product_id : (ENVIRONMENT == 'production' ? 27 : 26); $flyhi_pd_id = $this->Flyhi_Model->saveRecords($FLYHI_PD,SALES_PD_DATA); $section_data = json_encode($records); $this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1 )); $status = $records['is_complete']; $fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); $is_entry_done = $this->Flyhi_Model->saveRecords($fields,SALESPD_SECTION_DATA); } else { if(isset($records['status']) && $records['status'] == 'COMPLETED') { log_message('ERROR','####COMPLETE FLYHI-PD'.$records['sales_pd_id']); $drafted_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 0,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); $completed_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); $dup_of_section_names = $section_names; foreach ($completed_sections as $completed_section_key => $completed_section_value) { if($dup_of_section_names [ $completed_section_value['section_id'] ] ) { unset($dup_of_section_names [ $completed_section_value['section_id'] ]); } } unset($dup_of_section_names[9]);//unset photograph always $img_satellite_check = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'satellite','fk_sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALEPD_DOCS); $img_selfile_check = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'selfie_with_person_met','fk_sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALEPD_DOCS); if(count($drafted_sections) ) { $drafted_sections = array_map(function($single) use ($section_names) { return array('section_id' => $single['section_id'],'sectin_name' => $section_names [ $single['section_id'] ]); },$drafted_sections); unset($records['status']); $data['dataStatus'] = true; $data['records'] = $drafted_sections; $data['pd_status'] = 'DRAFT'; $data['status'] = REST_Controller::HTTP_OK; $this->response($data,REST_Controller::HTTP_OK); } else if($img_satellite_check[0]['count'] == 0 || $img_selfile_check[0]['count'] == 0) { unset($records['status']); $data['dataStatus'] = true; $data['records'][] = ($img_selfile_check[0]['count'] == 0) ? array('section_id' => 9,'section_name' => 'selfie image') : ( $img_satellite_check[0]['count'] == 0 ? array('section_id' => 9,'section_name' => 'satellite image') :('selfie image and satellite image ar not available')); $data['pd_status'] = 'DRAFT'; $data['status'] = REST_Controller::HTTP_OK; $this->response($data,REST_Controller::HTTP_OK); } else { $records['status'] = 'COMPLETED'; $records['is_cus_link_disabled'] = 1; $records['completed_date'] = date('Y-m-d H:i:s'); $flyhi_pd_id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); $this->prepareFlyhiPDReport($records['sales_pd_id'],false); sleep(10); log_message('ERROR','####FLYHI-PD AFTER 10 PREPARED REPORT'.$records['sales_pd_id']); } } else { log_message('ERROR','####UPDATE FLYHIPD'.$records['sales_pd_id']); // $gen_form = json_decode($form[0]['section_data'],true); $flyhi_pd_id = (int)$records['sales_pd_id']; if($records['questions']){ foreach ($records['questions'] as $g_key => $g_value) { if(isset($g_value['question_key']) && $g_value['question_key'] === 'loan_application_id') { $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_name') { $lender_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'loan_amount') { $loan_amount = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'branch') { $pd_branch_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_sales_person') { $lender_sales_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_credit_person') { $lender_credit_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'product_name') { $product_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'verification_type') { if(isset($g_value['onchange_properties'])) { foreach ($g_value['onchange_properties'] as $h_key => $h_value) { foreach ($h_value['form_controls'] as $i_key => $i_value) { foreach ($i_value['questions'] as $j_key => $j_value) { if($g_value['answer_value'] == 'Residence verification' && $j_value['question_key'] == 'residence_city'){ $city = $j_value['answer_value']; $flyhi_pd_type = 4; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'officer_city'){ $city = $j_value['answer_value']; $flyhi_pd_type = 3; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'employer_business_name') { $applicant_name = $j_value['answer_value']; } } } } } } } } $FLYHI_PD['applicant_name'] = $applicant_name; $FLYHI_PD['applicant_id'] = $applicant_id; $FLYHI_PD['city_id']=$city; $FLYHI_PD['loan_amount'] = $loan_amount; $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; $FLYHI_PD['pd_branch_id'] = $pd_branch_id; $FLYHI_PD['lender_id'] = $lender_id; $FLYHI_PD['product_id'] = $product_id ? $product_id : (ENVIRONMENT == 'production' ? 27 : 26); $status = $records['is_complete']; $section_data = json_encode($records); $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $flyhi_pd_id)); $this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$flyhi_pd_id,'section_id' => 1)); $fields = array('sales_pd_id' => $flyhi_pd_id, 'section_id' => 1, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); $is_entry_done = $this->Flyhi_Model->saveRecords($fields,SALESPD_SECTION_DATA); } // else 179 } // else 167 if($flyhi_pd_id) { $data['dataStatus'] = true; $data['records'] = $flyhi_pd_id; $data['status'] = REST_Controller::HTTP_OK; if(isset($records['rand_string'])){ $data['rand_string'] = $records['rand_string']; } $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Something went wrong! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function getFlyhiPD_post() { $records = $this->post('records'); $section_data = array(); if(!is_numeric($records['section_id'])){ $fields=array('id','sales_pd_id','section_id','status','createdby','createdon'); if($records['section_id'] == 'data'){ $fields[] = 'section_data'; } $section_data=$this->Flyhi_Model->selectCustomRecords($fields,array('sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); } else{ $section_data = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $records['sales_pd_id'],'isactive' => 1,'section_id' => $records['section_id']),SALESPD_SECTION_DATA); //print_r( json_decode($section_data[0]['section_data'],true));die(); if($records['section_id'] == 9 && count($section_data)) { $all_sales_pd_images = $this->Flyhi_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $records['sales_pd_id'],'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS); // print_r($all_sales_pd_images);die(); $photo_questions = (json_decode(($section_data[0]['section_data']),true)); foreach ($photo_questions['questions'] as $key => $value) { if(isset($value['answer_value']) && $value['answer_value'] && !$value['is_repeatable']) { $selfie = $this->Flyhi_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $records['sales_pd_id'],'img_name' => 'selfie_with_person_met','isactive' => 1),SALEPD_DOCS); if(count($selfie)) { $photo_questions['questions'][$key]['answer_value'] = $selfie[0]['img']; $photo_questions['questions'][$key]['image_location'] = $selfie[0]['location']; $photo_questions['questions'][$key]['image_id'] = $selfie[0]['doc_id']; //$photo_questions['questions'][$key]['answer_value'] = "CHNAGED"; } } else { foreach ($value['questions_group'] as $v_key => $individual_value) { //print_r($individual_value);die(); //if($individual_value['questions'][0]['answer_value']) if(isset($individual_value['questions'][0]['answer_value'])) { //iterate all_sales_pd_images to get one foreach ($all_sales_pd_images as $img_key => $img_value) { if($individual_value['questions'][0]['question_key'] == $img_value['img_name']) { $photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['answer_value'] = $img_value['img']; $photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['image_location'] = $img_value['location']; $photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['image_id'] = $img_value['doc_id']; //$photo_questions['questions'][$key]['questions_group'][$v_key]['questions'][0]['answer_value'] = "CHANGED"; unset($all_sales_pd_images[$img_key]); break; } } } } } } $photo_questions = json_encode($photo_questions); $section_data[0]['section_data'] = $photo_questions; } } if($section_data) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $section_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Data Found'; $this->response($data,REST_Controller::HTTP_OK); } } public function loadFlyhiPDTemplate_post() { $records = $this->post('records'); $lender_id = $records['lender_id']; // $product = $records['product_id']; $flyhi_pd_type = isset($records['sales_pd_type']) ? $records['sales_pd_type'] : null; $product = isset($records['product_id']) ? $records['product_id'] : null; $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' => $flyhi_pd_type,'isactive' => 1),SALESPDTEMPLATE); // $template = $this->Flyhi_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'product_id' => $product,'pd_type' => $pd_type,'sales_pd_type' => $flyhi_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','PRODUCT.name','PRODUCT.abbr','USERPROFILE.smc_emp_code'); // $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' => PRODUCTS. ' as PRODUCT', 'condition' =>'SALES_PD_DATA.product_id = PRODUCT.product_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); // $where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $flyhipd_id); $flyhipd_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); $pd_type = ""; if($flyhipd_data[0]['sales_pd_type'] == 3){$pd_type = "Workplace FI PD-"; }else if($flyhipd_data[0]['sales_pd_type'] == 4){$pd_type = "Residence FI PD-";} // print_r($flyhipd_data);die(); if($flyhipd_data) // if(1) { ini_set('max_execution_time', 0); $bucket_name = LENDER_BUCKET_NAME_PREFIX.$flyhipd_data[0]['lender_id']; // 1st Type Key name. (name,abbr and date). $pdf_name = strtolower(trim($flyhipd_data[0]['applicant_name'])); // $pdf_name .= '-'.$pd_type; $pdf_name .= '-'.$pd_type.$flyhipd_data[0]['abbr']; $pdf_name .= '-'.(date('dmY',strtotime($flyhipd_data[0]['completed_date']))); $key = 'sales_pd/'.$pd_id.'/'.$pdf_name.'.pdf'; $this->Flyhi_Model->updateRecords(array('pd_report_filename' => $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(!$flyhipd_data[0]['is_pdf'] || $flyhipd_data[0]['is_edited']) // if(1) { $all_section_data = $this->Flyhi_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]['json'],true));die(); $view_data['master'] = $flyhipd_data; $common_fields = array('pdid'=>$flyhipd_data[0]['sales_pd_id'], // 'product'=>$flyhipd_data[0]['abbr'], 'caseno'=>$flyhipd_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->processFlyhiPDJSON($section);//die(); // print_r($view_data['section'.$section['section_id'] ]);die; $section_fields['section'.$section['section_id'] ] = $this->processFlyhiPDJSON($section); } $view_data['section9'] = $this->Flyhi_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $pd_id,'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS); $view_data['product_id'] = $flyhipd_data[0]['product_id']; $view_data['geo_location'] = $flyhipd_data[0]['geo_location']; $view_data['satellite_image'] = $this->Flyhi_Model->selectCustomRecords(array('*'),array('fk_sales_pd_id' => $pd_id,'img_name' => 'satellite','isactive' => 1),SALEPD_DOCS); // die(); //$view_name = $flyhipd_data[0]['short_name'].'_'.$flyhipd_data[0]['abbr']; $view_name = $flyhipd_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->Flyhi_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 processFlyhiPDJSON($section_array) { if($section_array['section_id']) { $questions = json_decode($section_array['section_data'],true); // echo "770"; // print_r($questions['json']);die; return $this->processFlyhiPDData($questions['json'],$section_array['section_id']); // return $this->processFlyhiPDQuestions($questions['questions'],$section_array['section_id']); } } function processFlyhiPDData($questions,$section_id){ // print_r($questions);die(); $temp_array = array(); if(!empty($questions)){ foreach ($questions as $ques_key => $ques_value) { if($ques_key == 'permanent_state' && !empty($ques_value)){ $table = STATE; $fields = array('name'); $where_condition_array = array('isactive' => 1,'state_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } }if($ques_key == 'business_state' && !empty($ques_value)){ $table = STATE; $fields = array('name'); $where_condition_array = array('isactive' => 1,'state_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } }if($ques_key == 'officer_state' && !empty($ques_value)){ $table = STATE; $fields = array('name'); $where_condition_array = array('isactive' => 1,'state_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } } if($ques_key == 'permanent_city' && !empty($ques_value)){ $table = CITY; $fields = array('name'); $where_condition_array = array('isactive' => 1,'city_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } }if($ques_key == 'business_city' && !empty($ques_value)){ $table = CITY; $fields = array('name'); $where_condition_array = array('isactive' => 1,'city_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } }if($ques_key == 'officer_city' && !empty($ques_value)){ $table = CITY; $fields = array('name'); $where_condition_array = array('isactive' => 1,'city_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } } if($ques_key == 'business_pincode' && $ques_value != "1"){ $table = PINCODE; $fields = array('pincode'); $where_condition_array = array('pincode_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $ques_value; } }if($ques_key == 'business_pincode_others' && $ques_value == "1"){ $new_key = 'business_pincode_master'; $questions[$new_key] = $result_data[0]['pincode']; } if($ques_key == 'permanent_pincode' && $ques_value != "1"){ $table = PINCODE; $fields = array('pincode'); $where_condition_array = array('pincode_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['pincode']; } }if($ques_key == 'permanent_pincode_others' && $ques_value == "1"){ $new_key = $ques_key . 'permanent_pincode_master'; $questions[$new_key] = $ques_value; } if($ques_key == 'officer_pincode' && $ques_value != "1"){ // residence_pincode: "1" // residence_pincode_others: "600016" $table = PINCODE; $fields = array('pincode'); $where_condition_array = array('pincode_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['pincode']; } }if($ques_key == 'officer_pincode_others'){ $new_key = 'officer_pincode_master'; $questions[$new_key] = $ques_value; } if($ques_key == 'lender_name' && !empty($ques_value)){ $table = ENTITY; $fields = array('full_name','short_name'); $where_condition_array = array('entity_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['full_name']; $questions["lender_abbr"] = $result_data[0]['short_name']; } } if($ques_key == 'relationship_with_applicant' && !empty($ques_value)){ $table = RELATIONSHIPS; $fields = array('relationship_id','name'); $where_condition_array = array('relationship_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } } if($ques_key == 'branch' && !empty($ques_value)){ $table = ENTITYLENDERBRANCH; $fields = array('branch_name as name'); $where_condition_array = array('entity_lender_branch_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } } if($ques_key == 'lender_sales_person' && !empty($ques_value)){ $table = USERPROFILE; $fields = array('concat(first_name," ",last_name) as name'); $where_condition_array = array('userid'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } } if($ques_key == 'lender_credit_person' && !empty($ques_value)){ $table = USERPROFILE; $fields = array('concat(first_name," ",last_name) as name'); $where_condition_array = array('userid'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } } if($ques_key == 'product_name' && !empty($ques_value)){ $table = PRODUCTS; $fields = array('name'); $where_condition_array = array('product_id'=>$ques_value); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); if(count($result_data)) { $new_key = $ques_key . '_master'; $questions[$new_key] = $result_data[0]['name']; } } if($ques_key == 'residence_details' && !empty($ques_value)){ for($i=0;$i 1,'state_id'=>$ques_value[$i]['residence_state']); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); $new_key = 'residence_state_master'; if(count($result_data)) { $questions[$ques_key][$i][$new_key] = $result_data[0]['name']; }else{ $questions[$ques_key][$i][$new_key] = 'name'; } } if(isset($ques_value[$i]['residence_city'])){ $table = CITY; $fields = array('name'); $where_condition_array = array('isactive' => 1,'city_id'=>$ques_value[$i]['residence_city']); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); $new_key = 'residence_city_master'; if(count($result_data)) { $questions[$ques_key][$i][$new_key] = $result_data[0]['name']; } } if(isset($ques_value[$i]['residence_pincode'])){ $table = PINCODE; $fields = array('pincode'); $where_condition_array = array('pincode_id'=>$ques_value[$i]['residence_pincode']); $result_data = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,$table); $new_key = 'residence_pincode_master'; if(count($result_data)) { $questions[$ques_key][$i][$new_key] = $result_data[0]['pincode']; } } if(isset($ques_value[$i]['residence_pincode_others'])){ $new_key = 'residence_pincode_master'; $questions[$ques_key][$i][$new_key] = $ques_value[$i]['residence_pincode_others']; } } } } return $questions;} } function processFlyhiPDQuestions($questions,$section_id) { $temp_array = array(); foreach ($questions as $ques_key => $question) { 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'] == 'residence_state' || $question['question_key'] == 'residence_city' || $question['question_key'] == 'residence_pincode' || $question['question_key'] == 'business_state'|| $question['question_key'] == 'business_city'|| $question['question_key'] == 'business_pincode' || $question['question_key'] == 'permanent_state' || $question['question_key'] == 'permanent_city' || $question['question_key'] == 'permanent_pincode' || $question['question_key'] == 'officer_state' || $question['question_key'] == 'officer_city' || $question['question_key'] == 'officer_pincode' || $question['question_key'] == 'lender_name' || $question['question_key'] == 'branch' || $question['question_key'] == 'lender_sales_person' || $question['question_key'] == 'lender_credit_person') // $question['question_key'] == 'employer_business_state' || $question['question_key'] == 'employer_business_address_city' || $question['question_key'] == 'employer_business_pincode' || // $question['question_key'] == 'educational_institute_state' || $question['question_key'] == 'educational_institute_address_city' || $question['question_key'] == 'educational_institute_pincode' // ) { $temp_array[ $question['question_key'] ] = $this->getMasterData($question['answer_value'],$question['answers']); } if(isset($question['subfield_key'])) { $temp_array[ $question['question_key'] ] .= $question['subfield_value'].','; } if(isset($question['onchange_properties'])){ for ($a = 0; $a < count($question['onchange_properties']); $a++){ if(isset($question['onchange_properties'][$a]['form_controls'])){ $onchange_array = $question['onchange_properties'][$a]['form_controls']; $singleArray = []; for ($i = 0; $i < count($onchange_array); $i++){ $value = $this->processFlyhiPDQuestions($onchange_array[$i]['questions'],$section_id); foreach ($value as $key => $val){ $temp_array[$key] = $val; } } } } } // 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 { $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']; } } } } // 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; } } public function saveFlyhiPDImage_post() { $records = $this->post('records'); $is_customer_app = isset($records['is_customer_app']) ? $records['is_customer_app'] : null; unset($records['is_customer_app']); if($records['img_name'] == 'selfie_with_person_met') { $update_fields2 = array('isactive' => 0); $this->Flyhi_Model->updateRecords($update_fields2,SALEPD_DOCS,array('img_name' => 'selfie_with_person_met','fk_sales_pd_id' => $records['fk_sales_pd_id'])); if($is_customer_app) { $this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('section_id' => 9,'sales_pd_id' => $records['fk_sales_pd_id'])); } // $this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('section_id' => 9,'sales_pd_id' => $records['fk_sales_pd_id']));// temporary } if(!empty($records['img_id']) && $records['img_name'] != 'selfie_with_person_met'){ $update_fields2 = array('isactive' => 0); $this->Flyhi_Model->updateRecords($update_fields2,SALEPD_DOCS,array('doc_id'=>$records['img_id'])); } unset($records['img_id']); $id = $this->Flyhi_Model->saveRecords($records,SALEPD_DOCS); if($id) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = "Image Updated at ".$id; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Something went wrong! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function getFlyhiPDImgDataCusLink_post() { $rand_string = $this->post('rand_string'); $sales_pd_master_data = $this->Flyhi_Model->selectCustomRecords(array('*'),array('rand_string' => $rand_string),SALES_PD_DATA); $product_short_name = $this->Flyhi_Model->selectCustomRecords(array('abbr'),array('product_id' => $sales_pd_master_data[0]['product_id']),PRODUCTS); $sales_pd_img_data = $this->Flyhi_Model->selectCustomRecords(array('doc_id', 'fk_sales_pd_id','img','img_name','isactive'),array('fk_sales_pd_id' => $sales_pd_master_data[0]['sales_pd_id'],'isactive' => 1,'img_name!=' => 'satellite'),SALEPD_DOCS); // print_r($product_short_name);die(); //sales tele pd img structure array // $imgs = array('selfie_with_person_met' => array('is_multiple' => 0,'img_name' => 'Selfie of the person contacted')); $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')); $img_data = array(); if(count($sales_pd_img_data)) { foreach ($imgs as $key => $value) { //echo "FISRT LOOP****$key"; foreach ($sales_pd_img_data as $sales_pd_img_data_key => $sales_pd_img_data_value) { //echo "SEC LOOP****"; if($key == $sales_pd_img_data_value['img_name']) { if($value['is_multiple']) { if(!array_key_exists($key,$img_data)) { $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => [array('img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : '')],'is_multiple' => 1,'section_heading' => $value['img_name']); } else { $img_data[$key]['img_data'][] = array('img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : ''); } } else { $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : '','is_multiple' => 0,'section_heading' => $value['img_name']);//$sales_pd_img_data_value['img'] } unset($sales_pd_img_data[$sales_pd_img_data_key]); //break; } // else // { // if(!$value['is_multiple']) // { // $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => $value['is_multiple'] == 0 ? '' : array(),'is_multiple' => $value['is_multiple'],'section_heading' => $value['img_name']); // } // else // { // if(!array_key_exists($key,$img_data)) // { // $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => [array('img_url' => $sales_pd_img_data_value['img'] ? 'Y' : 'N')],'is_multiple' => 1,'section_heading' => $value['img_name']); // } // else // { // $img_data[$key]['img_data'][] = array('img_url' => $sales_pd_img_data_value['img'] ? 'yes' : 'No'); // } // } // } } //IF current img key is not exist in existing img arry if(!array_key_exists($key,$img_data)) { if(!$value['is_multiple']) { $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => '','is_multiple' => $value['is_multiple'],'section_heading' => $value['img_name']); } else { $img_data[$key] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => array(),'is_multiple' => $value['is_multiple'],'section_heading' => $value['img_name']); } } } $img_data = array_values($img_data); } else { foreach ($imgs as $key => $value) { if($value['is_multiple']) { $img_data[] = array('img_key' => $key,'img_name' => $value['img_name'],'img_data' => array(),'is_multiple' => 1,'section_heading' => $value['img_name']); } else { $img_data[] = array('img_key' => $key,'img_name' => $value['img_name'],'img_url' => '','is_multiple' => 0,'section_heading' => $value['img_name']); } } } //print_r($img_data); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = array('sales_pd_id' => $sales_pd_master_data[0]['sales_pd_id'],'img_data' => $img_data,'is_cus_link_disabled' => $sales_pd_master_data[0]['is_cus_link_disabled']); $this->response($data,REST_Controller::HTTP_OK); } public function saveFlyhiPD_post() { $records = $this->post('records'); $FHFSL_product = (ENVIRONMENT == 'production' ? 27 : 26); $FHFSL_lender = (ENVIRONMENT == 'production' ? 19 : 49); $lender = isset($records['lender_id']) ? $records['lender_id'] : $FHFSL_lender; $product = isset($records['product_id']) ? $records['product_id'] : $FHFSL_product; $records['lender_id'] = $lender; $records['product_id'] = $product; $id = null; // print_r($records);//die(); log_message('ERROR','####FLYHIPD SAVE CALLED'); $lender_short_name = $this->Flyhi_Model->selectCustomRecords(array('short_name'),array('entity_id' => $lender ),ENTITY); $product_short_name = $this->Flyhi_Model->selectCustomRecords(array('abbr'),array('product_id' => $product ),PRODUCTS); $section_names = array('1' => 'General Section','9' => 'Photography'); $count = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $lender,'product_id' => $product,'isactive' => 1),SALES_PD_DATA); if($records['sales_pd_id'] == '' || $records['sales_pd_id'] == null) { /************ASSIGN Random URL******************/ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } $records['rand_string'] = $randomString; log_message('ERROR','####INSERT NEW FLYHIPD'); $salepd_serial_no = count($lender_short_name)? $lender_short_name[0]['short_name']:'UNKNOWN'; $salepd_serial_no .= count($product_short_name)? '-'.$product_short_name[0]['abbr']:'-UNKNOWN'; $salepd_serial_no .= '-'.(++$count[0]['count']); $records['sales_pd_sno'] = $salepd_serial_no; $id = $this->Flyhi_Model->saveRecords($records,SALES_PD_DATA); } else { //echo $product_short_name[0]['abbr']; if(isset($records['status']) && $records['status'] == 'COMPLETED') { log_message('ERROR','####COMPLETE FLYHIPD'.$records['sales_pd_id']); $drafted_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 0,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); $completed_sections = $this->Flyhi_Model->selectCustomRecords(array('section_id'),array('status' => 1,'sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALESPD_SECTION_DATA); $img_satellite_check = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'satellite','fk_sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALEPD_DOCS); $img_selfile_check = $this->Flyhi_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'selfie_with_person_met','fk_sales_pd_id' => $records['sales_pd_id'],'isactive' => 1),SALEPD_DOCS); $dup_of_section_names = $section_names; // print_r($dup_of_section_names); foreach ($completed_sections as $completed_section_key => $completed_section_value) { if($dup_of_section_names [ $completed_section_value['section_id'] ] ) { unset($dup_of_section_names [ $completed_section_value['section_id'] ]); } } // print_r($dup_of_section_names); unset($dup_of_section_names[9]);//unset photograph always if(count($dup_of_section_names)) { $res_data = array(); foreach ($dup_of_section_names as $key => $value) { $res_data[] = array('section_id' => $key,'sectin_name' => $section_names[$key]); } $data['dataStatus'] = true; $data['records'] = $res_data; $data['pd_status'] = 'DRAFT'; $data['status'] = REST_Controller::HTTP_OK; $this->response($data,REST_Controller::HTTP_OK); } if(count($drafted_sections) ) { $drafted_sections = array_map(function($single) use ($section_names) { return array('section_id' => $single['section_id'],'sectin_name' => $section_names [ $single['section_id'] ]); }, $drafted_sections); //print_r($drafted_sections);die(); unset($records['status']); $data['dataStatus'] = true; $data['records'] = $drafted_sections; $data['pd_status'] = 'DRAFT'; $data['status'] = REST_Controller::HTTP_OK; $this->response($data,REST_Controller::HTTP_OK); } else if($img_satellite_check[0]['count'] == 0 || $img_selfile_check[0]['count'] == 0) { unset($records['status']); $data['dataStatus'] = true; $data['records'][] = array('section_id' => 9,'section_name' => 'selfie image'); $data['pd_status'] = 'DRAFT'; $data['status'] = REST_Controller::HTTP_OK; $this->response($data,REST_Controller::HTTP_OK); } else { $records['status'] = 'COMPLETED'; $records['is_cus_link_disabled'] = 1; $records['completed_date'] = date('Y-m-d H:i:s'); //echo 'final';die(); $id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); //CAMUNDA::completeSalesPDTask($records['sales_pd_id']); $this->prepareFlyhiPDReport($records['sales_pd_id'],false); // die(); sleep(10); log_message('ERROR','####FlyHiPD AFTER 10 PREPARED REPORT'.$records['sales_pd_id']); // $city = ''; // $form = $this->Flyhi_Model->selectCustomRecords(array(),array('isactive' => 1,'sales_pd_id' => $records['sales_pd_id'],'section_id' => 1,'status' => 1),SALESPD_SECTION_DATA); // $gen_form = json_decode($form[0]['section_data'],true); // if(!empty($gen_form)){ // foreach ($gen_form['questions'] as $g_key => $g_value) // { // // if($g_value['question_key'] == 'state') // // { // // $ids_to_send_mail['state'] = $g_value['answer_value']; // // } // if($g_value['question_key'] == 'city') // { // $city = $g_value['answer_value']; // } // } // }//gen_form closed here. // PDALERTS::sendSalesPDMail($this,$records['sales_pd_id'],$city); } } else { log_message('ERROR','####UPDATE FLYHIPD'.$records['sales_pd_id']); $id = $this->Flyhi_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); } } if($id) { $data['dataStatus'] = true; $data['records'] = $id; $data['status'] = REST_Controller::HTTP_OK; if(isset($records['rand_string'])){ $data['rand_string'] = $records['rand_string']; } $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Something went wrong! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function saveFlyhiPDsection_Aspersalespdtype_post() { $records = $this->post('records'); $sales_pd_id = $records['sales_pd_id']; $section_id = $records['section_id']; $fk_createdby = $records['fk_createdby']; $status = $records['is_complete']; $section_data = json_encode($records); //Get Sales PD master Data $columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.abbr'); $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' => PRODUCTS. ' as PRODUCT', 'condition' =>'SALES_PD_DATA.product_id = PRODUCT.product_id', 'jointype' => 'INNER') ); $where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $sales_pd_id); $sales_pd_master_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); //pre process works switch($section_id) { case 1: //General section //update Applicant ID and applicant Name to sales pD master Table $city = ''; if($records['questions']) { foreach ($records['questions'] as $g_key => $g_value) { if(isset($g_value['question_key']) && $g_value['question_key'] === 'loan_application_id') { $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_name') { $lender_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'loan_amount') { $loan_amount = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'branch') { $pd_branch_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_sales_person') { $lender_sales_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'lender_credit_person') { $lender_credit_person = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'product_name') { $product_id = $g_value['answer_value']; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'product_name') { $applicant_name = $g_value['applicant_name']; } if($g_value['answer_value'] == 'Residence verification'){ $flyhi_pd_type = 4; } if($g_value['answer_value'] == 'Office verification'){ $flyhi_pd_type = 3; } if(isset($g_value['question_key']) && $g_value['question_key'] == 'verification_type') { if(isset($g_value['onchange_properties'])) { foreach ($g_value['onchange_properties'] as $h_key => $h_value) { foreach ($h_value['form_controls'] as $i_key => $i_value) { foreach ($i_value['questions'] as $j_key => $j_value) { if($g_value['answer_value'] == 'Residence verification' && $j_value['question_key'] == 'residence_city'){ $city = $j_value['answer_value']; } if($g_value['answer_value'] == 'Office verification' && $j_value['question_key'] == 'officer_city'){ $city = $j_value['answer_value']; } } } } } } } } $FLYHI_PD['applicant_name'] = $applicant_name; $FLYHI_PD['applicant_id'] = $applicant_id; $FLYHI_PD['city_id']=$city; $FLYHI_PD['loan_amount'] = $loan_amount; $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; $FLYHI_PD['pd_branch_id'] = $pd_branch_id; $FLYHI_PD['lender_id'] = $lender_id; $FLYHI_PD['sales_pd_type'] = $flyhi_pd_type; $FLYHI_PD['product_id'] = $product_id ? $product_id : (ENVIRONMENT == 'production' ? 27 : 26); $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); break; case 9: //photosection break; default: } //make inactive previous records $this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$sales_pd_id,'section_id' => $section_id )); //insert new record $fields = array('sales_pd_id' => $sales_pd_id, 'section_id' => $section_id, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); $is_entry_created = $this->Flyhi_Model->saveRecords($fields,SALESPD_SECTION_DATA); if($is_entry_created) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $is_entry_created; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Something went wrong! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function saveFlyhiPDsection_post() { $records = $this->post('records'); $sales_pd_id = $records['sales_pd_id']; $section_id = $records['section_id']; $fk_createdby = $records['fk_createdby']; $status = $records['is_complete']; $section_data = json_encode($records); //Get Sales PD master Data $columns = array('SALES_PD_DATA.*','ENTITY.short_name','PRODUCT.abbr'); $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' => PRODUCTS. ' as PRODUCT', 'condition' =>'SALES_PD_DATA.product_id = PRODUCT.product_id', 'jointype' => 'INNER') ); $where_condition_array = array('SALES_PD_DATA.sales_pd_id' => $sales_pd_id); $sales_pd_master_data = $this->Flyhi_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); // print_r($records['json']); //pre process works switch($section_id) { case 1: //General section //update Applicant ID and applicant Name to sales pD master Table $applicant_id = null ; $city = null; $lender_id= null;$loan_amount = null; $pd_branch_id = null ; $lender_sales_person =null; $lender_credit_person =null; $flyhi_pd_type = null; $applicant_name =null;$current_resd_addr_check = 0 ; $current_office_addr_check = 0 ; if($records['json']) { foreach ($records['json'] as $g_key => $g_value) { if($g_key == 'loan_application_id'){ $applicant_id = (!empty($g_value)) ? $g_value : 'Not Provided'; } if($g_key == 'lender_name'){ $lender_id = (!empty($g_value)) ? $g_value : null ; } if($g_key == 'loan_amount'){ $loan_amount = (!empty($g_value)) ? $g_value : null ; } if($g_key == 'branch'){ $pd_branch_id = (!empty($g_value)) ? $g_value : null ; } if($g_key == 'lender_sales_person'){ $lender_sales_person = (!empty($g_value)) ? $g_value : null ; } if($g_key == 'lender_credit_person'){ $lender_credit_person = (!empty($g_value)) ? $g_value : null ; } if($g_key == 'product_name'){ $product_id = (!empty($g_value)) ? $g_value : null ; } if($g_key == 'applicant_name'){ $applicant_name = (!empty($g_value)) ? $g_value : null ; } if($g_key == 'verification_type' && $g_value == 'Residence verification'){ $flyhi_pd_type = 4; } if($g_key == 'verification_type' && $g_value == 'Office verification'){ $flyhi_pd_type = 3; } if($g_key == 'Same_as_current_residence_address' && $g_value == 'NO'){ $current_resd_addr_check = 1; } if($current_resd_addr_check && $g_key == 'permanent_city'){ $city = $g_value; }else if($g_key == 'residence_details'){ $city = $g_value[0]['residence_city']; } if($g_key == 'Same_as_current_business_address' && $g_value == 'NO'){ $current_office_addr_check = 1; } if($current_office_addr_check && $g_key == 'business_city'){ $city = $g_value; }else if($g_key == 'officer_city'){ $city = $g_value; } } } $FLYHI_PD['applicant_name'] = $applicant_name; $FLYHI_PD['applicant_id'] = $applicant_id; $FLYHI_PD['city_id']=$city; $FLYHI_PD['loan_amount'] = $loan_amount; $FLYHI_PD['lender_sales_person'] = $lender_sales_person ; $FLYHI_PD['lender_credit_person'] = $lender_credit_person ; $FLYHI_PD['pd_branch_id'] = $pd_branch_id; $FLYHI_PD['lender_id'] = $lender_id; $FLYHI_PD['sales_pd_type'] = $flyhi_pd_type; $FLYHI_PD['product_id'] = $product_id ? $product_id : (ENVIRONMENT == 'production' ? 27 : 26); $this->Flyhi_Model->updateRecords($FLYHI_PD,SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); break; case 9: //photosection break; default: } //make inactive previous records $this->Flyhi_Model->updateRecords(array('isactive' => 0),SALESPD_SECTION_DATA,array('sales_pd_id' =>$sales_pd_id,'section_id' => $section_id )); //insert new record $fields = array('sales_pd_id' => $sales_pd_id, 'section_id' => $section_id, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); $is_entry_created = $this->Flyhi_Model->saveRecords($fields,SALESPD_SECTION_DATA); if($is_entry_created) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $is_entry_created; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Something went wrong! Try Later'; $this->response($data,REST_Controller::HTTP_OK); } } public function saveCusFlyhiVideo_post() { $records = json_decode($this->post('records'),true); $id = null; //log_message('ERROR','hi'); // print_r($records); // print_r($_FILES); // die(); if(!empty($_FILES['video_file'])) { $pd_master_details = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $records['pd_id']),SALES_PD_DATA); $bucketname = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['lender_id']; $key = 'pd'.$records['pd_id'].'/video/'.$records['filename']; $file_name_wo_extension = explode('.', ($records['filename']))[0]; $file_type = explode('/', ($_FILES['video_file']['type']))[1]; $folder_to_check = XLPATH.'/sales_pd/'.$records['pd_id'].'/videos'; //echo $folder_to_check;//die(); if(!file_exists($folder_to_check)) { mkdir(XLPATH.'/sales_pd/'.$records['pd_id'],0777); mkdir($folder_to_check,0777); } //die(); $config = array('upload_path' => $folder_to_check,'overwrite' => TRUE,'allowed_types' => '*','file_name' => $file_name_wo_extension.'.'.$file_type); $this->load->library('upload', $config); if($this->upload->do_upload('video_file')) { $upload_data = $this->upload->data(); //$this->load->view('upload_success',$data); //print_r($upload_data); $command_to_execute = FFMPEG_PATH.' -i '.$folder_to_check.'/'.$file_name_wo_extension.'.'.$file_type.' '.$folder_to_check.'/'.$file_name_wo_extension.'.mp4'.' 2>&1' ; //print_r($command_to_execute);die(); exec($command_to_execute,$o,$v); // print_r($o); // echo $command_to_execute;die(); if($o) { $sourcefile = $folder_to_check.'/'.$file_name_wo_extension.'.mp4'; $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); // print_r($s3result); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { log_message('ERROR','###PDVIDEO stored in S3'.$records['pd_id']); $record_data = array('fk_pd_id' => $records['pd_id'],'video_part_name'=>$records['filename'],'video_key' => $records['video_key'],'flyhi_pd_flag'=>$records['flyhi_pd_flag']); $id = $this->Flyhi_Model->saveRecords($record_data,CUS_VIDEO); unlink($folder_to_check.'/'.$file_name_wo_extension.'.webm'); unlink($folder_to_check.'/'.$file_name_wo_extension.'.mp4'); } // if it is last part of a video call, then call video merge functionality if(isset($records['is_call_ended']) && $records['is_call_ended'] == 1) { $final_video_name = $records['pd_id'].'-'.$records['video_key']; sleep(10); $this->mergeVideo($records['pd_id'],$pd_master_details,$final_video_name,$records['video_key']); } if($id != null || $id != "") { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = 'Video Saved Successfully'; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'Something Wrong. Try Later!'; $this->response($data,REST_Controller::HTTP_OK); } } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'Something Wrong. Try Later!'; $this->response($data,REST_Controller::HTTP_OK); } } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'Something Wrong. Try Later!'; $this->response($data,REST_Controller::HTTP_OK); } } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'No Image found to upload'; $this->response($data,REST_Controller::HTTP_OK); } } //merge all splitted videos public function getFlyhiVideoURL_post() { $pd_id = $this->post('pd_id'); $random_string = $this->post('random_string'); $this->load->helper('video_grabber_helper'); $pd_master_details = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $pd_id,'rand_string'=>$random_string),SALES_PD_DATA); $result_data = (new video_grabber_helper)->grabAllVideo($pd_master_details[0]['sales_pd_id'],$pd_master_details[0]['rand_string'],$pd_master_details); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result_data; $this->response($data,REST_Controller::HTTP_OK); } // To Inactive Video Recorded. public function deleteFlyhiVideo_get(){ $id = $this->get('id'); // $id = (int) $id; // if(!empty($id)){ // // $multipleWhere['fk_pd_id'] = $multipleWhere['pd_id']; // // unset($multipleWhere['pd_id']); $this->load->helper('video_grabber_helper'); $result_data = (new video_grabber_helper)->deleteVideo($id); // }else{ // $result_data = "ID Not Available. Unable to Delete"; // } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = $result_data ; $this->response($data,REST_Controller::HTTP_OK); } function updateTwlioFlyhiVideoStatus_post() { $pd_id = $this->post('pd_id'); $random_string = $this->post('random_string'); $room_id = $this->post('room_id'); $result_data = $this->getTwiloVideoStatus($pd_id,$random_string,$room_id); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result_data; $this->response($data,REST_Controller::HTTP_OK); } function getTwiloVideoStatus($pd_id,$random_string,$room_id = '') { $this->load->library('twlio'); $result_data = 0; // $query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id and twilo_status = 'enqueued' and composition_id is not null;"; $pd_master_details = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $pd_id,'rand_string'=>$random_string),SALES_PD_DATA); $query = "SELECT * FROM ".VIDEO_ROOM_INFO." where fk_pd_id = $pd_id and isactive = 1 and is_uploaded = 0";// and twilo_status = 'enqueued' and composition_id is not null;"; if($room_id) { $query .=" and room_id = '$room_id'"; } $video_info = $this->db->query($query); if($video_info->num_rows()) { $video_info = $video_info->result_array(); //print_r($video_info);die(); foreach ($video_info as $key => $value) { if($value['composition_id'] && $value['vps'] != 'google') { $res = $this->twlio->getCompositionStatus($value['composition_id']); //echo $res['status']; if(count($res) && $res['status'] == 'completed') { $is_copied = $this->copyMediaFromTwiloToS3($pd_master_details,$value);// copy media from twlio s3 to our s3 $fields_to_update = array('twilo_status' => 'completed'); if($is_copied) { $fields_to_update['s3_copied'] = 1; } $id = $this->Flyhi_Model->updateRecords($fields_to_update,VIDEO_ROOM_INFO,array('video_room_info_id' => $value['video_room_info_id'])); if($id){ if($room_id) {$result_data = $is_copied;}else{$result_data++ ;}} } } else { $room_status = $this->twlio->getRoomDataByRoomID($value['room_id']); if($room_status == 'completed') { $composition_result_data = $this->twlio->startComposistion($value['room_id']); // $composition_result_data = $this->twlio->startComposistion('RM23b8d502434e46e696d1fbd5d64c59c8'); // print_r($composition_result_data); $composition_result_data_json = json_encode($composition_result_data); // print_r($composition_result_data_json); $records['res_json'] = $composition_result_data_json; $records['twilo_status'] = $composition_result_data['status']; $records['composition_id'] = $composition_result_data['compositionId']; $records['is_call_ended'] = 1; $records['flyhi_pd_flag'] = 1; $where_condition_array = array('fk_pd_id' => $pd_id); if($value['room_id']){ $where_condition_array['room_id'] = $value['room_id']; } $id = $this->Flyhi_Model->updateRecords($records,VIDEO_ROOM_INFO,$where_condition_array); } } } } return $result_data; } function copyMediaFromTwiloToS3($pd_master_details,$value)// copy media from twlio s3 to our s3 { EXTERNAL_DIR_CHECK::checkExternalDirectory($pd_master_details[0]['sales_pd_id']); //get media uri from twlio $singed_uri = $this->twlio->compositionVideoFile($value['composition_id']); //echo $singed_uri; $internal_server_tmp_location = XLPATH.'/sales_pd/'.$pd_master_details[0]['sales_pd_id'].'/videos'; $internal_server_tmp_location_filename = ($internal_server_tmp_location.'/'.$value['composition_id'].'.mp4'); //echo $internal_server_tmp_location; if(!file_exists($internal_server_tmp_location)){ mkdir($internal_server_tmp_location); }; $is_writed = file_put_contents($internal_server_tmp_location_filename,file_get_contents($singed_uri)); //upload it to aws s3 $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['lender_id']; $final_key = 'pd'.$pd_master_details[0]['sales_pd_id'].'/video/'.$value['composition_id'].'.mp4'; $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$final_key,'sourcefile'=>($internal_server_tmp_location_filename)); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { log_message('ERROR','###TWLIO TO S3 STARTED'.$value['composition_id']); unlink($internal_server_tmp_location_filename); return $temp_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+7 days'); //unlink($folder_to_check.'/'.$final_video_name.'.mp4'); } return null; } function mergeVideo($pd_id,$pd_master_details,$final_video_name,$video_key) { // $pd_id = $this->post('pd_id'); // $random_string = $this->post('random_string'); //$final_video_name = $pd_id.'-'.$random_string; //echo $final_video_name;die(); //Get PD master DEtails //$pd_master_details = $this->PD_Model->getPDMasterDetails($pd_id,$random_string); //$is_video_merged = $this->PD_Model->selectCustomRecords(array('*'),array('fk_pd_id' => $pd_id,'video_part_name' => $final_video_name),CUS_VIDEO); //prit_r($pd_master_details);die(); // if(count($pd_master_details) && isset($pd_master_details[0]['pd_id'])) // { $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['lender_id']; $final_key = 'pd'.$pd_master_details[0]['pd_id'].'/video/'.$final_video_name.'.mp4'; //Get all video info $qu = "SELECT *,convert(substr(substring_index(video_part_name,'-',1),6),UNSIGNED INTEGER) as sno FROM t_cus_video where fk_pd_id = $pd_id and video_key = '$video_key' and is_active = 1 and flyhi_pd_flag = 1 order by sno"; $video_info = $this->db->query($qu)->result_array(); $folder_to_check = XLPATH.'/sales_pd/'.$pd_id.'/videos'; $file_list = $folder_to_check.'/filelist.txt'; //Get All video and temp store it in xlpath $file_pointer = fopen($file_list, 'w+'); $all_input_files_names_with_path = ''; foreach ($video_info as $video_info_key => $video_info_value) { $key = 'pd'.$pd_id.'/video/'.$video_info_value['video_part_name']; $temp_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'+10 minutes'); $file_to_create = $folder_to_check.'/'.$video_info_value['video_part_name']; $output = file_put_contents($file_to_create,file_get_contents($temp_uri)); if($output) { $file_name_wo_extension = explode('.', ($video_info_value['video_part_name']))[0]; //fwrite($file_pointer,"file "."'".$file_name_wo_extension.".mp4"."'\n"); fwrite($file_pointer,"file "."'".$file_name_wo_extension."'\n"); } } fclose($file_pointer); // echo '***************************************';//die(); $merge_cmd = FFMPEG_PATH.' -f concat -safe 0 -i '.$folder_to_check.'/'.'filelist.txt -c copy '.$folder_to_check.'/'.$final_video_name.'.mp4 2>&1'; //echo '#########################################'; //echo $merge_cmd;//die(); exec($merge_cmd,$ou,$v); //print_r($ou);//die(); if($ou && file_exists($folder_to_check.'/'.$final_video_name.'.mp4')) { //echo 'upload to s3'; $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$final_key,'sourcefile'=>($folder_to_check.'/'.$final_video_name.'.mp4')); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { log_message('ERROR','###PDVIDEO merged video stored in S3'.$pd_id); $record_data = array('is_video_merged' => 1); //$id = $this->PD_Model->updateRecords($record_data,PDTRIGGER,array('pd_id' => $pd_id)); $id = 1; unlink($folder_to_check.'/'.$final_video_name.'.mp4'); } foreach($video_info as $video_info_key => $video_info_value) { $file_name_wo_extension = explode('.', ($video_info_value['video_part_name']))[0]; //unlink($folder_to_check.'/'.$file_name_wo_extension.'.ts'); unlink($folder_to_check.'/'.$file_name_wo_extension); } // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$final_key,'+3 hrs'); // $data['dataStatus'] = true; // $data['status'] = REST_Controller::HTTP_OK; // $data['url'] = $singed_uri; // $this->response($data,REST_Controller::HTTP_OK); } else { log_message('ERROR','###PDVIDEO merged video not stored in S3'.$pd_id); } } public function uploadFlyhiVideoFile_post() { $records = json_decode($this->post('records'),true); // $pd_master_details = $this->PD_Model->getPDMasterDetails($records['fk_pd_id'],$records['random_string']); $pd_master_details = $this->Flyhi_Model->selectCustomRecords(array('*'),array('sales_pd_id' => $records['fk_pd_id'],'rand_string'=>$records['random_string']),SALES_PD_DATA); $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_details[0]['lender_id']; // echo XLPATH; // print_r($records);die(); // print_r($pd_master_details);die(); $is_bucket_upload_sucess = false; $id = null; //die(); if(!empty($_FILES['video_file'])) { $folder_to_check = XLPATH.'/sales_pd/'.$records['fk_pd_id'].'/videos'; if(!file_exists($folder_to_check)) { mkdir($folder_to_check,0777); } // die(); // $modified_fname = $records['rand_key'].'~'.str_replace(' ','_',($_FILES['pd_excel_data']['name'])); $modified_fname = str_replace(' ','_',($_FILES['video_file']['name'])); // echo file_exists($folder_to_check);die(); $config = array('upload_path' => $folder_to_check,'overwrite' => TRUE,'allowed_types' => '*','file_name' => $modified_fname); $this->load->library('upload', $config); $this->upload->initialize($config); try { if($this->upload->do_upload('video_file')) { log_message('ERROR','video uplaod done :' . $folder_to_check); $sourcefile = $folder_to_check.'/'.$modified_fname; // echo $sourcefile; $key = 'pd'.$records['fk_pd_id'].'/video/'.$modified_fname; $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$key,'sourcefile'=>$sourcefile); // print_r($bucket_data);die(); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); //print_r($s3result);die(); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $is_bucket_upload_sucess = 1; $id = $this->PD_Model->saveRecords(array('fk_pd_id' =>$records['fk_pd_id'],'room_id' => $modified_fname,'composition_id' => $modified_fname,'twilo_status' => 'completed','is_call_ended' => 1,'s3_copied' => 1,'is_uploaded' => 1,'flyhi_pd_flag'=>1),VIDEO_ROOM_INFO); unlink($sourcefile); } } else { log_message('ERROR','video uplaod failed :' . $folder_to_check); } } catch (Exception $e) { log_message('ERROR','video uplaod failed exception:' . $folder_to_check.' - '.$e->getMessage()); } // die(); if($is_bucket_upload_sucess && $id) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = 'File Uploaded Successfully'; // $data['excel_file_id'] = $id; // $data['records'] = $result_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'Something Wrong. Try Later!'; $this->response($data,REST_Controller::HTTP_OK); } } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'No Data File Found!'; $this->response($data,REST_Controller::HTTP_OK); } } //api for Manually Report Generation. public function regenerateFlyhiReport_get(){ $sales_pd_id = $this->get('sales_pd_id'); if(!empty($sales_pd_id)){ $this->Flyhi_Model->updateRecords(array('is_pdf' => 0),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); log_message('ERROR','####Manually Called - Report Generated Flyhi pd = '.$sales_pd_id); $this->prepareFlyhiPDReport($sales_pd_id);} else{ $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'Sales PDID Not Found !'; $this->response($data,REST_Controller::HTTP_OK); } } public function getDigiLockerDocs_get(){ $this->load->helper('digital_locker'); // $code = "66e28b748d5f73186206a03f27f6aee73191a087"; $code = $this->get('code'); $co_applicant = $this->get('state'); log_message('ERROR',"### 1 Msg : Inside flyhi Controller GetDigilockerDocs fns"); log_message('ERROR',"### 1 Params : i have code :".$code." & applicant id : ".$co_applicant); $response_data = digital_locker::getAccessToken($code,$co_applicant); log_message('ERROR',"### 5 Helper Reponse : ".json_encode($response_data)); if(isset($response_data['dataStatus']) && $response_data['dataStatus'] == false){ $response_data['status'] = REST_Controller::HTTP_NOT_FOUND; $this->response($response_data,REST_Controller::HTTP_OK); }else{ $other_data = $response_data['dtls']; $view_data['token']= $response_data['token']; $view_data['list'] = json_decode($response_data['records'], true); $view_data['pd_id'] = (count($other_data)>0) ? $other_data[0]['fk_pd_id'] : null; $view_data['applicant_name'] = (count($other_data)>0) ? $other_data[0]['applicant_name'] : null; $view_data['pd_sno'] = (count($other_data)>0) ? $other_data[0]['pd_sno'] : null; $view_data['applicant_id']=(count($other_data)>0) ? $other_data[0]['pd_co_applicant_id'] : null; log_message('ERROR',"### 5 ViewData :".json_encode($view_data)); $this->header_title = "new"; $view_data['page_title']="PD GENIE : Digitial Documents"; $this->load->view("digital_locker",$view_data); // echo $html_content; die(); // $response_data['status'] = REST_Controller::HTTP_OK; } // $this->response($response_data,REST_Controller::HTTP_OK); } public function downloadDigiLockerDocs_post(){ $this->load->helper('digital_locker'); log_message('ERROR','### 5 User Choosen Files'.json_encode($this->post())); $temp_flag = 0 ; $form_data = $this->post(); $token = $form_data['token']; $pd_id = $form_data['pd_id']; $applicant_name = $form_data['applicant_name']; $applicant_id = $form_data['applicant_id']; log_message('ERROR','### 5th User Choosen Files token key'.$form_data['token']); unset($form_data['token']); unset($form_data['pd_id']); unset($form_data['applicant_name']); unset($form_data['applicant_id']); for($i=0;$i0){ for($i=0;$i $pd_id); $dtls = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER); $pd_id = (count($dtls)>0) ? $dtls[0]['pd_id'] : null; $fk_lender_id = (count($dtls)>0) ? $dtls[0]['fk_lender_id'] : null; $bucketname = LENDER_BUCKET_NAME_PREFIX.$fk_lender_id; $key = 'pd'.$pd_id.'/'.$doc_renamed ; $sourcefile = $tempdoc; $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); // $MyFile = file_get_contents($src_local_file); log_message('ERROR',"### 7.2 : Choosen Files s3-result :".json_encode($s3result)); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $pd_document_data = array('fk_pd_id' => $pd_id,'img_type' => 2,'pd_document_title'=>$doc_renamed,'pd_document_name'=>$doc_renamed,'fk_form_id'=>18,'co_applicant_id'=>$applicant_id); $pd_document_id = $this->Flyhi_Model->saveRecords($pd_document_data,PDDOCUMENTS); if($pd_document_id != "" || $pd_document_id != null){ $temp_flag++; } unlink($src_local_file); } log_message('ERROR',"### 8 : Choosen Files reponse :".json_encode($reponse)); }} if($temp_flag != 0){ $msg = count($reindexed_array). 'User Select File . '.$temp_flag.' File Uploaded Successfully'; $reponse_data['dataStatus'] = true; $reponse_data['status'] = REST_Controller::HTTP_OK; $reponse_data['msg'] = $msg; echo ''; // sleep for 8 seconds sleep(8); // redirect("https://demo.pdgenie.com/pd/#/home"); }else{ $reponse_data['dataStatus'] = false; $reponse_data['status'] = REST_Controller::HTTP_NO_CONTENT; $reponse_data['msg'] = 'No File Uploaded'; } $this->response($reponse_data,REST_Controller::HTTP_OK); } public function myFunction_post(){ echo ''; } public function getDigiLockerDocs3_get(){ $this->load->helper('digital_locker'); // echo " 1- ".digital_locker::userCh_check1(); $view_data['list2'] = array ( 'items' => array ( 0 => array ( 'name' => 'PAN Verification Record', 'type' => 'file', 'size' => '', 'date' => '21-06-2022', 'parent' => '', 'mime' => array ( 0 => 'application/json', 1 => 'application/xml', 2 => 'application/pdf', ), 'uri' => 'in.gov.pan-PANCR-GDLPS2188M', 'doctype' => 'PANCR', 'description' => 'PAN Verification Record', 'issuerid' => 'in.gov.pan', 'issuer' => 'Income Tax Department', ), ),'token'=>"response_data[token]" ); $view_data['list'] = array ( 'items' => array ( 0 => array ( 'name' => 'PAN Verification Record', 'type' => 'file', 'size' => '', 'date' => '21-06-2022', 'parent' => '', 'mime' => array ( 0 => 'application/json', 1 => 'application/xml', 2 => 'application/pdf', ), 'uri' => 'in.gov.pan-PANCR-GDLPS2188M', 'doctype' => 'PANCR', 'description' => 'PAN Verification Record', 'issuerid' => 'in.gov.pan', 'issuer' => 'Income Tax Department', ), 1 => array ( 'name' => '10th marksheet', 'type' => 'file', 'size' => '', 'date' => '21-06-2022', 'parent' => '', 'mime' => array ( 0 => 'application/json', 1 => 'application/xml', 2 => 'application/pdf', ), 'uri' => 'in.gov.pan-PANCR-GDLPS2188M', 'doctype' => 'PANCR', 'description' => 'PAN Verification Record', 'issuerid' => 'in.gov.pan', 'issuer' => 'Income Tax Department', ), 2 => array ( 'name' => '12th marksheet', 'type' => 'file', 'size' => '', 'date' => '21-06-2022', 'parent' => '', 'mime' => array ( 0 => 'application/json', 1 => 'application/xml', 2 => 'application/pdf', ), 'uri' => 'in.gov.pan-PANCR-GDLPS2188M', 'doctype' => 'PANCR', 'description' => 'PAN Verification Record', 'issuerid' => 'in.gov.pan', 'issuer' => 'Income Tax Department', ), ), ); $code = $this->get('code'); $co_applicant = $this->get('state'); $reponse = digital_locker::userCh_check3($code,$co_applicant); $view_data['token']= "response_data['token']"; $view_data['pd_id']="3258"; $view_data['applicant_name']="Sanjeev "; $view_data['applicant_id']="7128"; $view_data['pd_sno']="M7128"; $this->load->view("digital_locker",$view_data); // echo $html_content; die(); } public function getDigiLockerDos_get(){ $this->load->helper('digital_locker'); echo " 3- ".digital_locker::userCh_check3(); } public function previewDigiLockerDocs_post(){ $this->load->helper('digital_locker'); log_message('ERROR',"### 6 Msg : inside Controller PreviewDigiLockerDocs fns"); log_message('ERROR','### 6 Params : '.json_encode($this->post())); $temp_flag = 0 ; $form_data = $this->post(); $token = $form_data['token']; $pd_id = $form_data['pd_id']; $applicant_name = $form_data['applicant_name']; $applicant_id = $form_data['applicant_id']; $doc_name = $form_data['doc_name']; $doc_uri = $form_data['doc_uri']; log_message('ERROR','### 6 Form data : '.json_encode($form_data)); if(count($form_data)>0){ $doc_name = str_replace(' ', '_',$doc_name); $doc_renamed = $applicant_name."_".$doc_name.'.pdf'; log_message('ERROR','### 6 Doc renamed : '.$doc_renamed); // $src_local_file = XLPATH.'/tmp/'.$doc_renamed; $src_local_file = XLPATH.'/pd_reports/'. $pd_id .'/'.$doc_name.'.pdf'; log_message('ERROR','### 6 Doc path : '.$doc_renamed); if(!file_exists($src_local_file)) { mkdir(XLPATH.'/pd_reports/'. $pd_id .'/',0777); $reponse = digital_locker::downloadFiles($doc_uri,$token); log_message('ERROR',"### 6 Reponse :".json_encode($reponse)); $ifp = fopen( $src_local_file, 'wb' ); fwrite( $ifp, $reponse ); fclose( $ifp ); $tempdoc = $src_local_file; $tempdocname = $doc_renamed; $fields = array('pd_id','fk_lender_id'); $where_condition_array = array('pd_id' => $pd_id); $dtls = $this->Flyhi_Model->selectCustomRecords($fields,$where_condition_array,PDTRIGGER); $pd_id = (count($dtls)>0) ? $dtls[0]['pd_id'] : null; $fk_lender_id = (count($dtls)>0) ? $dtls[0]['fk_lender_id'] : null; $bucketname = LENDER_BUCKET_NAME_PREFIX.$fk_lender_id; $key = 'pd'.$pd_id.'/'.$doc_renamed ; $sourcefile = $tempdoc; $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); log_message('ERROR',"### 8 S3-result :".json_encode($s3result)); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $pd_document_data = array('fk_pd_id' => $pd_id,'img_type' => 2,'pd_document_title'=>$doc_renamed,'pd_document_name'=>$doc_renamed,'fk_form_id'=>18,'co_applicant_id'=>$applicant_id); $pd_document_id = $this->Flyhi_Model->saveRecords($pd_document_data,PDDOCUMENTS); if($pd_document_id != "" || $pd_document_id != null){ $temp_flag++; } // unlink($src_local_file); } }else{ log_message('ERROR','### 6 else '); } // chmod($src_local_file, 0777); $this->readfile($src_local_file); // $tofile= realpath($src_local_file); // header('Content-Type: application/pdf'); // // $MyFile = file_get_contents($src_local_file); // readfile($tofile); }else{ $reponse_data['dataStatus'] = false; $reponse_data['status'] = REST_Controller::HTTP_NO_CONTENT; $reponse_data['msg'] = 'No File Uploaded'; $this->response($reponse_data,REST_Controller::HTTP_OK); } } public function readfile($file){ chmod($file, 0777); $tofile= realpath($file); header('Content-Type: application/pdf'); // $MyFile = file_get_contents($file); readfile($tofile); } public function previewDigiLockerDoc_get(){ $this->load->helper('digital_locker'); $fname = $this->get('doc'); $fname = "Komal_Covid_old.pdf"; $token = $this->get('token'); $pdid = $this->get('pdid'); $src_local_file = XLPATH.'/tmp/'.$fname; // $src_local_file = XLPATH.'/pd_reports/'. $pdid .'/'.$fname.'.pdf'; if(!file_exists($src_local_file)) { // $reponse = digital_locker::downloadFiles($fname,$token); // $ifp = fopen( $src_local_file, 'wb' ); // fwrite( $ifp, $reponse ); // fclose( $ifp ); } chmod($src_local_file, 0777); $tofile= realpath($src_local_file); header('Content-Type: application/pdf'); readfile($tofile); // $call = digital_locker::callTheFiles($src_local_file); // return $fname; // $tofile= realpath("uploaddir/".$fname); // header('Content-Type: application/pdf'); // readfile($tofile); } }// Class Ends