Try Catch in Push Cet api : ps

This commit is contained in:
VE10-Sanjeev 2023-02-24 16:24:44 +05:30
parent 4937f919cb
commit f11df92593
3 changed files with 78 additions and 54 deletions

View File

@ -350,7 +350,7 @@ class Data_Dump_Controller extends REST_Controller
## Default Status section; ## Default Status section;
$pd_details['pd_status'] = TRIGGERED; $pd_details['pd_status'] = TRIGGERED;
$pd_details['pd_date_of_initiation'] = date('Y-m-d H-i-s'); $pd_details['pd_date_of_initiation'] = date('Y-m-d H-i-s');
$pd_details['fk_createdby'] = 379; // default user created for admin. $pd_details['fk_createdby'] = 318; // default user created for admin.
## Template ID Section. ## Template ID Section.
$fields = array('fk_template_id'); $fields = array('fk_template_id');
$where_condition_array = array('fk_lender_id' => $fk_lender_id, 'fk_product_id' => $fk_product_id, 'fk_customer_segment' => $fk_customer_segment, 'isactive' => 1); $where_condition_array = array('fk_lender_id' => $fk_lender_id, 'fk_product_id' => $fk_product_id, 'fk_customer_segment' => $fk_customer_segment, 'isactive' => 1);

View File

@ -289,6 +289,7 @@ class SMC_Credit_PD_Controller extends REST_Controller {
$details = $this->SMC_Credit_PD_Model->selectCustomRecords($columns, $where_arr, $table); $details = $this->SMC_Credit_PD_Model->selectCustomRecords($columns, $where_arr, $table);
if(!empty($details)){ if(!empty($details)){
$response = $this->dataSynchronization($smc_credit_pd); $response = $this->dataSynchronization($smc_credit_pd);
$data['CETresponse'] = $response;
if($response){ if($response){
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') status '.$response." Data Transfered"); log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') status '.$response." Data Transfered");
$update_fields2 = array('is_the_data_transfer_cet' => 1); $update_fields2 = array('is_the_data_transfer_cet' => 1);
@ -298,6 +299,7 @@ class SMC_Credit_PD_Controller extends REST_Controller {
$data['msg'] = 'Data Shared Successfully'; $data['msg'] = 'Data Shared Successfully';
$this->response($data,REST_Controller::HTTP_OK); $this->response($data,REST_Controller::HTTP_OK);
}else{ }else{
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') Data Not Transfered');
$data['dataStatus'] = false; $data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = 'Something went wrong! Try Later'; $data['msg'] = 'Something went wrong! Try Later';
@ -349,15 +351,20 @@ class SMC_Credit_PD_Controller extends REST_Controller {
$smc_credit_pd = $details[$i]['pd_id']; $smc_credit_pd = $details[$i]['pd_id'];
// echo $smc_credit_pd; // echo $smc_credit_pd;
$result = $this->dataSynchronization($smc_credit_pd); $result = $this->dataSynchronization($smc_credit_pd);
$data['CETresponse'][$smc_credit_pd] = $result;
sleep(2);
// $flag = $result == true ? $flag+1 : $flag; // $flag = $result == true ? $flag+1 : $flag;
if($result->status == 200){ if(isset($result->status) && $result->status == 200){
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') status '.$result->status." Data Transfered"); log_message('ERROR', '#### Smc Credit PD ('.$smc_credit_pd.') status '.$result->status." Data Transfered");
$flag = $flag+1; $flag = $flag+1;
array_push($ids, $smc_credit_pd); array_push($ids, $smc_credit_pd);
//update here. //update here.
$update_fields2 = array('is_the_data_transfer_cet' => 1); $update_fields2 = array('is_the_data_transfer_cet' => 1);
$this->SMC_Credit_PD_Model->updateRecords($update_fields2,PDTRIGGER,array('pd_id' => $smc_credit_pd)); $this->SMC_Credit_PD_Model->updateRecords($update_fields2,PDTRIGGER,array('pd_id' => $smc_credit_pd));
} }
else{
log_message('ERROR', '#### Smc Credit PD ('.$smc_credit_pd.") Data Not Transfered");
}
} }
$data['dataStatus'] = true; $data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK; $data['status'] = REST_Controller::HTTP_OK;
@ -388,14 +395,15 @@ class SMC_Credit_PD_Controller extends REST_Controller {
$this->load->helper('smc_creditpd'); $this->load->helper('smc_creditpd');
$mater_details = $this->PD_Model->getPDMasterDetails($smc_credit_pd); $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'); $pd_section_data = $this->SMC_Credit_PD_Model->getSMCTemplateForPD($smc_credit_pd,$mater_details[0]['fk_product_id'],null,null,'REPORT');
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') There are ' . count($pd_section_data).' Forms '); log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') ');
if (!empty($pd_section_data)) { if (!empty($pd_section_data)) {
$forms_data_to_be_get_direct_from_excel_sheet = array(3, 9, 10, 15); $forms_data_to_be_get_direct_from_excel_sheet = array(3, 9, 10, 15);
$companylist = $this->getCompanyName($pd_section_data[0]); $companylist = $this->getCompanyName($pd_section_data[0]);
if (count($pd_section_data) > 0) { if (count($pd_section_data) > 0) {
$common_fields = array('pdid'=>$mater_details[0]['pd_id'], $common_fields = array('pdid'=>$mater_details[0]['pd_id'],
'product'=>$mater_details[0]['product_abbr'], 'product'=>$mater_details[0]['product_abbr'],
'caseno'=>$mater_details[0]['pd_sno']); 'caseno'=>$mater_details[0]['pd_sno'],
'completed_date'=>$mater_details[0]['completed_on']);
// foreach ($pd_section_data as $key => $value) { // foreach ($pd_section_data as $key => $value) {
// if (isset($value['json']) && $value['json'] != '') { // if (isset($value['json']) && $value['json'] != '') {
// $filter_form_id[$key] = $value['fk_form_id']; // $filter_form_id[$key] = $value['fk_form_id'];
@ -476,14 +484,17 @@ class SMC_Credit_PD_Controller extends REST_Controller {
if($result == true){ if($result == true){
$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); $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); $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);
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') There are ' . count($photograph_data).' Images'); // log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') There are ' . count($photograph_data).' Images');
$totalimages = count($satellite_image)+count($photograph_data);
if(count($photograph_data)>0){ if(count($photograph_data)>0){
$j=0;
for ($i = 0; $i < count($photograph_data); $i++){ for ($i = 0; $i < count($photograph_data); $i++){
$img_fields = $common_fields; $img_fields = $common_fields;
$img_fields['img_name'] = $photograph_data[$i]['img_name']; $img_fields['img_name'] = $photograph_data[$i]['img_name'];
$img_split = explode( ',', $photograph_data[$i]['img']); $img_split = explode( ',', $photograph_data[$i]['img']);
$img_fields['img'] = $img_split[1]; $img_fields['img'] = $img_split[1];
$resultimages = cet_creditpd::pushwithcetphotographapi($img_fields,$i); $resultimages = cet_creditpd::pushwithcetphotographapi($img_fields,$i);
if(isset($resultimages->status) && ($resultimages->status == 200)){$j++;}else{ log_message('ERROR', '#### SMC Credit PD ('.$smc_credit_pd.') ' . $photograph_data[$i]['img_name'].' Image Not Transfer Check it'); }
}} }}
if(!empty($satellite_image)){ if(!empty($satellite_image)){
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') satellite Available'); log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') satellite Available');
@ -491,6 +502,7 @@ class SMC_Credit_PD_Controller extends REST_Controller {
$stt_fields['img_name'] = $satellite_image[0]['img_name']; $stt_fields['img_name'] = $satellite_image[0]['img_name'];
$stt_fields['img'] = $satellite_image[0]['img']; $stt_fields['img'] = $satellite_image[0]['img'];
$resultstatellite = cet_creditpd::pushwithcetphotographapi($stt_fields,0); $resultstatellite = cet_creditpd::pushwithcetphotographapi($stt_fields,0);
if(isset($resultstatellite->status) && ($resultstatellite->status == 200)){$j++;}else{ log_message('ERROR', '#### SMC Credit PD ('.$smc_credit_pd.') ' . $satellite_image[0]['img_name'].' Images Not Transfer Check it'); }
} }
// print_r($CETAPP_creditPD_data); // print_r($CETAPP_creditPD_data);
// $path = $this->external_path ."/pd_reports/" . $mater_details[0]['pd_id'] . "/new-file-5-".$mater_details[0]['pd_id'].".json"; // $path = $this->external_path ."/pd_reports/" . $mater_details[0]['pd_id'] . "/new-file-5-".$mater_details[0]['pd_id'].".json";
@ -503,7 +515,7 @@ class SMC_Credit_PD_Controller extends REST_Controller {
// $message = "<label class='text-success'>File createed and data added Success fully</p>"; // $message = "<label class='text-success'>File createed and data added Success fully</p>";
// echo $message; // echo $message;
// }die(); // }die();
$result->imageStatus = $j.'/'.$totalimages;
return $result; return $result;
}else{ }else{
log_message('ERROR', '#### Section Details pushed Images Details Not Pushed'); log_message('ERROR', '#### Section Details pushed Images Details Not Pushed');

View File

@ -7,7 +7,7 @@ class CET_CREDITPD
// } // }
public static function pushwithcetcreditpdapi($fields,$data) public static function pushwithcetcreditpdapi($fields,$data)
{ {
log_message('ERROR','#### Inside cet creditpd helper fns'); log_message('ERROR','#### pushwithcetcreditpd Helper FNS '.$fields['pdid']);
$CI =&get_instance(); $CI =&get_instance();
if (array_key_exists("Photograph's", $data)) { if (array_key_exists("Photograph's", $data)) {
unset($data["Photograph's"]); unset($data["Photograph's"]);
@ -25,6 +25,7 @@ class CET_CREDITPD
$fields['data'] = $data; $fields['data'] = $data;
$pdid = $fields['pdid']; $pdid = $fields['pdid'];
$headers = array('Content-Type: application/json'); $headers = array('Content-Type: application/json');
try{
$ch = curl_init(); $ch = curl_init();
$output_data = json_encode( $fields ); $output_data = json_encode( $fields );
// log_message('ERROR','#### output_data '.$output_data); // log_message('ERROR','#### output_data '.$output_data);
@ -50,6 +51,11 @@ class CET_CREDITPD
$response = json_decode($result); $response = json_decode($result);
log_message('ERROR',"CET APP CREDIT PDID (".$pdid.") response :".json_encode($response)); log_message('ERROR',"CET APP CREDIT PDID (".$pdid.") response :".json_encode($response));
curl_close( $ch ); curl_close( $ch );
}
catch (Exception $e) {
$response->error = array($e->getMessage());
log_message('ERROR', "CET APP CREDIT PDID (".$pdid.") ERR : " . $e->getMessage());
}
return $response; return $response;
} }
@ -63,6 +69,7 @@ class CET_CREDITPD
$img = str_replace('data:image/png;base64,', '', $img); $img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img); $img = str_replace(' ', '+', $img);
$data = base64_decode($img); $data = base64_decode($img);
try{
$file = $CI->external_path.'/tmp/temp'. $index .date('Y-m-d_h-i-s') .'.png'; $file = $CI->external_path.'/tmp/temp'. $index .date('Y-m-d_h-i-s') .'.png';
$curlFile = curl_file_create($file); $curlFile = curl_file_create($file);
$success = file_put_contents($file, $data); $success = file_put_contents($file, $data);
@ -84,6 +91,11 @@ class CET_CREDITPD
curl_close( $ch ); curl_close( $ch );
unlink($file); unlink($file);
// unlink($file_name_with_full_path); // unlink($file_name_with_full_path);
}
catch (Exception $e) {
$response->error = array($e->getMessage());
log_message('ERROR', "CET APP CREDIT PDID (".$pdid.") ERR : " . $e->getMessage());
}
return $response; return $response;
} }
} }