From 087134d74dd0cf5e9bce5fbdd983411957739be9 Mon Sep 17 00:00:00 2001 From: Velz2020 Date: Wed, 24 Mar 2021 15:07:16 +0530 Subject: [PATCH] SALES PD CAMUNDA INTEGRATION --- api/application/config/constants.php | 2 +- api/application/config/routes.php | 1 + api/application/controllers/PD_Controller.php | 23 ++- .../controllers/Sales_PD_Controller.php | 16 ++ api/application/helpers/camunda_helper.php | 154 ++++++++++++++++++ 5 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 api/application/helpers/camunda_helper.php diff --git a/api/application/config/constants.php b/api/application/config/constants.php index cebeac80..d8994241 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -99,7 +99,7 @@ defined('SAVEROOMINFO_API') OR define('SAVEROOMINFO_API', 'saveRoomInfo') defined('SAVESMCCREDITPDIMAGE_API') OR define('SAVESMCCREDITPDIMAGE_API', 'saveSMCCreditPDImage'); // no errors defined('GETSMCPDIMGSECTIONDATA_API') OR define('GETSMCPDIMGSECTIONDATA_API', 'getSMCPDImgSectionData'); // no errors //defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN','getFullPDDetails'); // no errors - +defined('CAMUNDA_URL') OR define('CAMUNDA_URL','http://34.121.71.79:8080/engine-rest/'); /*********************AWS resources Constants*************************************************/ defined('PROFILE_PICTURE_BUCKET_NAME') OR define('PROFILE_PICTURE_BUCKET_NAME','sineedgedevprofilepic'); if(ENVIRONMENT == 'development') diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 752d890e..2507b561 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -302,6 +302,7 @@ $route['filterSalesPDList']='Sales_PD_Controller/filterSalesPDList'; $route['generateSatelliteImg']='Sales_PD_Controller/generateSatelliteImg'; $route['getSalesPDImgDataCusLink']='Sales_PD_Controller/getSalesPDImgDataCusLink'; $route['sendSalesCusLinkViaSMS']='Sales_PD_Controller/sendSalesCusLinkViaSMS'; +$route['camundaTest']='Sales_PD_Controller/camundaTest'; $route['listSMCCreditPD/(:num)']='SMC_Credit_PD_Controller/listSMCCreditPD'; diff --git a/api/application/controllers/PD_Controller.php b/api/application/controllers/PD_Controller.php index 37c8c59a..21dd90dd 100644 --- a/api/application/controllers/PD_Controller.php +++ b/api/application/controllers/PD_Controller.php @@ -11028,15 +11028,28 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() if(!empty($_FILES['video_file'])) { $folder_to_check = XLPATH.'/pd_reports/'.$records['fk_pd_id'].'/videos'; + + if(!file_exists($folder_to_check)) + { + mkdir($folder_to_check,0777); + } + // die(); // $modified_fname = $records['rand_key'].'~'.str_replace(' ','_',($_FILES['pd_excel_data']['name'])); $modified_fname = str_replace(' ','_',($_FILES['video_file']['name'])); // echo file_exists($folder_to_check);die(); $config = array('upload_path' => $folder_to_check,'overwrite' => TRUE,'allowed_types' => '*','file_name' => $modified_fname); + $this->load->library('upload', $config); + $this->upload->initialize($config); + + + try { + + if($this->upload->do_upload('video_file')) { - + log_message('ERROR','video uplaod done :' . $folder_to_check); $sourcefile = $folder_to_check.'/'.$modified_fname; // echo $sourcefile; $key = 'pd'.$records['fk_pd_id'].'/video/'.$modified_fname; @@ -11052,6 +11065,14 @@ public function getCompaniesListsFromGeneralFormRawJSON_post() unlink($sourcefile); } } + else + { + log_message('ERROR','video uplaod failed :' . $folder_to_check); + } + + } catch (Exception $e) { + log_message('ERROR','video uplaod failed exception:' . $folder_to_check.' - '.$e->getMessage()); + } // die(); if($is_bucket_upload_sucess && $id) diff --git a/api/application/controllers/Sales_PD_Controller.php b/api/application/controllers/Sales_PD_Controller.php index 4188926b..0b93d7aa 100644 --- a/api/application/controllers/Sales_PD_Controller.php +++ b/api/application/controllers/Sales_PD_Controller.php @@ -9,6 +9,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); require_once APPPATH . '/libraries/REST_Controller.php'; +include_once APPPATH.'/vendor/autoload.php'; class Sales_PD_Controller extends REST_Controller { @@ -22,6 +23,7 @@ class Sales_PD_Controller extends REST_Controller { $this->load->library('AWS_S3'); $this->load->library('pdfgenerator'); $this->load->helper('satellite_image'); + $this->load->helper('camunda'); $this->load->library('phpmailer_library'); @@ -549,6 +551,9 @@ class Sales_PD_Controller extends REST_Controller { $records['sales_pd_sno'] = $salepd_serial_no; // print_r($records);die(); $id = $this->Sales_PD_Model->saveRecords($records,SALES_PD_DATA); + + //start camunda process + CAMUNDA::startSalesPDInstance($id); } else { @@ -659,6 +664,8 @@ class Sales_PD_Controller extends REST_Controller { //echo 'final';die(); $id = $this->Sales_PD_Model->updateRecords($records,SALES_PD_DATA,array('sales_pd_id' => $records['sales_pd_id'])); + CAMUNDA::completeSalesPDTask($id); + $this->prepareSalesPDReport($records['sales_pd_id'],false); sleep(10); log_message('ERROR','####SALESPD AFTER 10 PREPARED REPORT'.$records['sales_pd_id']); @@ -1191,6 +1198,15 @@ public function filterSalesPDList_post() { } } + + + public function camundaTest_post() + { + // echo 'hi'; + + CAMUNDA::completeSalesPDTask(1); + //CAMUNDA::startSalesPDInstance(1); + } } \ No newline at end of file diff --git a/api/application/helpers/camunda_helper.php b/api/application/helpers/camunda_helper.php new file mode 100644 index 00000000..3eab8ad3 --- /dev/null +++ b/api/application/helpers/camunda_helper.php @@ -0,0 +1,154 @@ +post( $url, [ + 'headers' => ['Content-Type' => 'application/json'] + //'body' => json_encode($data) + ]); + + if($response && $response->getStatusCode() == 200) + { + return (json_decode(($response->getBody()->getContents()))); + // echo $response->getBody()->getContents()->id; + // echo $response->getBody()->getContents()['id']; + // die(); + } + else + { + return null; + } + } catch (Exception $e) { + //return null; + echo $e->getMessage(); + } + } + + // complete an activity in an instance or instance + public static function completeInstance($instanceID,$data = array()) + { + $url = CAMUNDA_URL.'task/'.$instanceID.'/complete'; + $client = new \GuzzleHttp\Client(); + $response = $client->post( $url, [ + 'headers' => ['Content-Type' => 'application/json'] + //'body' => json_encode($data) + ]); + + if($response && $response->getStatusCode() == 200) + { + return json_encode($response->getBody()->getContents()); + } + else + { + return null; + } + } + + + public static function getListOfInstanceByProcessDefinitionKey($processDefinitionKey,$data = array()) + { + $url = CAMUNDA_URL . 'task?processDefinitionKey='.$processDefinitionKey; + // echo $url;//die(); + + $client = new \GuzzleHttp\Client(); + $response = $client->request('GET',$url); + + // $client = new \GuzzleHttp\Client(); + // $res = $client->get( $url, [ + // 'headers' => ['Content-Type' => 'application/json'], + // 'body' => json_encode($data) + // ]); + if($response && $response->getStatusCode() == 200) + { + return json_decode($response->getBody()->getContents()); + } + else + { + return null; + } + // print_r(); + // print_r($response->getStatusCode()); + } + + + public static function startSalesPDInstance($sales_pd_id) + { + + $CI =& get_instance(); + if($sales_pd_id) + { + $newProcessInstanceID = SELF::startNewInstance('sales_pd_demo:1:38949d25-8c83-11eb-a4f2-42010a800002'); + if($newProcessInstanceID && property_exists($newProcessInstanceID, 'id')) + { + $updated = $CI->Sales_PD_Model->updateRecords(array('t_process_instance_id' => $newProcessInstanceID->id),SALES_PD_DATA,array('sales_pd_id' => $sales_pd_id)); + log_message('ERROR','####Camunda start new instance success - ', $sales_pd_id); + } + else + { + log_message('ERROR','####Camunda start new instance failed - ', $sales_pd_id); + } + } + } + + + public static function completeSalesPDTask($sales_pd_id)//completeSalesPDTask ot instance + { + + $CI =& get_instance(); + if($sales_pd_id) + { + $fields=array('t_process_instance_id'); + $sales_pd_data = $CI->Sales_PD_Model->selectCustomRecords($fields,array('sales_pd_id' => $sales_pd_id),SALES_PD_DATA); + + if($sales_pd_data && count($sales_pd_data)) + { + //get list of task + $task_id = null; + $list_of_task = SELF::getListOfInstanceByProcessDefinitionKey('sales_pd_demo'); + if($list_of_task && count($list_of_task)) + { + foreach ($list_of_task as $task_key => $task) + { + if($sales_pd_data[0]['t_process_instance_id'] == $task->processInstanceId) + { + $task_id = $task->id; + break; + } + } + } + else + { + log_message('ERROR','####Couldn`t identify Camunda instance - ', $sales_pd_id); + } + + + if($task_id) + { + SELF::completeInstance($task_id); + } + else + { + log_message('ERROR','####Couldn`t identify task id - ', $sales_pd_id); + } + } + else + { + log_message('ERROR','#### could not get sales pd data - ', $sales_pd_id); + } + } + } + + +} + +?> \ No newline at end of file