1277 lines
46 KiB
PHP
1277 lines
46 KiB
PHP
<style>
|
||
.accordion {
|
||
margin-bottom: 1rem;
|
||
}
|
||
|
||
.accordion h4 {
|
||
font-weight: bold;
|
||
cursor: pointer;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
background-color: #438e96;
|
||
color: #fff;
|
||
border-radius: 10px;
|
||
font-size: 17px;
|
||
padding-left: 13px;
|
||
padding-top: 3px;
|
||
padding-bottom: 3px;
|
||
padding-right: 12px;
|
||
}
|
||
|
||
.accordion-content {
|
||
display: none;
|
||
padding: 10px;
|
||
background-color: #bfe0e2;
|
||
margin-top: 5px;
|
||
border-radius: 7px;
|
||
margin: 5px;
|
||
}
|
||
|
||
.accordion-content.show {
|
||
display: block;
|
||
}
|
||
|
||
.arrow {
|
||
transition: transform 0.2s;
|
||
}
|
||
|
||
.arrow.rotate {
|
||
transform: rotate(90deg);
|
||
}
|
||
|
||
/* Ensure the dropdown matches the width of the input field */
|
||
/* .select2-container {
|
||
width: 100% !important;
|
||
} */
|
||
|
||
/* Ensure the dropdown appears ABOVE the modal and is visible */
|
||
/* .select2-container--open {
|
||
z-index: 9999999 !important;
|
||
} */
|
||
|
||
/* Fix for the "empty" or "misaligned" look in your screenshot */
|
||
/* .select2-results__option {
|
||
display: block !important;
|
||
width: 100%;
|
||
clear: both;
|
||
} */
|
||
|
||
</style>
|
||
|
||
|
||
<?php
|
||
if (!isset($view_ticket_page)) {
|
||
if ($selected_ticket_type == 1 || $selected_ticket_type == 72) {
|
||
include('ticket_form_gmc.php');
|
||
} else if ($selected_ticket_type == 8) {
|
||
include('ticket_form_motor.php');
|
||
} else {
|
||
include('ticket_form_gpa.php');
|
||
}
|
||
}
|
||
?>
|
||
|
||
<!-- <div class="modal fade" id="empDetailsModal" role="dialog" aria-labelledby="empDetailsModalLabel" aria-hidden="true">
|
||
<div class="modal-dialog modal-lg" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h5 class="modal-title" id="empDetailsModalLabel">Fetch Employee Data</h5>
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"
|
||
onclick="toResetTheModelFields()">
|
||
<span aria-hidden="true">×</span>
|
||
</button>
|
||
</div> -->
|
||
<div class="modal fade"
|
||
id="empDetailsModal"
|
||
tabindex="-1"
|
||
data-bs-backdrop="static"
|
||
data-bs-keyboard="false">
|
||
|
||
<div class="modal-dialog modal-lg">
|
||
<div class="modal-content">
|
||
|
||
<div class="modal-header">
|
||
<h5 class="modal-title">Fetch Employee Data</h5>
|
||
<!-- <button type="button" class="btn-close" data-bs-dismiss="modal"></button> -->
|
||
<button type="button" class="close" data-dismiss="modal">
|
||
<span aria-hidden="true">×</span>
|
||
</button>
|
||
|
||
</div>
|
||
<div class="modal-body">
|
||
<div class="accordion">
|
||
<!-- Search by Mobile Number -->
|
||
<div>
|
||
<h4 onclick="toggleAccordion('mobileAccordion')">
|
||
Search by Employee ID / Mobile Number
|
||
<span class="arrow" id="mobileArrow">➤</span>
|
||
</h4>
|
||
<div class="accordion-content" id="mobileAccordion">
|
||
<div id="mobileSearch" class="search-method">
|
||
<div class="row">
|
||
|
||
<div class="col-md-3" style="display:true;">
|
||
<div class="form-group">
|
||
<label>Employee Data Points</label>
|
||
<select name="employee_data_points" id="employee_data_points"
|
||
class="form-control">
|
||
<option value="emp_code">Employee ID</option>
|
||
<option value="mobile">Mobile Number</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-3">
|
||
<div class="form-group">
|
||
<label>Client</label>
|
||
<select id="mobile_emp_client_data_list" name="client"
|
||
class="form-control custom-select">
|
||
<option value="0">Select Client</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label id="employee_data_points_label">Mobile Number</label>
|
||
<input class="form-control" type="text" id="emp_mobile_number_for_claim"
|
||
name="mobile_numbers" onkeypress="return onlyNumbers(event)"
|
||
maxlength="10">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label>Insured List</label>
|
||
<select name="employee_by_number" id="member_by_number"
|
||
class="form-control SelExample" onchange="setMemberData(this)">
|
||
<option value="0">Select Member</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-4">
|
||
</div>
|
||
|
||
<div class="col-md-2">
|
||
<div class="form-group" style="margin-top: 9px; float:right;">
|
||
<br>
|
||
<button class="btn btn-primary"
|
||
onclick="getTheEmpDataForClaimSearchByMobile(this)">Search</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Search by Client, Branch, and Policy -->
|
||
<div class="mt-4">
|
||
<h4 onclick="toggleAccordion('clientBranchAccordion')">
|
||
Search by Client, Branch, and Policy
|
||
<span class="arrow" id="clientBranchArrow">➤</span>
|
||
</h4>
|
||
<div class="accordion-content" id="clientBranchAccordion">
|
||
<div class="row">
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label>Client</label>
|
||
<select id="emp_client_data_list" name="client"
|
||
class="form-control custom-select">
|
||
<option value="0">Select Client</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label>Branch</label>
|
||
<select id="emp_client_branch_data_list" name="branch"
|
||
class="form-control custom-select">
|
||
<option value="0">Select Branch</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label>Policy</label>
|
||
<select id="emp_client_policy_data_list" name="policy_client_branch"
|
||
class="form-control custom-select" onchange="getEmpData(this)">
|
||
<option value="0">Select Policy</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="row">
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label>Employee</label>
|
||
<select name="search_by_client_employee" id="search_by_client_employee"
|
||
class="form-control SelExample"
|
||
onchange="getTheEmpDataForClaimSearchByMobile(this, 'client')">
|
||
<option value="0">Select Employee</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-6">
|
||
<div class="form-group">
|
||
<label>Insured List</label>
|
||
<select name="member" id="search_by_client_member"
|
||
class="form-control SelExample" onchange="setMemberData(this)">
|
||
<option value="0">Select Member</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="modal-footer">
|
||
<a class="btn btn-primary" data-dismiss="modal" aria-label="Close"
|
||
onclick="toResetTheModelFields()">Submit</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="modal fade"
|
||
id="empDetailsModal"
|
||
role="dialog"
|
||
tabindex="-1"
|
||
data-bs-backdrop="static"
|
||
data-bs-keyboard="false"
|
||
aria-labelledby="empDetailsModalLabel"
|
||
aria-hidden="true">
|
||
<div class="modal-dialog modal-lg" role="document">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h5 class="modal-title" id="empDetailsModalLabel">Fetch Employee Data</h5>
|
||
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close" onclick="toResetTheModelFields()">
|
||
<span aria-hidden="true">×</span>
|
||
</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<!-- your modal body content -->
|
||
</div>
|
||
<div class="modal-footer">
|
||
<a class="btn btn-primary" data-bs-dismiss="modal" aria-label="Close" onclick="toResetTheModelFields()">Submit</a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script src="<?= base_url('assets/js/pages/ticket_form_input_validation.js') ?>"></script>
|
||
<!-- Inline JS right after modal HTML -->
|
||
<script>
|
||
|
||
var empModal; // global modal instance
|
||
|
||
// ✅ Initialize after DOM is fully loaded
|
||
document.addEventListener("DOMContentLoaded", function () {
|
||
|
||
var empModalEl = document.getElementById("empDetailsModal");
|
||
if (!empModalEl) {
|
||
console.error("Modal element not found!");
|
||
return;
|
||
}
|
||
|
||
empModal = new bootstrap.Modal(empModalEl, {
|
||
backdrop: 'static',
|
||
keyboard: false
|
||
});
|
||
});
|
||
|
||
// ✅ FINAL OPEN FUNCTION (RESET → THEN OPEN)
|
||
function openFetchEmpDataodal() {
|
||
|
||
// 1️⃣ FIRST reset everything
|
||
toResetTheModelFields();
|
||
|
||
// 2️⃣ THEN open modal
|
||
empModal.show();
|
||
}
|
||
|
||
// ✅ FINAL RESET FUNCTION (WORKS FOR INPUT + SELECT + SELECT2)
|
||
function toResetTheModelFields() {
|
||
|
||
var modal = document.getElementById("empDetailsModal");
|
||
if (!modal) return;
|
||
|
||
// ✅ Reset all input fields
|
||
modal.querySelectorAll("input").forEach(function (el) {
|
||
el.value = "";
|
||
});
|
||
|
||
// ✅ Reset all select dropdowns
|
||
modal.querySelectorAll("select").forEach(function (el) {
|
||
el.selectedIndex = 0;
|
||
});
|
||
|
||
// ✅ Reset Select2 / custom dropdowns
|
||
if (window.$) {
|
||
$("#empDetailsModal .SelExample").val(null).trigger("change");
|
||
}
|
||
|
||
// ✅ Optional: Close accordion
|
||
modal.querySelectorAll(".accordion-content").forEach(function (el) {
|
||
el.style.display = "none";
|
||
});
|
||
|
||
// ✅ Optional: Reset arrows
|
||
modal.querySelectorAll(".arrow").forEach(function (el) {
|
||
el.innerHTML = "➤";
|
||
});
|
||
|
||
console.log("✅ Modal reset completed");
|
||
}
|
||
|
||
var client_list = ''; // local variable for storing the client branch list
|
||
var branch_list = ''; // local variable for storing the client branch list
|
||
var policy_list = ''; // local variable for storing the client policy list
|
||
var selected_ticket_type_id = `<?= $selected_ticket_type ?? null ?>`;
|
||
|
||
$(document).ready(function() {
|
||
getClientAndBranchAndPolicy();
|
||
$('#emp_client_data_list').select2();
|
||
$('#emp_client_branch_data_list').select2();
|
||
$('#emp_client_policy_data_list').select2();
|
||
$('#search_by_client_member').select2();
|
||
$('#search_by_client_employee').select2();
|
||
$('#employee_by_number').select2();
|
||
$('#member_by_number').select2();
|
||
})
|
||
|
||
//on change functions
|
||
$(document).ready(function() {
|
||
|
||
$('#emp_client_data_list').change(function() {
|
||
|
||
let client_id = $(this).val();
|
||
let client_name = $('#emp_client_data_list option:selected').data('name');
|
||
|
||
console.log('client_id', client_id);
|
||
console.log('client_name', client_name);
|
||
|
||
if (branch_list != '') {
|
||
// console.log(branch_list[client_id]);
|
||
let data = branch_list[client_id];
|
||
appendBranch(data);
|
||
}
|
||
|
||
})
|
||
|
||
$('#emp_client_branch_data_list').change(function() {
|
||
|
||
let branch_id = $(this).val();
|
||
|
||
console.log('branch_id', branch_id);
|
||
|
||
if (policy_list != '') {
|
||
// console.log(branch_list[client_id]);
|
||
let data = policy_list[branch_id];
|
||
console.log(data);
|
||
appendPolicy(data);
|
||
}
|
||
|
||
})
|
||
|
||
$('#employee_data_points').on('change', function() {
|
||
let value = $(this).val();
|
||
let $label = $('#employee_data_points_label');
|
||
let $input = $('#emp_mobile_number_for_claim');
|
||
|
||
// Remove old attributes but DO NOT clear the .val()
|
||
$input.removeAttr('onkeypress maxlength oninput');
|
||
|
||
if (value == "mobile") {
|
||
$label.text('Employee Mobile Number');
|
||
$input.attr('onkeypress', 'return onlyNumbers(event)').attr('maxlength', '10');
|
||
|
||
$input.val($input.val().replace(/[^0-9]/g, '').substring(0, 10));
|
||
$input.attr('oninput', "this.value = this.value.replace(/[^0-9]/g, '').substring(0, 10)");
|
||
} else {
|
||
$label.text('Employee ID');
|
||
$input.removeAttr('onkeypress maxlength');
|
||
|
||
$input.attr('onkeypress', 'return onlyEmployee(event)');
|
||
$input.val($input.val().replace(/[^a-zA-Z0-9\s\-_/]/g, ''));
|
||
$input.attr('oninput', "this.value = this.value.replace(/[^a-zA-Z0-9\\s\\-_/]/g, '')");
|
||
|
||
}
|
||
});
|
||
|
||
})
|
||
|
||
function toggleAccordion(id) {
|
||
const content = document.getElementById(id);
|
||
const arrow = document.querySelector(`#${id === 'mobileAccordion' ? 'mobileArrow' : 'clientBranchArrow'}`);
|
||
|
||
// Define the other accordion to close
|
||
const otherId = id === 'mobileAccordion' ? 'clientBranchAccordion' : 'mobileAccordion';
|
||
if(id === 'mobileAccordion'){
|
||
$('#employee_data_points').trigger('change');
|
||
}
|
||
const otherContent = document.getElementById(otherId);
|
||
const otherArrow = document.querySelector(`#${id === 'mobileAccordion' ? 'clientBranchArrow' : 'mobileArrow'}`);
|
||
|
||
// Close the other accordion
|
||
otherContent.classList.remove('show');
|
||
otherArrow.classList.remove('rotate');
|
||
|
||
// Toggle the current accordion
|
||
if (content.classList.contains('show')) {
|
||
content.classList.remove('show');
|
||
arrow.classList.remove('rotate');
|
||
} else {
|
||
content.classList.add('show');
|
||
arrow.classList.add('rotate');
|
||
}
|
||
}
|
||
|
||
|
||
// function openFetchEmpDataodal() {
|
||
// var myModal = new bootstrap.Modal(document.getElementById('empDetailsModal'));
|
||
// myModal.show();
|
||
// }
|
||
|
||
//get client , branch, policy data
|
||
function getClientAndBranchAndPolicy() {
|
||
$.ajax({
|
||
url: '<?= base_url("/util/getClientAndBranchAndPolicy") ?>',
|
||
type: "GET",
|
||
dataType: 'json',
|
||
success: function(res) {
|
||
|
||
console.log('getClientAndBranchAndPolicy', res);
|
||
if (res.status == true) {
|
||
client_list = res.client_data;
|
||
branch_list = res.branch_data;
|
||
policy_list = res.policy_data;
|
||
appendClients(res.client_data);
|
||
appendClientsForMobileSearch(res.client_data);
|
||
} else {
|
||
console.log('No data found');
|
||
}
|
||
|
||
},
|
||
error: function(xhr, status, error) {
|
||
console.error(xhr.responseText);
|
||
console.error(status, error);
|
||
}
|
||
});
|
||
}
|
||
|
||
//append the clients data to the modal
|
||
// function appendClients(data) {
|
||
// $('#emp_client_data_list').empty();
|
||
|
||
// $('#emp_client_data_list').append($('<option>', {
|
||
// value: '0',
|
||
// text: 'Select Client'
|
||
// }));
|
||
|
||
// $.each(data, function(index, item) {
|
||
// var option = $('<option>', {
|
||
// value: item.id,
|
||
// text: item.client_name,
|
||
// 'data-name': item.client_name,
|
||
// });
|
||
|
||
// $('#emp_client_data_list').append(option).select2();
|
||
// });
|
||
|
||
// }
|
||
|
||
function appendClients(data) {
|
||
let $select = $('#emp_client_data_list');
|
||
$select.empty();
|
||
|
||
let options = '<option value="0">Select Client</option>';
|
||
|
||
$.each(data, function(index, item) {
|
||
options += `<option value="${item.id}" data-name="${item.client_name}">${item.client_name}</option>`;
|
||
});
|
||
|
||
$select.html(options);
|
||
$select.select2(); // ✅ Only call once after building all options
|
||
}
|
||
|
||
|
||
//append the clients data for mobile search to the modal
|
||
// function appendClientsForMobileSearch(data) {
|
||
// $('#mobile_emp_client_data_list').empty();
|
||
|
||
// $('#mobile_emp_client_data_list').append($('<option>', {
|
||
// value: '0',
|
||
// text: 'Select Client'
|
||
// }));
|
||
|
||
// $.each(data, function(index, item) {
|
||
// var option = $('<option>', {
|
||
// value: item.id,
|
||
// text: item.short_name,
|
||
// });
|
||
|
||
// $('#mobile_emp_client_data_list').append(option).select2();
|
||
// });
|
||
|
||
// }
|
||
|
||
// function appendClientsForMobileSearch(data) {
|
||
// let $select = $('#mobile_emp_client_data_list');
|
||
// $select.empty();
|
||
|
||
// let options = '<option value="0">Select Client</option>';
|
||
|
||
// $.each(data, function(index, item) {
|
||
// options += `<option value="${item.id}">${item.short_name}</option>`;
|
||
// });
|
||
|
||
// $select.html(options);
|
||
// $select.select2(); // ✅ Only once
|
||
// }
|
||
|
||
function appendClientsForMobileSearch(data) {
|
||
let $select = $('#mobile_emp_client_data_list');
|
||
$select.empty();
|
||
|
||
let options = '<option value="0">Select Client</option>';
|
||
|
||
$.each(data, function (index, item) {
|
||
|
||
let safeName = item.client_name.slice(0, 12) + "...";
|
||
let safeShortName = item.short_name;
|
||
|
||
options += `<option value="${item.id}">
|
||
${safeShortName} - ${safeName}
|
||
</option>`;
|
||
});
|
||
|
||
$select.html(options).select2(); // init once
|
||
}
|
||
|
||
|
||
// function appendClientsForMobileSearch(data) {
|
||
// let $select = $('#mobile_emp_client_data_list');
|
||
|
||
// // 1. Destroy any existing Select2 to ensure our new settings apply
|
||
// if ($select.data('select2')) {
|
||
// $select.select2('destroy');
|
||
// }
|
||
|
||
// // 2. Re-build the options
|
||
// $select.empty();
|
||
// let options = '<option value="0">Select Client</option>';
|
||
// $.each(data, function(index, item) {
|
||
// // Store both names in data attributes
|
||
// options += `<option value="${item.id}"
|
||
// data-shortname="${item.short_name}"
|
||
// data-fullname="${item.client_name}">
|
||
// ${item.short_name}
|
||
// </option>`;
|
||
// });
|
||
// $select.html(options);
|
||
|
||
// // 3. Initialize Select2 with the template logic
|
||
// $select.select2({
|
||
// dropdownParent: $('.modal-body').length ? $('.modal-body') : $(document.body), // Fix for modals
|
||
// escapeMarkup: function(m) { return m; }, // This allows HTML to render
|
||
// templateResult: function(data) {
|
||
// // Check if it's the placeholder
|
||
// if (!data.id || data.id == "0") return data.text;
|
||
|
||
// // Get data from the attributes we saved in step 2
|
||
// let short = $(data.element).data('shortname');
|
||
// let full = $(data.element).data('fullname');
|
||
|
||
// // Return the two-line HTML string
|
||
// return `
|
||
// <div style="line-height: 1.2; padding: 4px 0;">
|
||
// <div style="font-weight: bold;">${short}</div>
|
||
// <div style="font-size: 0.75em; color: #6c757d;">${full}</div>
|
||
// </div>
|
||
// `;
|
||
// },
|
||
// templateSelection: function(data) {
|
||
// if (!data.id || data.id == "0") return data.text;
|
||
// // Only show short name in the selection box
|
||
// return $(data.element).data('shortname');
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
// function appendClientsForMobileSearch(data) {
|
||
// let $select = $('#mobile_emp_client_data_list');
|
||
|
||
// // Destroy existing instance to reset position logic
|
||
// if ($select.data('select2')) {
|
||
// $select.select2('destroy');
|
||
// }
|
||
// $select.empty();
|
||
|
||
// // Initialize Select2
|
||
// $select.select2({
|
||
// // THIS IS KEY: Attach the dropdown to the modal container
|
||
// // Replace '.modal' with your specific modal ID if needed (e.g., '#myModal')
|
||
// dropdownParent: $select.closest('.modal'),
|
||
|
||
// data: $.map(data, function (item) {
|
||
// return {
|
||
// id: item.id,
|
||
// text: item.short_name,
|
||
// full: item.client_name // Passing extra data here
|
||
// };
|
||
// }),
|
||
// escapeMarkup: function(m) { return m; },
|
||
// templateResult: function (item) {
|
||
// if (!item.id || item.id == "0") return item.text;
|
||
|
||
// // Using template literals for the two lines
|
||
// return `
|
||
// <div style="padding: 5px; line-height: 1.2;">
|
||
// <div style="font-weight: bold; color: #333;">${item.text}</div>
|
||
// <div style="font-size: 11px; color: #6c757d;">${item.full}</div>
|
||
// </div>
|
||
// `;
|
||
// },
|
||
// templateSelection: function (item) {
|
||
// return item.text; // Only show short name when closed
|
||
// }
|
||
// });
|
||
// }
|
||
|
||
//append the clients branch data to the modal
|
||
function appendBranch(data) {
|
||
$('#emp_client_branch_data_list').empty();
|
||
|
||
$('#emp_client_branch_data_list').append($('<option>', {
|
||
value: '0',
|
||
text: 'Select Branch'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.branch_name,
|
||
'data-name': item.branch_name,
|
||
});
|
||
|
||
$('#emp_client_branch_data_list').append(option).select2();
|
||
});
|
||
|
||
}
|
||
|
||
//append the clients policy data to the modal
|
||
function appendPolicy(data) {
|
||
|
||
console.log("function called appendPOlicy : ", data);
|
||
let ticket_type = $('#ticket_type_id').val();
|
||
$('#emp_client_policy_data_list').empty();
|
||
|
||
$('#emp_client_policy_data_list').append($('<option>', {
|
||
value: '0',
|
||
text: 'Select Policy'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
|
||
if (ticket_type == 1) {
|
||
// console.log("inside if 1");
|
||
if (item.policy_type_id == 2 || item.policy_type_id == 3 || item.policy_type_id == 4 || item
|
||
.policy_type_id == 5) {
|
||
// console.log("inside if 2");
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.policy_type + '-' + item.policy_no,
|
||
});
|
||
|
||
$('#emp_client_policy_data_list').append(option).select2();
|
||
}
|
||
|
||
} else if (ticket_type == 2) {
|
||
// console.log("inside if 3");
|
||
if (item.policy_type_id == 1) {
|
||
// console.log("inside if 4");
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.policy_type + '-' + item.policy_no,
|
||
});
|
||
|
||
$('#emp_client_policy_data_list').append(option).select2();
|
||
}
|
||
|
||
} else if (ticket_type == 3) {
|
||
|
||
if (item.policy_type_id == 6) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.policy_type + '-' + item.policy_no,
|
||
});
|
||
|
||
$('#emp_client_policy_data_list').append(option).select2();
|
||
}
|
||
|
||
} else if (ticket_type == 4) {
|
||
|
||
if (item.policy_type == 7) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.policy_type + '-' + item.policy_no,
|
||
});
|
||
|
||
$('#emp_client_policy_data_list').append(option).select2();
|
||
}
|
||
|
||
} else if (ticket_type == 72) {
|
||
|
||
if (item.policy_type == 72) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.policy_type + '-' + item.policy_no,
|
||
});
|
||
|
||
$('#emp_client_policy_data_list').append(option).select2();
|
||
}
|
||
|
||
} else {
|
||
// console.log("inside else condition");
|
||
}
|
||
|
||
});
|
||
|
||
}
|
||
|
||
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 = '<?= isset($view_ticket_page) ? base_url("ticket/update") : base_url("ticket/create"); ?>';
|
||
|
||
// 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
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
console.log('Form submitted response:', response);
|
||
|
||
if (response.status === true) {
|
||
toastr.success(response.message, 'Success');
|
||
window.location.href = '<?= base_url('ticket/list') ?>';
|
||
} else {
|
||
if(response.code == 409){
|
||
toastr.warning(response.message, 'Warning');
|
||
}else{
|
||
toastr.error(response.message, 'Error');
|
||
}
|
||
}
|
||
|
||
},
|
||
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 getEmpData(input) {
|
||
|
||
console.log('STEP 1', new Date().toLocaleString());
|
||
|
||
console.log(input)
|
||
let param = $(input).val();
|
||
let url = '<?= base_url('util/getTheEmpDataForClaim/') ?>' + param;
|
||
|
||
// Data to send in the AJAX request
|
||
let requestData = {
|
||
param: param,
|
||
};
|
||
|
||
// Show loader
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
console.log('STEP 2', new Date().toLocaleString());
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status) {
|
||
console.log(response.message, 'Success');
|
||
appendEmployee(response.data, 'search_by_client_employee');
|
||
setClientAndInsurerData(response.dataForClientAndInsurer);
|
||
setClientPolicyData(input);
|
||
} else {
|
||
toastr.warning(response.message, 'Warning');
|
||
}
|
||
|
||
// Hide loader
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while fetch data.', 'Error');
|
||
|
||
// Hide loader
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
});
|
||
}
|
||
|
||
function getTheEmpDataForClaimSearchByMobile(input, searchType = null) {
|
||
|
||
console.log(input);
|
||
let type = $('#employee_data_points').val()
|
||
let param = $('#emp_mobile_number_for_claim').val()
|
||
let client_policy_id = $('#emp_client_policy_data_list').val()
|
||
let client_id = $('#mobile_emp_client_data_list').val();
|
||
console.log('selected_ticket_type_id', selected_ticket_type_id);
|
||
|
||
if (searchType == 'client') {
|
||
type = 'emp_code';
|
||
param = $(input).val();
|
||
client_id = $('#emp_client_data_list').val()
|
||
}
|
||
|
||
// let url = '<?= base_url('util/getTheEmpDataForClaimSearchByMobile/') ?>' + param + '/' + type + '/' +
|
||
// client_policy_id + '/' + client_id + '/'+ selected_ticket_type_id;
|
||
|
||
let url = '<?= base_url('util/getTheEmpDataForClaimSearchByMobile') ?>';
|
||
|
||
// Data to send in the AJAX request
|
||
let requestData = {
|
||
param: param,
|
||
type: type,
|
||
client_policy_id: client_policy_id,
|
||
client_id: client_id,
|
||
ticket_type_id: selected_ticket_type_id,
|
||
};
|
||
|
||
// Show loader
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status == true) {
|
||
console.log(response.message, 'SUCCESS');
|
||
if (searchType == 'client') {
|
||
appendMember(response.memberData, 'search_by_client_member');
|
||
} else {
|
||
appendMember(response.memberData, 'member_by_number');
|
||
}
|
||
// if (response.data.emp_id == null || response.data.emp_id == ''){
|
||
unSetClientPolicy();
|
||
// }
|
||
setClientAndInsurerData(response.data, true);
|
||
setClientBranchPolicy(response.data.emp_id, searchType ?? null, response.data.policy_id ?? null);
|
||
appendACMS(response.acms)
|
||
|
||
} else {
|
||
toastr.warning(response.message, 'Warning');
|
||
appendACMS(response.acms);
|
||
unSetClientPolicy();
|
||
unSetClientAndInsurerData()
|
||
}
|
||
|
||
// Hide loader
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
toastr.error('An error occurred while fetch data.', 'Error');
|
||
|
||
// Hide loader
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
});
|
||
}
|
||
|
||
function setClientBranchPolicy(emp_id, searchType = null, policy_id = null) {
|
||
|
||
data = {
|
||
// branch_id : branch_id,
|
||
// policy_id : policy_id,
|
||
emp_id: emp_id,
|
||
searchType: searchType ?? null,
|
||
policy_id: policy_id ?? null
|
||
}
|
||
|
||
data = JSON.stringify(data);
|
||
console.log("set client branch function is called : ", data);
|
||
console.log("hidden input value before is ", $("#empIDHidden").val());
|
||
$("#empIDHidden").val(data).trigger('change');;
|
||
console.log("hidden input value after is ", $("#empIDHidden").val());
|
||
|
||
}
|
||
|
||
// function appendEmployee(data, attrId) {
|
||
|
||
// console.log('STEP 3', new Date().toLocaleString());
|
||
// console.log('data', data)
|
||
|
||
// $('#' + attrId).empty();
|
||
// $('#' + attrId).append($('<option>', {
|
||
// value: '0',
|
||
// text: 'Select Employee'
|
||
// }));
|
||
|
||
// $.each(data, function(index, item) {
|
||
// // console.log(item)
|
||
// var option = $('<option>', {
|
||
// value: item.emp_code,
|
||
// text: item.emp_name + ' - ' + item.emp_code,
|
||
// });
|
||
|
||
// $('#' + attrId).append(option).select2();
|
||
// });
|
||
|
||
// console.log('STEP 4', new Date().toLocaleString());
|
||
|
||
// }
|
||
|
||
function appendEmployee(data, attrId) {
|
||
console.log('STEP 3', new Date().toLocaleString());
|
||
console.log('data', data);
|
||
|
||
let $select = $('#' + attrId);
|
||
$select.empty();
|
||
|
||
let options = '<option value="0">Select Employee</option>';
|
||
|
||
$.each(data, function(index, item) {
|
||
options += `<option value="${item.emp_code}">${item.emp_name} - ${item.emp_code}</option>`;
|
||
});
|
||
|
||
$select.html(options); // ⬅ Append all at once
|
||
$select.select2(); // ⬅ Initialize once after options are set
|
||
|
||
console.log('STEP 4', new Date().toLocaleString());
|
||
}
|
||
|
||
function appendMember(data, attrId) {
|
||
|
||
console.log('data', data);
|
||
|
||
// Clear the existing options
|
||
$('#' + attrId).empty();
|
||
|
||
// Add the default 'Select Member' option
|
||
$('#' + attrId).append($('<option>', {
|
||
value: '0',
|
||
text: 'Select Member'
|
||
}));
|
||
|
||
// Append options dynamically with data attributes
|
||
$.each(data, function(index, item) {
|
||
console.log('Item:', item); // Log each item to debug
|
||
|
||
// Ensure all properties exist, set fallback if necessary
|
||
var empID = item.emp_id ?? '';
|
||
var empName = item.emp_name ?? '';
|
||
var policyNo = item.policy_no ?? '';
|
||
var tpaNo = item.tpa_no ?? '';
|
||
var relationship = item.emp_relationship ?? '';
|
||
|
||
// Create an option and set data attributes
|
||
var option = $('<option>', {
|
||
value: item.emp_code,
|
||
text: empName + " - " + relationship
|
||
}).attr({
|
||
'data-empID': empID,
|
||
'data-empName': empName,
|
||
'data-policyNo': policyNo,
|
||
'data-tpaNo': tpaNo,
|
||
'data-relationship': relationship
|
||
});
|
||
|
||
$('#' + attrId).append(option);
|
||
});
|
||
|
||
// Reinitialize select2
|
||
$('#' + attrId).select2();
|
||
}
|
||
|
||
function appendACMS(data) {
|
||
|
||
console.log("account manger data : ",data);
|
||
|
||
$('#acm_id').empty();
|
||
|
||
$('#acm_id').append($('<option>', {
|
||
value: '',
|
||
text: 'Select Account Manager'
|
||
}));
|
||
|
||
$.each(data, function(index, item) {
|
||
var option = $('<option>', {
|
||
value: item.id,
|
||
text: item.first_name,
|
||
});
|
||
|
||
$('#acm_id').append(option);
|
||
});
|
||
|
||
}
|
||
|
||
function onlyNumbers(event) {
|
||
var charcode;
|
||
charcode = event.which || event.keyCode;
|
||
if (charcode >= 48 && charcode <= 57 || charcode == 46) return true;
|
||
return false;
|
||
}
|
||
|
||
function onlyEmployee(event) {
|
||
var charCode = (event.which) ? event.which : event.keyCode;
|
||
|
||
// Allow Numbers (48-57)
|
||
// Allow Uppercase (65-90)
|
||
// Allow Lowercase (97-122)
|
||
// Allow Space (32), Hyphen (45), Underscore (95), Forward Slash (47)
|
||
if (
|
||
(charCode >= 48 && charCode <= 57) ||
|
||
(charCode >= 65 && charCode <= 90) ||
|
||
(charCode >= 97 && charCode <= 122) ||
|
||
[32, 45, 95, 47].includes(charCode)
|
||
) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
function setClientPolicyData(input) {
|
||
|
||
// console.log('policy_value ',input);
|
||
var selectedValue = $(input).val(); // Get selected value
|
||
var selectedText = $(input).find(":selected").text();
|
||
console.log('Selected value ', selectedValue, " selected text ", selectedText);
|
||
|
||
var targetDropdown = $("#emp_client_policy");
|
||
|
||
targetDropdown.select2();
|
||
targetDropdown.empty();
|
||
targetDropdown.append(new Option(selectedText, selectedValue));
|
||
targetDropdown.addClass('readonly-select ').select2('destroy');
|
||
let ticket_type = $('#ticket_type_id').val();
|
||
if (ticket_type == 1) {
|
||
setMinDateDOA(selectedValue);
|
||
}else{
|
||
setDateValidation(selectedValue,false);
|
||
}
|
||
// targetDropdown.attr("readonly");
|
||
|
||
}
|
||
|
||
function setClientAndInsurerData(data, insurer_data = false) {
|
||
|
||
if(insurer_data == false){
|
||
$('#insurer_id').val(data.insurer_id);
|
||
$('#insurer_name').val(data.insurer_name);
|
||
$('#tpa_id').val(data.tpa_id);
|
||
$('#tpa_name').val(data.tpa_name);
|
||
}
|
||
|
||
$('#client_id').val(data.client_id);
|
||
$('#client_name').val(data.client_name);
|
||
|
||
$('#emp_code').val(data.emp_code);
|
||
$('#emp_id').val(data.emp_id);
|
||
$('#emp_name').val(data.emp_name);
|
||
$('#emp_mobile').val(data.emp_mobile);
|
||
$('#emp_mail').val(data.emp_email);
|
||
}
|
||
|
||
function unSetClientPolicy() {
|
||
var targetDropdown = $("#emp_client_policy");
|
||
|
||
if (targetDropdown.hasClass("readonly-select")) {
|
||
console.log("Class exists, removing...");
|
||
targetDropdown.removeClass("readonly-select");
|
||
targetDropdown.select2();
|
||
} else {
|
||
console.log("Class not found.");
|
||
}
|
||
var targetDropdown2 = $("#doa");
|
||
if (targetDropdown2.hasClass("readonly-select")) {
|
||
console.log("Class exists, removing...");
|
||
targetDropdown2.removeClass("readonly-select");
|
||
// targetDropdown.select2();
|
||
} else {
|
||
console.log("Class not found.");
|
||
}
|
||
var targetDropdown3 = $("#date_of_joininig");
|
||
if (targetDropdown3.hasClass("readonly-select")) {
|
||
console.log("Class exists, removing...");
|
||
targetDropdown3.removeClass("readonly-select");
|
||
// targetDropdown.select2();
|
||
} else {
|
||
console.log("Class not found.");
|
||
}
|
||
|
||
}
|
||
|
||
function unSetClientAndInsurerData() {
|
||
|
||
$('#insurer_id').val("");
|
||
$('#insurer_name').val("");
|
||
$('#tpa_id').val("");
|
||
$('#tpa_name').val("");
|
||
$('#client_id').val("");
|
||
$('#client_name').val("");
|
||
|
||
$('#emp_code').val("");
|
||
$('#emp_id').val("");
|
||
$('#emp_name').val("");
|
||
$('#emp_mobile').val("");
|
||
$('#emp_mail').val("");
|
||
}
|
||
|
||
function setMemberData(input) {
|
||
|
||
var selectedOption = $(input).find(':selected');
|
||
var ticket_type_id = $('#ticket_type_id').val();
|
||
|
||
// 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);
|
||
}
|
||
});
|
||
|
||
if (tpaNo == "") {
|
||
|
||
if(ticket_type_id == 1){
|
||
$('#claim_status_id').val(1)
|
||
}else{
|
||
$('#claim_status_id').val(67)
|
||
}
|
||
$('#non_id_reason').attr('required', true);
|
||
var $label = $("#non_id_reason_lable_id");
|
||
$label.text('*');
|
||
|
||
} else {
|
||
if(ticket_type_id == 1){
|
||
$('#claim_status_id').val(2)
|
||
}else{
|
||
$('#claim_status_id').val(68)
|
||
}
|
||
$('#non_id_reason').attr('required', false);
|
||
var $label = $("#non_id_reason_lable_id");
|
||
$label.text("");
|
||
}
|
||
}
|
||
|
||
// $('#employee_data_points').on('change', function() {
|
||
|
||
// let value = $(this).val()
|
||
// if (value == "mobile") {
|
||
// $('#employee_data_points_label').text('Employee Mobile Number')
|
||
// } else {
|
||
// $('#employee_data_points_label').text('Employee ID')
|
||
// }
|
||
// })
|
||
|
||
|
||
|
||
function toResetTheModelFields() {
|
||
|
||
$('#emp_mobile_number_for_claim').val('');
|
||
$('#employee_data_points').val('emp_code').attr('autocomplete', 'off').trigger('change');
|
||
$('#mobile_emp_client_data_list').val('0').select2();
|
||
$('#employee_by_number').val('');
|
||
$('#member_by_number').val('0').select2();
|
||
$('#emp_client_data_list').val('0').select2();
|
||
$('#emp_client_branch_data_list').val('0').select2();
|
||
$('#emp_client_policy_data_list').val('0').select2();
|
||
$('#search_by_client_employee').val('0').select2();
|
||
$('#search_by_client_member').val('0').select2();
|
||
}
|
||
|
||
$('#tpa_no').on('input', function() {
|
||
let tpaNo = $(this).val().trim();
|
||
console.log('tpaNo:', tpaNo);
|
||
|
||
let isEmpty = tpaNo === "";
|
||
$('#claim_status_id').val(isEmpty ? 1 : 2);
|
||
$('#non_id_reason').prop('required', isEmpty);
|
||
$('#non_id_reason_lable_id').text(isEmpty ? '*' : '');
|
||
});
|
||
|
||
</script>
|