diff --git a/api/application/config/constants.php b/api/application/config/constants.php index e421ead1..613d0655 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -142,7 +142,9 @@ defined('CET_CREDIT_PD_INTEGRATION_IMG_URL') OR define('CET_CREDIT_PD_INTEGRATIO defined('DIGILOCKER_TOKEN_URI') OR define('DIGILOCKER_TOKEN_URI','https://api.digitallocker.gov.in/public/oauth2/1/token'); defined('DIGILOCKER_FILESLIST_URI') OR define('DIGILOCKER_FILESLIST_URI','https://api.digitallocker.gov.in/public/oauth2/2/files/issued'); defined('DIGILOCKER_GETFILE_URI') OR define('DIGILOCKER_GETFILE_URI','https://api.digitallocker.gov.in/public/oauth2/1/file/'); -defined('GCP_BUCKET_NAME') OR define('GCP_BUCKET_NAME','sales-pd-demo'); +defined('GCP_BUCKET_NAME') OR define('GCP_BUCKET_NAME','pd-giene-data'); +defined('GCP_CREDIT_BUCKET_NAME') OR define('GCP_CREDIT_BUCKET_NAME','credit-pd-demo'); +defined('CET_CREDITPD_INTEGRATION_REINSERTIMG_URL') OR define('CET_CREDITPD_INTEGRATION_REINSERTIMG_URL','https://demo.devopsmcfinance.com/cet_creditpd/api/ReInsertImageData'); } else if(ENVIRONMENT == 'testing') { @@ -169,7 +171,9 @@ else if(ENVIRONMENT == 'testing') defined('DIGILOCKER_TOKEN_URI') OR define('DIGILOCKER_TOKEN_URI','https://api.digitallocker.gov.in/public/oauth2/1/token'); defined('DIGILOCKER_FILESLIST_URI') OR define('DIGILOCKER_FILESLIST_URI','https://api.digitallocker.gov.in/public/oauth2/2/files/issued'); defined('DIGILOCKER_GETFILE_URI') OR define('DIGILOCKER_GETFILE_URI','https://api.digitallocker.gov.in/public/oauth2/1/file/'); - defined('GCP_BUCKET_NAME') OR define('GCP_BUCKET_NAME','sales-pd-demo'); + defined('GCP_BUCKET_NAME') OR define('GCP_BUCKET_NAME','pd-giene-data'); + defined('GCP_CREDIT_BUCKET_NAME') OR define('GCP_CREDIT_BUCKET_NAME','credit-pd-demo'); + defined('CET_CREDITPD_INTEGRATION_REINSERTIMG_URL') OR define('CET_CREDITPD_INTEGRATION_REINSERTIMG_URL','https://demo.devopsmcfinance.com/cet_creditpd/api/ReInsertImageData'); } else if(ENVIRONMENT == 'production') { @@ -197,6 +201,8 @@ else if(ENVIRONMENT == 'production') defined('DIGILOCKER_FILESLIST_URI') OR define('DIGILOCKER_FILESLIST_URI','https://api.digitallocker.gov.in/public/oauth2/2/files/issued'); defined('DIGILOCKER_GETFILE_URI') OR define('DIGILOCKER_GETFILE_URI','https://api.digitallocker.gov.in/public/oauth2/1/file/'); defined('GCP_BUCKET_NAME') OR define('GCP_BUCKET_NAME','sales-pd'); + defined('GCP_CREDIT_BUCKET_NAME') OR define('GCP_CREDIT_BUCKET_NAME','credit-pd'); + defined('CET_CREDITPD_INTEGRATION_REINSERTIMG_URL') OR define('CET_CREDITPD_INTEGRATION_REINSERTIMG_URL','https://demo.devopsmcfinance.com/cet_creditpd/api/ReInsertImageData'); } /*********************END of AWS resources Constants*************************************************/ diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 969e24a5..93c56506 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -424,7 +424,8 @@ $route['saveShortsVideo'] = 'PD_Controller/saveShortsVideo'; $route['transferSalesPDToCETApp'] = 'Sales_PD_Controller/transferSalesPDToCETApp'; $route['transferSalesPDImgToCETApp'] = 'Sales_PD_Controller/transferSalesPDImgToCETApp'; -$route['transferCreditPDToCETApp'] = 'SMC_Credit_PD_Controller/transferCreditPDToCETApp'; +$route['transferCreditPDToCETApp'] = 'SMC_Credit_PD_Controller/transferCreditPDToCETApp'; +$route['transferCreditPDImgToCETApp'] = 'SMC_Credit_PD_Controller/transferCreditPDImgToCETApp'; $route['newSalesPd'] = 'Sales_PD_Controller/cetNewSalesPd'; $route['login'] = 'Common_Masters_Controller/login'; diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php index 5a27bec2..7e722771 100644 --- a/api/application/controllers/SMC_Credit_PD_Controller.php +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -153,6 +153,7 @@ class SMC_Credit_PD_Controller extends REST_Controller { // } function prepareSalesPDReport($smc_credit_pd,$api = true) { + $this->load->library('Googlecloud'); 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'; @@ -228,22 +229,36 @@ class SMC_Credit_PD_Controller extends REST_Controller { if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { - + /*** GCP Report Upload here */ + $gcpBucketName = GCP_CREDIT_BUCKET_NAME; + $gcpObjectName = "credit_pd/pd".$smc_credit_pd."/".$smc_credit_pd.".pdf"; + $source=$output_file; + $gcpResult = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$gcpObjectName,$source); + $report_gcp_url = ''; + if($gcpResult == true){ + $report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$gcpObjectName); + } + $this->SMC_Credit_PD_Model->updateRecords(array('is_pdf' => 1, 'is_edited' => 0),SMC_CREDIT_PD,array('smc_credit_pd' => $smc_credit_pd)); - // ### Automation CET Data Push Credit PD - 2/2/23 - // sleep(10); - // $result = $this->dataSynchronization($smc_credit_pd); - // log_message('ERROR', '#### Automation CET Data Push Credit PD ('.$smc_credit_pd.') status '.$result->status.' Data Transfered'); - // if($result->status == 200){ - // log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') status '.$result->status." Data Transfered"); - // $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', '#### Credit PD ('.$smc_credit_pd.') status '.$result->status); - // } + ### Automation CET Data Push Credit PD + sleep(10); + $result = $this->dataSynchronization($smc_credit_pd); + log_message('ERROR', '#### Automation CET Data Push Credit PD ('.$smc_credit_pd.') status '.$result->status.' Data Transfered'); + if(isset($result->status) && $result->status == 200){ + log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') status '.$result->status." Data Transfered"); + $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', '#### Credit PD ('.$smc_credit_pd.') status '.$result->status); + } if($api) { // $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); + /*** GCP Report Upload here */ + $gcpBucketName = GCP_CREDIT_BUCKET_NAME; + $gcpObjectName = "credit_pd/pd".$smc_credit_pd."/".$smc_credit_pd.".pdf"; + $report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$gcpObjectName); + $_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $headers = @get_headers($_uri); if($headers && strpos( $headers[0], '200')) { @@ -254,6 +269,7 @@ class SMC_Credit_PD_Controller extends REST_Controller { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; + $data['gcpURL'] = $report_gcp_url; $this->response($data,REST_Controller::HTTP_OK); } } @@ -262,10 +278,14 @@ class SMC_Credit_PD_Controller extends REST_Controller { { if($api) { + $gcpBucketName = GCP_CREDIT_BUCKET_NAME; + $gcpObjectName = "credit_pd/pd".$smc_credit_pd."/".$smc_credit_pd.".pdf"; + $report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$gcpObjectName); $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI($bucket_name,$key,'30 minutes'); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; + $data['gcpURL'] = $report_gcp_url; $this->response($data,REST_Controller::HTTP_OK); } } @@ -344,6 +364,7 @@ class SMC_Credit_PD_Controller extends REST_Controller { $where_arr = array('PDTRIGGER.is_the_data_transfer_cet'=>0,'PDTRIGGER.fk_lender_id' => $smc_lender_id,'PDTRIGGER.pd_status' => COMPLETED, $where => null); $details = $this->SMC_Credit_PD_Model->selectCustomRecords($columns, $where_arr, $table); log_message('ERROR', $msg." Changed ".$newDate1." to ".$newDate2." Total Records => " . count($details)); + // print_r($details);die(); if(!empty($details)){ $flag = 0;$ids=array(); for ($i = 0; $i < count($details); $i++) { @@ -403,7 +424,9 @@ class SMC_Credit_PD_Controller extends REST_Controller { $common_fields = array('pdid'=>$mater_details[0]['pd_id'], 'product'=>$mater_details[0]['product_abbr'], 'caseno'=>$mater_details[0]['pd_sno'], - 'completed_date'=>$mater_details[0]['completed_on']); + 'credit_pd_type'=>$mater_details[0]['fk_pd_type'], + 'pd_type_name'=>$mater_details[0]['pd_type_name'], + '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']; @@ -479,6 +502,10 @@ class SMC_Credit_PD_Controller extends REST_Controller { } } } + $photograph_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('img_name','IF(img_name="satellite","satellite.png",rand_name) AS img'),array('fk_smc_credit_pd_id' => $smc_credit_pd,'isactive' => 1),SMC_CREDIT_PD_DOCS); + if(count($photograph_data)>0){ + $CETAPP_creditPD_data['Photograph Details']['photo']=$photograph_data; + } $result = cet_creditpd::pushwithcetcreditpdapi($common_fields, $CETAPP_creditPD_data); if($result == true){ @@ -783,12 +810,33 @@ class SMC_Credit_PD_Controller extends REST_Controller { } unset($records['is_multiple']); + $source=$records['img']; + //Google Library - GCP + $this->load->library('Googlecloud'); + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 6; $i++) + { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + $rand_name = $records['img_name'] == 'satellite' ? $records['img_name'].".png" : $records['img_name']."_".$randomString.".png"; + $gcpBucketName = GCP_CREDIT_BUCKET_NAME; + $objectName = "credit_pd/pd".$records['fk_smc_credit_pd_id']."/images/".$rand_name; + $gcpResult = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$objectName,$source); + $report_gcp_url = ''; + if($gcpResult == true){ + $report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$objectName); + } + log_message('ERROR','#### SMC Credit PD '.$records['img_name'].' Image GCP Result = '.$gcpResult ? 1 : 0 ); + $records['rand_name'] = $rand_name; $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; + $data['gcpURL'] = $report_gcp_url; $this->response($data,REST_Controller::HTTP_OK); } else @@ -1952,8 +2000,16 @@ public function filterSalesPDList_post() { $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) - { - + { + $gcpBucketName = GCP_CREDIT_BUCKET_NAME; + $gcpObjectName = "credit_pd/pd".$smc_credit_pd."/".$smc_credit_pd.".pdf"; + $source=$output_file; + $gcpResult = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$gcpObjectName,$source); + $report_gcp_url = ''; + if($gcpResult == true){ + $report_gcp_url = $this->googlecloud->getSingleObjectInaBucketAsSignedURI($gcpBucketName,$gcpObjectName); + } + // $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'); @@ -1967,6 +2023,7 @@ public function filterSalesPDList_post() { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; + $data['gcpURL'] = $report_gcp_url; $this->response($data,REST_Controller::HTTP_OK); } @@ -2241,6 +2298,85 @@ public function filterSalesPDList_post() { $this->response($response_data,REST_Controller::HTTP_OK); } + + function transferCreditPDImgToCETApp_post(){ + $this->load->helper('smc_creditpd'); + $this->load->library('Googlecloud'); + + $records = $this->post('records'); + log_message('ERROR',"### CET APP Credit PD-IMG, PDID are :".implode(', ', $records)); + if(!empty($records)) + { + $j = 0;$common_fields=array(); + foreach ($records as $key => $value) + { + $credit_pd_id = $value; + if(!empty($credit_pd_id)){ + $mater_details = $this->PD_Model->getPDMasterDetails($credit_pd_id); + $pd_section_data = $this->SMC_Credit_PD_Model->getSMCTemplateForPD($credit_pd_id,$mater_details[0]['fk_product_id'],null,null,'REPORT'); + 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'], + 'credit_pd_type'=>$mater_details[0]['fk_pd_type'], + 'pd_type_name'=>$mater_details[0]['pd_type_name'], + 'completed_date'=>$mater_details[0]['completed_on']); + $photograph_data = $this->SMC_Credit_PD_Model->selectCustomRecords(array('*'),array('fk_smc_credit_pd_id' => $credit_pd_id,'isactive' => 1),SMC_CREDIT_PD_DOCS); + log_message('ERROR', '#### Credit PD ('.$credit_pd_id.') - Total Images'.count($photograph_data)); + + if(!empty($photograph_data)){ + + $k=0; + foreach ($photograph_data as $key => $value){ + + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < 6; $i++) + { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + $rand_name = $value['img_name'] == 'satellite' ? "satellite.png" : $value['img_name']."_".$randomString.".png"; + $common_fields['data']['Photograph Details']['photo'][$k]['img_name'] = $value['img_name']; + $common_fields['data']['Photograph Details']['photo'][$k]['img'] = $rand_name; + $photograph_data[$k]['rand_name'] = $rand_name;$k++; + } + $CET_response = cet_creditpd::repushwithcetphotographapi($common_fields); + $CET_api_response[$credit_pd_id] = $CET_response; + + if(isset($CET_response->status) && $CET_response->status == 200){ + foreach ($photograph_data as $key => $value){ + $rand_name = $value['rand_name']; + $source=$value['img_name'] == 'satellite' ? 'data:image/png;base64,'.$value['img'] : $value['img']; + //Google Library - GCP + $gcpBucketName = GCP_CREDIT_BUCKET_NAME; + $objectName = "credit_pd/pd".$credit_pd_id."/images/".$rand_name; + $gcp_result = $this->googlecloud->uploadFileToGCPBucket($gcpBucketName,$objectName,$source); + if($gcp_result == true) log_message('ERROR', '### Credit-PD ('.$credit_pd_id.') '.$value['img_name'].' Image Stored In GCP'); + else log_message('ERROR', '### Credit-PD ('.$credit_pd_id.') '.$records['img_name'].' Image Not Stored In GCP'); + if($gcp_result == true && $value['img_name'] != 'satellite') $this->Sales_PD_Model->updateRecords(array('rand_name' => $rand_name),SMC_CREDIT_PD_DOCS,array('doc_id'=>$value['doc_id'])); + } + log_message('ERROR', '#### Credit PD ('.$credit_pd_id.') - CET response - '.json_encode($CET_response,true)); + } else log_message('ERROR', '#### Credit PD ('.$credit_pd_id.') - CET response - '.json_encode($CET_response,true)); + }else log_message('ERROR', '#### Credit PD ('.$credit_pd_id.') - No Images'); + }else log_message('ERROR', '#### Credit PD ('.$credit_pd_id.') - No Data In ParentTable'); + }else log_message('ERROR', '#### Credit PDID Not Founded'); + } + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['reInsertImageDataApiResponse'] = $CET_api_response; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + log_message('ERROR', '#### Sales PDID Array Empty'); + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Data Found'; + $this->response($data,REST_Controller::HTTP_OK); + } + } + } \ No newline at end of file diff --git a/api/application/controllers/Sales_PD_Controller.php b/api/application/controllers/Sales_PD_Controller.php index 1b22f48d..a47ccda5 100644 --- a/api/application/controllers/Sales_PD_Controller.php +++ b/api/application/controllers/Sales_PD_Controller.php @@ -1989,6 +1989,7 @@ public function filterSalesPDList_post() { $photograph_data[$k]['rand_name'] = $rand_name;$k++; } $CET_response = cet_salespd::repushwithcetphotographapi($section_fields); + $CET_api_response[$sales_pd_id] = $CET_response; if(isset($CET_response->status) && $CET_response->status == 200){ foreach ($photograph_data as $key => $value){ $rand_name = $value['rand_name']; @@ -2011,7 +2012,7 @@ public function filterSalesPDList_post() { log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$value['img_name'].' Image Stored In S3'); }else{ log_message('ERROR', '### Sales-PD ('.$sales_pd_id.') '.$records['img_name'].' Image Not Stored In S3'); } - if($gcp_result == true && is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200){ + if($gcp_result == true && is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200 && $value['img_name'] != 'satellite'){ $update_fields2 = array('rand_name' => $rand_name); $this->Sales_PD_Model->updateRecords($update_fields2,SALEPD_DOCS,array('doc_id'=>$value['doc_id'])); } @@ -2036,7 +2037,7 @@ public function filterSalesPDList_post() { } $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; - $data['reInsertImageDataApiResponse'] = $CET_response; + $data['reInsertImageDataApiResponse'] = $CET_api_response; $this->response($data,REST_Controller::HTTP_OK); } else diff --git a/api/application/helpers/cet_creditpd_helper.php b/api/application/helpers/cet_creditpd_helper.php index c02cb794..6bd26b92 100644 --- a/api/application/helpers/cet_creditpd_helper.php +++ b/api/application/helpers/cet_creditpd_helper.php @@ -28,6 +28,7 @@ class CET_CREDITPD try{ $ch = curl_init(); $output_data = json_encode( $fields ); + // print_r($output_data);die(); // log_message('ERROR','#### output_data '.$output_data); // $path = $CI->external_path."/tmp/".$fields['pdid']."1.json"; // // $fp = fopen($path, 'w'); @@ -98,6 +99,32 @@ class CET_CREDITPD } return $response; } + + public static function repushwithcetphotographapi($fields) + { + $headers = array('Content-Type: application/json'); + try{ + $ch = curl_init(); + $output_data = json_encode( $fields ); + // print_r($output_data);die(); + log_message('ERROR',"ReInsertImageData api Request Format : ".$output_data); + curl_setopt( $ch,CURLOPT_URL, CET_CREDITPD_INTEGRATION_REINSERTIMG_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',"ReInsertImageData api response :".json_encode($response)); + curl_close( $ch ); + } + catch (Exception $e) { + $response->error = array($e->getMessage()); + log_message('ERROR', "ReInsertImageData ERR : " . $e->getMessage()); + } + return $response; + } } ?> \ No newline at end of file diff --git a/api/application/helpers/smc_creditpd_helper.php b/api/application/helpers/smc_creditpd_helper.php index 708b9663..0029a039 100644 --- a/api/application/helpers/smc_creditpd_helper.php +++ b/api/application/helpers/smc_creditpd_helper.php @@ -189,6 +189,7 @@ class smc_creditpd static function getAssestSectionData($section) { $json = json_decode($section['json'],true); + print_r($json); $rupee_symbol = ""; // $CI =&get_instance(); // $CI->load->model('PD_Model'); @@ -368,7 +369,7 @@ class smc_creditpd } - static function getStockSectionData($section) + static function getStockSectionData($section,$company) { $json = json_decode($section['json'],true);