nhance/app/Views/ticket_edit_onbording.php
2026-05-19 17:50:04 +05:30

516 lines
23 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style>
.bg-staff {
background-color: #FFF5E5;
}
.label-font-size {
font-size: 0.875rem;
}
.nav-pills,
.nav-link {
background-color: #F5FFFF !important;
color: #00999E !important;
border-radius: 10px;
}
.nav-pills {
background-color: #F5FFFF !important;
color: #00999E !important;
box-shadow: 0px 2px 4px 0px #00000040;
padding-top: 5px;
}
.nav-link.active-tab {
color: white !important;
background-color: #00999E !important;
font-size: small !important;
padding: 8px 16px;
border-radius: 10px !important;
box-shadow: 0px 2px 4px 0px #00000040;
}
</style>
<div class="row">
<div class="col-12">
<div class="card" style="margin-right: 23px;">
<div class="card-body">
<?php
$tpaActionButtons = '';
if (
!empty($ticket_data['is_tpa_api_service_enabled']) &&
empty($ticket_data['tpa_claim_push_reference_no']) &&
($ticket_data['claim_created_by'] ?? '') !== 'TPA'
) {
$tpaActionButtons .= ' <a href="#" class="btn btn-success btn-sm mr-2" onclick="manualTpaClaimPush(); return false;">Manual TPA Claim Push</a>';
}
if (!empty($ticket_data['tpa_claim_push_reference_no'])) {
$tpaActionButtons .= ' <a href="#" class="btn btn-success btn-sm mr-2" onclick="fetchTpaClaimStatus(); return false;">Fetch Claim Status</a>';
}
?>
<script>
var pageHideMainNavTitle = true;
var pageTitle = 'Claims <?= $tpaActionButtons ?>';
var pageBackButton = '<a href="<?= base_url("ticket/list"); ?>" class="topbar-icon-btn" data-toggle="tooltip" data-placement="top" title="Back" aria-label="Back to list"><i class="ri-arrow-left-s-line"></i></a>';
</script>
<!-- Header Section (TPA actions rendered in top navbar via pageTitle) -->
<!-- <div class="row mb-3 align-items-center justify-content-between">
<div class="col-auto">
<h4 class="mb-0">Claims</h4>
</div>
<div class="col-auto d-flex align-items-center">
<?php if (
$ticket_data['is_tpa_api_service_enabled'] == true &&
empty($ticket_data['tpa_claim_push_reference_no']) &&
$ticket_data['claim_created_by'] != 'TPA'
) : ?>
<a href="#" class="btn btn-success mr-2" onclick="manualTpaClaimPush(); return false;">
Manual TPA Claim Push
</a>
<?php endif; ?>
<?php if(isset($ticket_data['tpa_claim_push_reference_no']) && !empty($ticket_data['tpa_claim_push_reference_no'])) : ?>
<a href="#" class="btn btn-success mr-2" onclick="fetchTpaClaimStatus()">
Fetch Claim Status
</a>
<?php endif; ?>
<a href="<?= base_url('ticket/list'); ?>" aria-label="Back to ticket list">
<i class="mdi mdi-arrow-left" style="font-size: 24px;"></i>
</a>
</div>
</div> -->
<!-- Navigation Tabs -->
<div class="tab-wrapper position-relative">
<ul class="nav nav-pills navtab-bg" id="myTab">
<li class="nav-item d-flex justify-content-center align-items-center">
<button class="scroll-btn left-btn" type="button">&#9664;</button>
</li>
<li class="nav-item">
<a href="#general-tab" data-toggle="tab" class="nav-link px-3 py-2 active label-font-size" id="general_tab"
aria-expanded="true">
<i class="mdi mdi-ticket-account"></i>
<span class="d-none d-sm-inline-block ">General</span>
</a>
</li>
<li class="nav-item">
<a href="#reply-tab" data-toggle="tab" class="nav-link px-3 py-2 label-font-size" id="reply_tab"
aria-expanded="false">
<i class="mdi mdi-message-processing"></i>
<span class="d-none d-sm-inline-block">Reply</span>
</a>
</li>
<li class="nav-item">
<a href="#note-tab" data-toggle="tab" class="nav-link px-3 py-2 label-font-size" id="note_tab"
aria-expanded="false">
<i class="mdi mdi-note-text"></i>
<span class="d-none d-sm-inline-block">Notes</span>
</a>
</li>
<li class="nav-item">
<a href="#history-tab" data-toggle="tab" class="nav-link px-3 py-2 label-font-size" id="history_tab"
aria-expanded="false">
<i class="mdi mdi-history"></i>
<span class="d-none d-sm-inline-block">History</span>
</a>
</li>
<?php if (in_array($ticket_data['ticket_type_id'], [1, 2, 3, 4, 5, 6, 7])) { ?>
<li class="nav-item">
<a href="#autoQuery-tab" data-toggle="tab" class="nav-link px-3 py-2 label-font-size" id="auto_query_tab"
aria-expanded="false">
<i class="mdi mdi-robot mr-1"></i>
<span class="d-none d-sm-inline-block">Auto Query Content</span>
</a>
</li>
<?php } ?>
<li class="nav-item">
<a href="#uploads-tab" data-toggle="tab" class="nav-link px-3 py-2 label-font-size" id="uploads_tab"
aria-expanded="false">
<i class="mdi mdi-file mr-1"></i>
<span class="d-none d-sm-inline-block">Claim Files</span>
</a>
</li>
<?php if (in_array($ticket_data['ticket_type_id'], [1, 2, 3, 4, 5, 6, 7])) { ?>
<li class="nav-item">
<a href="#viewpolicyterms-tab" data-toggle="tab" class="nav-link px-3 py-2 label-font-size" id="viewpolicyterms_tab"
aria-expanded="false">
<i class="mdi mdi-eye mr-1"></i>
<span class="d-none d-sm-inline-block">View Policy Terms</span>
</a>
</li>
<?php } ?>
<li class="nav-item d-flex justify-content-center align-items-center">
<!-- Right Arrow -->
<button class="scroll-btn right-btn" type="button">&#9654;</button>
</li>
</ul>
</div>
<!-- Must load before tab includes: claim_files_upload.php has inline scripts that reference validateTicketFormInputs / refresh helpers -->
<script src="<?= base_url('assets/js/pages/ticket_form_input_validation.js') ?>"></script>
<!-- Tab Content -->
<div class="tab-content">
<div class="tab-pane fade show active" id="general-tab">
<?php
if ($ticket_data['ticket_type_id'] == 1) {
include('ticket_form_gmc.php');
} else if ($ticket_data['ticket_type_id'] == 8) {
include('ticket_form_motor.php');
} else {
include('ticket_form_gpa.php');
}
?>
</div>
<div class="tab-pane fade" id="reply-tab">
<?php include('ticket_reply.php'); ?>
</div>
<div class="tab-pane fade" id="note-tab">
<?php include('ticket_note.php'); ?>
</div>
<div class="tab-pane fade" id="history-tab">
<?php include('ticket_history.php'); ?>
</div>
<?php if (in_array($ticket_data['ticket_type_id'], [1, 2, 3, 4, 5, 6, 7])) { ?>
<div class="tab-pane fade" id="autoQuery-tab">
<?php include('ticket_auto_query.php'); ?>
</div>
<?php } ?>
<div class="tab-pane fade" id="uploads-tab">
<?php include('claim_files_upload.php'); ?>
</div>
<?php if (in_array($ticket_data['ticket_type_id'], [1, 2, 3, 4, 5, 6, 7])) { ?>
<div class="tab-pane fade" id="viewpolicyterms-tab">
<?php include('view_policy_terms.php'); ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="member_data_modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel"></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="form-row">
<div class="form-group col-md-12">
<label for="acm_id">Insured Member<span class="text-danger"></span></label>
<select class="form-control" onchange="setMemberData(this)">
<option value="0">Select Insured Member</option>
<?php if (!empty($member_data)) : ?>
<?php foreach ($member_data as $value) : ?>
<option value="<?= isset($value['emp_code']) ? $value['emp_code'] : '' ?>"
data-empID="<?= isset($value['emp_id']) ? $value['emp_id'] : '' ?>"
data-empName="<?= isset($value['emp_name']) ? htmlspecialchars($value['emp_name'], ENT_QUOTES, 'UTF-8') : '' ?>"
data-policyNo="<?= isset($value['policy_no']) ? $value['policy_no'] : '' ?>"
data-tpaNo="<?= isset($value['tpa_no']) ? $value['tpa_no'] : '' ?>"
data-relationship="<?= isset($value['emp_relationship']) ? htmlspecialchars($value['emp_relationship'], ENT_QUOTES, 'UTF-8') : '' ?>">
<?= isset($value['emp_name']) && isset($value['emp_relationship'])
? htmlspecialchars($value['emp_name'] . ' - ' . $value['emp_relationship'], ENT_QUOTES, 'UTF-8')
: 'Unknown Member' ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-primary" data-dismiss="modal" aria-label="Close">Submit</a>
</div>
</div>
</div>
</div>
<div id="ticket_conversation_div">
<?php include("ticket_conversation.php") ?>
</div>
<?php //include("ticket_form_handler.php")
?>
<script>
function submitClaimForm(event, form) {
event.preventDefault();
if (typeof window.validateTicketFormInputs === 'function' && !window.validateTicketFormInputs(form)) {
toastr.warning('Form validation failed. Please correct the highlighted fields.', 'Validation');
var $firstInvalid = $('#ticket_form_data').find('.parsley-error').first();
if (!$firstInvalid.length) {
$firstInvalid = $('#ticket_form_data').find('input.parsley-error, select.parsley-error, textarea.parsley-error').first();
}
if ($firstInvalid.length) {
$('html, body').animate({ scrollTop: $firstInvalid.offset().top - 100 }, 400);
$firstInvalid.focus();
}
return false;
}
const formAction = '<?= base_url("ticket/update"); ?>';
// Show loader
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// Collect IDs and form data
const formData = new FormData(form);
// AJAX request
$.ajax({
data: formData,
url: formAction,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(response) {
// Hide loader
console.log('Form submitted response:', response);
if (response.status === true) {
location.reload();
toastr.success(response.message, 'Success');
} else {
toastr.error(response.message, 'Error');
}
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
// Hide loader
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if (xhr.status === 400) {
let response = JSON.parse(xhr.responseText);
let errorMessages = "";
let seenMessages = []; // Array to store unique messages
if (response.errors) {
$.each(response.errors, function (field, message) {
if (!seenMessages.includes(message)) {
errorMessages += `• ${message}<br>`;
seenMessages.push(message); // Mark this message as "seen"
}
});
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
} else {
toastr.warning(response.message || 'Validation failed', 'Warning');
}
} else if (xhr.status === 403) {
let response = JSON.parse(xhr.responseText);
toastr.error(response.message, 'Security Policy');
} else if (xhr.status === 500) {
toastr.error('Something went wrong . Please try again later.', 'Server Error');
} else {
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
}
}
});
}
function openFetchEmpDataodal() {
var myModal = new bootstrap.Modal(document.getElementById('member_data_modal'));
myModal.show();
}
function setMemberData(input) {
is_head_approved
var selectedOption = $(input).find(':selected');
// Retrieve the data-* attributes
var empId = selectedOption.data('empid');
var empName = selectedOption.data('empname');
var policyNo = selectedOption.data('policyno');
var tpaNo = selectedOption.data('tpano');
var relationship = selectedOption.data('relationship');
$('#tpa_no').val(tpaNo);
$('#insured_emp_id').val(empId);
$('#insured_name').val(empName);
$('#policy_no').val(policyNo);
$('#relationship option').each(function() {
if ($(this).text() === relationship) {
$(this).prop('selected', true);
}
});
}
function showConfirmationModal(event) {
Swal.fire({
title: "Approve Claim Rejection",
// text: "Do you want to save this?",
icon: "warning",
showCancelButton: true,
showDenyButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#6c757d",
denyButtonColor: "#d33",
confirmButtonText: "Approve",
denyButtonText: "Reject",
cancelButtonText: "Cancel"
}).then((result) => {
if (result.isConfirmed) {
$('#is_head_approved').val(1);
console.log($('#ticket_form_data')[0])
submitClaimForm(event, $('#ticket_form_data')[0]); // Fixed selector
} else if (result.isDenied) {
// Show second Swal for rejection reason
Swal.fire({
title: "Rejection Reason",
text: "Please provide a reason for rejection",
input: "textarea",
inputPlaceholder: "Enter your reason here...",
icon: "info",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#6c757d",
confirmButtonText: "Submit",
cancelButtonText: "Back"
}).then((reasonResult) => {
if (reasonResult.isConfirmed) {
// Check if reason is not empty
if (reasonResult.value && reasonResult.value.trim() !== "") {
$('#is_head_approved').val(2);
$('#rejection_reason').val(reasonResult.value.trim());
console.log($('#ticket_form_data')[0]);
$('#head_rejection_reason').val(reasonResult.value.trim());
submitClaimForm(event, $('#ticket_form_data')[0]);
} else {
// Alert if reason is empty
Swal.fire({
title: "Error",
text: "Rejection reason cannot be empty",
icon: "error",
confirmButtonColor: "#3085d6"
}).then(() => {
// Go back to the rejection reason dialog
showConfirmationModal(event);
});
}
} else {
// If canceled, go back to first Swal
showConfirmationModal(event);
}
});
} else {
$('#is_head_approved').val(0);
return false;
}
});
}
function manualTpaClaimPush() {
let ticket_master_id = $('#ticket_master_id').val();
if (!ticket_master_id) {
toastr.warning('Claim ID not found. Please ensure the form is loaded.', 'Warning');
return;
}
Swal.fire({
title: 'Manual TPA Claim Push',
text: 'Do you want to push this claim to the TPA now?',
icon: 'question',
showCancelButton: true,
confirmButtonColor: '#00999E',
cancelButtonColor: '#6c757d',
confirmButtonText: 'Yes, push claim',
cancelButtonText: 'Cancel'
}).then((result) => {
if (result.isConfirmed) {
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
let requestData = { claim_id: ticket_master_id };
let url = '<?= base_url('ticket/manualTpaClaimPush') ?>';
sendAjaxRequestForGlobal(url, 'POST', requestData, function(response) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('Manual TPA claim push response:', response);
if (response.status) {
toastr.success(response.message || 'Claim pushed to TPA successfully', 'Success');
window.location.reload(true);
} else {
toastr.warning(response.message || 'Claim push failed', 'Warning');
}
}, function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error('Error pushing claim:', error);
console.error(xhr.responseText);
let msg = 'An error occurred while pushing the claim to TPA.';
if (xhr.responseJSON && xhr.responseJSON.message) {
msg = xhr.responseJSON.message;
} else if (xhr.status === 404) {
msg = 'Manual TPA Claim Push endpoint is not configured. Please contact support.';
}
toastr.error(msg, 'Error');
});
}
});
}
function fetchTpaClaimStatus(){
let ticket_master_id = $('#ticket_master_id').val();
console.log({ticket_master_id});
if (!ticket_master_id) {
toastr.warning('Claim ID not found. Please ensure the form is loaded.', 'Warning');
return;
}
let requestData = {
claim_id: ticket_master_id,
};
let url = '<?= base_url('ticket/getTpaClaimStatus') ?>';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
// Send AJAX request
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('Data fetched successfully:', response);
if (response.status) {
toastr.success(response.message || 'Status updated successfully', 'Success');
window.location.reload(true);
} else {
toastr.warning(response.message || 'Failed to update status', 'Warning');
}
}, function(xhr, status, error) {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.error('Error fetching data:', error);
console.error(xhr.responseText);
toastr.error('An error occurred while saving docs.', 'Error');
});
}
</script>