transferCreditPDReportToCETApp api : ps

This commit is contained in:
VE10-Sanjeev 2023-03-30 16:15:25 +05:30
parent 0fafea9c6a
commit 34e82a0700
2 changed files with 80 additions and 0 deletions

View File

@ -426,6 +426,7 @@ $route['transferSalesPDToCETApp'] = 'Sales_PD_Controller/transferSalesPDToCETApp
$route['transferSalesPDImgToCETApp'] = 'Sales_PD_Controller/transferSalesPDImgToCETApp';
$route['transferCreditPDToCETApp'] = 'SMC_Credit_PD_Controller/transferCreditPDToCETApp';
$route['transferCreditPDImgToCETApp'] = 'SMC_Credit_PD_Controller/transferCreditPDImgToCETApp';
$route['transferCreditPDReportToCETApp'] = 'SMC_Credit_PD_Controller/transferCreditPDReportToCETApp';
$route['newSalesPd'] = 'Sales_PD_Controller/cetNewSalesPd';
$route['login'] = 'Common_Masters_Controller/login';

View File

@ -2396,6 +2396,85 @@ public function filterSalesPDList_post() {
}
}
function transferCreditPDReportToCETApp_get(){
$this->load->helper('smc_creditpd');
$this->load->library('Googlecloud');
$from_date = $this->get('from_date');
$to_date = $this->get('to_date');
if(($from_date != "" || $from_date != null) && ($to_date != "" || $to_date != null)){
$newDate1 = date("Y-m-d", strtotime($from_date));
$newDate2 = date("Y-m-d", strtotime($to_date));
$smc_lender_id = ENVIRONMENT == 'production' ? 7 : 35; //SMC lender id MWISE in live and demo
$msg = "SMC-Credit-PD-Report Given Date => " . $from_date ." to ".$to_date;
$where = ' AND DATE(PDTRIGGER.pd_date_of_initiation) BETWEEN ' ."'$newDate1'". ' AND ' ."'$newDate2'";
$sql = 'SELECT PDTRIGGER.pd_id,PDAPPLICANTSDETAILS.applicant_name as main_applicant
FROM ' . PDTRIGGER . ' AS PDTRIGGER
LEFT JOIN '.PDAPPLICANTSDETAILS.' AS PDAPPLICANTSDETAILS ON PDTRIGGER.pd_id = PDAPPLICANTSDETAILS.fk_pd_id AND PDAPPLICANTSDETAILS.applicant_type = 1
WHERE PDTRIGGER.pd_status = "'.COMPLETED.'" AND PDTRIGGER.fk_lender_id = ' . $smc_lender_id.$where;
$details = $this->db->query($sql)->result_array();
log_message('ERROR', $msg." Changed ".$newDate1." to ".$newDate2." Total Records => " . count($details));
if(!empty($details)){
$flag = 0;$ids=array();
$data['dataStatus'] = true;
$data['status'] = REST_Controller::HTTP_OK;
for ($i = 0; $i < count($details); $i++) {
$smc_credit_pd = $details[$i]['pd_id'];
log_message('ERROR', "SMC-Credit-PD-Report inx = $i ".$smc_credit_pd);
$old_pdf_name = $details[$i]['main_applicant'];
$new_pdf_name = "PD_Report_".$details[$i]['main_applicant'];
$old_key = 'pd'.$smc_credit_pd.'/pd_reports/'.$old_pdf_name.'.pdf';
$new_key = 'pd'.$smc_credit_pd.'/pd_reports/'.$new_pdf_name.'.pdf';
$bucket_name = LENDER_BUCKET_NAME_PREFIX.(ENVIRONMENT == 'production' ? 7 : 35);
$path = $this->external_path ."/tmp/" . $smc_credit_pd.".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');
}
$sucess = file_put_contents($path, file_get_contents($singed_uri));
$gcpBucketName = GCP_BUCKET_NAME;
$prefixToObject = ENVIRONMENT == 'production' ? "credit-pd":"credit-pd-demo";
$gcpObjectName = $prefixToObject."/pd".$smc_credit_pd."/".$smc_credit_pd.".pdf";
$source = $path;
$gcpResult = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$gcpObjectName,$source);
$report_gcp_url = '';
if($gcpResult == true){
$report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$gcpObjectName);
}
$flag = $flag+1;
array_push($ids, $smc_credit_pd);
$data[$smc_credit_pd]['AwsURI'] = $singed_uri;
$data[$smc_credit_pd]['GcpURI'] = $report_gcp_url;
unlink($path);
}
$data['msg'] = implode(', ', $ids).' ( '.$flag.' ) Report Shared Successfully';
$this->response($data, REST_Controller::HTTP_OK);
}else{
$msg = 'There is no data for Given Date! Try Later';
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = $msg;
log_message('ERROR', $msg);
$this->response($data, REST_Controller::HTTP_OK);
}
}
else {
$msg = 'Can`t Upload the Report. Date Not Founded! Try Later';
$data['dataStatus'] = false;
$data['status'] = REST_Controller::HTTP_NO_CONTENT;
$data['msg'] = $msg;
log_message('ERROR', $msg);
$this->response($data, REST_Controller::HTTP_OK);
}
}
}