diff --git a/api/application/config/constants.php b/api/application/config/constants.php index c020fe03..91b9a896 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -96,6 +96,8 @@ defined('ROUTE_LOGIN_V') OR define('ROUTE_LOGIN_V', 'generateSatelliteImg defined('ROUTE_LOGIN_U') OR define('ROUTE_LOGIN_U', 'generateOTP'); defined('ROUTE_LOGIN_T') OR define('ROUTE_LOGIN_T', 'verifyOTP'); defined('ROUTE_LOGIN_S') OR define('ROUTE_LOGIN_S', 'purge_pddata'); +defined('ROUTE_LOGIN_H') OR define('ROUTE_LOGIN_H', 'transferCreditPDToCETApp'); +defined('ROUTE_LOGIN_G') OR define('ROUTE_LOGIN_G', 'transferSalesPDToCETApp'); defined('ROUTE_LOGIN_F') OR define('ROUTE_LOGIN_F', 'previewDigiLockerDocs'); // defined('ROUTE_LOGIN_F') OR define('ROUTE_LOGIN_F', 'downloadDigiLockerDocs'); defined('ROUTE_LOGIN_E') OR define('ROUTE_LOGIN_E', 'getDigiLockerDocs'); diff --git a/api/application/config/routes.php b/api/application/config/routes.php index d80d4741..40f75386 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -421,3 +421,7 @@ $route['checkjsonPD']='Data_Dump_Controller/checkjsonPD'; $route['deleteS3Image']='Data_Dump_Controller/deleteS3Images'; $route['saveShortsVideo'] = 'PD_Controller/saveShortsVideo'; + +$route['transferSalesPDToCETApp'] = 'Sales_PD_Controller/transferSalesPDToCETApp'; +$route['transferCreditPDToCETApp'] = 'SMC_Credit_PD_Controller/transferCreditPDToCETApp'; + diff --git a/api/application/controllers/SMC_Credit_PD_Controller.php b/api/application/controllers/SMC_Credit_PD_Controller.php index 47d17a54..deca81ee 100644 --- a/api/application/controllers/SMC_Credit_PD_Controller.php +++ b/api/application/controllers/SMC_Credit_PD_Controller.php @@ -269,45 +269,149 @@ class SMC_Credit_PD_Controller extends REST_Controller { } function uploadCreditPDDataToCETApp_get() { - log_message('ERROR', '#### upload SMC Credit PDData To CETApp Called'); $smc_credit_pd = $this->uri->segment(2); + if($smc_credit_pd){ + log_message('ERROR', '#### upload SMC-Credit PDData To CETApp Function Called'); + $columns = array('PDTRIGGER.pd_id'); + $table = PDTRIGGER . ' as PDTRIGGER'; + $where_arr = array('PDTRIGGER.is_the_data_transfer_cet'=>0,'PDTRIGGER.pd_status' => COMPLETED,'PDTRIGGER.pd_id'=>$smc_credit_pd); + $details = $this->SMC_Credit_PD_Model->selectCustomRecords($columns, $where_arr, $table); + if(!empty($details)){ + $response = $this->dataSynchronization($smc_credit_pd); + if($response){ + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = 'Data Shared Successfully'; + $this->response($data,REST_Controller::HTTP_OK); + }else{ + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Something went wrong! Try Later'; + $this->response($data, REST_Controller::HTTP_OK); + } + }else{ + log_message('ERROR', $smc_credit_pd.' Data already uploaded'); + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Data already uploaded! Try Later'; + $this->response($data, REST_Controller::HTTP_OK); + } + + }else{ + $msg = 'Can`t Upload ID 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); + } + + } + public function transferCreditPDToCETApp_get() + { + $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 PDData To CETApp Date Given Format => " . $from_date ." to ".$to_date; + // $where = 'DATE(PDTRIGGER.completed_on) BETWEEN ' ."'$newDate1'". ' AND ' ."'$newDate2'"; + $columns = array('PDTRIGGER.pd_id', 'PDTRIGGER.pd_status'); + $table = PDTRIGGER . ' as PDTRIGGER'; + + $where = '(SELECT + MAX(DATE(logmaster.createdon)) + FROM h_common_masters as logmaster + WHERE logmaster.new_value = "COMPLETED" AND PDTRIGGER.pd_id = logmaster.primary_key) + BETWEEN ' ."'$newDate1'". ' AND ' ."'$newDate2'"; + $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)); + if(!empty($details)){ + $flag = 0;$ids=array(); + for ($i = 0; $i < count($details); $i++) { + $smc_credit_pd = $details[$i]['pd_id']; + // echo $smc_credit_pd; + $result = $this->dataSynchronization($smc_credit_pd); + // $flag = $result == true ? $flag+1 : $flag; + if($result == true){ + $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)); + + } + } + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = implode(', ', $ids).' ( '.$flag.' ) Data 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 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); + } + + } + function dataSynchronization($smc_credit_pd) + { + $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', '#### Total Credit PD is ' . count($pd_section_data)); + log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') There are ' . count($pd_section_data).' Forms '); 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']); - foreach ($pd_section_data as $key => $value) { + // foreach ($pd_section_data as $key => $value) { + // if (isset($value['json']) && $value['json'] != '') { + // $filter_form_id[$key] = $value['fk_form_id']; + // $CETAPP_creditPD_data[$value['form_name']] = json_decode($value['json'],true); + // } else { + // if (in_array($value['fk_form_id'], $forms_data_to_be_get_direct_from_excel_sheet)) { + // $data_from_excel = $this->loadDataFromExcelBusiProcess($mater_details, $value['fk_form_id']); + // $filter_form_id[$key] = $value['fk_form_id']; + // $CETAPP_creditPD_data[$value['form_name']] = json_decode($data_from_excel,true); + // } + // } + // } + foreach ($pd_section_data as $key => $value) + { if (isset($value['json']) && $value['json'] != '') { + $value['json'] = smc_creditpd::getSMCCreditPDReportContent($value,$smc_credit_pd,$companylist); $filter_form_id[$key] = $value['fk_form_id']; + // $view_data['pd_section_data'][$value['fk_form_id']] = $value['json']; $CETAPP_creditPD_data[$value['form_name']] = $value['json']; - } else { - if (in_array($value['fk_form_id'], $forms_data_to_be_get_direct_from_excel_sheet)) { + } + else + { + if (in_array($value['fk_form_id'], $forms_data_to_be_get_direct_from_excel_sheet)) { $data_from_excel = $this->loadDataFromExcelBusiProcess($mater_details, $value['fk_form_id']); + //print_r($data_from_excel);die(); + // $view_data['pd_section_data'][$value['fk_form_id']] = $data_from_excel; + $CETAPP_creditPD_data[$value['form_name']] = $data_from_excel; $filter_form_id[$key] = $value['fk_form_id']; - $CETAPP_creditPD_data[$value['form_name']] = $data_from_excel; } } - } - $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); - if(count($photograph_data)>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]; - cet_creditpd::pushwithcetphotographapi($img_fields,$i); - }} - if(!empty($satellite_image)){ - $stt_fields = $common_fields; - $stt_fields['img_name'] = $satellite_image[0]['img_name']; - $stt_fields['img'] = $satellite_image[0]['img']; - cet_creditpd::pushwithcetphotographapi($stt_fields,0); - } + } if ($mater_details[0]['product_abbr'] == 'LFMP' && (array_key_exists("key_stakeholders",$pd_section_data[5])) ) { $LFMP_KeyStackholders = $pd_section_data[5]['key_stakeholders']; $temp_arr = []; @@ -340,9 +444,7 @@ class SMC_Credit_PD_Controller extends REST_Controller { $CETAPP_creditPD_data['Key Stakeholders in Business']['key_stakeholders'] = $temp_arr; } } // ### LFMP key_stakeholders ends - if ((in_array(1, $filter_form_id)) && (in_array(21, $filter_form_id))) - // && (in_array(4,$filter_form_id))) - { + // print_r($filter_form_id);die(); $officer_id = isset($mater_details[0]['fk_updatedby']) ? $mater_details[0]['fk_updatedby'] : ''; $visit_date = isset($mater_details[0]['pd_visit_date']) ? $mater_details[0]['pd_visit_date'] : ''; if (!empty($officer_id)) { @@ -354,13 +456,48 @@ class SMC_Credit_PD_Controller extends REST_Controller { } } } + + $result = cet_creditpd::pushwithcetcreditpdapi($common_fields, $CETAPP_creditPD_data); + 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'); + if(count($photograph_data)>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(!empty($satellite_image)){ + log_message('ERROR', '#### Credit PD ('.$smc_credit_pd.') satellite Available'); + $stt_fields = $common_fields; + $stt_fields['img_name'] = $satellite_image[0]['img_name']; + $stt_fields['img'] = $satellite_image[0]['img']; + $resultstatellite = cet_creditpd::pushwithcetphotographapi($stt_fields,0); + } + // 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"; + // $json = json_decode($view_data['pd_section_data'],true); + // $fp = fopen($path, 'w'); + // fwrite($fp, $jsonString); + // fclose($fp); + // if(file_put_contents($path, $output_data)) + // { + // $message = "