576 lines
18 KiB
PHP
576 lines
18 KiB
PHP
<!-- Body page content -->
|
|
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script>
|
|
|
|
<!-- bootstrap-daterangepicker -->
|
|
<script src="https://localhost/ams//assets/default/moment/min/moment.min.js"></script>
|
|
<script src="https://localhost/ams//assets/default/bootstrap-daterangepicker/daterangepicker.js"></script>
|
|
<!-- bootstrap-datetimepicker -->
|
|
<script src="https://localhost/ams//assets/default/bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
|
|
|
|
<!-- bootstrap-daterangepicker -->
|
|
<link href="https://localhost/ams//assets/default/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">
|
|
<!-- bootstrap-datetimepicker -->
|
|
<link href="https://localhost/ams//assets/default/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css" rel="stylesheet">
|
|
<!-- style.css -->
|
|
<link href="https://localhost/ams//assets/default/customize/style.css" rel="stylesheet">
|
|
|
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
|
|
|
|
|
<style>
|
|
|
|
input[type=date] {
|
|
position: relative;
|
|
/* width: 150px; height: 20px;
|
|
color: white;*/
|
|
}
|
|
|
|
input[type=date]:before {
|
|
position: absolute;
|
|
top: 3px; left: 3px;
|
|
content: attr(data-date);
|
|
display: inline-block;
|
|
color: black;
|
|
}
|
|
|
|
/* input[type=date]::-webkit-datetime-edit, input::-webkit-inner-spin-button, input::-webkit-clear-button {
|
|
display: none;s
|
|
}
|
|
|
|
input[type=date]::-webkit-calendar-picker-indicator {
|
|
position: absolute;
|
|
top: 3px;
|
|
right: 0;
|
|
color: black;
|
|
opacity: 1;
|
|
} */
|
|
</style>
|
|
|
|
|
|
<button hidden id="button" class="btn btn-secondary source" onclick="new PNotify({
|
|
text: 'No sufficient leave balance please check the Date.',
|
|
type: 'error',
|
|
styling: 'bootstrap3'
|
|
});">Error</button>
|
|
<input type="hidden" id="error" value="<?php echo $this->session->userdata('error');?>" >
|
|
<?php echo $this->session->unset_userdata('error');?>
|
|
<script>
|
|
$(document).ready(function(){
|
|
|
|
if($('#error').val() == 1)
|
|
{
|
|
$('#button').click();
|
|
}
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
<div class="">
|
|
<div class="page-title">
|
|
|
|
<div class="title_left">
|
|
<h3>Edit Leave</h3>
|
|
</div>
|
|
</div>
|
|
<div class="clearfix"></div>
|
|
<div class="row">
|
|
<div class="col-md-12 col-sm-12 ">
|
|
<div class="x_panel">
|
|
<div class="x_title">
|
|
|
|
|
|
<!-- <h6>General Information</h6> -->
|
|
<div class="clearfix"></div>
|
|
</div>
|
|
<div class="x_content">
|
|
<br />
|
|
|
|
<?php if(!empty($editleave)) { ?>
|
|
|
|
<?php foreach( $editleave as $leave) { ?>
|
|
|
|
<form id="myForm" data-parsley-validate class="form-horizontal form-label-left" method="post" action="<?php echo base_url()?>Leave/editleave" enctype="multipart/form-data">
|
|
|
|
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
|
|
|
|
|
|
<div class="item form-group">
|
|
|
|
<label class="control-label col-md-2 col-sm-2 " for="last-name">Leave Applied For</label>
|
|
<div class="col-md-5 col-sm-5 ">
|
|
|
|
<input type="radio" name="risedby" value="self"style="margin:10px;"checked /><b>Self</b>
|
|
|
|
<input type="radio" name="risedby" value="<?php echo user()->name;?>" style="margin: 10px;" /><b>Others</b>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="item form-group">
|
|
<label class="control-label col-md-2 col-sm-2 " for="last-name"> Employee Name </label>
|
|
<div class="col-md-5 col-sm-5 ">
|
|
<select id="user_dropdown" name="emp_id" style="margin-top: 10px;padding-bottom: 10px;" class="form-control" > </select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="item form-group">
|
|
|
|
<label class="control-label col-md-2 col-sm-2 " for="last-name">Leave Type<a style="color:red;">*</a> </label>
|
|
<div class="col-md-5 col-sm-5 ">
|
|
<select id="type" name="type" required class="form-control" >
|
|
<?php foreach ($leavetype as $key => $val) { ?>
|
|
<?php if ($leave->type == $val->id) { ?>
|
|
<option name="leaveCode" id="<?php echo $val->code; ?>" value="<?php echo $leave->type; ?>" selected><?php echo $val->type; ?></option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
<?php foreach ($leavetype as $key => $value) { ?>
|
|
<?php if ($leave->type != $value->id) { ?>
|
|
<option name="leaveCode2" id="<?php echo $value->code; ?>" value="<?php echo $value->id; ?>"><?php echo $value->type; ?></option>
|
|
<?php } ?>
|
|
<?php } ?>
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<label class="control-label col-md-1 col-sm-1 " for="first-name"> Balance</label>
|
|
<div class="col-md-1 col-sm-1 ">
|
|
<input type="text" id="leave_bal" name="" value="<?php echo $leave->leave_bal; ?>" style="width:90px;" class="form-control " readonly>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
<div class="item form-group" id="hidedate">
|
|
|
|
<label class="control-label col-md-2 col-sm-2 " for="first-name"> From Date<a style="color:red;">*</a> </label>
|
|
<div class="col-md-2 col-sm-2 ">
|
|
<div class='input-group date'>
|
|
<input type='text' class="form-control" placeholder="DD-MM-YYYY" id="fromdate" name="from_date_new" value="<?php echo dateFormat('d-m-Y', $leave->from_date_new); ?>" required />
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<label class="control-label col-md-1 col-sm-1" for="last-name">To Date<a style="color:red;">*</a> </label>
|
|
<div class="col-md-2 col-sm-2 ">
|
|
<div class='input-group date' >
|
|
<input type='text' class="form-control" placeholder="DD-MM-YYYY" id="todate" name= "to_date_new" value="<?php echo dateFormat('d-m-Y', $leave->to_date_new); ?>" required />
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<label class="control-label col-md-1 col-sm-1 " for="last-name"></label>
|
|
<div class="col-md-2 col-sm-2 ">
|
|
<input id="dateDifference" value="<?php echo $leave->no_of_days; ?>days" readonly class="form-control" style="width:90px;" type="text" >
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="item form-group" id="showdate" >
|
|
|
|
<label class="control-label col-md-2 col-sm-2 " for="first-name">Date<a style="color:red;">*</a> </label>
|
|
<div class="col-md-5 col-sm-5 ">
|
|
<div class='input-group date'>
|
|
<?php
|
|
// Assuming $leave->perm_date_new is in the 'Y-m-d' format
|
|
$formatted_date = date('d-m-y', strtotime($leave->perm_date_new));
|
|
?>
|
|
<input type='text' class="form-control" required name="perm_date_new" placeholder="DD-MM-YYYY" value="<?php echo $formatted_date; ?>" id='myDatepicker' />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="item form-group" id="showtime" >
|
|
|
|
<label class="control-label col-md-2 col-sm-2 " for="first-name"> From<a style="color:red;">*</a> </label>
|
|
<div class="col-md-2 col-sm-2 ">
|
|
<select class="custom-select" id="from_time" name=from_time required >
|
|
<option value="<?php echo $leave->from_time; ?>"><?php echo $leave->from_time; ?></option>
|
|
</select>
|
|
</div>
|
|
|
|
<label class="control-label col-md-1 col-sm-1 " for="last-name">To<a style="color:red;">*</a> </label>
|
|
<div class="col-md-2 col-sm-2 ">
|
|
<select id="to_time" class="custom-select" name="to_time" required>
|
|
<option value="<?php echo $leave->to_time; ?>"><?php echo $leave->to_time; ?></option>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="item form-group">
|
|
|
|
<label class="control-label col-md-2 col-sm-2 " for="last-name">Note</label>
|
|
<div class="col-md-5 col-sm-5">
|
|
<textarea id="comments" name="comments" value="" class="form-control" style="height:100px !important;" type="text" ><?php echo $leave->comments; ?></textarea>
|
|
|
|
<input type="hidden" name="manager" value="<?php echo employee()->manager ?>">
|
|
<input type="hidden" name="id" value="<?php echo $leave->id; ?>">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="ln_solid"></div>
|
|
<div class="item form-group">
|
|
<div class=" offset-md-8">
|
|
<a href="<?php echo base_url();?>Leave/LeaveHistory" class="btn btn-secondary">Cancel</a>
|
|
<button type="submit" id="submit" onclick="sweert()" class="btn btn-success">Update</button>
|
|
</div>
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<?php } }?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<!-- /Body page content -->
|
|
|
|
|
|
|
|
<script>
|
|
$(document).ready(function(){
|
|
|
|
var currentUserName = '<?php echo user()->name; ?>';
|
|
var currentUserId = '<?php echo user()->id; ?>';
|
|
$('#user_dropdown').append('<option value="' + currentUserId + '">' +
|
|
currentUserName + '</option>');
|
|
$('#user_dropdown').prop('disabled', true);
|
|
|
|
$('#user_dropdown').on('change',function() {
|
|
|
|
$('#type').prop('selectedIndex',0);
|
|
|
|
});
|
|
|
|
|
|
$('#type').on('change',function() {
|
|
let id = $("#user_dropdown").val();
|
|
|
|
var type_id = $('option:selected', this).val();
|
|
console.log('type_id : ', type_id)
|
|
var fromdate = document.getElementById("fromdate").value;
|
|
console.log('userID : ', id)
|
|
|
|
|
|
if (id)
|
|
{
|
|
$.ajax({
|
|
data: {id : id, type_id : type_id},
|
|
type: 'get',
|
|
url: "<?php echo base_url()?>Leave/get_leave_count/",
|
|
success: function(response) {
|
|
response = JSON.parse(response);
|
|
if(response.length == 0 )
|
|
{
|
|
$.ajax({
|
|
type: "get",
|
|
data: {type_id : type_id},
|
|
url: "<?php echo base_url()?>Leave/get_all_leave_count/",
|
|
success: function(response) {
|
|
response = JSON.parse(response);
|
|
$('#leave_bal').val( response[0].days + ' days');
|
|
},
|
|
});
|
|
}
|
|
else
|
|
{
|
|
if(response[0].remaining_days == 1 )
|
|
{
|
|
$('#leave_bal').val(response[0].remaining_days + ' day');
|
|
}
|
|
else
|
|
{
|
|
$('#leave_bal').val(response[0].remaining_days + ' days');
|
|
}
|
|
}
|
|
},
|
|
|
|
});
|
|
}
|
|
else
|
|
{
|
|
$('#leave_bal').val("");
|
|
}
|
|
});
|
|
|
|
$('input[type="radio"][name="risedby"]').change(function() {
|
|
var selectedValue = $(this).val();
|
|
var $userDropdown = $('#user_dropdown');
|
|
|
|
$userDropdown.empty();
|
|
|
|
if (selectedValue === 'self') {
|
|
|
|
var currentUserName = '<?php echo user()->name; ?>';
|
|
var currentUserId = '<?php echo user()->id; ?>';
|
|
$userDropdown.append('<option value="' + currentUserId + '">' + currentUserName + '</option>');
|
|
$userDropdown.prop('disabled', true);
|
|
} else if (selectedValue === '<?php echo user()->name; ?>') {
|
|
|
|
$.ajax({
|
|
url: '<?php echo base_url('Leave/get_emp_name/')?>"',
|
|
method: 'GET',
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
$('#user_dropdown').append(response);
|
|
$('#user_dropdown').prop('disabled', false);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(error);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
function get_all_count(id) {
|
|
|
|
$.ajax({
|
|
type: "get",
|
|
url: "<?php echo base_url()?>Leave/get_all_leave_count/"+id,
|
|
success: function(response) {
|
|
response = JSON.parse(response);
|
|
console.log(response);
|
|
$('#leave_bal').val( response[0].days);
|
|
},
|
|
error: function(jqXHR, textStatus, err) { alert('text status '+textStatus+', err '+err) }
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
<script>
|
|
// Initialize datepickers
|
|
var dateFormat = "dd-mm-yy";
|
|
var fromDateInput = $("#fromdate");
|
|
console.log(fromDateInput);
|
|
var toDateInput = $("#todate");
|
|
console.log(toDateInput);
|
|
|
|
fromDateInput.datepicker({
|
|
dateFormat: dateFormat,
|
|
changeYear: true,
|
|
changeMonth: true,
|
|
minDate: 0,
|
|
onSelect: function (dateText, inst) {
|
|
toDateInput.datepicker("option", "minDate", dateText);
|
|
calculateDateDifference();
|
|
DateValidate();
|
|
}
|
|
});
|
|
|
|
toDateInput.datepicker({
|
|
dateFormat: dateFormat,
|
|
changeYear: true,
|
|
changeMonth: true,
|
|
minDate: 0,
|
|
onSelect: function (dateText, inst) {
|
|
calculateDateDifference();
|
|
DateValidate();
|
|
}
|
|
});
|
|
|
|
// Function to validate the date range
|
|
function validateDateRange() {
|
|
var fromDate = fromDateInput.datepicker("getDate");
|
|
var toDate = toDateInput.datepicker("getDate");
|
|
|
|
// Check if both dates are selected
|
|
if (!fromDate || !toDate) {
|
|
$("#error-msg").text("Please select both From Date and To Date");
|
|
return false;
|
|
}
|
|
|
|
// Compare the dates
|
|
if (fromDate > toDate) {
|
|
$("#error-msg").text("From Date cannot be after To Date");
|
|
return false;
|
|
}
|
|
|
|
// Clear the error message if the date range is valid
|
|
$("#error-msg").text("");
|
|
return true;
|
|
}
|
|
|
|
function calculateDateDifference() {
|
|
var fromDate = fromDateInput.datepicker("getDate");
|
|
var toDate = toDateInput.datepicker("getDate");
|
|
|
|
if (!isNaN(fromDate) && !isNaN(toDate)) {
|
|
var difference = Math.ceil((toDate - fromDate) / (1000 * 60 * 60 * 24) + 1 );
|
|
if(difference == 1)
|
|
{
|
|
$("#dateDifference").val(difference + ' day');
|
|
}
|
|
else
|
|
{
|
|
$("#dateDifference").val(difference + ' days');
|
|
}
|
|
|
|
} else {
|
|
$("#dateDifference").val("");
|
|
}
|
|
}
|
|
|
|
</script>
|
|
|
|
<script>
|
|
$('#showtime').hide()
|
|
$('#showdate').hide()
|
|
|
|
$(document).ready(function() {
|
|
|
|
let type = $('#type').val();
|
|
|
|
|
|
var element = $('[name="leaveCode"]');
|
|
var id = element.attr('id');
|
|
|
|
console.log($('#showtime').val())
|
|
|
|
if( id === 'permission' ){
|
|
|
|
$('#hidedate').hide()
|
|
$('#balance').hide()
|
|
$('#leave_bal').hide()
|
|
$('#fromdate').removeAttr('required');
|
|
$('#todate').removeAttr('required');
|
|
$('#showtime').show();
|
|
$('#showdate').show();
|
|
}
|
|
else{
|
|
|
|
$('#from_time').removeAttr('required');
|
|
$('#to_time').removeAttr('required');
|
|
$('#myDatepicker').removeAttr('required');
|
|
$('#hidedate').show();
|
|
$('#showtime').hide();
|
|
$('#showdate').hide();
|
|
$('#balance').show()
|
|
$('#leave_bal').show()
|
|
|
|
}
|
|
|
|
});
|
|
$('#showtime').hide()
|
|
$('#showdate').hide()
|
|
|
|
$('#type').change(function() {
|
|
$('#fromdate').val('');
|
|
$('#todate').val('');
|
|
|
|
var selectedOptionId = $(this).find(":selected").attr("id");
|
|
var element2 = $('[name="leaveCode2"]');
|
|
var id2 = element2.attr('id');
|
|
console.log('ID:', selectedOptionId);
|
|
|
|
if( selectedOptionId === 'permission'){
|
|
|
|
$('#hidedate').hide();
|
|
$('#balance').hide();
|
|
$('#leave_bal').hide();
|
|
$('#fromdate').removeAttr('required');
|
|
$('#todate').removeAttr('required');
|
|
$('#myDatepicker').prop('required', true);
|
|
$('#showtime').show();
|
|
$('#showdate').show();
|
|
$('#from_time').prop('required', true);
|
|
$('#to_time').prop('required', true);
|
|
}
|
|
else{
|
|
|
|
$('#from_time').removeAttr('required');
|
|
$('#to_time').removeAttr('required');
|
|
$('#perm_id').removeAttr('required');
|
|
$('#hidedate').show();
|
|
$('#showtime').hide();
|
|
$('#showdate').hide();
|
|
$('#balance').show();
|
|
$('#leave_bal').show();
|
|
$('#fromdate').prop('required', true);
|
|
$('#todate').prop('required', true);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
var selectField = $('#from_time');
|
|
|
|
var options = [ '12:00 AM', '12:30 AM', '1:00 AM', '1:30 AM', '2:00 AM', '2:30 AM', '3:00 AM', '3:30 AM', '4:00 AM', '4:30 AM', '5:00 AM', '5:30 AM', '6:00 AM', '6:30 AM', '7:00 AM', '7:30 AM', '8:00 AM', '8:30 AM', '9:00 AM', '9:30 AM', '10:00 AM', '10:30 AM', '11:00 AM', '11:30 AM', '12:00 Noon', '12:30 PM', '1:00 PM', '1:30 PM', '2:00 PM', '2:30 PM', '3:00 PM', '3:30 PM', '4:00 PM', '4:30 PM', '5:00 PM', '5:30 PM', '6:00 PM', '6:30 PM', '7:00 PM', '7:30 PM', '8:00 PM', '8:30 PM', '9:00 PM', '9:30 PM', '10:00 PM', '10:30 PM', '11:00 PM', '11:30 PM'];
|
|
|
|
|
|
for (var i = 0; i < options.length; i++) {
|
|
selectField.append('<option value="' + options[i] + '">' + options[i] + '</option>');
|
|
}
|
|
});
|
|
|
|
var selectField = $('#from_time');
|
|
selectField.on('click', function() {
|
|
|
|
var selectedValue = $(this).val();
|
|
console.log(selectedValue);
|
|
|
|
var timeSlots = [ '12:00 AM', '12:30 AM', '1:00 AM', '1:30 AM', '2:00 AM', '2:30 AM', '3:00 AM', '3:30 AM', '4:00 AM', '4:30 AM', '5:00 AM', '5:30 AM', '6:00 AM', '6:30 AM', '7:00 AM', '7:30 AM', '8:00 AM', '8:30 AM', '9:00 AM', '9:30 AM', '10:00 AM', '10:30 AM', '11:00 AM', '11:30 AM', '12:00 Noon', '12:30 PM', '1:00 PM', '1:30 PM', '2:00 PM', '2:30 PM', '3:00 PM', '3:30 PM', '4:00 PM', '4:30 PM', '5:00 PM', '5:30 PM', '6:00 PM', '6:30 PM', '7:00 PM', '7:30 PM', '8:00 PM', '8:30 PM', '9:00 PM', '9:30 PM', '10:00 PM', '10:30 PM', '11:00 PM', '11:30 PM'];
|
|
|
|
|
|
function filterTimeSlots(startingTime, numberOfHours) {
|
|
// Find the index of the starting time in the array
|
|
console.log(startingTime,numberOfHours);
|
|
const startIndex = timeSlots.findIndex(time => time === startingTime);
|
|
console.log(startIndex);
|
|
if (startIndex !== -1) {
|
|
|
|
const endIndex = startIndex + (numberOfHours * 2) - 1;
|
|
|
|
return timeSlots.slice(startIndex, endIndex + 2);
|
|
}
|
|
return [];
|
|
}
|
|
|
|
// Usage example
|
|
const startingTime = selectedValue;
|
|
const numberOfHours = 4 ;
|
|
const filteredTimeSlots = filterTimeSlots(startingTime, numberOfHours);
|
|
|
|
filteredTimeSlots.shift();
|
|
var totime = $('#to_time');
|
|
totime.empty();
|
|
for (var i = 0; i < filteredTimeSlots.length; i++) {
|
|
totime.append('<option value="' + filteredTimeSlots[i] + '">' + filteredTimeSlots[i] + '</option>');
|
|
|
|
}
|
|
|
|
console.log(filteredTimeSlots);
|
|
|
|
});
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|