382 lines
13 KiB
PHP
Executable File
382 lines
13 KiB
PHP
Executable File
<style>
|
|
.table th,
|
|
.table td {
|
|
padding: 8px;
|
|
}
|
|
|
|
table.dataTable tbody td {
|
|
padding: 4px 4px !important;
|
|
}
|
|
</style>
|
|
|
|
<div class="row">
|
|
<div class="col-xl-12">
|
|
<div id="accordion" class="mb-3">
|
|
<div class="card mb-1">
|
|
<h5 class="m-1">
|
|
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne"
|
|
aria-expanded="true">
|
|
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
|
|
</a>
|
|
</h5>
|
|
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
|
|
<div class="card-body">
|
|
<!-- <div class="text-center"> -->
|
|
<div class="form-row">
|
|
<div class="form-group col-md-4">
|
|
<label>Client</label> <br />
|
|
<select class="form-control" id="clients">
|
|
<option value="0">Select</option>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
<div class="form-group col-md-4">
|
|
<label>Branch</label> <br />
|
|
<select name="branch_id" class="form-control" id="branch_id">
|
|
<option value="0">Select</option>
|
|
</select>
|
|
</div>
|
|
|
|
|
|
<div class="form-group col-md-4">
|
|
<label>Policy</label> <br />
|
|
<select class="form-control" id="policies">
|
|
<option value="0">Select</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label>Status</label> <br />
|
|
<select class="form-control" id="status2">
|
|
<option value="0">Select</option>
|
|
<?php foreach($status as $key => $value) { ?>
|
|
<option value="<?= $key ?>"
|
|
<?= (isset($getData) && $getData['status'] == $key) ? 'selected' : '' ?>>
|
|
<?= $value ?>
|
|
</option>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label>Employee Code</label> <br />
|
|
<input type="text" class="form-control" id="emp_code" name="emp_code" value="<?= isset($getData['emp_code']) && !empty($getData['emp_code']) ? $getData['emp_code'] : '' ?>">
|
|
</div>
|
|
|
|
<div class="form-group col-md-4">
|
|
<label>Employee Name</label> <br />
|
|
<input type="text" class="form-control" id="emp_name" name="emp_name" value="<?= isset($getData['emp_name']) && !empty($getData['emp_name']) ? $getData['emp_name'] : '' ?>">
|
|
</div>
|
|
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-12" style="text-align: right;">
|
|
<a href="<?= base_url("employee/list"); ?>"
|
|
class="btn btn-primary waves-effect waves-light" id="get-emp-list"
|
|
onclick="fetchEmpolyeeList(event);">Submit</a>
|
|
</div>
|
|
</div>
|
|
<!-- </div> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<?php include('employee_data_list.php');?>
|
|
|
|
|
|
<!-- end row -->
|
|
<div id="loader" class="loader" style="display:none;">SPINNER</div>
|
|
|
|
<script>
|
|
|
|
$(document).ready(function() {
|
|
// Initialize select2
|
|
$("#clients").select2();
|
|
$("#policies").select2();
|
|
$("#branch_id").select2();
|
|
|
|
// if ($('.select2-selection__arrow').length > 0) {
|
|
// $('.select2-selection__arrow').removeClass('select2-selection__arrow').addClass('fa fa-chevron-down');
|
|
// }
|
|
});
|
|
|
|
// Declare a global variable to store API response data
|
|
var clientPolicies = [];
|
|
var clientPoliciesWithBranch = {
|
|
policies: []
|
|
};
|
|
var client_id = '<?= isset($getData) ? $getData['client_id'] : '0' ?>';
|
|
var client_branch_id = '<?= isset($getData) ? $getData['branch_id'] : '0' ?>';
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
console.log("document loaded");
|
|
//fetchClientPolicies();
|
|
|
|
});
|
|
|
|
$(window).on("load", function() {
|
|
console.log("window loaded");
|
|
fetchClientPolicies();
|
|
});
|
|
|
|
|
|
function fetchClientPolicies() {
|
|
$('#loader').show();
|
|
var apiURL = '<?php echo base_url();?>' + 'util/clients-with-policies';
|
|
console.log('fetchClientPolicies');
|
|
// console.log(apiURL);
|
|
$.ajax({
|
|
url: apiURL,
|
|
method: 'GET',
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"X-Requested-With": "XMLHttpRequest"
|
|
},
|
|
success: function(response) {
|
|
// console.log(response.code);
|
|
// console.log(response.dataStatus);
|
|
// console.log(response.data);
|
|
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
|
|
try {
|
|
clientPolicies = (response.data);
|
|
|
|
response.data.forEach(policy => {
|
|
// console.log('policies', policy.policies);
|
|
policy.policies.forEach(p => {
|
|
clientPoliciesWithBranch.policies.push(p);
|
|
});
|
|
});
|
|
|
|
// console.log('1',clientPolicies);
|
|
appendClients(clientPolicies);
|
|
|
|
//this function for reselect the policy
|
|
setTimeout(function() {
|
|
if (client_id != 0 ) {
|
|
var foundPolicies = clientPolicies.find(function(item) {
|
|
// console.log(typeof item.id)
|
|
return item.id == client_id;
|
|
});
|
|
appendBranch(foundPolicies.branchs);
|
|
}
|
|
}, 500);
|
|
|
|
setTimeout(function() {
|
|
if (client_branch_id != 0 ) {
|
|
|
|
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
|
|
// console.log('item', item);
|
|
return item.branch_id === client_branch_id;
|
|
});
|
|
|
|
if (foundPolicies) {
|
|
// console.log('foundPolicies', foundPolicies);
|
|
appendPolicies(foundPolicies);
|
|
} else {
|
|
console.log('No policies found for the selected client');
|
|
}
|
|
}
|
|
}, 500);
|
|
//end
|
|
|
|
} catch (error) {
|
|
console.error('Error parsing API response data:', error);
|
|
}
|
|
} else if (response.code === 404 && response.dataStatus === false) {
|
|
console.error('no data found', response);
|
|
} else {
|
|
console.error('Something went wrong!');
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('Error fetching data from API:', error);
|
|
}
|
|
});
|
|
|
|
$('#loader').hide();
|
|
}
|
|
|
|
|
|
function appendClients(data) {
|
|
var clientID = <?= isset($getData) ? $getData['client_id'] : '0' ?>;
|
|
$.each(data, function(index, item) {
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.client_name
|
|
});
|
|
if (clientID == item.id) {
|
|
option.attr('selected', true);
|
|
}
|
|
$('#clients').append(option);
|
|
});
|
|
}
|
|
|
|
|
|
function appendBranch(data) {
|
|
|
|
$('#branch_id').empty();
|
|
$('#branch_id').append($('<option>', {
|
|
value: '0',
|
|
text: 'Select'
|
|
}));
|
|
$.each(data, function(index, item) {
|
|
var option = $('<option>', {
|
|
value: item.id,
|
|
text: item.branch_name
|
|
});
|
|
if (client_branch_id == item.id) {
|
|
option.attr('selected', true);
|
|
}
|
|
$('#branch_id').append(option);
|
|
});
|
|
}
|
|
|
|
|
|
function appendPolicies(data) {
|
|
|
|
$('#policies').empty();
|
|
$('#policies').append($('<option>', {
|
|
value: '0',
|
|
text: 'Select'
|
|
}));
|
|
|
|
var PolicyID = <?= isset($getData) ? $getData['policy_id'] : '0'?>;
|
|
// console.log(PolicyID)
|
|
$.each(data, function(index, item) {
|
|
var option = $('<option>', {
|
|
value: item.client_policy_id,
|
|
// text: `${item.name ?? ''} - ${item.policy_no ?? ''} - ${item.policy_type ?? ''}`
|
|
text:`${item.policy_type ?? ''} - ${item.policy_no ?? ''}`
|
|
});
|
|
if (PolicyID == item.client_policy_id) {
|
|
option.attr('selected', true);
|
|
}
|
|
$('#policies').append(option);
|
|
});
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('#clients').on('change', function() {
|
|
|
|
$('#policies').empty();
|
|
$('#policies').append($('<option>', {
|
|
value: '0',
|
|
text: 'Select'
|
|
}));
|
|
|
|
var selectedClient = $(this).val();
|
|
// console.log('selectedClient', selectedClient);
|
|
// $('#selectedOptionInfo').text('Selected option: ' + selectedOption);
|
|
|
|
// Check if the selected option exists in apiData
|
|
var foundPolicies = clientPolicies.find(function(item) {
|
|
return item.id === selectedClient;
|
|
});
|
|
// console.log(foundPolicies.branchs);
|
|
appendBranch(foundPolicies.branchs);
|
|
});
|
|
});
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('#branch_id').on('change', function() {
|
|
|
|
var selectedClient = $(this).val();
|
|
|
|
// console.log('selectedBranch', selectedClient);
|
|
// console.log('clientPolicies', clientPoliciesWithBranch);
|
|
|
|
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
|
|
// console.log('item', item);
|
|
return item.branch_id === selectedClient;
|
|
});
|
|
|
|
|
|
if (Array.isArray(foundPolicies) && foundPolicies.length === 0) {
|
|
|
|
appendPolicies(foundPolicies);
|
|
toastr.warning('No policies found for the selected client branch.');
|
|
|
|
} else {
|
|
|
|
// console.log('foundPolicies', foundPolicies);
|
|
appendPolicies(foundPolicies);
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
// Function to convert object to query parameters
|
|
function objectToQueryString(obj) {
|
|
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
|
|
}
|
|
|
|
|
|
function fetchEmpolyeeList(event) {
|
|
event.preventDefault(); // Prevent default action
|
|
|
|
var client_id = $('#clients').val();
|
|
var policy_id = $('#policies').val();
|
|
var status = $('#status2').val();
|
|
var branch_id = $('#branch_id').val();
|
|
var emp_code = $('#emp_code').val();
|
|
var emp_name = $('#emp_name').val();
|
|
|
|
// console.log(client_id + '-' + policy_id);
|
|
// if (client_id == '0' || policy_id == '0') {
|
|
// alert('Please select values in both dropdowns.');
|
|
// return;
|
|
// }
|
|
|
|
var queryParams = {
|
|
|
|
client_id: client_id,
|
|
policy_id: policy_id,
|
|
branch_id: branch_id,
|
|
emp_code : emp_code,
|
|
emp_name : emp_name,
|
|
status : status,
|
|
};
|
|
|
|
const queryString = objectToQueryString(queryParams);
|
|
const apiURL = $('#get-emp-list').attr('href') + "?" + queryString;
|
|
// console.log(apiURL);
|
|
window.location.href = apiURL;
|
|
|
|
|
|
// var apiURL2 = $('#get-emp-list').attr('href'); // Get href attribute value
|
|
// console.log(apiURL);
|
|
// $.ajax({
|
|
// url: apiURL,
|
|
// method: 'GET',
|
|
// data: queryParams,
|
|
// success: function(response) {
|
|
// // Assuming response is a JSON array
|
|
// // displayDataTables(response);
|
|
// console.log(response);
|
|
// },
|
|
// error: function(xhr, status, error) {
|
|
// console.error('Error:', error);
|
|
// }
|
|
// });
|
|
}
|
|
|
|
|
|
document.getElementById('toggleIcon').addEventListener('click', function() {
|
|
var icon = document.getElementById('icon');
|
|
icon.classList.toggle('mdi-chevron-down');
|
|
icon.classList.toggle('mdi-chevron-up');
|
|
});
|
|
|
|
</script>
|