Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
sanjeev.p 2026-04-22 11:45:05 +05:30
commit eb49f2b03a
11 changed files with 1008 additions and 334 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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();
}
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;
}
}

View File

@ -2438,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");
@ -2454,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']);
@ -2628,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' => []
];
@ -2826,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' => []
];
@ -2987,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);
@ -3722,7 +3727,7 @@ class TicketController extends BaseController
return $input;
}
function convertTermsToDisplay(array $data)
public function convertTermsToDisplay(array $data)
{
$result = [];
@ -3902,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 ----------------------------------------------------------------------------------------------

View File

@ -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;
}

View File

@ -196,14 +196,15 @@
<div class="form-group col-md-4">
<label for="issuer">Issuer<span class="text-danger">*</span></label>
<select class="form-control" id="issuer" name="issuer" required>
<option value="">Select Issuer</option>
<?php
<option value='2' selected>Nhance</option>;
<!-- <?php
if (isset($issuer) && count($issuer)) {
foreach ($issuer as $key => $value) {
echo "<option value=" . $key . ">" . $value . "</option>";
}
}
?>
?> -->
</select>
</div>
@ -229,14 +230,14 @@
<hr>
<div class="form-row">
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloverhide" style="display: none;">
<label for="client_id">Client<span class="text-danger">*</span></label>
<select class="form-control" id="client_id" name="client_id">
<option value="">Select Client</option>
</select>
</div>
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloverhide" style="display: none;">
<label for="client_branch_id">Branch<span class="text-danger">*</span></label>
<select class="form-control" id="client_branch_id" name="client_branch_id"
onchange="getBranchData(this,1)">
@ -343,7 +344,7 @@
placeholder="Enter Branch Code" required>
</div>
<div class="form-group col-md-4 renewalFields">
<div class="form-group col-md-4 renewalFields rolloverhide">
<label for="contact_person_summary">Contact Person<span class="text-danger">*</span></label>
<select class="form-control" name="contact_person_summary" id="contact_person_summary">
<option value="">Select a Contact</option>
@ -541,8 +542,8 @@
var lead_type = $(this).val();
var increment = 1; // Example increment value (modify as needed)
var start_date_id = (lead_type == "1" || lead_type == "3") ? `policy_start_date_${increment}` : "policy_start_date";
var end_date_id = (lead_type == "1" || lead_type == "3") ? `policy_end_date_${increment}` : "policy_end_date";
var start_date_id = (lead_type == "1") ? `policy_start_date_${increment}` : "policy_start_date";
var end_date_id = (lead_type == "1") ? `policy_end_date_${increment}` : "policy_end_date";
$(".policy_start_date").attr("id", start_date_id);
// $("label[for]").attr("for", start_date_id);
@ -553,7 +554,7 @@
// $('#leads_form_id')[0].reset();
// console.log("Updated ID:", newId);
if (lead_type == 1 || lead_type == 3) {
if (lead_type == 1) {
var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
dateFormat: "d/m/Y",
@ -561,8 +562,7 @@
onChange: function(selectedDates) {
var policy_end_date = new Date(selectedDates[0]);
policy_end_date.setFullYear(policy_end_date.getFullYear() + 1);
policy_end_date.setDate(policy_end_date.getDate() -
1); // Set end date to last day of selected year
policy_end_date.setDate(policy_end_date.getDate() - 1); // Set end date to last day of selected year
policy_end_datePicker.setDate(policy_end_date);
// console.log('this object', this);
@ -585,7 +585,7 @@
// }
}
});
} else if (lead_type != 1 && lead_type != 3) {
} else if (lead_type == 2) {
$("#source_policy_id").prop("required", true);
$("#source_policy_start_date").prop("required", true);
$("#source_policy_end_date").prop("required", true);
@ -624,7 +624,7 @@
}
if (lead_type != 1 && lead_type != 3) {
if (lead_type != 1) {
dataIncrement = 1;
// updateRenewalFields(dataIncrement);
@ -744,12 +744,9 @@
leadTypeBsedHideAndShow(lead_type)
if (lead_type == 1 || lead_type == 3) {
if (lead_type == 1) {
$('.claim-row').hide();
} else {
$('.claim-row').show();
if (policy_type_id == 1) {
$('.gpaClaimFileds').show();
@ -757,50 +754,50 @@
} else if (policy_type_id == 6 || policy_type_id == 7) {
$('.gpaClaimFileds').hide();
$('.lifeClaimFields').show();
} else {
// updateRenewalFields(dataIncrement);
// let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement;
let incurred_claim_date_id = 'incurred_claim_date';
var incurred_claim_datepicker = flatpickr("#" + incurred_claim_date_id, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function(selectedDates) {
console.log('Flatpickr instance:', this);
console.log('ID of this element:', this.input.id);
// Extract the increment value from the element's ID
let increment = this.input.id.split('_').pop();
console.log('Extracted increment:', increment);
let lead_type = $('#lead_type').val();
var policyStartDate = $("#source_policy_start_date");
if (lead_type == 3) {
policyStartDate = $("#policy_start_date");
}
console.log('Selected Dates:', selectedDates);
console.log('policy start date instance', policyStartDate)
console.log('Policy Start Date:', policyStartDate.val());
// Recalculate policy_run_days if policy start date is already selected
// if (policyStartDate.val()) {
// calculatePolicyRunDays(increment);
// }
}
});
// var premium_date_datepicker = flatpickr("#" + premium_date_id, {
// dateFormat: "d/m/Y",
// allowInput: false
// });
$('#proposed_insurer_' + dataIncrement).select2();
$('#proposed_tpa_' + dataIncrement).select2();
}
}
if (lead_type != 1 && policy_type_id != 1 && policy_type_id != 6 && policy_type_id != 7) {
// updateRenewalFields(dataIncrement);
// let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement;
let incurred_claim_date_id = 'incurred_claim_date';
var incurred_claim_datepicker = flatpickr("#" + incurred_claim_date_id, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function(selectedDates) {
console.log('Flatpickr instance:', this);
console.log('ID of this element:', this.input.id);
// Extract the increment value from the element's ID
let increment = this.input.id.split('_').pop();
console.log('Extracted increment:', increment);
let lead_type = $('#lead_type').val();
var policyStartDate = $("#source_policy_start_date");
if (lead_type == 3) {
policyStartDate = $("#policy_start_date");
}
console.log('Selected Dates:', selectedDates);
console.log('policy start date instance', policyStartDate)
console.log('Policy Start Date:', policyStartDate.val());
// Recalculate policy_run_days if policy start date is already selected
// if (policyStartDate.val()) {
// calculatePolicyRunDays(increment);
// }
}
});
// var premium_date_datepicker = flatpickr("#" + premium_date_id, {
// dateFormat: "d/m/Y",
// allowInput: false
// });
$('#proposed_insurer_' + dataIncrement).select2();
$('#proposed_tpa_' + dataIncrement).select2();
}
hide_list_show_add();
pageTitle = 'Edit Opportunities - (EB)';
@ -1131,12 +1128,9 @@
leadTypeBsedHideAndShow(lead_type)
if (lead_type == 1 || lead_type == 3) {
if (lead_type == 1) {
$('.claim-row').hide();
} else {
$('.claim-row').show();
if (policy_type_id == 1) {
@ -1145,47 +1139,47 @@
} else if (policy_type_id == 6 || policy_type_id == 7) {
$('.gpaClaimFileds').hide();
$('.lifeClaimFields').show();
} else {
if (lead_type == 1 || lead_type == 3) {
updateRenewalFields(dataIncrement);
}
// let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement;
let incurred_claim_date_id = 'incurred_claim_date';
var incurred_claim_datepicker = flatpickr("#" + incurred_claim_date_id, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function(selectedDates) {
console.log('Flatpickr instance:', this);
console.log('ID of this element:', this.input.id);
// Extract the increment value from the element's ID
let increment = this.input.id.split('_').pop();
console.log('Extracted increment:', increment);
var policyStartDate = $("#source_policy_start_date");
if (lead_type == 3) {
policyStartDate = $("#policy_start_date");
}
console.log('Selected Dates:', selectedDates);
console.log('policy start date instance', policyStartDate)
console.log('Policy Start Date:', policyStartDate.val());
// Recalculate policy_run_days if policy start date is already selected
// if (policyStartDate.val()) {
// calculatePolicyRunDays(increment);
// }
}
});
$('#proposed_insurer_' + dataIncrement).select2();
$('#proposed_tpa_' + dataIncrement).select2();
}
}
if (lead_type != 1 && policy_type_id != 1 && policy_type_id != 6 && policy_type_id != 7) {
if (lead_type == 1) {
updateRenewalFields(dataIncrement);
}
// let incurred_claim_date_id = 'incurred_claim_date_' + dataIncrement;
let incurred_claim_date_id = 'incurred_claim_date';
var incurred_claim_datepicker = flatpickr("#" + incurred_claim_date_id, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function(selectedDates) {
console.log('Flatpickr instance:', this);
console.log('ID of this element:', this.input.id);
// Extract the increment value from the element's ID
let increment = this.input.id.split('_').pop();
console.log('Extracted increment:', increment);
var policyStartDate = $("#source_policy_start_date");
if (lead_type == 3) {
policyStartDate = $("#policy_start_date");
}
console.log('Selected Dates:', selectedDates);
console.log('policy start date instance', policyStartDate)
console.log('Policy Start Date:', policyStartDate.val());
// Recalculate policy_run_days if policy start date is already selected
// if (policyStartDate.val()) {
// calculatePolicyRunDays(increment);
// }
}
});
$('#proposed_insurer_' + dataIncrement).select2();
$('#proposed_tpa_' + dataIncrement).select2();
}
} else {
console.log(response.message, 'WARNING');
}
@ -1287,7 +1281,7 @@
<div class="form-group col-md-4">
<label for="policy_start_date">Date of Commencement <span class="text-danger">*</span></label>
<div class="input-icon">
<input type="text" class="form-control policy_start_date" id="policy_start_date_${increment}" name="policy_start_date[]" placeholder="Enter DOC" onchange="calculatePolicyMetrics(this)">
<input type="text" class="form-control policy_start_date" id="policy_start_date_${increment}" name="policy_start_date[]" placeholder="Enter DOC" onchange="calculatePolicyMetrics(this)" autocomplete="off" >
<i class="mdi mdi-calendar-blank-outline additional-icon"></i>
</div>
@ -1296,7 +1290,7 @@
<div class="form-group col-md-4">
<label for="policy_end_date">Date of Expiry <span class="text-danger">*</span></label>
<div class="input-icon">
<input type="text" class="form-control policy_end_date" id="policy_end_date_${increment}" name="policy_end_date[]" placeholder="Enter DOE">
<input type="text" class="form-control policy_end_date" id="policy_end_date_${increment}" name="policy_end_date[]" placeholder="Enter DOE" autocomplete="off">
<i class="mdi mdi-calendar-blank-outline additional-icon"></i>
</div>
</div>
@ -1351,7 +1345,7 @@
// $(".policy_end_date").attr("id", end_date_id);
// Initialize date pickers
if (lead_type == 1 || lead_type == 3) {
if (lead_type == 1) {
var policy_start_datePicker = flatpickr("#policy_start_date_" + increment, {
dateFormat: "d/m/Y",
@ -1565,7 +1559,7 @@
console.log('Lead Type:', lead_type);
let increment = input.id.split('_').pop(); // Extract increment
if (lead_type == 1 || lead_type == 3) {
if (lead_type == 1) {
return;
}
@ -1683,7 +1677,7 @@
var lead_type = $('#lead_type').val();
if (lead_type == 1 || lead_type == 3) {
if (lead_type == 1) {
let formRow = input.closest('.form-row');
@ -1924,6 +1918,7 @@
onChange: function(selectedDates) {
try {
let increment = this.input.id.split('_').pop();
console.log('Incurred claim date changed:', selectedDates);
let policyStartDate = $("#source_policy_start_date");
if (policyStartDate.val()) {
calculatePolicyRunDays(increment);
@ -2301,7 +2296,7 @@
function leadTypeBsedHideAndShow(value, resetValues = false) {
if (value == 1 || value == 3) {
if (value == 1) {
$('.btnDiv').show();
$('.claim-row').hide();
@ -2317,6 +2312,56 @@
// $('.proposed_div').hide().find('select, input').removeAttr('required');
if (resetValues) {
$('#gst').val('');
$('#pan').val('');
$('#branch_name').val('');
$('#branch_code').val('');
$('#contact_person_name').val('');
$('#contact_person_mobile').val('');
$('#contact_person_email').val('');
$('#client_type').val('');
$('#client_name').val('');
$('#client_short_name').val('');
$('#entity_type_id').val('');
}
$('#exixting_client').removeAttr('required');
} else if (value == 3) {
$('.btnDiv').hide();
$('.claim-row').show();
$('.emp_title_text').text('No of Employees at Inception')
$('.depnd_title_text').text(' No of Dependents at Inception')
$('.total_title_text').text('Total Lives at Inception')
$('.freshFields').find('select, input').attr('required', 'required');
$('.freshFields').show();
$('.rolloOverFields').find('select, input').attr('required', 'required');
$('.renewalFields').show();
$('#source_policy_id').hide();
$('#source_policy_start_date').hide();
$('#source_policy_end_date').hide();
$('#source_policy_id').closest('.form-group').hide();
$('#source_policy_start_date').closest('.form-group').hide();
$('#source_policy_end_date').closest('.form-group').hide();
$('.source_policy_id').find('select, input').attr('required', 'required');
$('.source_policy_start_date').find('select, input').attr('required', 'required');
$('.source_policy_end_date').find('select, input').attr('required', 'required');
$('.rolloverhide').hide();
if (resetValues) {
$('#gst').val('');

View File

@ -935,6 +935,30 @@ if (isset($selected_lead_type)) {
}
}
if(lead_type == 3){
let incurred_claim_date_id = 'incurred_claim_date';
if ($('#' + incurred_claim_date_id).length) {
flatpickr("#" + incurred_claim_date_id, {
dateFormat: "d/m/Y",
allowInput: false,
onChange: function (selectedDates) {
try {
let increment = this.input.id.split('_').pop();
let policyStartDate = $("#source_policy_start_date");
if (policyStartDate.val()) {
calculatePolicyRunDays(increment);
}
} catch (error) {
console.error('Error in incurred_claim_datepicker:', error);
}
}
});
} else {
console.warn(`Incurred claim date field #${incurred_claim_date_id} not found.`);
}
}
// if (lead_type == 3) {
// $('#client_id').prepend($('<option>', {

View File

@ -233,6 +233,7 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
<input type="file" class="form-control" name="aadhar_file_name" id="aadhar_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation>
<i class="mdi mdi-upload additional-icon"></i>
</div>
<small id="aadhar_file_name_display" class="text-muted d-block" style="display:none !important;"></small>
<small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small>
</div>
<div class="form-group col-md-4">
@ -241,6 +242,7 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
<input type="file" class="form-control" name="pan_file_name" id="pan_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation>
<i class="mdi mdi-upload additional-icon"></i>
</div>
<small id="pan_file_name_display" class="text-muted d-block" style="display:none !important;"></small>
<small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small>
</div>
<div class="form-group col-md-4">
@ -249,6 +251,7 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
<input type="file" class="form-control" name="certificate_file_name" id="certificate_file_name" accept=".pdf,.jpg,.jpeg,.png" data-parsley-file-validation>
<i class="mdi mdi-upload additional-icon"></i>
</div>
<small id="certificate_file_name_display" class="text-muted d-block" style="display:none !important;"></small>
<small class="text-muted d-block">Allowed: PDF, PNG, JPG, JPEG.</small>
</div>
</div>
@ -433,11 +436,17 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
},
error: function (xhr) {
$('.loader, .loader-mask').fadeOut();
let response = null;
try {
response = xhr.responseText ? JSON.parse(xhr.responseText) : null;
} catch (e) {
response = null;
}
if (xhr.status === 400) {
let response = JSON.parse(xhr.responseText);
let errorMessages = "";
let seenMessages = []; // Array to store unique messages
if (response.errors) {
if (response && response.errors) {
$.each(response.errors, function (field, message) {
if (!seenMessages.includes(message)) {
errorMessages += `• ${message}<br>`;
@ -446,16 +455,15 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
});
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
} else {
toastr.warning(response.message || 'Validation failed', 'Warning');
toastr.warning((response && response.message) ? response.message : 'Validation failed', 'Warning');
}
} else if (xhr.status === 403) {
let response = JSON.parse(xhr.responseText);
toastr.error(response.message, 'Security Policy');
toastr.error((response && response.message) ? response.message : 'Security policy error', 'Security Policy');
} else if (xhr.status === 500) {
toastr.error('Something went wrong . Please try again later.', 'Server Error');
toastr.error((response && response.message) ? response.message : 'Something went wrong . Please try again later.', 'Server Error');
} else {
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
toastr.error((response && response.message) ? response.message : 'An unexpected error occurred. Please try again later.', 'Error');
}
console.error('Unexpected error:', xhr.responseText);
@ -470,9 +478,32 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
$('#partnerPOSForm').parsley().reset();
}
$('#manager_id').val(null).trigger('change');
updateFileNameDisplay('#aadhar_file_name', '#aadhar_file_name_display', '');
updateFileNameDisplay('#pan_file_name', '#pan_file_name_display', '');
updateFileNameDisplay('#certificate_file_name', '#certificate_file_name_display', '');
}
function updateFileNameDisplay(inputSelector, displaySelector, existingName = '') {
const $display = $(displaySelector);
let fileName = '';
if (existingName && String(existingName).trim() !== '') {
fileName = String(existingName).trim();
} else {
const inputEl = $(inputSelector)[0];
if (inputEl && inputEl.files && inputEl.files.length > 0) {
fileName = inputEl.files[0].name || '';
}
}
if (fileName) {
$display.text('Uploaded: ' + fileName).show();
} else {
$display.text('').hide();
}
}
function appendEditData(data){
$('#pos_id').val(data.id);
@ -481,14 +512,12 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
$('#mobile').val(data.mobile);
$('#pos_code').val(data.pos_code);
// Instead of setting the file input
$('#current_file_name').text(data['certificate_file_name'] || 'No file uploaded');
$('#aadhar').val(data.aadhar);
$('#aadhar_file_name').text(data['aadhar_file_name'] || 'No file uploaded');
updateFileNameDisplay('#aadhar_file_name', '#aadhar_file_name_display', data['aadhar_file_name'] || '');
$('#pan').val(data.pan);
$('#pan_file_name').text(data['pan_file_name'] || 'No file uploaded');
updateFileNameDisplay('#pan_file_name', '#pan_file_name_display', data['pan_file_name'] || '');
updateFileNameDisplay('#certificate_file_name', '#certificate_file_name_display', data['certificate_file_name'] || '');
$('#bank_name').val(data.bank_name);
$('#account_holder_name').val(data.account_holder_name);
@ -508,6 +537,18 @@ $pos_col_width_px = nhance_dt_column_widths_px($pos_header_labels, $pos_col_max_
});
}
$('#aadhar_file_name').on('change', function () {
updateFileNameDisplay('#aadhar_file_name', '#aadhar_file_name_display');
});
$('#pan_file_name').on('change', function () {
updateFileNameDisplay('#pan_file_name', '#pan_file_name_display');
});
$('#certificate_file_name').on('change', function () {
updateFileNameDisplay('#certificate_file_name', '#certificate_file_name_display');
});
$('#aadhar').on('input', function () {
this.value = this.value.replace(/[^0-9]/g, '');

View File

@ -5,75 +5,75 @@
<div class="form-row renewalCalculation">
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="incurred_claim_date">Incurred Claim Date<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['incurred_claims_date']) ? $lead_edit_data['incurred_claims_date'] : '' ?>" type="text" class="form-control incurred_claim" id="incurred_claim_date<?= $increment ?>"
name="incurred_claim_date[]" placeholder="Enter DOE" oninput="calculatePolicyMetrics(this)">
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="paid_claims">Paid Claims<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['paid_claims']) ? $lead_edit_data['paid_claims'] : '' ?>" type="text" class="form-control" id="paid_claims<?= $increment ?>" name="paid_claims[]"
placeholder="Enter Paid Claims" oninput="calculatePolicyMetrics(this)">
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="outstanding_claims">Outstanding Claims<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['outstanding_claims']) ? $lead_edit_data['outstanding_claims'] : '' ?>" type="text" class="form-control" id="outstanding_claims<?= $increment ?>" name="outstanding_claims[]"
placeholder="Enter Outstanding Claims" oninput="calculatePolicyMetrics(this)">
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="incurred_claims">Incurred Claim<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['incurred_claims']) ? $lead_edit_data['incurred_claims'] : '' ?>" type="text" class="form-control" id="incurred_claims<?= $increment ?>" name="incurred_claims[]"
placeholder="Enter Incurred Claim" oninput="calculatePolicyMetrics(this)" readonly>
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="policy_run_days">Policy Run Days<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['policy_run_days']) ? $lead_edit_data['policy_run_days'] : '' ?>" type="text" class="form-control" id="policy_run_days<?= $increment ?>" name="policy_run_days[]"
placeholder="Enter Policy Run Days" oninput="calculatePolicyMetrics(this)" readonly>
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="premium_at_inception">Premium Paid at Inception<span
class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['premium_at_inception']) ? $lead_edit_data['premium_at_inception'] : '' ?>" type="text" class="form-control" id="premium_at_inception<?= $increment ?>" name="premium_at_inception[]"
placeholder="Enter Premium Paid" oninput="calculatePolicyMetrics(this)">
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="premium_date">Premium as on Date<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['premium_date']) ? $lead_edit_data['premium_date'] : '' ?>" type="text" class="form-control" id="premium_date<?= $increment ?>" name="premium_date[]"
placeholder="Enter Premium Date" oninput="calculatePolicyMetrics(this)">
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="earned_premium">Earned Premium<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['earned_premium']) ? $lead_edit_data['earned_premium'] : '' ?>" type="text" class="form-control" id="earned_premium<?= $increment ?>" name="earned_premium[]"
placeholder="Enter Earned Premium" oninput="calculatePolicyMetrics(this)" readonly>
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="annualised_claims">Annualised Claims<span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['annualised_claims']) ? $lead_edit_data['annualised_claims'] : '' ?>" type="text" class="form-control" id="annualised_claims<?= $increment ?>" name="annualised_claims[]"
placeholder="Enter Annualised Claims" oninput="calculatePolicyMetrics(this)" readonly>
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="incurred_claims_ratio">Incurred Claims Ratio(%) <span
class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['incurred_claims_ratio']) ? $lead_edit_data['incurred_claims_ratio'] : '' ?>" type="text" class="form-control" id="incurred_claims_ratio<?= $increment ?>"
name="incurred_claims_ratio[]" placeholder="Enter Incurred Claims Ratio" readonly>
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="earned_claims_ratio">Earned Claims Ratio(%) <span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['earned_claims_ratio']) ? $lead_edit_data['earned_claims_ratio'] : '' ?>" type="text" class="form-control" id="earned_claims_ratio<?= $increment ?>" name="earned_claims_ratio[]"
placeholder="Enter Earned Claims Ratio" readonly>
</div>
<div class="form-group col-md-3 renewalFields" style="display: none;">
<div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<span class="info-icon-wrapper">
<i class="mdi mdi-information-outline text-primary"></i>
<div class="info-tooltip">
@ -89,7 +89,7 @@
</div>
<!-- <div class="form-group col-md-3 renewalFields" style="display: none;">
<!-- <div class="form-group col-md-3 renewalFields rolloOverFields" style="display: none;">
<label for="location">Location <span class="text-danger">*</span></label>
<input value="<?php //echo isset($lead_edit_data['location']) ? $lead_edit_data['location'] : '' ?>" type="text" class="form-control" id="location" name="location[]" placeholder="Enter Location">
</div> -->
@ -161,20 +161,20 @@
<div class="form-row">
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloOverFields" style="display: none;">
<label for="exp_emp_count"> No of Employees at Expiry <span class="text-danger"></span></label>
<input value="<?= isset($lead_edit_data['exp_emp_count']) ? $lead_edit_data['exp_emp_count'] : '' ?>" type="text" class="form-control" id="exp_emp_count" name="exp_emp_count[]"
placeholder="Enter Lives">
</div>
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloOverFields" style="display: none;">
<label for="exp_dept_count"> No of Dependents at Expiry <span
class="text-danger"></span></label>
<input value="<?= isset($lead_edit_data['exp_dept_count']) ? $lead_edit_data['exp_dept_count'] : '' ?>" type="text" class="form-control" id="exp_dept_count" name="exp_dept_count[]"
placeholder="Enter Lives">
</div>
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloOverFields" style="display: none;">
<label for="exp_no_of_lives"> Total Lives at Expiry <span class="text-danger"></span></label>
<input value="<?= isset($lead_edit_data['exp_no_of_lives']) ? $lead_edit_data['exp_no_of_lives'] : '' ?>" type="text" class="form-control" id="exp_no_of_lives" name="exp_no_of_lives[]"
placeholder="Enter Lives">
@ -184,21 +184,21 @@
<div class="form-row">
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloOverFields" style="display: none;">
<label for="renewal_emp_count"> No of Employees at Renewal <span
class="text-danger"></span></label>
<input value="<?= isset($lead_edit_data['renewal_emp_count']) ? $lead_edit_data['renewal_emp_count'] : '' ?>" type="text" class="form-control" id="renewal_emp_count" name="renewal_emp_count[]"
placeholder="Enter Lives">
</div>
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloOverFields" style="display: none;">
<label for="renewal_dept_count"> No of Dependents at Renewal <span
class="text-danger"></span></label>
<input value="<?= isset($lead_edit_data['renewal_dept_count']) ? $lead_edit_data['renewal_dept_count'] : '' ?>" type="text" class="form-control" id="renewal_dept_count" name="renewal_dept_count[]"
placeholder="Enter Lives">
</div>
<div class="form-group col-md-4 renewalFields" style="display: none;">
<div class="form-group col-md-4 renewalFields rolloOverFields" style="display: none;">
<label for="renewal_no_of_lives"> Total Lives at Renewal <span
class="text-danger"></span></label>
<input value="<?= isset($lead_edit_data['renewal_no_of_lives']) ? $lead_edit_data['renewal_no_of_lives'] : '' ?>" type="text" class="form-control" id="renewal_no_of_lives" name="renewal_no_of_lives[]"

View File

@ -13,25 +13,25 @@
<div class="form-group col-md-4">
<label for="total_lives_at_incept" class="total_title">
<span class="total_title_text"> Total Lives at Inception </span> <span class="text-danger"></span></label>
<input value="<?= isset($lead_edit_data['total_lives_at_incept']) ? $lead_edit_data['total_lives_at_incept'] : '' ?>" type="text" class="form-control" id="total_lives_at_incept" name="total_lives_at_incept[]" placeholder="Enter Lives" disabled>
<input value="<?= isset($lead_edit_data['total_lives_at_incept']) ? $lead_edit_data['total_lives_at_incept'] : '' ?>" type="text" class="form-control" id="total_lives_at_incept" name="total_lives_at_incept[]" placeholder="Enter Lives">
</div>
<div class="form-group col-md-4 renewalFields">
<div class="form-group col-md-4 renewalFields rolloOverFields">
<label for="total_si_at_incept"> Total Sum Insured at Inception <span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['total_si_at_incept']) ? $lead_edit_data['total_si_at_incept'] : '' ?>" type="text" class="form-control" id="total_si_at_incept" name="total_si_at_incept[]" placeholder="Enter Sum Insured" required>
</div>
<div class="form-group col-md-4 renewalFields">
<div class="form-group col-md-4 renewalFields rolloOverFields">
<label for="premium_at_incept"> Premium at inception <span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['premium_at_incept']) ? $lead_edit_data['premium_at_incept'] : '' ?>" type="text" class="form-control" id="premium_at_incept" name="premium_at_incept[]" placeholder="Enter Premium" required>
</div>
<div class="form-group col-md-4 renewalFields">
<div class="form-group col-md-4 renewalFields rolloOverFields">
<label for="renewal_emp_count"> No of Employees at Renewal <span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['renewal_emp_count']) ? $lead_edit_data['renewal_emp_count'] : '' ?>" type="text" class="form-control" id="renewal_emp_count" name="renewal_emp_count[]" placeholder="Enter Lives" >
</div>
<div class="form-group col-md-4 renewalFields">
<div class="form-group col-md-4 renewalFields rolloOverFields">
<label for="total_si_at_renewal"> Total Sum Insured at Renewal <span class="text-danger">*</span></label>
<input value="<?= isset($lead_edit_data['total_si_at_renewal']) ? $lead_edit_data['total_si_at_renewal'] : '' ?>" type="text" class="form-control" id="total_si_at_renewal" name="total_si_at_renewal[]" placeholder="Enter Sum Insured" >
</div>

View File

@ -4,6 +4,27 @@
<form role="form" class="parsley-examples" style="color:black;" method="post" id="ticket_reply_form" enctype="multipart/form-data">
<div class="form-group">
<div class="form-row">
<?php
$showApprovedStatusDropdown =
isset($ticket_data['claim_status_id'], $ticket_data['ticket_type_id']) && (int) $ticket_data['claim_status_id'] === 10 && (int) $ticket_data['ticket_type_id'] === 1 &&
(
(isset($ticket_data['claim_created_by']) && $ticket_data['claim_created_by'] == 'TPA') ||
(array_key_exists('tpa_claim_push_reference_no', $ticket_data) && $ticket_data['tpa_claim_push_reference_no'] !== null)
);
?>
<?php if ($showApprovedStatusDropdown): ?>
<div class="form-group col-md-4">
<label for="status_back_option">Status</label>
<select class="form-control" id="status_back_option">
<option value="">Select</option>
<option value="9">APPROVED</option>
</select>
</div>
<?php endif; ?>
<!-- Email To Field -->
<div class="form-group col-md-4">
<label for="emp_mail_for_to">To</label>
@ -46,10 +67,140 @@
</div>
</div>
<style>
.approved-letter-mode-option {
border: 1px solid #dee2e6;
border-radius: 8px;
padding: 10px 12px;
margin-bottom: 10px;
cursor: pointer;
}
.approved-letter-mode-option.selected {
border-color: #0a8794;
background-color: #f2fbfc;
}
</style>
<div class="modal fade" id="approvedLetterUploadModal" tabindex="-1" role="dialog" aria-labelledby="approvedLetterUploadModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="approvedLetterUploadModalLabel">Upload Approved Letter</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="approved-letter-mode-option selected" onclick="selectApprovedLetterOption(this, 'approved_letter_mode_url')">
<div class="form-check">
<input class="form-check-input" type="radio" name="approved_letter_mode" id="approved_letter_mode_url" value="url" checked>
<label class="form-check-label" for="approved_letter_mode_url">Approved Letter URL</label>
</div>
</div>
<div class="approved-letter-mode-option" onclick="selectApprovedLetterOption(this, 'approved_letter_mode_pdf')">
<div class="form-check">
<input class="form-check-input" type="radio" name="approved_letter_mode" id="approved_letter_mode_pdf" value="pdf">
<label class="form-check-label" for="approved_letter_mode_pdf">Approved Letter PDF</label>
</div>
</div>
<div class="form-group" id="approved_letter_url_block">
<label for="approved_letter_reply_url">Approved Letter URL</label>
<input type="text" class="form-control" id="approved_letter_reply_url" placeholder="Enter Approved Letter URL">
<small class="text-danger d-none" id="approved_letter_reply_url_error"></small>
</div>
<div class="form-group mb-0" id="approved_letter_pdf_block" style="display:none;">
<label for="approved_letter_reply_file">Approved Letter PDF</label>
<input type="file" class="form-control" id="approved_letter_reply_file" accept=".pdf,application/pdf">
<small class="text-muted">Only PDF is allowed for file upload.</small>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="uploadApprovedLetterBtn">Upload</button>
</div>
</div>
</div>
</div>
<script>
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
function selectApprovedLetterOption(element, inputId) {
$('.approved-letter-mode-option').removeClass('selected');
$(element).addClass('selected');
$('#' + inputId).prop('checked', true).trigger('change');
}
function validateApprovedLetterPdf(fileInput) {
const file = fileInput.files && fileInput.files[0] ? fileInput.files[0] : null;
if (!file) {
return true;
}
const fileName = (file.name || '').toLowerCase();
const isPdfByName = fileName.endsWith('.pdf');
const mimeType = (file.type || '').toLowerCase();
const isPdfByType = mimeType === '' || mimeType === 'application/pdf' || mimeType === 'application/x-pdf';
if (!isPdfByName || !isPdfByType) {
fileInput.value = '';
toastr.warning('Only PDF files are allowed for Approved Letter.', 'Warning');
return false;
}
return true;
}
function isValidApprovedLetterUrl(urlValue) {
const url = (urlValue || '').trim();
if (!url) {
return false;
}
try {
const normalizedUrl = /^https?:\/\//i.test(url) ? url : `https://${url}`;
const parsed = new URL(normalizedUrl);
if (!['http:', 'https:'].includes(parsed.protocol)) {
return false;
}
const host = (parsed.hostname || '').toLowerCase();
if (!host) {
return false;
}
if (host === 'localhost') {
return true;
}
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(host)) {
return true;
}
return host.includes('.');
} catch (e) {
return false;
}
}
function setApprovedLetterUrlError(message) {
const $urlInput = $('#approved_letter_reply_url');
const $errorEl = $('#approved_letter_reply_url_error');
if (message) {
$urlInput.addClass('is-invalid');
$errorEl.text(message).removeClass('d-none');
} else {
$urlInput.removeClass('is-invalid');
$errorEl.text('').addClass('d-none');
}
}
const editorConfig = {
buttons: toolbar.concat(['fontsize']),
fontsize: [8, 10, 12, 14, 16, 18, 20, 22, 24], // Customize font sizes
@ -71,6 +222,13 @@ const editorConfig = {
};
$(document).ready(function() {
const replyTicketId = `<?= isset($ticket_data['id']) ? (int) $ticket_data['id'] : 0 ?>`;
let replyApprovedLetter = <?= json_encode($ticket_data['approved_letter'] ?? null) ?>;
console.log('Approved Letter from server:', replyApprovedLetter);
function hasApprovedLetterValue(value) {
return value !== null && value !== undefined && String(value).trim() !== '';
}
var toolbar = "bold,italic,strikethrough,|,superscript,subscript,|,align,";
@ -134,6 +292,216 @@ $(document).ready(function() {
}
});
async function loadClaimTemplateForStatus(ticketId, statusId) {
if (!ticketId || !statusId) {
return;
}
$.ajax({
url: '<?= base_url('/ticket/getClaimTemplateData') ?>',
type: 'POST',
dataType: 'json',
data: {
ticket_id: ticketId,
status_id: statusId
},
success: function(res) {
if (res && res.status && res.data) {
if (typeof res.data.subject !== 'undefined') {
$('#mail_subject').val(res.data.subject || '');
}
if (typeof res.data.message !== 'undefined') {
editor.value = res.data.message || '';
}
} else {
toastr.warning(res.message || 'Failed to load mail template', 'Warning');
}
},
error: function(xhr) {
console.error(xhr.responseText);
toastr.error('Unable to fetch mail template.', 'Error');
}
});
}
function openApprovedLetterUploadModalAndHandle(ticketId, statusId) {
const dfd = $.Deferred();
const $modal = $('#approvedLetterUploadModal');
const $modeUrl = $('#approved_letter_mode_url');
const $modePdf = $('#approved_letter_mode_pdf');
const $urlBlock = $('#approved_letter_url_block');
const $pdfBlock = $('#approved_letter_pdf_block');
const $urlInput = $('#approved_letter_reply_url');
const $fileInput = $('#approved_letter_reply_file');
const $uploadBtn = $('#uploadApprovedLetterBtn');
const approvedLetterModalEl = document.getElementById('approvedLetterUploadModal');
const approvedLetterModalInstance = new bootstrap.Modal(approvedLetterModalEl, {
backdrop: 'static',
keyboard: false
});
$urlInput.val('');
$fileInput.val('');
$modeUrl.prop('checked', true).trigger('change');
$('.approved-letter-mode-option').removeClass('selected');
$('.approved-letter-mode-option').first().addClass('selected');
$uploadBtn.prop('disabled', false);
approvedLetterModalInstance.show();
function cleanup() {
$uploadBtn.off('click.approvedUpload');
$modal.off('hidden.bs.modal.approvedUpload');
$modeUrl.off('change.approvedUpload');
$modePdf.off('change.approvedUpload');
}
$modal.on('hidden.bs.modal.approvedUpload', function() {
cleanup();
if (dfd.state() === 'pending') {
dfd.reject('Upload cancelled');
}
});
$modeUrl.on('change.approvedUpload', function() {
if ($(this).is(':checked')) {
$urlBlock.show();
$pdfBlock.hide();
$fileInput.val('');
}
});
$modePdf.on('change.approvedUpload', function() {
if ($(this).is(':checked')) {
$pdfBlock.show();
$urlBlock.hide();
$urlInput.val('');
}
});
$urlInput.on('input.approvedUpload', function() {
const currentValue = $.trim($(this).val());
if (currentValue === '') {
setApprovedLetterUrlError('');
return;
}
if (!isValidApprovedLetterUrl(currentValue)) {
setApprovedLetterUrlError('Approved Letter URL format is invalid.');
} else {
setApprovedLetterUrlError('');
}
});
$urlInput.on('blur.approvedUpload', function() {
const currentValue = $.trim($(this).val());
if (currentValue === '') {
setApprovedLetterUrlError('');
return;
}
if (!isValidApprovedLetterUrl(currentValue)) {
setApprovedLetterUrlError('Approved Letter URL format is invalid.');
} else {
setApprovedLetterUrlError('');
}
});
$fileInput.on('change.approvedUpload', function() {
validateApprovedLetterPdf(this);
});
$uploadBtn.on('click.approvedUpload', function() {
const selectedMode = $('input[name="approved_letter_mode"]:checked').val();
const urlValue = $.trim($urlInput.val());
const file = $fileInput[0].files && $fileInput[0].files[0] ? $fileInput[0].files[0] : null;
if (selectedMode === 'url' && !urlValue) {
setApprovedLetterUrlError('Please enter Approved Letter URL.');
return;
}
if (selectedMode === 'url' && !isValidApprovedLetterUrl(urlValue)) {
setApprovedLetterUrlError('Approved Letter URL format is invalid.');
return;
}
setApprovedLetterUrlError('');
if (selectedMode === 'pdf' && !file) {
toastr.warning('Please select Approved Letter PDF.', 'Warning');
return;
}
if (selectedMode === 'pdf' && file) {
if (!validateApprovedLetterPdf($fileInput[0])) {
return;
}
}
const formData = new FormData();
formData.append('ticket_id', ticketId);
formData.append('status_id', statusId);
formData.append('approved_letter', selectedMode === 'url' ? urlValue : '');
if (selectedMode === 'pdf' && file) {
formData.append('approved_letter_file', file);
}
$uploadBtn.prop('disabled', true);
$.ajax({
url: '<?= base_url('/ticket/uploadApprovedLetterFromReply') ?>',
type: 'POST',
data: formData,
processData: false,
contentType: false,
dataType: 'json',
success: function(res) {
if (res && res.status) {
replyApprovedLetter = (res.data && res.data.approved_letter) ? res.data.approved_letter : replyApprovedLetter;
toastr.success(res.message || 'Approved letter uploaded successfully', 'Success');
cleanup();
approvedLetterModalInstance.hide();
dfd.resolve();
} else {
$uploadBtn.prop('disabled', false);
toastr.error((res && res.message) ? res.message : 'Approved letter upload failed', 'Error');
}
},
error: function(xhr) {
$uploadBtn.prop('disabled', false);
console.error(xhr.responseText);
toastr.error('Unable to upload approved letter.', 'Error');
}
});
});
return dfd.promise();
}
function handleStatusTemplateFlow() {
const selectedStatusId = $('#status_back_option').val();
if (!selectedStatusId || !replyTicketId) {
return;
}
if (String(selectedStatusId) === '9' && !hasApprovedLetterValue(replyApprovedLetter)) {
openApprovedLetterUploadModalAndHandle(replyTicketId, selectedStatusId)
.done(function() {
loadClaimTemplateForStatus(replyTicketId, selectedStatusId);
});
return;
}
loadClaimTemplateForStatus(replyTicketId, selectedStatusId);
}
$('#status_back_option').on('change', function() {
handleStatusTemplateFlow();
});
if ($('#status_back_option').length && hasApprovedLetterValue(replyApprovedLetter)) {
const selectedStatusId = $('#status_back_option').val();
if (selectedStatusId) {
loadClaimTemplateForStatus(replyTicketId, selectedStatusId);
}
}
function insertAtCursor(input, textToInsert) {
if (document.selection) {
input.focus();