306 lines
13 KiB
PHP
306 lines
13 KiB
PHP
<?php //echo fancy_date_time_format('2024-01-01 15:40:32');echo '<br>';?>
|
||
<?php //echo fancy_date_time_format('2024-02-01 15:40:32');echo '<br>';?>
|
||
<!-- <?php echo fancy_date_time_format('2024-02-10 15:40:32');echo '<br>';?> -->
|
||
<!-- <?php echo fancy_date_time_format('2024-02-13 14:40:32');echo '<br>';?> -->
|
||
<!-- <?php echo fancy_date_time_format('2024-02-13 14:58:00');echo '<br>';?> -->
|
||
|
||
<br>
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body">
|
||
<!-- <div class="text-center"> -->
|
||
<form id="emp-upload-form" action="<?php echo base_url().'employee/bulk-event-uplod'?>" method="post">
|
||
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" id="csrf_token">
|
||
<div class="row">
|
||
<div class="col-md-4 col-xl-3">
|
||
<div class="form-group mb-3">
|
||
<label>Client</label> <br/>
|
||
<select name="client_id" class="form-control" id="client_id">
|
||
<option value="0">Select</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="col-md-4 col-xl-3">
|
||
<div class="form-group mb-3">
|
||
<label>Policy</label> <br/>
|
||
<select name="policy_id" class="form-control" id="policy_id">
|
||
<option value="0">Select</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-md-4 col-xl-3">
|
||
<div class="form-group mb-3">
|
||
<label>Action</label> <br/>
|
||
<select name="upload-action-type" class="form-control" id="upload-action-type">
|
||
<option value="0">Select</option>
|
||
<?php
|
||
if(isset($actions) && count($actions))
|
||
{
|
||
foreach($actions as $key => $action)
|
||
{
|
||
echo "<option value=".$key.">".$action."</option>";
|
||
}
|
||
}
|
||
|
||
?>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
<div class="row">
|
||
<div class="col-md-4 col-xl-3">
|
||
<div class="form-group mb-3">
|
||
<label>Choose file</label> <br/>
|
||
<input type="file" name="emplist" id="emplist">
|
||
</div></div>
|
||
|
||
<div class="col-8" style="text-align: right;">
|
||
<button type="submit" class="btn btn-primary waves-effect waves-light">Submit</button>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
<!-- </div> -->
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<!-- start page title -->
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<div class="page-title-box page-title-box-alt">
|
||
<h4 class="page-title"></h4>
|
||
<div class="page-title-right">
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<!-- end page title -->
|
||
<div class="row" id="file_list">
|
||
<?php include('file_list.php');?>
|
||
</div>
|
||
<!-- end row -->
|
||
<!-- Center modal content -->
|
||
<div class="modal fade" id="file-err-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">File Rejected Reason</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<h5>Overflowing text to show scroll behavior</h5>
|
||
<p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
|
||
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
|
||
</div>
|
||
</div>
|
||
</div><!-- /.modal-dialog -->
|
||
</div><!-- /.modal -->
|
||
|
||
|
||
<div id="loader" class="loader" style="display:none;">SPINNER</div>
|
||
|
||
<script>
|
||
|
||
// Declare a global variable to store API response data
|
||
var clientPolicies = [];
|
||
|
||
$( document ).ready(function() {
|
||
console.log( "document loaded" );
|
||
//fetchClientPolicies();
|
||
//for modal pop up
|
||
$('#file-err-modal').on('show.bs.modal', function (event) {
|
||
var myVal = $(event.relatedTarget).data('err');
|
||
$(this).find(".modal-body").text(myVal);
|
||
});
|
||
|
||
//for form submit
|
||
$("#emp-upload-form").submit(function(event) {
|
||
event.preventDefault(); // Prevent default form submission
|
||
console.log('submit called');
|
||
// Check required fields
|
||
if (!$(this)[0].checkValidity()) {
|
||
// Form is invalid, handle error or notify user
|
||
console.log('failed');
|
||
return false;
|
||
}
|
||
console.log($(this));
|
||
console.log($(this)[0]);
|
||
|
||
|
||
// Create FormData object
|
||
var formData = new FormData($(this)[0]);
|
||
for (var pair of formData.entries()) {
|
||
console.log(pair[0]+ ', ' + pair[1]);
|
||
}
|
||
// var formData = $("#emp-upload-form").serialize();
|
||
// var file = document.getElementById('emplist').files[0];
|
||
// formData.append('file', file);
|
||
console.log(formData);
|
||
// return false;
|
||
// AJAX request
|
||
$.ajax({
|
||
url: $(this).attr("action"),
|
||
type: "POST",
|
||
data: formData,
|
||
processData: false, // Prevent jQuery from automatically processing the data
|
||
contentType: false, // Let jQuery handle the content type
|
||
headers: {
|
||
// "Content-Type":"multipart/form-data",
|
||
"X-Requested-With": "XMLHttpRequest"
|
||
},
|
||
success: function(response) {
|
||
// Request successful, handle response
|
||
console.log(response);
|
||
alert('success');
|
||
window.location.reload();
|
||
},
|
||
error: function(xhr, status, error) {
|
||
// Request failed, handle error
|
||
console.error("Request failed:", status, error);
|
||
alert('falied try again');
|
||
}
|
||
});
|
||
});//end
|
||
|
||
|
||
|
||
});
|
||
|
||
$( 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);
|
||
// console.log(clientPolicies);
|
||
appendClients(clientPolicies);
|
||
} 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) {
|
||
$.each(data, function(index, item) {
|
||
$('#client_id').append($('<option>', {
|
||
value: item.id,
|
||
text: item.client_name
|
||
}));
|
||
});
|
||
}
|
||
|
||
function appendPolicies(data) {
|
||
$('#policy_id').empty();
|
||
$('#policy_id').append($('<option>', { value: '0',text: 'Select'}));
|
||
|
||
$.each(data, function(index, item) {
|
||
$('#policy_id').append($('<option>', {
|
||
value: item.id,
|
||
text: item.name
|
||
}));
|
||
});
|
||
}
|
||
|
||
$('#client_id').on('change', function() {
|
||
var selectedClient = $(this).val();
|
||
console.log(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.policies);
|
||
appendPolicies(foundPolicies.policies);
|
||
});
|
||
|
||
// 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 = $('#client_id').val();
|
||
var policy_id = $('#policy_id').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
|
||
};
|
||
|
||
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);
|
||
// }
|
||
// });
|
||
}
|
||
|
||
|
||
</script>
|