load->model('SMC_Credit_PD_Model'); $this->load->model('PD_Model'); $this->external_path = $this->config->item('external_data_path'); $this->load->library('AWS_S3'); $this->load->library('pdfgenerator'); $this->load->helper('satellite_image'); $this->load->library('phpmailer_library'); $this->load->helper('cet_creditpd'); } public function loadSalesPDTemplate_post() { $records = $this->post('records'); $lender_id = $records['lender_id']; $product = $records['product_id']; $sales_pd_type = $records['sales_pd_type']; $template = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('lender_id' => $lender_id,'product_id' => $product,'sales_pd_type' => $sales_pd_type,'isactive' => 1),SALESPDTEMPLATE); if(is_array($template) && count($template)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $template[0]; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Tempate Found!'; $this->response($data,REST_Controller::HTTP_OK); } } // public function saveSalesPDOld_post() // { // $records = $this->post('records'); // $applicant_name = ''; // $applicant_id = ''; // $officer = ''; // //satellite_image::getSatelliteImage(22,2);//die(); // foreach (json_decode($records['pd_json'],true) as $key => $value) // { // //print_r($value);die(); // if($value['section_id'] == 1) // { // foreach ($value['questions'] as $g_key => $g_value) // { // if($g_value['question_key'] == 'application_id') // { // $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; // } // if($records['product_id'] == 4) // { // if($g_value['question_key'] == 'company_name') // { // $applicant_name = $g_value['answer_value']; // } // } // else // { // if($g_value['question_key'] == 'person_met_during_visit') // { // $applicant_name = $g_value['answer_value']; // } // } // } // } // if($value['section_id'] == 8) // { // foreach ($value['questions'] as $g_key => $g_value) // { // if($g_value['question_key'] == 'name_of_sales_team_member') // { // $officer = $g_value['answer_value']; // } // } // } // } // $records['applicant_id'] = $applicant_id; // $records['applicant_name'] = $applicant_name; // $records['officer_name'] = $officer; // $id = null; // if(!$records['smc_credit_pd']) // { // //generate sales pd serial no // $count = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id']),SMC_CREDIT_PD); // $lender_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY); // $product_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS); // //print_r($product_short_name); // $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']); // //echo $salepd_serial_no; // //end generate sales pd serial no // // echo $salepd_serial_no; // // die(); // $records['sales_pd_sno'] = $salepd_serial_no; // $id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD); // satellite_image::getSatelliteImage($id,2); // } // else // { // $id = $this->SMC_Credit_PD_Model->updateRecords($records,SMC_CREDIT_PD,array('smc_credit_pd' => $records['smc_credit_pd'])); // } // if($id) // { // $data['dataStatus'] = true; // $data['status'] = REST_Controller::HTTP_OK; // $data['records'] = $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); // } // } function prepareSalesPDReport($smc_credit_pd,$api = true) { log_message('ERROR','####PREPARE SALESPD REPORT CALLED'.$smc_credit_pd); $columns = array('SMC_CREDIT_PD.*','ENTITY.short_name','PRODUCT.abbr'); $table = SMC_CREDIT_PD.' as SMC_CREDIT_PD'; $joins = array( array('table' => ENTITY. ' as ENTITY', 'condition' =>'SMC_CREDIT_PD.lender_id = ENTITY.entity_id', 'jointype' => 'INNER'), array('table' => PRODUCTS. ' as PRODUCT', 'condition' =>'SMC_CREDIT_PD.product_id = PRODUCT.product_id', 'jointype' => 'INNER') ); $where_condition_array = array('SMC_CREDIT_PD.smc_credit_pd' => $smc_credit_pd); $SMC_CREDIT_PD = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array); if($SMC_CREDIT_PD) { ini_set('max_execution_time', 0); $bucket_name = LENDER_BUCKET_NAME_PREFIX.$SMC_CREDIT_PD[0]['lender_id']; // 1st Type Key name. (name,abbr and date). $pdf_name = strtolower(trim($SMC_CREDIT_PD[0]['applicant_name'])); $pdf_name .= '-'.$SMC_CREDIT_PD[0]['abbr']; $pdf_name .= '-'.(date('dmY',strtotime($SMC_CREDIT_PD[0]['completed_date']))); // 2nd Type Key name. (name,type,abbr and date). $new_pdf_name = strtolower(trim($SMC_CREDIT_PD[0]['applicant_name'])); $new_pdf_name .= '-'.$SMC_CREDIT_PD[0]['abbr']; $new_pdf_name .= 'PD_Report-'.(date('dmY',strtotime($SMC_CREDIT_PD[0]['completed_date']))); // $this->PD_Model->updateRecords(array('pd_report_filename' => $pdf_name),SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); //$pdf_name = str_replace(' ', '_', $pdf_name); $key = 'sales_pd/'.$smc_credit_pd.'/'.$pdf_name.'.pdf'; $new_key = 'sales_pd/'.$smc_credit_pd.'/'.$new_pdf_name.'.pdf'; if(!file_exists($this->external_path.'/sales_pd/'.$smc_credit_pd)) { mkdir($this->external_path.'/sales_pd/'.$smc_credit_pd,0777); } if(!$SMC_CREDIT_PD[0]['is_pdf'] || $SMC_CREDIT_PD[0]['is_edited']) { $all_section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('smc_credit_pd' => $smc_credit_pd,'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); // print_r($this->db->last_query());die(); $view_data['master'] = $SMC_CREDIT_PD; foreach ($all_section_data as $sec_key => $section) { //print_r($section);die(); $view_data['section'.$section['section_id'] ] = $this->processSalesPDJSON($section); } //print_r($view_data['section1']);die(); $view_data['section9'] = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $smc_credit_pd,'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS); $view_data['satellite_image'] = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $smc_credit_pd,'img_name' => 'satellite','isactive' => 1),SALEPD_DOCS); $view_data['product_id'] = $SMC_CREDIT_PD[0]['product_id']; $view_data['geo_location'] = $SMC_CREDIT_PD[0]['geo_location']; //print_r($this->db->last_query());die(); //$view_name = $SMC_CREDIT_PD[0]['short_name'].'_'.$SMC_CREDIT_PD[0]['abbr']; $view_name = $SMC_CREDIT_PD[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/" . $smc_credit_pd . "/temp.pdf"; $bytes = file_put_contents($output_file, $pdf_doc); // echo $bytes; // die(); $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$new_key,'sourcefile'=>$this->external_path.'/sales_pd/'.$smc_credit_pd.'/temp.pdf'); log_message('ERROR','####SALES PD REPORT UPLOAD TO S3'.$smc_credit_pd); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $this->SMC_Credit_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); if($api) { // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { $singed_uri = $_uri; }else { $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$new_key,'30 minutes'); } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; $this->response($data,REST_Controller::HTTP_OK); } } } else { if($api) { $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; $this->response($data,REST_Controller::HTTP_OK); } } } } public function getSalesPDReport_get() { $smc_credit_pd = $this->uri->segment(2); $this->prepareSalesPDReport($smc_credit_pd); } function uploadCreditPDDataToCETApp_get() { log_message('ERROR', '#### upload SMC Credit PDData To CETApp Called'); $smc_credit_pd = $this->uri->segment(2); $mater_details = $this->PD_Model->getPDMasterDetails($smc_credit_pd); $pd_section_data = $this->SMC_Credit_PD_Model->getSMCTemplateForPD($smc_credit_pd,$mater_details[0]['fk_product_id'],null,null,'REPORT'); log_message('ERROR', '#### Total Credit PD is ' . count($pd_section_data)); if (!empty($pd_section_data)) { $forms_data_to_be_get_direct_from_excel_sheet = array(3, 9, 10, 15); if (count($pd_section_data) > 0) { $common_fields = array('pdid'=>$mater_details[0]['pd_id'], 'product'=>$mater_details[0]['product_abbr'], 'caseno'=>$mater_details[0]['pd_sno']); foreach ($pd_section_data as $key => $value) { if (isset($value['json']) && $value['json'] != '') { $filter_form_id[$key] = $value['fk_form_id']; $CETAPP_creditPD_data[$value['form_name']] = $value['json']; } else { if (in_array($value['fk_form_id'], $forms_data_to_be_get_direct_from_excel_sheet)) { $data_from_excel = $this->loadDataFromExcelBusiProcess($mater_details, $value['fk_form_id']); $filter_form_id[$key] = $value['fk_form_id']; $CETAPP_creditPD_data[$value['form_name']] = $data_from_excel; } } } $photograph_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $smc_credit_pd,'isactive' => 1,'img_name!=' => 'satellite'),SMC_CREDIT_PD_DOCS); $satellite_image = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $smc_credit_pd,'isactive' => 1,'img_name=' => 'satellite'),SMC_CREDIT_PD_DOCS); if(count($photograph_data)>0){ for ($i = 0; $i < count($photograph_data); $i++){ $img_fields = $common_fields; $img_fields['img_name'] = $photograph_data[$i]['img_name']; $img_split = explode( ',', $photograph_data[$i]['img']); $img_fields['img'] = $img_split[1]; cet_creditpd::pushwithcetphotographapi($img_fields,$i); }} if(!empty($satellite_image)){ $stt_fields = $common_fields; $stt_fields['img_name'] = $satellite_image[0]['img_name']; $stt_fields['img'] = $satellite_image[0]['img']; cet_creditpd::pushwithcetphotographapi($stt_fields,0); } if ($mater_details[0]['product_abbr'] == 'LFMP' && (array_key_exists("key_stakeholders",$pd_section_data[5])) ) { $LFMP_KeyStackholders = $pd_section_data[5]['key_stakeholders']; $temp_arr = []; for ($i = 0; $i < count($LFMP_KeyStackholders); $i++) { $value = $LFMP_KeyStackholders[$i]; if (isset($value["stakeholder_name0"])) { $temp_arr[] = array( "company_name" => $value["company_name"], "stakeholder_name" => $value["stakeholder_name0"], "share_holding" => $value["share_holding0"], "vintage_in_current_biz" => $value["vintage_in_current_biz0"], "total_work_exp" => $value["total_work_exp0"], "started_biz" => $value["started_biz0"], "previous_experience_details" => (isset($value['previous_experience_details0']) ? $value['previous_experience_details0'] : '') ); } if (isset($value["stakeholder_name1"])) { $temp_arr[] = array( "company_name" => $value["company_name"], "stakeholder_name" => $value["stakeholder_name1"], "share_holding" => $value["share_holding1"], "vintage_in_current_biz" => $value["vintage_in_current_biz1"], "total_work_exp" => $value["total_work_exp1"], "started_biz" => $value["started_biz1"], "previous_experience_details" => (isset($value['previous_experience_details1']) ? $value['previous_experience_details1'] : '') ); } if (isset($value["stakeholder_name2"])) { $temp_arr[] = array( "company_name" => $value["company_name"], "stakeholder_name" => $value["stakeholder_name2"], "share_holding" => $value["share_holding2"], "vintage_in_current_biz" => $value["vintage_in_current_biz2"], "total_work_exp" => $value["total_work_exp2"], "started_biz" => $value["started_biz2"], "previous_experience_details" => (isset($value['previous_experience_details2']) ? $value['previous_experience_details2'] : '') ); } $CETAPP_creditPD_data['Key Stakeholders in Business']['key_stakeholders'] = $temp_arr; } } // ### LFMP key_stakeholders ends if ((in_array(1, $filter_form_id)) && (in_array(21, $filter_form_id))) // && (in_array(4,$filter_form_id))) { $officer_id = isset($mater_details[0]['fk_updatedby']) ? $mater_details[0]['fk_updatedby'] : ''; $visit_date = isset($mater_details[0]['pd_visit_date']) ? $mater_details[0]['pd_visit_date'] : ''; if (!empty($officer_id)) { $officer_details = $this->SMC_Credit_PD_Model->selectCustomRecords(array('userid as officer_id', 'email', 'mobile_no', 'concat(first_name," ",last_name) as officer'), array('userid' => $officer_id), USERPROFILE); if (!empty($officer_details)) { foreach ($officer_details as $key => $value) { $CETAPP_creditPD_data['Officer Details'] = $value; $CETAPP_creditPD_data['Officer Details']['pd_visit_date'] = $visit_date; } } } } cet_creditpd::pushwithcetcreditpdapi($common_fields, $CETAPP_creditPD_data); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = 'Data Shared Successfully'; $this->response($data, REST_Controller::HTTP_OK); } else { log_message('ERROR', '#### There is No Data Found relevant Credit PDID '); $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'There is No Data Found relevant Credit PDID ! Try Later'; $this->response($data, REST_Controller::HTTP_OK); } } else { log_message('ERROR', '#### Can`t able Found the Credit PDID '); $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Can`t able Found the Creditpd PDID ! Try Later'; $this->response($data, REST_Controller::HTTP_OK); } } public function listSMCCreditPD_get() { $lender_id = $this->uri->segment(2); $user_id = $this->uri->segment(3); $columns = array('SMC_CREDIT_PD.smc_credit_pd','SMC_CREDIT_PD.fk_sales_pd_id','SALES_PD_DATA.sales_pd_sno','SMC_CREDIT_PD.smc_credit_pd_sno','SMC_CREDIT_PD.applicant_name','concat(USERPROFILE.first_name," ",USERPROFILE.last_name) as officer_name','SMC_CREDIT_PD.applicant_id','SMC_CREDIT_PD.lender_id','SMC_CREDIT_PD.product_id','SMC_CREDIT_PD.is_pdf','SMC_CREDIT_PD.is_edited','ENTITY.short_name','PRODUCT.abbr','SMC_CREDIT_PD.createdon','SMC_CREDIT_PD.status','SMC_CREDIT_PD.smc_credit_pd_type','SMC_CREDIT_PD.rand_string','SMC_CREDIT_PD.isactive' // ,"DATE_FORMAT(SMC_CREDIT_PD.createdon,'%Y-%m-%d') as modify","DATE_ADD(CURDATE(),INTERVAL '-10' DAY) as currd", // "(CURDATE()) as daye10" ); $table = SMC_CREDIT_PD.' as SMC_CREDIT_PD'; $joins = array( array('table' => ENTITY. ' as ENTITY', 'condition' =>'SMC_CREDIT_PD.lender_id = ENTITY.entity_id', 'jointype' => 'INNER'), array('table' => SALES_PD_DATA. ' as SALES_PD_DATA', 'condition' =>'SMC_CREDIT_PD.fk_sales_pd_id = SALES_PD_DATA.sales_pd_id', 'jointype' => 'INNER'), array('table' => PRODUCTS. ' as PRODUCT', 'condition' =>'SMC_CREDIT_PD.product_id = PRODUCT.product_id', 'jointype' => 'INNER'), array('table' => USERPROFILE. ' as USERPROFILE', 'condition' =>'SMC_CREDIT_PD.createdby = USERPROFILE.userid', 'jointype' => 'LEFT') ); $where_condition_array['SMC_CREDIT_PD.isactive'] = 1; if(is_numeric($lender_id)) { $where_condition_array['SMC_CREDIT_PD.lender_id'] = $lender_id; } // FILTERING THE LAST 10 DAYS RECORDS $key_date='SMC_CREDIT_PD.createdon BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW()'; $condition_value=null; $where_condition_array[$key_date] = $condition_value; // print_r ($where_condition_array); // ----END OF FILTERING THE LAST 10 DAYS RECORDS--- if($user_id && is_numeric($user_id)) { $where_condition_array['SMC_CREDIT_PD.createdby'] = $user_id; } $order_by = 'SMC_CREDIT_PD.smc_credit_pd'; $SMC_CREDIT_PD = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC'); //print_r($this->db->last_query());die(); if(count($SMC_CREDIT_PD)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $SMC_CREDIT_PD; $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); } } function processSalesPDJSON($section_array) { // //print_r($section_array);die(); //echo '###'.$section_array['section_id'].'####'; if($section_array['section_id'] == 6) { // print_r(json_decode($section_array['section_data'],true)); // die(); } if($section_array['section_id']) { //print_r($section_array);//die(); $questions = json_decode($section_array['section_data'],true); return $this->processSalesPDQuestions($questions['questions'],$section_array['section_id']); } // die(); // $general_section_dta = array(); // foreach ($section_array as $sec_key => $section) // { //} } function processSalesPDQuestions($questions,$section_id) { //print_r($questions);die(); $temp_array = array(); foreach ($questions as $ques_key => $question) { //if($question['section_id']){} if($question['is_repeatable'] == null && ($question['type'] == 1 || $question['type'] == 2 || $question['type'] == 3 || $question['type'] == 4 || $question['type'] == 6 || $question['type'] == 7 || $question['type'] == 8))//text,radio,SDD,MDD,camera,txt area, searchable dd { $temp_array[ $question['question_key'] ] = isset($question['answer_value']) ? $question['answer_value'] : null; if($question['question_key'] == 'state' || $question['question_key'] == 'city' || $question['question_key'] == 'pincode' || $question['question_key'] == 'loan_purpose') { //if($question['type'] == 4) { print_r($question['answer_value']); } $temp_array[ $question['question_key'] ] = $this->getMasterData($question['answer_value'],$question['answers']); //if($question['type'] == 4) { print_r($temp_array[ $question['question_key'] ]); } } if(isset($question['subfield_key'])) { $temp_array[ $question['question_key'] ] .= $question['subfield_value'].','; } 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); } if(substr_count($temp_array[ $question['question_key'] ], ',')) { $temp_array[ $question['question_key'] ] = substr_replace($temp_array[ $question['question_key'] ],' and ', strrpos($temp_array[ $question['question_key'] ],','),1); } } else if($question['is_repeatable'] == 1 ) { //print_r($question['questions_group']);die(); if($section_id != 9) { foreach ($question['questions_group'] as $group_key => $group_value) { //print_r($group_value['questions']);//die(); $group_temp = array(); foreach ($group_value['questions'] as $q_key => $q_value) { //print_r($q_value);die(); //echo $group_key; $group_temp[ $q_value['question_key'] ] = $q_value['answer_value']; if(isset($q_value['subfield_key'])){ $group_temp[ $q_value['question_key'] ] = $q_value['subfield_value']; } //print_r($group_temp); } //print_r($group_temp); $temp_array[ $group_key ] = $group_temp; } } else { //echo "SDKJHKSJ**"; $group_temp = array(); foreach ($question['questions_group'] as $group_key => $group_value) { $temp_array[ $group_value['questions'][0]['question_key'] ][] = isset($group_value['questions'][0]['subfield_key']) ? $group_value['questions'][0]['subfield_value'] : $group_value['questions'][0]['answer_value']; } } } } // //print_r($temp_array);die(); // if($section_id == 2) // { // //print_r(json_decode($section_array['section_data'],true)); die(); // die(); // } return $temp_array; } function getMasterData($id,$array) { //print_r($id); if(!is_array($id)) { foreach($array as $value) { if($id == $value['answer_id']) { return $value['answer']; break; } } } else { $final_string = ''; foreach($id as $value) { foreach($array as $mas_value) { if( !strcasecmp($value,$mas_value['answer_id']) && (substr_count($value,'Others') == 0)) { $final_string .= $mas_value['answer'] . ','; } } } //print_r($final_string);die(); return $final_string; } } public function saveSMCCreditPDImage_post() { // echo 'called';die(); $records = $this->post('records'); $is_customer_app = isset($records['is_customer_app']) ? $records['is_customer_app'] : null; unset($records['is_customer_app']); // print_r($records); if($records['img_name'] == 'person_met') { // echo 'slefie'; $location = $records['location']; $update_fields = array('start_location' => $records['location']); $this->SMC_Credit_PD_Model->updateRecords($update_fields,PDTRIGGER,array('pd_id' => $records['fk_smc_credit_pd_id'])); // print_r($this->db->last_query());die(); satellite_image::getSatelliteImage($records['fk_smc_credit_pd_id'],3); } // die(); if(!$records['is_multiple']) { // // //disable previous selfie img // $update_fields2 = array('isactive' => 0); // $this->SMC_Credit_PD_Model->updateRecords($update_fields2,SALEPD_DOCS,array('img_name' => 'selfie_with_person_met','fk_smc_credit_pd' => $records['fk_smc_credit_pd'])); // if($is_customer_app) // { $this->SMC_Credit_PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_DOCS,array('fk_smc_credit_pd_id' => $records['fk_smc_credit_pd_id'],'img_name' => $records['img_name'])); // print_r($this->db->last_query()); // } } unset($records['is_multiple']); $id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD_DOCS); if($id) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $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 saveSMCCreditPD_post() { $records = $this->post('records'); $is_entry_done = null; $id = null; //print_r($records);die(); // log_message('ERROR','####SALESPD SAVE CALLED'); $section_names = array('1' => 'General Section','2' => 'Fund Requirement','3' => 'stakeholders','4' => 'Brief of business','5' => 'Financial','6' => 'Property Details','7' => 'Final Remraks','8' => 'Officer Details','9' => 'Photography'); $count = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('lender_id' => $records['lender_id'],'product_id' => $records['product_id']),SMC_CREDIT_PD); $lender_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('short_name'),array('entity_id' => $records['lender_id']),ENTITY); $product_short_name = $this->SMC_Credit_PD_Model->selectCustomRecords(array('abbr'),array('product_id' => $records['product_id']),PRODUCTS); if($records['smc_credit_pd'] == '' || $records['smc_credit_pd'] == 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 SALESPD'); $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['smc_credit_pd_sno'] = $salepd_serial_no; //print_r($records);die(); $id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD); } else { //echo $product_short_name[0]['abbr']; if(isset($records['status']) && $records['status'] == 'COMPLETED') { // log_message('ERROR','####COMPLETE SALESPD'.$records['smc_credit_pd']); // $drafted_sections = $this->SMC_Credit_PD_Model->selectCustomRecords(array('section_id'),array('status' => 0,'smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); // $completed_sections = $this->SMC_Credit_PD_Model->selectCustomRecords(array('section_id'),array('status' => 1,'smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); // //print_r($completed_sections); // if($records['sales_pd_type'] == 1) // { // $img_satellite_check = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'satellite','smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SALEPD_DOCS); // } // else if($records['sales_pd_type'] == 2) // { // log_message('ERROR','###TELE SALES PD satellite check overrided'); // $img_satellite_check[0]['count'] = array();//for sales tele pd avoid satellite img check // } // $img_selfile_check = $this->SMC_Credit_PD_Model->selectCustomRecords(array('count(*) as count'),array('img_name' => 'selfie_with_person_met','smc_credit_pd' => $records['smc_credit_pd'],'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'] ]); // } // } // unset($dup_of_section_names[9]);//unset photograph always // if($product_short_name[0]['abbr'] == "WCTL"){ unset($dup_of_section_names[6]);} // //print_r($dup_of_section_names);die(); // 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,'sectin_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->SMC_Credit_PD_Model->updateRecords($records,SMC_CREDIT_PD,array('smc_credit_pd' => $records['smc_credit_pd'])); log_message('ERROR','####COMPLETE SMC Credit PD = '.$records['smc_credit_pd']); // $random_string = $this->SMC_Credit_PD_Model->selectCustomRecords(array('rand_string'),array('smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD); // $random_string = $random_string[0]['rand_string']; // $ZIP = smc_creditpd::covertSMCImgs2ZIP($records['smc_credit_pd'],$random_string,array(),0); // log_message('ERROR','####COMPLETE SMC IMAGE ZIP = '.$ZIP); // $PDF = smc_creditpd::covertSMCImgs2PDF($records['smc_credit_pd'],$random_string,array(),0); // log_message('ERROR','####COMPLETE SMC IMAGE PDF = '.$PDF); //$this->prepareSalesPDReport($records['smc_credit_pd'],false); // sleep(10); // log_message('ERROR','####SALESPD AFTER 10 PREPARED REPORT'.$records['smc_credit_pd']); //echo 'afetr 10'; //trigger mail function //PDALERTS::sendSalesPDMail($this,$records['smc_credit_pd']); //} } else { log_message('ERROR','####UPDATE SALESPD'.$records['smc_credit_pd']); $id = $this->SMC_Credit_PD_Model->updateRecords($records,SMC_CREDIT_PD,array('smc_credit_pd' => $records['smc_credit_pd'])); } } 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 saveSMCCreditPDsection_post() // { // $records = $this->post('records'); // $smc_credit_pd = $records['smc_credit_pd']; // $section_id = $records['section_id']; // $fk_createdby = $records['fk_createdby']; // //$status = $records['is_complete']; // $status = 1; // $section_data = json_encode($records); // //Get Sales PD master Data // $columns = array('SMC_CREDIT_PD.*','ENTITY.short_name','PRODUCT.abbr'); // $table = SMC_CREDIT_PD.' as SMC_CREDIT_PD'; // $joins = array( // array('table' => ENTITY. ' as ENTITY', // 'condition' =>'SMC_CREDIT_PD.lender_id = ENTITY.entity_id', // 'jointype' => 'INNER'), // array('table' => PRODUCTS. ' as PRODUCT', // 'condition' =>'SMC_CREDIT_PD.product_id = PRODUCT.product_id', // 'jointype' => 'INNER') // ); // $where_condition_array = array('SMC_CREDIT_PD.smc_credit_pd' => $smc_credit_pd); // $sales_pd_master_data = $this->SMC_Credit_PD_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 // $applicant_id = null; // $applicant_name = ''; // if($records['questions']) // { // foreach ($records['questions'] as $g_key => $g_value) // { // if($g_value['question_key'] == 'application_id') // { // $applicant_id = $g_value['answer_value'] ? $g_value['answer_value'] : 'Not Provided'; // } // if($g_value['question_key'] == 'company_name') // { // $applicant_name = $g_value['answer_value']; // } // } // } // $update_fields = array('applicant_name' => $applicant_name,'applicant_id' => $applicant_id); // $this->SMC_Credit_PD_Model->updateRecords($update_fields,SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); // break; // case 2: //Fund Requirement // break; // case 3: //stakeholders // break; // case 4: //brief of business // break; // case 5: //Financial // break; // case 6: //property // break; // case 7: //Officer self details // break; // case 8: //final remarks of PD officer // //update PD officer Name to sales pD master Table // $officer = ''; // if($records['questions']) // { // foreach($records['questions'] as $g_key => $g_value) // { // if($g_value['question_key'] == 'name_of_sales_team_member') // { // $officer = $g_value['answer_value']; // break; // } // } // } // $update_fields = array('officer_name' => $officer); // $this->SMC_Credit_PD_Model->updateRecords($update_fields,SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); // break; // case 9: //photosection // break; // default: // } // //make inactive previous records // $this->SMC_Credit_PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_SECTION_DATA,array('smc_credit_pd' =>$smc_credit_pd,'section_id' => $section_id )); // //insert new record // $fields = array('smc_credit_pd' => $smc_credit_pd, 'section_id' => $section_id, 'status' =>$status ,'section_data' => $section_data,'createdby' => $fk_createdby); // $is_entry_created = $this->SMC_Credit_PD_Model->saveRecords($fields,SMC_CREDIT_PD_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 saveSMCCreditPDsection_post() { $records = $this->post('records'); //print_r($records); //de active old entries $is_updated = $this->SMC_Credit_PD_Model->updateRecords(array('isactive' => 0),SMC_CREDIT_PD_SECTION_DATA,array('fk_pd_id' => $records['fk_pd_id'],'fk_form_id' => $records['fk_form_id'])); $records['json'] = json_encode($records['json']); //make new entry $new_json_id = $this->SMC_Credit_PD_Model->saveRecords($records,SMC_CREDIT_PD_SECTION_DATA); if($new_json_id) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $new_json_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 loadSMCPDTemplate_get() { $pd_id = ""; $client = ""; $random_string = ""; $api = ""; $return_data = array(); if($this->get('pd_id')) { $pd_id = $this->get('pd_id'); } if($this->get('client')) { $client = $this->get('client'); } if($this->get('random_string')) { $random_string = $this->get('random_string'); } if($this->get('api')) { $api = $this->get('api'); } if($pd_id != "" || $pd_id != null) { $return_data['pdmaster_details'] = $this->PD_Model->getPDMasterDetails($pd_id,$random_string); $product_id = $return_data['pdmaster_details'][0]['fk_product_id']; $return_data['template_details'] = $this->SMC_Credit_PD_Model->getSMCTemplateForPD($pd_id,$product_id,$client,$random_string,$api); $return_data['pdapplicants_detials'] = $this->PD_Model->getApplicantsDetails($pd_id); $photo_count = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('isactive' => 1,'fk_smc_credit_pd_id' => $pd_id),SMC_CREDIT_PD_DOCS); if(is_array($photo_count) && count($photo_count)) { $return_data['template_details'][ (count($return_data['template_details'])-1) ]['is_answered'] = "1"; } // print_r($return_data['template_details']);die(); if(count($return_data['template_details'])) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $return_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'Template Not Available'; $this->response($data,REST_Controller::HTTP_OK); } } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_BAD_REQUEST; $data['msg'] = 'No Param Available'; $this->response($data,REST_Controller::HTTP_OK); } } public function getSMCCreditPDSectionData_post() { $records = $this->post('records'); $section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_pd_id' => $records['fk_pd_id'],'fk_form_id' => $records['fk_form_id'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); if(is_array($section_data )&& count($section_data)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $section_data[0]; $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 getSMCCreditPDSectionData_post() // { // $records = $this->post('records'); // $section_data = array(); // if($records['section_id'] == 'all'){ // // die(); // $fields=array('id','smc_credit_pd','section_id','status','createdby','createdon'); // $section_data=$this->SMC_Credit_PD_Model->selectCustomRecords($fields,array('smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); // } // else{ // $section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('smc_credit_pd' => $records['smc_credit_pd'],'isactive' => 1,'section_id' => $records['section_id']),SMC_CREDIT_PD_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->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $records['smc_credit_pd'],'img_name !=' => 'satellite','isactive' => 1),SALEPD_DOCS); // //print_r($all_sales_pd_images);die(); // $photo_questions = (json_decode(($section_data[0]['section_data']),true)); // // print_r($photo_questions); // foreach ($photo_questions['questions'] as $key => $value) // { // if(isset($value['answer_value']) && $value['answer_value'] && !$value['is_repeatable']) // { // $selfie = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd' => $records['smc_credit_pd'],'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]['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']) // { // //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]['answer_value'] = "CHANGED"; // unset($all_sales_pd_images[$img_key]); // break; // } // } // } // } // } // } // //die(); // $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); // } // } // updatepdstatus // zip auto generate script public function testAPISalesPD_post() { //PDALERTS::sendSalesPDMail($this,32);die(); satellite_image::getSatelliteImage(32,2);//die(); // $url = "https://maps.googleapis.com/maps/api/staticmap?center=12.9788141,80.1871334&zoom=14&markers=color:red|12.9788141,80.1871334&size=800x300&maptype=roadmap&key=AIzaSyA3lYDYxwtn5vLSl45SOKbtK7G6cEyXGr0"; // file_put_contents('test.jpg', file_get_contents($url)); } public function smcCreditPDMisReport_post() { //$lender_id = $this->uri->segment(2); $officer_name = $this->post('officer_name'); $from_date = $this->post('from_date'); $to_date = $this->post('to_date'); // $columns = array('PDTRIGGER.pd_id','PDTRIGGER.pd_sno','PDTYPE.type_name','PDTRIGGER.lender_applicant_id','PDTRIGGER.fk_product_id','PRODUCT.abbr','PDTRIGGER.pd_status','PDAPPLICANTSDETAILS.applicant_name','COMMONMASTER.createdon',('(SELECT createdon FROM h_common_masters where PDTRIGGER.pd_id = primary_key AND field_name = "pd_status" order by log_id DESC limit 1) as updatedon'),('(SELECT m_user_profile.first_name FROM h_common_masters JOIN m_user_profile on h_common_masters.new_value = m_user_profile.userid where PDTRIGGER.pd_id = primary_key AND field_name = "fk_pd_allocated_to" order by log_id DESC limit 1) as officer_name')); // $table = PDTRIGGER.' as PDTRIGGER'; // $joins = array( // array('table' => PRODUCTS. ' as PRODUCT', // 'condition' =>'PDTRIGGER.fk_product_id = PRODUCT.product_id', // 'jointype' => 'INNER'), // // array('table' => USERPROFILE. ' as CMUSERPROFILE', // // 'condition' =>'cmofficer = USERPROFILE.user_id', // // 'jointype' => 'LEFT'), // array('table' => PDTYPE. ' as PDTYPE', // 'condition' =>'PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id', // 'jointype' => 'INNER'), // array('table' => PDAPPLICANTSDETAILS. ' as PDAPPLICANTSDETAILS', // 'condition' =>'PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id and applicant_type = 1', // 'jointype' => 'LEFT'), // array('table' => COMMONMASTER. ' as COMMONMASTER', // 'condition' =>'PDTRIGGER.pd_id = COMMONMASTER.primary_key and COMMONMASTER.table_name = "'.PDTRIGGER.'" and COMMONMASTER.field_name = "pd_status" and COMMONMASTER.new_value = "COMPLETED"', // 'jointype' => 'LEFT'), // ); // $where_condition_array = array('PDTRIGGER.pd_status' => 'COMPLETED'); // if($officer_name) // { // //$where_condition_array[] = array('SMC_CREDIT_PD.officer_name like' => '%'.$officer_name.'%'); // // $where_condition_array['officer_name like'] = '%'.$officer_name.'%'; // } // if($from_date) // { // $where_condition_array['date(PDTRIGGER.createdon) >='] = $from_date; // } // if($to_date) // { // $where_condition_array['date(PDTRIGGER.createdon) <='] = $to_date; // } // $order_by = 'PDTRIGGER.pd_id'; //$SMC_CREDIT_PD = $this->SMC_Credit_PD_Model->getJoinRecords($columns,$table,$joins,$where_condition_array,$order_by,'DESC'); $this->db->SELECT('PDTRIGGER.pd_id, PDTRIGGER.pd_sno, PDTYPE.type_name, PDTRIGGER.lender_applicant_id, PDTRIGGER.fk_product_id, PRODUCT.abbr, PDTRIGGER.pd_status, PDAPPLICANTSDETAILS.applicant_name, (SELECT createdon FROM h_common_masters where PDTRIGGER.pd_id = primary_key AND field_name = "pd_status" order by log_id DESC limit 1) as updatedon, (SELECT concat(m_user_profile.first_name," " ,m_user_profile.last_name) FROM h_common_masters JOIN m_user_profile on h_common_masters.new_value = m_user_profile.userid where PDTRIGGER.pd_id = primary_key AND field_name = "fk_pd_allocated_to" order by log_id DESC limit 1) as officer_name,PDTRIGGER.mis_report_remarks,PDTRIGGER.vendor_status'); $this->db->FROM(PDTRIGGER.' as PDTRIGGER'); $this->db->JOIN(PRODUCTS.' as PRODUCT','PDTRIGGER.fk_product_id = PRODUCT.product_id','LEFT'); $this->db->JOIN(PDTYPE.' as PDTYPE','PDTRIGGER.fk_pd_type = PDTYPE.pd_type_id','LEFT'); $this->db->JOIN(PDAPPLICANTSDETAILS.' as PDAPPLICANTSDETAILS','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id and and PDAPPLICANTSDETAILS.applicant_type = 1','LEFT'); //$this->db->JOIN(COMMONMASTER.' as COMMONMASTER','PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id and and PDAPPLICANTSDETAILS.applicant_type = 1 and COMMONMASTER.primary_key and COMMONMASTER.table_name = "t_pd_triggered" and COMMONMASTER.field_name = "pd_status" and COMMONMASTER.new_value = "COMPLETED"'); //$this->db->WHERE('PDTRIGGER.pd_status','COMPLETED'); $this->db->WHERE('PDTRIGGER.fk_lender_id',(ENVIRONMENT == 'production' ? 7 : 35)); if($from_date) { $this->db->WHERE('date(PDTRIGGER.updatedon) >=',$from_date); } if($to_date) { $this->db->WHERE('date(PDTRIGGER.updatedon) <=',$to_date); } if($officer_name) { $this->db->HAVING('officer_name like',"%$officer_name%"); } // AND date(PDTRIGGER.createdon) >= '2021-02-16' // AND date(PDTRIGGER.createdon) <= '2021-02-19' $this->db->ORDER_BY('PDTRIGGER.pd_id DESC'); $SMC_CREDIT_PD = $this->db->GET()->result_array(); if(count($SMC_CREDIT_PD)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $SMC_CREDIT_PD; $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 filterSalesPDList_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_products = $records['pd_products']; $pd_lender = $records['pd_lender']; $pd_applicant_name = strtolower($records['pd_applicant_name']); $pd_officer_name = isset($records['pd_officer']) ? $records['pd_officer'] : null ; $sales_pd_officer_id = isset($records['sales_pd_officer_id']) ? $records['sales_pd_officer_id'] : null ; $result_data=$this->SMC_Credit_PD_Model->getSalesPDListwithFilters($pd_status,$pd_from_date,$pd_to_date,$pd_products,$pd_lender,$pd_applicant_name,$pd_officer_name,$sales_pd_officer_id); // print_r ($result_data); 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 generateSatelliteImg_post() { $input_data = $this->post(); log_message('ERROR','####Satellite IMG CALLED smc credit pd ='.$input_data['smc_credit_pd']); $id = $this->SMC_Credit_PD_Model->updateRecords($input_data,SMC_CREDIT_PD,array('smc_credit_pd' => $input_data['smc_credit_pd'])); satellite_image::getSatelliteImage($input_data['smc_credit_pd'],2); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $id; $this->response($data,REST_Controller::HTTP_OK); } public function getSalesPDImgDataCusLink_post() { $rand_string = $this->post('rand_string'); $sales_pd_master_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('rand_string' => $rand_string),SMC_CREDIT_PD); $sales_pd_img_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd','img','img_name','isactive'),array('fk_smc_credit_pd' => $sales_pd_master_data[0]['smc_credit_pd'],'isactive' => 1,'img_name!=' => 'satellite'),SALEPD_DOCS); //print_r($sales_pd_img_data);die(); //sales tele pd img structure array $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('smc_credit_pd' => $sales_pd_master_data[0]['smc_credit_pd'],'img_data' => $img_data,'is_cus_link_disabled' => $sales_pd_master_data[0]['is_cus_link_disabled']); $this->response($data,REST_Controller::HTTP_OK); } function sendSalesCusLinkViaSMS_post() { //$mobile_no = $this->post('mobile_no'); $random_string = $this->post('random_string'); $smc_credit_pd = $this->post('smc_credit_pd'); // $response = false; //select mobile no from general form $gen_form = $this->SMC_Credit_PD_Model->selectCustomRecords(array(),array('isactive' => 1,'smc_credit_pd' => $smc_credit_pd,'section_id' => 1,'status' => 1),SMC_CREDIT_PD_SECTION_DATA); //print_r($gen_form);die(); if(is_array($gen_form) && isset($gen_form[0]['smc_credit_pd']) && $gen_form[0]['smc_credit_pd'] == $smc_credit_pd) { //separate mobile no //print_r( json_decode($gen_form[0]['section_data'],true)); $msg = "Dear Applicant, Please click the link to upload the photographs. " . SALESPD_CUSTOMER_IMG_URL .$random_string; echo $msg;die(); //SALESPD_CUSTOMER_IMG_URL $res = SMS_GUPSHUP::sendSMS($msg,$mobile_no,array('pd_id' => $smc_credit_pd,'status' => 'SALES PD SMS','msg' => 'Cus Link snd sms from SALES PD controlller'),true); //print_r($res); $res = explode('|', $res); if(is_array($res) && count($res)) { if(trim($res[0]) == "success") { $response = true; } } if($response) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = 'SMS Sent Successfully'; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'SMS Sent Falied. Try Later!'; $this->response($data,REST_Controller::HTTP_OK); } } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'Mobile No Not Found!'; $this->response($data,REST_Controller::HTTP_OK); } } function getStakeHoldersInfo_post() { $stakeholders = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('smc_credit_pd' => $this->post('smc_credit_pd'),'section_id' => 3,'isactive' => 1),SMC_CREDIT_PD_SECTION_DATA); if(count($stakeholders)) { $stakeholders = json_decode($stakeholders[0]['section_data'],true); $stakeholders = $stakeholders['questions'][0]['questions_group']; $result_data = array(); foreach($stakeholders as $k => $s) { $result_data[] = $s['questions']['0']['answer_value']; } $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_NOT_FOUND; $data['msg'] = 'Mobile No Not Found!'; $this->response($data,REST_Controller::HTTP_OK); } } function loadDataFromExcel_post() { $records = $this->post('records'); $pd_master_data = $this->PD_Model->getPDMasterDetails($records['pd_id'],$records['random_string']); // $cur_section_data = array(); $cur_section_data = $this->loadDataFromExcelBusiProcess($pd_master_data,(isset($records['form_id']) && $records['form_id'] ? $records['form_id'] : null)); // print_r($pd_master_data);die(); // echo $records['form_id'];die(); //check excel file in local, otherwise get it from s3 and store locallly if(count($cur_section_data)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $cur_section_data; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'No Data Available!'; $this->response($data,REST_Controller::HTTP_OK); } } function loadDataFromExcelBusiProcess($pd_master_data,$form_id) { $is_file_uploaded = ($pd_master_data[0]['re_uploaded'] ? true : ($pd_master_data[0]['modified_fname'] ? true : false)); if($is_file_uploaded){ $filename = ($pd_master_data[0]['re_uploaded'] ? XLPATH.'/tmp/'.$pd_master_data[0]['re_uploaded_file_name'] : XLPATH.'/tmp/'.$pd_master_data[0]['modified_fname']); // $filename = XLPATH.'/tmp/mySMCPD_client_working.xlsx'; // $filename = '/home/venba/Downloads/Book1_2021-07-17_02-00-02225.xlsx'; // $filename = '/home/venba/Downloads/Sample_CET_Upload_LFMP_s1.xls'; // $filename = '/home/venba/Downloads/Sample_CET_Upload_WCTL_s1.xls'; if(!file_exists($filename)) { //echo 'getting it from s3'; $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_data[0]['fk_lender_id']; $key = 'tmp/'. ($pd_master_data[0]['re_uploaded'] ? $pd_master_data[0]['re_uploaded_file_name'] : $pd_master_data[0]['modified_fname']); $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'+5 minutes'); //echo $singed_uri; $sucess = file_put_contents($filename, file_get_contents($singed_uri)); //echo '*'.$sucess; } return $cur_section_data = readexceldata::getExcelSectionData($filename,$form_id,$pd_master_data[0]['pd_id']); // print_r($cur_section_data); }else{ return []; } } public function getSMCPDImgSectionData_post() { $rand_string = $this->post('rand_string'); $pd_id = $this->post('pd_id'); //echo $rand_string.'#'.$pd_id;die(); if(!$pd_id) { $pd_id = $this->PD_Model->selectCustomRecords(array('*'),array('random_string' => $rand_string),PDTRIGGER); $pd_id = $pd_id[0]['pd_id']; } $where_condition_array = array('fk_smc_credit_pd_id' => $pd_id,'isactive' => 1,'img_name!=' => 'satellite'); $sales_pd_img_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),$where_condition_array,SMC_CREDIT_PD_DOCS); //print_r($sales_pd_img_data);die(); //sales tele pd img structure array $imgs = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('isactive' => 1),SMC_CREDITPD_IMGS); //print_r($imgs); $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($value['key_name'] == $sales_pd_img_data_value['img_name']) { if($value['is_multiple']) { if(!array_key_exists($value['key_name'],$img_data)) { $img_data[$value['key_name']] = array('img_key' => $value['key_name'],'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']); // $img_data[$value['key_name']] = array('img_key' => $value['key_name'],'img_name' => $value['img_name'],'img_data' => [array('img_url' => $sales_pd_img_data_value['img'] ? 'BLOB' : '')],'is_multiple' => 1,'section_heading' => $value['img_name']); } else { $img_data[$value['key_name']]['img_data'][] = array('img_url' => $sales_pd_img_data_value['img'] ? $sales_pd_img_data_value['img'] : ''); // $img_data[$value['key_name']]['img_data'][] = array('img_url' => $sales_pd_img_data_value['img'] ? 'BLOB' : ''); } } else { $img_data[$value['key_name']] = array('img_key' => $value['key_name'],'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'] // $img_data[$value['key_name']] = array('img_key' => $value['key_name'],'img_name' => $value['img_name'],'img_url' => $sales_pd_img_data_value['img'] ? 'BLOB' : '','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; } } //IF current img key is not exist in existing img arry if(!array_key_exists($value['key_name'],$img_data)) { if(!$value['is_multiple']) { $img_data[$key] = array('img_key' => $value['key_name'],'img_name' => $value['img_name'],'img_url' => '','is_multiple' => $value['is_multiple'],'section_heading' => $value['img_name']); } else { $img_data[$key] = array('img_key' => $value['key_name'],'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' => $value['key_name'],'img_name' => $value['img_name'],'img_data' => array(),'is_multiple' => 1,'section_heading' => $value['img_name']); } else { $img_data[] = array('img_key' => $value['key_name'],'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('smc_credit_pd' => $sales_pd_master_data[0]['smc_credit_pd'],'img_data' => $img_data,'is_cus_link_disabled' => $sales_pd_master_data[0]['is_cus_link_disabled']); $data['records'] = array('smc_credit_pd' => $pd_id,'img_data' => $img_data); $this->response($data,REST_Controller::HTTP_OK); } public function smcCreditPDReport_post() { $records = $this->post('records'); $this->load->helper('smc_creditpd'); $this->load->helper('cet_creditpd'); $this->load->helper('smcpdscore'); $this->load->helper('report_attachments'); $view_data['pd_master_details'] = $this->PD_Model->getPDMasterDetails($records['pd_id']); $view_data['applicant_details'] = $this->PD_Model->getApplicantsDetails($records['pd_id']); //$pd_section_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('isactive' => 1,'fk_pd_id' => $records['pd_id']),SMC_CREDIT_PD_SECTION_DATA,array(),'','fk_form_id','ASC'); $pd_section_data = $this->SMC_Credit_PD_Model->getSMCTemplateForPD($records['pd_id'],$view_data['pd_master_details'][0]['fk_product_id'],null,null,'REPORT'); // print_r($pd_section_data);die(); $forms_data_to_be_get_direct_from_excel_sheet = array(3,9,10,15); // Using borrower_details in $pd_section_data To Get the company name for SMC Credit PD => MWISE; $companylist = $this->getCompanyName($pd_section_data[0]); $view_data['company'] = $companylist ; $filter_form_id =array(); // $officerdetails_form_id =array(1,4,21); if(count($pd_section_data)) { foreach ($pd_section_data as $key => $value) { if(isset($value['json']) && $value['json'] != '') { $value['json'] = smc_creditpd::getSMCCreditPDReportContent($value,$records['pd_id'],$companylist); $filter_form_id[$key] = $value['fk_form_id']; // if($value['fk_form_id'] == 2){print_r($value['json']);die();} $view_data['pd_section_data'][$value['fk_form_id']] = $value['json']; } else { if(in_array($value['fk_form_id'],$forms_data_to_be_get_direct_from_excel_sheet)) { $data_from_excel = $this->loadDataFromExcelBusiProcess($view_data['pd_master_details'],$value['fk_form_id']); //print_r($data_from_excel);die(); $view_data['pd_section_data'][$value['fk_form_id']] = $data_from_excel; $filter_form_id[$key] = $value['fk_form_id']; } } //die(); } } // print_r($filter_form_id);die(); // print_r($view_data['pd_section_data'][15]);die(); $view_data['smc_images'] = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $records['pd_id'],'isactive' => 1,'img_name!=' => 'satellite'),SMC_CREDIT_PD_DOCS); $view_data['satellite'] = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $records['pd_id'],'isactive' => 1,'img_name=' => 'satellite'),SMC_CREDIT_PD_DOCS); // print_r($view_data['smc_images']);die(); //print_r(count($view_data['smc_images']));die(); //score card part // $score_card_questions = $this->seperateScorecardQuestions($view_data); // $view_data['pd_score'] = SMCPDSCORE::genericDIPDScoreCalculate($score_card_questions,$view_data['pd_master_details']); // $final_score = round($view_data['pd_score']['score_summary']['overall_score']['final_score'],1); // // echo $final_score;die(); // //GET phantom script from DB // $phantom_script = $this->PD_Model->selectCustomRecords(array('*'),array('script_name' => PHANTOMJSSCRIPT_LOCATION),SCRIPTS); // $exact_script = $phantom_script[0]['script_content']; // // print_r($exact_script);die(); // $apppath = str_replace('\\','/',$this->external_path.'/pd_reports/'.$records['pd_id']); // $exact_script = str_replace('{{APPPATH}}',$apppath,$exact_script); // $exact_script = str_replace('{{place_score_here}}',$final_score,$exact_script); // //print_r($exact_script);die(); // //GENERATE CHART PART // file_put_contents(APPPATH.'/views/js/phantomchart.js',$exact_script,LOCK_EX); // $str = 'phantomjs '.APPPATH.'/views/js/phantomchart.js'; // exec($str,$ou); // exec('phantom.exit();'); // //print_r($ou); // $chart_img_path = $this->external_path.'/pd_reports/'.$records['pd_id'].'/chart.png'; // $type = pathinfo($chart_img_path, PATHINFO_EXTENSION); // $chart_img_content = file_get_contents($chart_img_path); // $base64_pdscore_chart_url = 'data:image/' . $type . ';base64,' . base64_encode($chart_img_content); // $view_data['base64_pdscore_chart_url'] = $base64_pdscore_chart_url; // echo $base64_pdscore_chart_url; // die(); //score card part // print_r($view_data); // 25 "product_abbr": "NBFC/MFI", //### LFMP key_stakeholders ends if($view_data['pd_master_details'][0]['product_abbr'] == 'LFMP'){ $LFMP_KeyStackholders = $view_data['pd_section_data'][5]['key_stakeholders']; $temp_arr = []; // print_r($LFMP_KeyStackholders); // count($LFMP_KeyStackholders); for($i=0;$i$value["company_name"],"stakeholder_name"=>$value["stakeholder_name0"], "share_holding"=>$value["share_holding0"],"vintage_in_current_biz"=>$value["vintage_in_current_biz0"], "total_work_exp"=>$value["total_work_exp0"],"started_biz"=>$value["started_biz0"], "previous_experience_details"=>(isset($value['previous_experience_details0']) ? $value['previous_experience_details0'] : '' )); } if(isset($value["stakeholder_name1"])){ $temp_arr[]=array("company_name"=>$value["company_name"],"stakeholder_name"=>$value["stakeholder_name1"], "share_holding"=>$value["share_holding1"],"vintage_in_current_biz"=>$value["vintage_in_current_biz1"], "total_work_exp"=>$value["total_work_exp1"],"started_biz"=>$value["started_biz1"], "previous_experience_details"=>(isset($value['previous_experience_details1']) ? $value['previous_experience_details1'] : '')); } if(isset($value["stakeholder_name2"])){ $temp_arr[] = array("company_name"=>$value["company_name"], "stakeholder_name"=> $value["stakeholder_name2"],"share_holding"=>$value["share_holding2"], "vintage_in_current_biz"=>$value["vintage_in_current_biz2"],"total_work_exp"=>$value["total_work_exp2"],"started_biz"=>$value["started_biz2"], "previous_experience_details"=> (isset($value['previous_experience_details2'])?$value['previous_experience_details2'] : '' )); } } $view_data['pd_section_data'][5]['key_stakeholders'] = $temp_arr; }// ### LFMP key_stakeholders ends $view_data['report_attachments'] = (new report_attachments)->getSMCReportAttchments($records['pd_id'],$view_data['pd_master_details'][0]['random_string'],$view_data['pd_master_details']); if($view_data['pd_master_details'][0]['product_abbr'] == "NBFC/MFI"){ $html_content = $this->load->view('smc_creditpd_reports/NBFC',$view_data,true); }else{ $html_content = $this->load->view('smc_creditpd_reports/MWISE',$view_data,true); } // print_r($html_content);exit(); $pdf_name = $view_data['pd_master_details'][0]['main_applicant']; $new_pdf_name = "PD_Report_".$view_data['pd_master_details'][0]['main_applicant']; $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 ."/pd_reports/" . $records['pd_id'] . "/temp.pdf"; $bytes = file_put_contents($output_file, $pdf_doc); //echo $bytes;die(); $bucket_name = LENDER_BUCKET_NAME_PREFIX.(ENVIRONMENT == 'production' ? 7 : 35); $key = 'pd'.$records['pd_id'].'/pd_reports/'.$pdf_name.'.pdf'; $new_key = 'pd'.$records['pd_id'].'/pd_reports/'.$new_pdf_name.'.pdf'; $bucket_data = array('bucket_name'=>$bucket_name,'key'=>$new_key,'sourcefile'=>$output_file); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { // $this->Sales_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$new_key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { $singed_uri = $_uri; }else { $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; $this->response($data,REST_Controller::HTTP_OK); } } function seperateScorecardQuestions($view_data) { $score_card_questions = array(); $customer_behaviour = array('1' => 'Others','2' => 'Rude','3' => 'Polite'); $over_all = array('2' => 'Positive','3' => 'Negative'); // print_r($view_data['pd_section_data'][4]);die(); $score_card_questions['approcah_to_pd_location'] = array('answer_id' => $view_data['pd_section_data'][2]['pd_location']['pd_location_approach_id'],'answer' => $view_data['pd_section_data'][2]['pd_location']['description']); $score_card_questions['comment_locality'] = array('answer_id' => $view_data['pd_section_data'][2]['comment_locality']['comments_on_locality_id'],'answer' => $view_data['pd_section_data'][2]['comment_locality']['rating']); $score_card_questions['customer_behaviour'] = array('answer_id' => $view_data['pd_section_data'][19]['customer_behaviour'],'answer' => $customer_behaviour[ $view_data['pd_section_data'][19]['customer_behaviour'] ]); $score_card_questions['pd_officer_recommendation'] = array('answer_id' => $view_data['pd_section_data'][19]['pd_officer_recommendation'],'answer' => $over_all[ $view_data['pd_section_data'][19]['pd_officer_recommendation'] ]); //$score_card_questions['neighbourhood_status'] = array('answer_id' => $view_data['pd_section_data'][17]['neighbourhood_status'],'answer' => $view_data['pd_section_data'][17]['neighbourhood_status']); $score_card_questions['business_seasonality'] = array('answer_id' => $view_data['pd_section_data'][4]['seasonality'],'answer' => $view_data['pd_section_data'][4]['seasonality']); $score_card_questions['name_board_seen'] = array('answer_id' => 'no','answer' => 'no' ); $name_board_seen_img = $this->SMC_Credit_PD_Model->selectCustomRecords(array('doc_id', 'fk_smc_credit_pd_id','img','img_name','isactive'),array('fk_smc_credit_pd_id' => $view_data['pd_master_details'][0]['pd_id'],'isactive' => 1,'img_name=' => 'name_board_seen'),SMC_CREDIT_PD_DOCS); if(is_array($name_board_seen_img) && count($name_board_seen_img)) { $score_card_questions['name_board_seen'] = array('answer_id' => 'yes','answer' => 'yes' ); } $score_card_questions['no_of_years_business_run'] = array('answer_id' => (isset($view_data['pd_section_data'][8]['business_years']) ? $view_data['pd_section_data'][8]['business_years'].'.'.(isset($view_data['pd_section_data'][8]['business_years']) ? $view_data['pd_section_data'][8]['business_months'] : '0') : 'NA' ) ,'answer' => ( isset($view_data['pd_section_data'][8]['business_years']) ? $view_data['pd_section_data'][8]['business_years'].'.'.(isset($view_data['pd_section_data'][8]['business_years']) ? $view_data['pd_section_data'][8]['business_months'] : '0') : 'NA')); $score_card_questions['business_activity_has_seen'] = array('answer_id' => isset($view_data['pd_section_data'][8]['business_is_pd_visited']) ? $view_data['pd_section_data'][8]['business_is_pd_visited'] : 'NA','answer' => isset($view_data['pd_section_data'][8]['business_is_pd_visited']) ? $view_data['pd_section_data'][8]['business_is_pd_visited'] : 'NA'); $score_card_questions['employees_total'] = array('answer_id' => ($view_data['pd_section_data'][7]['permanant_employees_person_met'] + $view_data['pd_section_data'][7]['temporary_employees_person_met'] ),'answer' => ($view_data['pd_section_data'][7]['permanant_employees_person_met'] + $view_data['pd_section_data'][7]['temporary_employees_person_met'] )); $score_card_questions['owned_property'] = array('answer_id' => (isset($view_data['pd_section_data'][8]['business_ownership_type']) ? ($view_data['pd_section_data'][8]['business_ownership_type'] == 'Rented' ? 'No' : 'Yes') : 'NA') ,'answer' => (isset($view_data['pd_section_data'][8]['business_ownership_type']) ? ($view_data['pd_section_data'][8]['business_ownership_type'] == 'Rented' ? 'No' : 'Yes') : 'NA')); //$score_card_questions['business_activity'] = array('answer_id' => $view_data['pd_section_data'][8]['business_is_pd_visited'],'answer' => $view_data['pd_section_data'][8]['business_is_pd_visited']); $score_card_questions['stock_visited'] = array('answer_id' => (isset($view_data['pd_section_data'][13]['estimated_uom']) ? $view_data['pd_section_data'][13]['estimated_uom'] : 'NA'),'answer' => (isset($view_data['pd_section_data'][13]['estimated_uom']) ? $view_data['pd_section_data'][13]['estimated_uom'] : 'NA')); $score_card_questions['location_suited_for_busienss'] = array('answer_id' => $view_data['pd_section_data'][19]['business_location_suited'],'answer' =>$view_data['pd_section_data'][19]['business_location_suited']); return ($score_card_questions); } //get List of credit managers list for allocation public function getCMUsers_get() { $state = $this->get('state_id'); $usertype = $this->get('usertype'); $role = ''; if($usertype == 'RCM') { $role = 27; } else if($usertype == 'CM') { $role = 26; } $users = $this->SMC_Credit_PD_Model->getSMCFlowUsers($state,$role); if(count($users)) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $users; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'Data Not Found!'; $this->response($data,REST_Controller::HTTP_OK); } // print_r($this->db->last_query()); } function getCompanyListForSMCList_post() { $records = $this->post('records'); $pd_master_data = $this->PD_Model->getPDMasterDetails($records['pd_id'],$records['random_string']); $is_file_uploaded = ($pd_master_data[0]['re_uploaded'] ? true : ($pd_master_data[0]['modified_fname'] ? true : false)); if($is_file_uploaded){ $filename = ($pd_master_data[0]['re_uploaded'] ? XLPATH.'/tmp/'.$pd_master_data[0]['re_uploaded_file_name'] : XLPATH.'/tmp/'.$pd_master_data[0]['modified_fname']); //$filename = '/home/venba/Downloads/Sample_CET_Upload4.xls'; if(!file_exists($filename)) { $bucket_name = LENDER_BUCKET_NAME_PREFIX.$pd_master_data[0]['fk_lender_id']; $key = 'tmp/'. ($pd_master_data[0]['re_uploaded'] ? $pd_master_data[0]['re_uploaded_file_name'] : $pd_master_data[0]['modified_fname']); $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'+5 minutes'); $sucess = file_put_contents($filename, file_get_contents($singed_uri)); } $cur_section_data = readexceldata::getCompanyListForSMCList($filename,$pd_master_data[0]['pd_id']); }else{ $arr = $this->PD_Model->getApplicantsDetails($pd_master_data[0]['pd_id']); $filtered_arr = array_filter($arr, function ($var) { return ($var['applicant_type'] != 0); }); if(!empty($filtered_arr)){ for($i=0;$iresponse($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'No Data Available!'; $this->response($data,REST_Controller::HTTP_OK); } } public static function getCompanyName($section){ $json = json_decode($section['json'],true); $cpny = array(); if(!empty($json['borrower_details'])){ $inx = 1; foreach ($json['borrower_details'] as $key => $value) { $entity_type = $value['entity_type']; if($entity_type != "Individual"){ $cpny[$inx] =$value['borrower_name']; $inx++; } } } return $cpny; } function getStateWiseAgency_get(){ $state_id = $this->get('state_id') ? $this->get('state_id') : ""; $Lenderlist = $this->PD_Model->getStateWiseSMCAgency($state_id); $data = (!empty($Lenderlist)) ? array('dataStatus' => true,'status' => REST_Controller::HTTP_OK,'records' => $Lenderlist) : array('dataStatus' => false,'status' => REST_Controller::HTTP_NOT_FOUND,'msg' =>'No Records Found!'); $this->response($data,REST_Controller::HTTP_OK); } //3 roles = SMC Vendor PD officer and SMC Vendor PD manager,lender admin function getSMCVendorPDOfficersList_get(){ // $role_id = $this->get('role_id'); // $entity_id = $this->get('entity_id'); // $Lenderlist = $this->PD_Model->getSMCVendorPDOfficersList($role_id,$entity_id); $agency_id = $this->get('agency_id'); $Lenderlist = $this->PD_Model->getSMCVendorPDOfficersList($agency_id); $data = (!empty($Lenderlist)) ? array('dataStatus' => true,'status' => REST_Controller::HTTP_OK,'records' => $Lenderlist) : array('dataStatus' => false,'status' => REST_Controller::HTTP_NOT_FOUND,'msg' =>'No Records Found!'); $this->response($data,REST_Controller::HTTP_OK); } function getCreditPDReportforCETApp_get(){ // 3090 log_message('ERROR','## CreditPDReportforCETApp Fns Entered'); $get = $this->get('credit_pd_id'); if(!empty($get)){ $pd_master_details = $this->PD_Model->getPDMasterDetails($get); if($pd_master_details[0]['pd_status'] == "COMPLETED"){ $old_pdf_name = $pd_master_details[0]['main_applicant']; $old_key = 'pd'.$get.'/pd_reports/'.$old_pdf_name.'.pdf'; $new_pdf_name = "PD_Report_".$pd_master_details[0]['main_applicant']; $new_key = 'pd'.$get.'/pd_reports/'.$new_pdf_name.'.pdf'; $bucket_name = LENDER_BUCKET_NAME_PREFIX.(ENVIRONMENT == 'production' ? 7 : 35); $output_file = $this->external_path ."/pd_reports/" . $get . "/temp.pdf"; $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$old_key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { $singed_uri = $_uri; }else { $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$new_key,'30 minutes'); } $data['records'] = $singed_uri; log_message('ERROR',"Credit Report Generated for CET App"); $statusMsg = 'Report Available.'; }else{ log_message('ERROR',"Credit Report Is Not Completed Given PDID"); $statusMsg = 'Report is Not Completed For Given PDID.'; } }else{ log_message('ERROR','Credit Report Not Available for CET App'); $statusMsg = 'Report Not Available.'; } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = $statusMsg; $this->response($data,REST_Controller::HTTP_OK); } public function archivePDImages_post() { $records = $this->post('records'); $pdid = $records['pd_id']; $random_string = $records['random_string']; $regenerate = isset($records['regenerate']) ? $records['regenerate'] : 0; $this->load->helper('smc_creditpd'); $res_data = smc_creditpd::covertSMCImgs2ZIP($pdid,$random_string,array(),$regenerate); if(!empty($res_data)){ $response_data['dataStatus'] = true; $response_data['status'] = REST_Controller::HTTP_OK; $response_data['records'] = $res_data; } else { $response_data['dataStatus'] = false; $response_data['status'] = REST_Controller::HTTP_NOT_FOUND; $response_data['msg'] = 'NO Image Found'; } $this->response($response_data,REST_Controller::HTTP_OK); } public function imgPDFDownload_post() { $records = $this->post('records'); $this->load->helper('smc_creditpd'); $pdid = $records['pd_id']; $random_string = $records['random_string']; $regenerate = isset($records['regenerate']) ? $records['regenerate'] : 0; $res_data = smc_creditpd::covertSMCImgs2PDF($pdid,$random_string,array(),$regenerate); if(!empty($res_data)){ $response_data['dataStatus'] = true; $response_data['status'] = REST_Controller::HTTP_OK; $response_data['records'] = $res_data; } else { $response_data['dataStatus'] = false; $response_data['status'] = REST_Controller::HTTP_NOT_FOUND; $response_data['msg'] = 'NO Image Found'; } $this->response($response_data,REST_Controller::HTTP_OK); } }