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;
$pd_details['pd_status'] = TRIGGERED;
$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.
$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);

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);
if(!empty($details)){
$response = $this->dataSynchronization($smc_credit_pd);
$data['CETresponse'] = $response;
if($response){
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') status '.$response." Data Transfered");
$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';
$this->response($data,REST_Controller::HTTP_OK);
}else{
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') Data Not Transfered');
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$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'];
// echo $smc_credit_pd;
$result = $this->dataSynchronization($smc_credit_pd);
$data['CETresponse'][$smc_credit_pd] = $result;
sleep(2);
// $flag = $result == true ? $flag+1 : $flag;
if($result->status == 200){
log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') status '.$result->status." Data Transfered");
if(isset($result->status) && $result->status == 200){
log_message('ERROR', '#### Smc Credit PD ('.$smc_credit_pd.') status '.$result->status." Data Transfered");
$flag = $flag+1;
array_push($ids, $smc_credit_pd);
//update here.
$update_fields2 = array('is_the_data_transfer_cet' => 1);
$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['status'] = REST_Controller::HTTP_OK;
@ -388,14 +395,15 @@ class SMC_Credit_PD_Controller extends REST_Controller {
$this->load->helper('smc_creditpd');
$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', '#### 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)) {
$forms_data_to_be_get_direct_from_excel_sheet = array(3, 9, 10, 15);
$companylist = $this->getCompanyName($pd_section_data[0]);
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']);
'caseno'=>$mater_details[0]['pd_sno'],
'completed_date'=>$mater_details[0]['completed_on']);
// foreach ($pd_section_data as $key => $value) {
// if (isset($value['json']) && $value['json'] != '') {
// $filter_form_id[$key] = $value['fk_form_id'];
@ -476,14 +484,17 @@ class SMC_Credit_PD_Controller extends REST_Controller {
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);
$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){
$j=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];
$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)){
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'] = $satellite_image[0]['img'];
$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);
// $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>";
// echo $message;
// }die();
$result->imageStatus = $j.'/'.$totalimages;
return $result;
}else{
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)
{
log_message('ERROR','#### Inside cet creditpd helper fns');
log_message('ERROR','#### pushwithcetcreditpd Helper FNS '.$fields['pdid']);
$CI =&get_instance();
if (array_key_exists("Photograph's", $data)) {
unset($data["Photograph's"]);
@ -25,31 +25,37 @@ class CET_CREDITPD
$fields['data'] = $data;
$pdid = $fields['pdid'];
$headers = array('Content-Type: application/json');
$ch = curl_init();
$output_data = json_encode( $fields );
// log_message('ERROR','#### output_data '.$output_data);
// $path = $CI->external_path."/tmp/".$fields['pdid']."1.json";
// // $fp = fopen($path, 'w');
// // fwrite($fp, $output_data);
// if(file_put_contents($path, $output_data))
// {
// $message = "<label class='text-success'>File createed and data added Success fully</p>";
// echo $message;
// }
// return false;
// print_r($fields);die();
// log_message('ERROR',"PullcreditPDData api Request Format : ".$output_data);
// curl_setopt( $ch,CURLOPT_URL, "https://demo.devopsmcfinance.com/cet_creditpd/api/PullCreditPdData");
curl_setopt( $ch,CURLOPT_URL, CET_CREDIT_PD_INTEGRATION_URL);
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, $output_data);
$result = curl_exec($ch );
$response = json_decode($result);
log_message('ERROR',"CET APP CREDIT PDID (".$pdid.") response :".json_encode($response));
curl_close( $ch );
try{
$ch = curl_init();
$output_data = json_encode( $fields );
// log_message('ERROR','#### output_data '.$output_data);
// $path = $CI->external_path."/tmp/".$fields['pdid']."1.json";
// // $fp = fopen($path, 'w');
// // fwrite($fp, $output_data);
// if(file_put_contents($path, $output_data))
// {
// $message = "<label class='text-success'>File createed and data added Success fully</p>";
// echo $message;
// }
// return false;
// print_r($fields);die();
// log_message('ERROR',"PullcreditPDData api Request Format : ".$output_data);
// curl_setopt( $ch,CURLOPT_URL, "https://demo.devopsmcfinance.com/cet_creditpd/api/PullCreditPdData");
curl_setopt( $ch,CURLOPT_URL, CET_CREDIT_PD_INTEGRATION_URL);
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, $output_data);
$result = curl_exec($ch );
$response = json_decode($result);
log_message('ERROR',"CET APP CREDIT PDID (".$pdid.") response :".json_encode($response));
curl_close( $ch );
}
catch (Exception $e) {
$response->error = array($e->getMessage());
log_message('ERROR', "CET APP CREDIT PDID (".$pdid.") ERR : " . $e->getMessage());
}
return $response;
}
@ -63,27 +69,33 @@ class CET_CREDITPD
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = $CI->external_path.'/tmp/temp'. $index .date('Y-m-d_h-i-s') .'.png';
$curlFile = curl_file_create($file);
$success = file_put_contents($file, $data);
$headers = array('Content-Type: multipart/form-data');
// $headers = array('Content-Type: application/json');
$ch = curl_init();
$log_msg = " PullcreditPdPhotographsData api (".$fields['img_name'].")";
$fields['img'] = $curlFile;
log_message('ERROR',"CET APP CREDIT PDID (".$pdid.") response :".json_encode($fields));
curl_setopt( $ch,CURLOPT_URL, CET_CREDIT_PD_INTEGRATION_IMG_URL);
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
// curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result=curl_exec($ch);
$response = json_decode($result);
log_message('ERROR',"###CET APP CREDIT PDID (".$pdid.") ".$log_msg."response :".json_encode($response));
curl_close( $ch );
unlink($file);
// unlink($file_name_with_full_path);
try{
$file = $CI->external_path.'/tmp/temp'. $index .date('Y-m-d_h-i-s') .'.png';
$curlFile = curl_file_create($file);
$success = file_put_contents($file, $data);
$headers = array('Content-Type: multipart/form-data');
// $headers = array('Content-Type: application/json');
$ch = curl_init();
$log_msg = " PullcreditPdPhotographsData api (".$fields['img_name'].")";
$fields['img'] = $curlFile;
log_message('ERROR',"CET APP CREDIT PDID (".$pdid.") response :".json_encode($fields));
curl_setopt( $ch,CURLOPT_URL, CET_CREDIT_PD_INTEGRATION_IMG_URL);
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
// curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result=curl_exec($ch);
$response = json_decode($result);
log_message('ERROR',"###CET APP CREDIT PDID (".$pdid.") ".$log_msg."response :".json_encode($response));
curl_close( $ch );
unlink($file);
// 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;
}
}