diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 15c4aa0a..251e26ee 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -817,6 +817,8 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) { $routes->post('saveIRDocsJson',"TicketController::saveIRDocsJson"); $routes->get('getTpaClaimStatus',"ApiServiceController::getClaimStatus"); $routes->post('manualTpaClaimPush',"ApiServiceController::manualTpaClaimPush"); + $routes->match(['get', 'post'], 'getClaimTemplateData', 'TicketController::getClaimTemplateData'); + $routes->post('uploadApprovedLetterFromReply', 'TicketController::uploadApprovedLetterFromReply'); }); // Non-EB Claims diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 7d5e4c97..d590bae4 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3925,7 +3925,6 @@ class EmployeeRestController extends AdminController $count = $this->ticketMaster->where('id', $ticket_id)->where('is_active', 1)->where('tpa_claim_push_reference_no IS NULL')->countAllResults(); log_message('error', 'Ticket validation | Ticket ID: ' . $ticket_id . ' | Matching active tickets with NULL TPA reference: ' . $count); - if ($count > 0 && $pdf_exist_in_the_file && $tpa_claim_push == true) { try { // this call for TPA integration @@ -3945,6 +3944,16 @@ class EmployeeRestController extends AdminController } } + if($tpa_claim_push == false){ + try { + // this call for TPA integration Multiple document push for IR DOCUMENTS + $apiServiceController = new ApiServiceController(); + $apiServiceController->pushClaimFiles($ticket_id); + log_message('error', "pushClaimFiles IR FILE SUBMISSION function called with Ticket ID: {$ticket_id}, In Employee Rest Controller"); + } catch (\Throwable $e) { + log_message('error', "Error in TPA Claim Files Push via CRM : ApiServiceController pushClaims function call for Ticket ID: {$ticket_id}. Error: " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); + } + } return $insert_ids; } @@ -4530,8 +4539,8 @@ class EmployeeRestController extends AdminController // print_r($post_data); die; - $Query = $this->clientPolicyModel - ->select(" + $Query = $this->clientPolicyModel + ->select(" client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, @@ -4544,14 +4553,14 @@ class EmployeeRestController extends AdminController DATE_FORMAT(client_policy.policy_end_date, '%d-%m-%Y') AS policy_expiry_date, CASE WHEN policy_type.allocg IN ('Non-EB', 'Marine') THEN 'Non-EB' ELSE 'EB' END as allocg ", false) - ->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left') - ->where('md5(client_policy.client_id)', $post_data['client_id']) - ->where('client_policy.client_branch_id', $post_data['client_branch_id']) - ->where('client_policy.is_active', 1); + ->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left') + ->where('md5(client_policy.client_id)', $post_data['client_id']) + ->where('client_policy.client_branch_id', $post_data['client_branch_id']) + ->where('client_policy.is_active', 1); // ->where('client_policy.policy_status', $this->request->getGet('policy_status')) - if(is_array($post_data['policy_id'])){ + if (is_array($post_data['policy_id'])) { $Query->whereIn('client_policy.id', $post_data['policy_id']); - }else{ + } else { $Query->where('client_policy.id', $post_data['policy_id']); } $ClientPolicyData = $Query->first(); @@ -4581,9 +4590,9 @@ class EmployeeRestController extends AdminController } return $this->respondCreated($responce); - } catch (\Exception $e) { // return $this->failServerError($e->getMessage()); + log_message('error', 'Error in hrFileUpload: ' . $e->getMessage() . ' in file ' . $e->getFile() . ' on line ' . $e->getLine() . ' Trace: ' . $e->getTraceAsString()); return $this->respondCreated(['status' => false, 'message' => $e->getMessage(), 'data' => []]); } } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 75fd9800..863b1bb1 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -277,61 +277,61 @@ class MasterController extends AdminController echo view('insurer_onboarding', $data); echo view('layout/footer'); - } + } public function createInsurerGeneralInfo() { - $this->myLogger->logme('error','Insurer general info function called'); + $this->myLogger->logme('error', 'Insurer general info function called'); $rules = [ - 'name' => [ - 'label' => 'Insurer Name', - 'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s\-_]+$/]'], - 'errors' => [ - 'required' => 'Insurer Name is required.', - 'regex_match' => 'Insurer Name can only contain letters, numbers, spaces, hyphens, and underscores.', - ] - ], - 'short_name' => [ - 'label' => 'Insurer Short Name', - 'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\-_]+$/]'], - 'errors' => [ - 'required' => 'Short Name is required.', - 'regex_match' => 'Short Name can only contain letters, numbers, hyphens, and underscores.', - ] - ], - 'type' => [ - 'label' => 'Insurer Type', - 'rules' => 'permit_empty|in_list[pvt,psu]', - 'errors' => [ - 'in_list' => 'Please select a valid Insurer Type (PVT or PSU).' - ] - ], - 'category' => [ - 'label' => 'Insurer Category', - 'rules' => 'permit_empty|in_list[life,general]', - 'errors' => [ - 'in_list' => 'Please select a valid Category (Life or General).' - ] - ], - 'addition_add_day' => [ - 'rules' => 'permit_empty' // Checkboxes return null if unchecked - ], - 'deletion_add_day' => [ - 'rules' => 'permit_empty' - ], - 'is_multi_event' => [ - 'rules' => 'permit_empty' - ], - 'insurer_logo' => [ + 'name' => [ + 'label' => 'Insurer Name', + 'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\s\-_]+$/]'], + 'errors' => [ + 'required' => 'Insurer Name is required.', + 'regex_match' => 'Insurer Name can only contain letters, numbers, spaces, hyphens, and underscores.', + ] + ], + 'short_name' => [ + 'label' => 'Insurer Short Name', + 'rules' => ['required', 'regex_match[/^[a-zA-Z0-9\-_]+$/]'], + 'errors' => [ + 'required' => 'Short Name is required.', + 'regex_match' => 'Short Name can only contain letters, numbers, hyphens, and underscores.', + ] + ], + 'type' => [ + 'label' => 'Insurer Type', + 'rules' => 'permit_empty|in_list[pvt,psu]', + 'errors' => [ + 'in_list' => 'Please select a valid Insurer Type (PVT or PSU).' + ] + ], + 'category' => [ + 'label' => 'Insurer Category', + 'rules' => 'permit_empty|in_list[life,general]', + 'errors' => [ + 'in_list' => 'Please select a valid Category (Life or General).' + ] + ], + 'addition_add_day' => [ + 'rules' => 'permit_empty' // Checkboxes return null if unchecked + ], + 'deletion_add_day' => [ + 'rules' => 'permit_empty' + ], + 'is_multi_event' => [ + 'rules' => 'permit_empty' + ], + 'insurer_logo' => [ 'rules' => 'if_exist|is_image[insurer_logo]|max_size[insurer_logo,200]|ext_in[insurer_logo,jpg,jpeg,png]', 'errors' => [ 'is_image' => 'The uploaded file must be an image', 'max_size' => 'File size should not exceed 200 KB', 'ext_in' => 'Allowed file types: jpg, jpeg, png', ] - ], -]; + ], + ]; // $rules = [ // 'name' => [ // 'rules' => 'required', @@ -3538,8 +3538,9 @@ class MasterController extends AdminController { $posModel = new PartnerPosModel(); $method = $this->request->getMethod(); - + if ($this->request->getMethod() === 'post') { + try { $rules = [ 'manager_id' => [ @@ -3555,7 +3556,7 @@ class MasterController extends AdminController 'required' => 'Name is required', 'min_length' => 'Name must be at least 3 characters', 'max_length' => 'Name cannot exceed 100 characters', - 'alpha_space'=> 'Name can contain only letters and spaces' + 'alpha_space' => 'Name can contain only letters and spaces' ] ], 'pos_code' => [ @@ -3589,27 +3590,27 @@ class MasterController extends AdminController ] ], 'state' => [ - 'label' => 'State', - 'rules' => 'required|regex_match[/^[a-zA-Z0-9\/\-\_\.\s]+$/]', - 'errors' => [ - 'required' => 'State is required.', - 'regex_match' => 'State name can only contain letters, spaces, and hyphens.' - ] - ], - 'city' => [ - 'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-]+$/]', - 'errors' => [ - 'regex_match' => 'City can contain letters, numbers, spaces, and hyphens.' - ] - ], - 'pincode' => [ - 'rules' => 'required|numeric|exact_length[6]', - 'errors' => [ - 'required' => 'Pincode is required.', - 'numeric' => 'Pincode must be digits only.', - 'exact_length' => 'Pincode must be exactly 6 digits.' - ] - ], + 'label' => 'State', + 'rules' => 'required|regex_match[/^[a-zA-Z0-9\/\-\_\.\s]+$/]', + 'errors' => [ + 'required' => 'State is required.', + 'regex_match' => 'State name can only contain letters, spaces, and hyphens.' + ] + ], + 'city' => [ + 'rules' => 'required|regex_match[/^[a-zA-Z0-9\s\-]+$/]', + 'errors' => [ + 'regex_match' => 'City can contain letters, numbers, spaces, and hyphens.' + ] + ], + 'pincode' => [ + 'rules' => 'required|numeric|exact_length[6]', + 'errors' => [ + 'required' => 'Pincode is required.', + 'numeric' => 'Pincode must be digits only.', + 'exact_length' => 'Pincode must be exactly 6 digits.' + ] + ], 'aadhar' => [ 'rules' => 'required|numeric|exact_length[12]', 'errors' => [ @@ -3632,25 +3633,22 @@ class MasterController extends AdminController ] ], 'aadhar_file_name' => [ - 'rules' => 'permit_empty|uploaded[aadhar_file_name]|max_size[aadhar_file_name,5120]|ext_in[aadhar_file_name,pdf,jpg,jpeg,png]', + 'rules' => 'if_exist|max_size[aadhar_file_name,5120]|ext_in[aadhar_file_name,pdf,jpg,jpeg,png]', 'errors' => [ - 'uploaded' => 'Invalid Aadhaar file', 'max_size' => 'Aadhaar file size should not exceed 5MB', 'ext_in' => 'Aadhaar must be PDF or image (jpg, jpeg, png)' ] ], 'pan_file_name' => [ - 'rules' => 'permit_empty|uploaded[pan_file_name]|max_size[pan_file_name,5120]|ext_in[pan_file_name,pdf,jpg,jpeg,png]', + 'rules' => 'if_exist|max_size[pan_file_name,5120]|ext_in[pan_file_name,pdf,jpg,jpeg,png]', 'errors' => [ - 'uploaded' => 'Invalid PAN file', 'max_size' => 'PAN file size should not exceed 5MB', 'ext_in' => 'PAN must be PDF or image (jpg, jpeg, png)' ] ], 'certificate_file_name' => [ - 'rules' => 'permit_empty|uploaded[certificate_file_name]|max_size[certificate_file_name,5120]|ext_in[certificate_file_name,pdf,jpg,jpeg,png]', + 'rules' => 'if_exist|max_size[certificate_file_name,5120]|ext_in[certificate_file_name,pdf,jpg,jpeg,png]', 'errors' => [ - 'uploaded' => 'Invalid Certificate file', 'max_size' => 'Certificate file size should not exceed 5MB', 'ext_in' => 'Certificate must be PDF or image (jpg, jpeg, png)' ] @@ -3669,138 +3667,217 @@ class MasterController extends AdminController $data = $this->request->getPost(); $sanitized_post_data = sanitizeInputArrayAdvanced($data); $id = $sanitized_post_data['pk'] ?? null; - unset($sanitized_post_data['pk']); + unset($sanitized_post_data['pk']); try { // Certificate $certificate = $this->uploadPOSFile('certificate_file_name', 'pos_certificate_files'); - if ($certificate !== null) { $sanitized_post_data['certificate_file_name'] = $certificate; } else { unset($sanitized_post_data['certificate_file_name']); } + if ($certificate !== null) { + $sanitized_post_data['certificate_file_name'] = $certificate; + } else { + unset($sanitized_post_data['certificate_file_name']); + } // PAN file $panFile = $this->uploadPOSFile('pan_file_name', 'pos_certificate_files'); - if ($panFile !== null) { $sanitized_post_data['pan_file_name'] = $panFile; } else { unset($sanitized_post_data['pan_file_name']);} + if ($panFile !== null) { + $sanitized_post_data['pan_file_name'] = $panFile; + } else { + unset($sanitized_post_data['pan_file_name']); + } // Aadhaar file $aadharFile = $this->uploadPOSFile('aadhar_file_name', 'pos_certificate_files'); - if ($aadharFile !== null) { $sanitized_post_data['aadhar_file_name'] = $aadharFile; } else { unset($sanitized_post_data['aadhar_file_name']);} - - } catch (\RuntimeException $e) { - return $this->respond([ 'status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $sanitized_post_data ], 400); + if ($aadharFile !== null) { + $sanitized_post_data['aadhar_file_name'] = $aadharFile; + } else { + unset($sanitized_post_data['aadhar_file_name']); + } + } catch (\Exception $e) { + log_message('error', 'File upload error: ' . $e->getMessage() . ' | POST data: ' . json_encode($sanitized_post_data) . $e->getTraceAsString()); + return $this->respond(['status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $sanitized_post_data], 400); } - foreach ($sanitized_post_data as $k => $v) { - if ($v === '' || $v === null) { - unset($sanitized_post_data[$k]); - } + foreach ($sanitized_post_data as $k => $v) { + if ($v === '' || $v === null) { + unset($sanitized_post_data[$k]); } - + } + // INSERT / UPDATE - if (empty($id)) { - $status = $posModel->insert($sanitized_post_data); - } else { - $status = $posModel->update($id, $sanitized_post_data); - } + try { + if (empty($id)) { + $status = $posModel->insert($sanitized_post_data); + } else { + $status = $posModel->update($id, $sanitized_post_data); + } - if ($status) { - return $this->respond([ 'status' => true, 'code' => 200, 'message' => 'POS updated successfully', 'data' => $sanitized_post_data ], 200); - } + if ($status) { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'POS updated successfully', 'data' => $sanitized_post_data], 200); + } - return $this->respond([ 'status' => false, 'code' => 400, 'message' => 'Failed to update', 'data' => $sanitized_post_data ], 400); - } - elseif ($method === 'get') { + $modelErrors = method_exists($posModel, 'errors') ? $posModel->errors() : []; + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to update', + 'errors' => $modelErrors, + 'data' => $sanitized_post_data + ], 400); + } catch (\Throwable $e) { + log_message('error', 'partnerPOS DB error: ' . $e->getMessage() . ' | payload: ' . json_encode($sanitized_post_data) . ' | trace: ' . $e->getTraceAsString()); - $id = $this->request->getGet('pk') ?? null; + $message = 'Something went wrong while saving POS details.'; + $statusCode = 500; - $db = db_connect(); - - $builder = $db->table('partner_staff'); - - $data['manager_list'] = $builder->select('partner_staff.id, partner_staff.name') - ->where('partner_staff.is_active', 1) - ->where('partner_staff.role_id', 1) - ->get() - ->getResultArray(); - - - if (!empty($id)) { - - $data['pos_list'] = $posModel - ->select('partner_pos.*, partner_staff.name AS manager_name') - ->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left') - ->where('partner_pos.id', $id) - ->orderBy('partner_pos.id', 'DESC') - ->findAll(); - - if (!empty($data)) { - return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200); - } else { - return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200); - } - } - - $data['pos_list'] = $posModel - ->select('partner_pos.*, ps.name AS manager_name') - ->join('partner_staff ps', 'ps.id = partner_pos.manager_id', 'left') - ->orderBy('partner_pos.id', 'DESC') - ->findAll(); - - - return $this->loadLayout('pos_list', ['data' => $data,'tab_name' => 'POS details','page_name' => 'POS details']); - - } elseif ($method === 'delete') { - - // $input = $this->request->getRawInput(); - $id = $this->request->getGet('pk'); // ✅ THIS - $id = $id ?? null; - - if (empty($id)) { - return $this->respond([ - 'status' => false, - 'code' => 404, - 'message' => 'No ID provided for deletion' - ], 200); - } - - $update_status = $posModel->where('id', $id)->set(['is_active' => 0])->update(); - - if ($update_status) { - return $this->respond([ - 'status' => true, - 'code' => 200, - 'message' => 'Data removed successfully', - 'pk' => $id - ], 200); - } else { - return $this->respond([ - 'status' => false, - 'code' => 400, - 'message' => 'Failed to remove data', - 'pk' => $id - ], 200); - } + if (stripos($e->getMessage(), 'Duplicate entry') !== false) { + $statusCode = 400; + if (stripos($e->getMessage(), 'email') !== false) { + $message = 'Email already exists.'; + } elseif (stripos($e->getMessage(), 'mobile') !== false) { + $message = 'Mobile number already exists.'; + } else { + $message = 'Duplicate data found. Please check email/mobile.'; } } - private function uploadPOSFile(string $fieldName, string $uploadDir) - { - $file = $this->request->getFile($fieldName); + return $this->respond([ + 'status' => false, + 'code' => $statusCode, + 'message' => $message + ], $statusCode); + } + } catch (\Throwable $e) { + log_message( + 'error', + 'partnerPOS fatal error: ' . $e->getMessage() . + ' | file: ' . $e->getFile() . + ' | line: ' . $e->getLine() . + ' | trace: ' . $e->getTraceAsString() + ); + return $this->respond([ + 'status' => false, + 'code' => 500, + 'message' => 'Internal server error while processing POS request.' + ], 500); + } + } elseif ($method === 'get') { - if (!$file || !$file->isValid()) { return null; } + $id = $this->request->getGet('pk') ?? null; - $allowedMime = [ 'image/jpg', 'image/jpeg', 'image/png', 'image/webp', 'application/pdf']; + $db = db_connect(); - if (!in_array($file->getMimeType(), $allowedMime)) { throw new \RuntimeException('Invalid file format'); } + $builder = $db->table('partner_staff'); - $path = ROOTPATH . 'public/uploads/' . $uploadDir . '/'; + $data['manager_list'] = $builder->select('partner_staff.id, partner_staff.name') + ->where('partner_staff.is_active', 1) + ->where('partner_staff.role_id', 1) + ->get() + ->getResultArray(); - if (!is_dir($path)) { mkdir($path, 0755, true); } - $newName = $file->getRandomName(); - $file->move($path, $newName); + if (!empty($id)) { - return $newName; + $data['pos_list'] = $posModel + ->select('partner_pos.*, partner_staff.name AS manager_name') + ->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left') + ->where('partner_pos.id', $id) + ->orderBy('partner_pos.id', 'DESC') + ->findAll(); + + if (!empty($data)) { + return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200); + } else { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200); } + } + + $data['pos_list'] = $posModel + ->select('partner_pos.*, ps.name AS manager_name') + ->join('partner_staff ps', 'ps.id = partner_pos.manager_id', 'left') + ->orderBy('partner_pos.id', 'DESC') + ->findAll(); - } \ No newline at end of file + return $this->loadLayout('pos_list', ['data' => $data, 'tab_name' => 'POS details', 'page_name' => 'POS details']); + } elseif ($method === 'delete') { + + // $input = $this->request->getRawInput(); + $id = $this->request->getGet('pk'); // ✅ THIS + $id = $id ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $posModel->where('id', $id)->set(['is_active' => 0])->update(); + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Data removed successfully', + 'pk' => $id + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to remove data', + 'pk' => $id + ], 200); + } + } + } + + private function uploadPOSFile(string $fieldName, string $uploadDir) + { + $file = $this->request->getFile($fieldName); + + if (!$file) { + return null; + } + + // No file selected for this optional input. + if ($file->getError() === UPLOAD_ERR_NO_FILE) { + return null; + } + + if (!$file->isValid()) { + throw new \RuntimeException('File upload failed for ' . $fieldName); + } + + $allowedMime = [ + 'image/jpg', + 'image/jpeg', + 'image/pjpeg', + 'image/png', + 'image/x-png', + 'image/webp', + 'application/pdf' + ]; + + $mimeType = (string) $file->getMimeType(); + if (!in_array($mimeType, $allowedMime, true)) { + throw new \RuntimeException('Invalid file format for ' . $fieldName); + } + + $path = ROOTPATH . 'public/uploads/' . $uploadDir . '/'; + + if (!is_dir($path)) { + mkdir($path, 0755, true); + } + + $newName = $file->getRandomName(); + $file->move($path, $newName); + + return $newName; + } + + +} \ No newline at end of file diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index d46306d4..b3607027 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -539,6 +539,7 @@ class TicketController extends BaseController 'tm.emp_personal_mail', 'tm.mode_of_intimation', 'tm.claim_type', + 'tm.tpa_claim_type', 'tm.hospital_name', 'tm.doa', 'tm.dod', @@ -673,6 +674,7 @@ class TicketController extends BaseController 'tm.emp_personal_mail', 'tm.mode_of_intimation', 'tm.claim_type', + 'tm.tpa_claim_type', 'tm.hospital_name', 'tm.doa', 'tm.dod', @@ -2319,8 +2321,8 @@ class TicketController extends BaseController ->findAll(); foreach ($dataToSend['messages'] as &$message) { - $mail_content_converted = $this->convertHtmlToText($message['mail_content']); - $message['mail_content'] = $mail_content_converted; + // $mail_content_converted = $this->convertHtmlToText($message['mail_content']); + // $message['mail_content'] = $mail_content_converted; $claimFiles = new ClaimFilesModel(); $message["files_data"] = $claimFiles->where('is_active', 1) @@ -2436,7 +2438,7 @@ class TicketController extends BaseController //---- Email Trigger Part---------------------------------------------------------------------------------------------- - public function constructMailContent($ticket_id) + public function constructMailContent($ticket_id, $status_id = null) { $this->myLogger->logme('error', "Constructing mail content for Ticket ID: $ticket_id"); @@ -2452,9 +2454,14 @@ class TicketController extends BaseController $this->myLogger->logme('error', "Fetched ticket data: " . json_encode($ticket_data)); + if (!empty($status_id)) { + $ticket_data['claim_status_id'] = (int) $status_id; + } + // Fetch Email Template Data - $template_data = $this->ticketMasterModel->getTemplateDataByTicketID($ticket_id); - // print_r($template_data); die; + $template_data = !empty($status_id) + ? ($this->ticketMasterModel->getTemplateDataByStatusID((int) $status_id, (int) ($ticket_data['ticket_type_id'] ?? 0))[0] ?? null) + : $this->ticketMasterModel->getTemplateDataByTicketID($ticket_id); if (!$template_data) { $this->myLogger->logme('error', "No email template found for Claim Status ID: " . $ticket_data['claim_status_id']); @@ -2626,7 +2633,7 @@ class TicketController extends BaseController 'mail' => [$mail_data['emp_mail'], $ticket_data['emp_personal_mail'] ?? ""], 'subject' => $mail_data['mail_subject'], 'message' => $mail_data['mail_content'], - 'common' => [], + 'common' => ['module' => "claim", 'pk' => $mail_data['ticket_id']], 'cc' => $acm_mails['common_mails'], 'attachments' => [] ]; @@ -2824,7 +2831,7 @@ class TicketController extends BaseController 'mail' => $template_data['emp_mail'], 'subject' => $template_data['subject'], 'message' => $template_data['mail_content'], - 'common' => [], + 'common' => ['module' => "claim", 'pk' => $ticket_id], 'cc' => $acm_mails['common_mails'], 'attachments' => [] ]; @@ -2985,7 +2992,7 @@ class TicketController extends BaseController 'mail' => $head_mail['email'], 'subject' => $subject, 'message' => $message, - 'common' => [], + 'common' => ['module' => "claim", 'pk' => $ticket_data['id']], ]; $this->sendTrigger($emailData); @@ -3720,7 +3727,7 @@ class TicketController extends BaseController return $input; } - function convertTermsToDisplay(array $data) + public function convertTermsToDisplay(array $data) { $result = []; @@ -3900,6 +3907,106 @@ class TicketController extends BaseController return $result; } + public function getClaimTemplateData() + { + try { + $ticket_id = $this->request->getPost('ticket_id') ?? $this->request->getGet('ticket_id'); + $status_id = $this->request->getPost('status_id') ?? $this->request->getGet('status_id'); + + if (empty($ticket_id) || empty($status_id)) { + return $this->respond(['status' => false, 'message' => 'Ticket ID and Status ID are required'], 400); + } + + $mail_content = $this->constructMailContent($ticket_id, $status_id); + if ($mail_content) { + return $this->respond(['status' => true, 'data' => $mail_content], 200); + } + + return $this->respond(['status' => false, 'message' => 'Failed to construct mail content'], 200); + } catch (\Exception $e) { + $this->myLogger->logme('error', 'Error in getClaimTemplateData: ' . $e->getMessage() . ' in file ' . $e->getFile() . ' on line ' . $e->getLine() . $e->getTraceAsString()); + return $this->respond(['status' => false, 'message' => 'An error occurred while fetching template data'], 500); + } + } + + public function uploadApprovedLetterFromReply() + { + try { + $ticket_id = $this->request->getPost('ticket_id'); + $status_id = $this->request->getPost('status_id'); + $approvedLetterUrl = trim((string) $this->request->getPost('approved_letter')); + $approvedLetterFile = $this->request->getFile('approved_letter_file'); + + if (empty($ticket_id) || empty($status_id)) { + return $this->respond(['status' => false, 'message' => 'Ticket ID and Status ID are required'], 400); + } + + if ((int) $status_id !== 9) { + return $this->respond(['status' => false, 'message' => 'Approved letter upload is allowed only for APPROVED status'], 400); + } + + $ticket_data = $this->ticketMasterModel->getTicketDataByTicketID($ticket_id); + if (empty($ticket_data)) { + return $this->respond(['status' => false, 'message' => 'Ticket not found'], 404); + } + + if (!empty($ticket_data['approved_letter'])) { + return $this->respond([ + 'status' => false, + 'message' => 'Approved letter already available', + 'data' => ['approved_letter' => $ticket_data['approved_letter']], + ], 200); + } + + $hasApprovedLetterFile = $approvedLetterFile !== null + && $approvedLetterFile->isValid() + && $approvedLetterFile->getError() !== UPLOAD_ERR_NO_FILE; + + if ($approvedLetterUrl !== '' && $hasApprovedLetterFile) { + return $this->respond([ + 'status' => false, + 'message' => 'Provide either Approved Letter URL or Approved Letter PDF file, not both.', + ], 400); + } + + if ($approvedLetterUrl !== '' && !$this->isClaimUploadUrl($approvedLetterUrl)) { + return $this->respond(['status' => false, 'message' => 'Approved Letter URL format is invalid.'], 400); + } + + if ($approvedLetterUrl === '' && !$hasApprovedLetterFile) { + return $this->respond(['status' => false, 'message' => 'Provide Approved Letter URL or Approved Letter PDF file.'], 400); + } + + $approvedLetterValue = $approvedLetterUrl; + if ($hasApprovedLetterFile) { + $uploadResult = $this->uploadApprovedLetterPdf($approvedLetterFile, 'Approved Letter'); + if (!($uploadResult['status'] ?? false)) { + return $this->respond(['status' => false, 'message' => $uploadResult['message'] ?? 'Invalid Approved Letter file.'], 400); + } + + $approvedLetterValue = $this->createApprovedLetterFileUrl( + (int) $ticket_id, + (int) ($ticket_data['ticket_type_id'] ?? 1), + $uploadResult['data'], + 'APPROVED_LETTER_PDF' + ); + } + + $this->ticketMasterModel + ->where('id', (int) $ticket_id) + ->set(['approved_letter' => $approvedLetterValue]) + ->update(); + + return $this->respond([ + 'status' => true, + 'message' => 'Approved letter uploaded successfully', + 'data' => ['approved_letter' => $approvedLetterValue], + ], 200); + } catch (\Exception $e) { + $this->myLogger->logme('error', 'Error in uploadApprovedLetterFromReply: ' . $e->getMessage() . ' in file ' . $e->getFile() . ' on line ' . $e->getLine() . $e->getTraceAsString()); + return $this->respond(['status' => false, 'message' => 'An error occurred while uploading approved letter'], 500); + } + } // -------- CLAIM DUMP UPLOAD ---------------------------------------------------------------------------------------------- diff --git a/app/Filters/AclFilter.php b/app/Filters/AclFilter.php index c3b052b8..d629afa7 100644 --- a/app/Filters/AclFilter.php +++ b/app/Filters/AclFilter.php @@ -143,7 +143,7 @@ class AclFilter implements FilterInterface $response = service('response'); $response->setStatusCode(403); - $response->setBody(view('errors/404', [ + $response->setBody(view('errors/403', [ 'message' => '403 Access denied - You do not have permission to access this resource' ])); diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index 475df9b1..d6202941 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -133,17 +133,20 @@ class TicketMasterModel extends Model return $data; } - public function getTemplateDataByStatusID($claim_status_id) + public function getTemplateDataByStatusID($claim_status_id, $ticket_type_id = null) { - - $template_data = $this->table('ticket_claim_status') + $builder = $this->db->table('ticket_claim_status tcs') ->select('ticket_mail_template.*') - ->join('ticket_mail_template', 'ticket_mail_template.trigger_type = ticket_claim_status.trigger_type') + ->join('ticket_mail_template', 'ticket_mail_template.trigger_type = tcs.trigger_type') ->where('ticket_mail_template.is_active', 1) - ->where('ticket_claim_status.is_active', 1) - ->where('ticket_claim_status.id', $claim_status_id) - ->get() - ->getResultArray(); + ->where('tcs.id', $claim_status_id) + ->where('tcs.is_active', 1); + + if ($ticket_type_id !== null && $ticket_type_id !== '') { + $builder->where('ticket_mail_template.ticket_type', $ticket_type_id); + } + + $template_data = $builder->get()->getResultArray(); return $template_data; } diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php index 96d441b0..c7618915 100755 --- a/app/Views/batch_list.php +++ b/app/Views/batch_list.php @@ -1,4 +1,5 @@ diff --git a/app/Views/claim_files_upload.php b/app/Views/claim_files_upload.php index 4a86c1bd..4a8380b7 100644 --- a/app/Views/claim_files_upload.php +++ b/app/Views/claim_files_upload.php @@ -163,7 +163,6 @@ \ No newline at end of file diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 57070c62..fd00a267 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -171,12 +171,16 @@ input:checked + .slider-branch-contact:before {
| S.No | @@ -243,7 +266,7 @@ $gst_total = 0;Policy status | (₹)Sum Insured | (₹)Premium | -(₹)Pro Rata Premium |
+ (₹)Pro Rata Premium | (₹)GST | Action | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| - - | - - | - - | - | - | - | - | - | - | - | - | - | - | - | Total | -- | - | + + + | Total | + ++ + | + + | + + |