diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index dac26cb1..52de9c37 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -51,16 +51,31 @@ class ApiServiceController extends BaseController } // E-Card Request - public function ecardRequest() + public function ecardRequest($params = [], $return_type = 'api') { try{ - $payload = $this->request->getJSON(true); - $id = $payload['id'] ?? null; - $emp_code = $payload['emp_code'] ?? null; - $client_policy_id = $payload['client_policy_id'] ?? null; - $policy_no = $payload['policy_no'] ?? null; + if(empty($params) && $this->response){ + $payload = $this->request->getJSON(true); + $id = $payload['id'] ?? null; + $emp_code = $payload['emp_code'] ?? null; + $client_policy_id = $payload['client_policy_id'] ?? null; + $policy_no = $payload['policy_no'] ?? null; + $type = $payload['type'] ?? 'download'; + log_message('error', 'Received Payload API : '. json_encode($payload ?? "")); + + }else{ + + $id = $params['id'] ?? null; + $emp_code = $params['emp_code'] ?? null; + $client_policy_id = $params['client_policy_id'] ?? null; + $policy_no = $params['policy_no'] ?? null; + $type = $params['type'] ?? 'download'; + + log_message('error', 'Received Payload INTERNAL : '. json_encode($params ?? "")); + + } $employee_policy = $this->employeePolicyModel ->select('employees.*, employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid , client_policy.tpa_id as tpa_primary_id ') @@ -71,7 +86,6 @@ class ApiServiceController extends BaseController ->where('employee_polices.is_active', 1 )->findAll(); - if(count($employee_policy) > 0) { if($employee_policy[0]['tpa_id'] != null) @@ -81,21 +95,33 @@ class ApiServiceController extends BaseController $mediAssistController = new MediAssistApiController(); $data['eCardDownload'] = $mediAssistController->EcardRequest( $emp_code, $policy_no ); }else{ - $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/1'; + + if($type == "download"){ + // direct download + $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/1'; + }else{ + // view and download + $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/0/1'; + } } $data['message'] = "E-card generated"; } else { $data['eCardDownload'] = null; $data['message'] = "E-card not generated"; + log_message('error', 'TPA number is null'); } }else{ $data['eCardDownload'] = null; $data['message'] = "E-card not generated"; + log_message('error', 'Employee not found'); } - - return $this->respond(['status' => true, 'code' => 200, 'message' => '', 'data' => $data]); + if($return_type == 'api'){ + return $this->respond(['status' => true, 'code' => 200, 'message' => '', 'data' => $data]); + }else{ + return $data; + } } catch(\Exception $e){ @@ -136,7 +162,7 @@ class ApiServiceController extends BaseController 'created_by'=> get_session_userid(), ]; - if ($tpa_id == 1) // MediAssist + if ($tpa_id == 2) // MediAssist { $file_id = $fileModel->insert($data); log_message('error', "Files table inserted successfully, File id : {$file_id}"); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index c2021479..dfaac349 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -4934,6 +4934,7 @@ class EmpDataServiceController extends BaseController cp.policy_type_id, cp.is_addon, + cp.policy_no, employee_polices.id as emp_policy_id, employee_polices.client_policy_id, @@ -4960,6 +4961,11 @@ class EmpDataServiceController extends BaseController 'notification' => $notification, 'client_data' => $client_data, 'get_emp_email_and_other_details' => $emp_details, + + 'id' => $emp_details['emp_id'], + 'emp_code' => $emp_details['emp_code'], + 'policy_no' => $emp_details['policy_no'], + 'client_policy_id' => $emp_details['client_policy_id'], ]; $params['common'] = [ diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 4ac2580e..9b1a8d4a 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -126,7 +126,8 @@ class sendMailNotification $subject = $cleanedText; - $link = generate_download_link($rand_string).'/1'; + // $link = generate_download_link($rand_string).'/1'; + $link = generate_ecard_download_link_based_on_tpa($params); $app_link = $_ENV['App_Url']; $name = $get_emp_email_and_other_details['name']; diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 4e89f10a..04cc5ba5 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -5,6 +5,7 @@ use App\Models\FileModel; use App\Models\BatchFileModelFileModel; use App\Controllers\GoogleDriveController; use App\Models\BatchFileModel; +use App\Controllers\ApiServiceController; // File: app/Helpers/Uuid_helper.php @@ -926,3 +927,20 @@ if (!function_exists('getMimeTypeByFileName')) { return $mime_types[$ext] ?? 'application/octet-stream'; // default fallback } } + +if (!function_exists('generate_ecard_download_link_based_on_tpa')) { + + function generate_ecard_download_link_based_on_tpa($params) { + + $apiServiceController = new ApiServiceController(); + $data = $apiServiceController->ecardRequest($params, $return_type = 'internal'); + log_message('error', 'E-card request call from the helper for mail send'); + + if(isset($data['eCardDownload']) && !empty($data['eCardDownload'])){ + return $data['eCardDownload']; + }else{ + return $data['message']; + } + } +} + diff --git a/app/Views/employee_data_list.php b/app/Views/employee_data_list.php index a3948cce..75e5125e 100755 --- a/app/Views/employee_data_list.php +++ b/app/Views/employee_data_list.php @@ -1,81 +1,81 @@ @@ -195,7 +195,8 @@ - " class="dropdown-item" target="_blank">View E-Card + + View E-Card @@ -586,25 +587,6 @@ }); } - // function validateInput(input, table, field){ - - // let value = $(input).val(); - // let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim(); - - // let message = "Value is duplicate!"; - // if(label){ - // message = label + " already exists!"; - // } - - // checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) { - // if (isDuplicate) { - // toastr.warning(message, 'WARNING'); - // $(input).val('') - // } - // }); - - // } - function validateInput(input, table, field) { let emp_code = $('#emp_code_for_edit').val(); @@ -739,12 +721,51 @@ }); } - // function closeModal(){ - // var myModalEl = document.getElementById('emp_history_modal'); - // var modalInstance = bootstrap.Modal.getInstance(myModalEl); - // if (modalInstance) { - // modalInstance.hide(); - // } - // } + function viewEcard(emp_id, emp_code, policy_id, policy_no){ + + console.log({emp_id, emp_code, policy_id, policy_no}); + + let url_type = 'view'; + let url = ''; + + // Data to send in the AJAX request + let requestData = { + id: emp_id, + emp_code: emp_code, + client_policy_id: policy_id, + policy_no: policy_no, + type: url_type, + }; + + // Convert to JSON + let jsonData = JSON.stringify(requestData); + + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); + + // Send AJAX request + sendAjaxRequestForGlobal(url, 'POST', jsonData, function(response) { + + console.log('Data fetched successfully:', response); + + if (response.status == true && response.data.eCardDownload) { + console.log(response.data.message || 'Initiating successafully', 'SUCCESS'); + const newTab = window.open(response.data.eCardDownload, '_blank'); + if (newTab) newTab.focus(); + } else { + toastr.error(response.data.message || 'Unable to fetch e-card', 'ERROR'); + } + + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + + }, function(xhr, status, error) { + console.error('Error fetching data:', error); + console.error(xhr.responseText); + toastr.error('An error occurred while checking the CD amount.', 'ERROR'); + }); + + + }