ria/app/Views/attendance.php
2025-03-26 12:18:41 +05:30

1021 lines
40 KiB
PHP
Executable File

<
<?php
$datefordropdown = format_date($datefordropdown, 0, 'M-Y');
//echo $datefordropdown;
$attendance = array_merge($attendance, $emppay);
date_default_timezone_set('Asia/Kolkata');
$currentday = date('d');
// print_r($attendance);
// echo "<br>------------------------------<br>";
?>
<style type="text/css">
.num {
text-align: right;
}
.fht-table,
.fht-table thead,
.fht-table tfoot,
.fht-table tbody,
.fht-table tr,
.fht-table th,
.fht-table td {
margin: 0;
}
.fht-table td {
text-align: center;
}
.fht-table td:hover {
background-color: #00a65a;
color: #ffffff;
}
.fht-table {
border: 0 none;
height: auto;
width: auto;
border-collapse: collapse;
border-spacing: 0;
/*table-layout: fixed; Algoritmo de distribucion fijo */
white-space:nowrap;
}
.fht-table th,
.fht-table td {
overflow: hidden;
}
.fht-table-wrapper,
.fht-table-wrapper .fht-thead,
.fht-table-wrapper .fht-tfoot,
.fht-table-wrapper .fht-fixed-column .fht-tbody,
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: hidden;
position: relative;
}
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: auto;
}
.fht-table-wrapper .fht-table .fht-cell {
overflow: hidden;
height: 1px;
}
.fht-table-wrapper .fht-fixed-column,
.fht-table-wrapper .fht-fixed-body {
top: 0;
left: 0;
position: absolute;
}
.fht-table-wrapper .fht-fixed-column {
z-index: 1;
}
.fht-fixed-body .fht-thead table {
margin-right: 20px;
border: 0 none;
}
/*For Examples*/
.ContenedorTabla {
height: 500px;
margin: 0 auto;
overflow: auto;
width: auto;
position: relative;
}
.header,
.main {
display: inline-block;
height: auto;
width: 100%;
}
.titulosHeader {
border-bottom: 1px solid #e8bb25;
height: auto;
margin-bottom: 10px;
padding-bottom: 8px;
padding-top: 8px;
width: 100%;
}
.celda_encabezado_general {
background-color: #00a65a;
border: 1px solid #ccc;
color: #ffffff;
font-weight: bold;
padding: 2px 4px;
text-align: center;
}
._Separador {
background-color: #fff;
height: 12px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
width: 7px;
}
._Separador div {
width: 4px;
}
.celda_normal {
/*background-color: #fff;*/
/* <!-- ad9271 into ffffff brown-light to green-light --> */
border: 1px solid #ccc;
padding: 2px 4px;
}
.summary{
background-color: bisque;
}
/*style excel*/
.excel_cell {
border: 1px solid #CCC;
color: #222;
text-align: center;
font-size: 13px;
font-weight: normal;
padding: 4px;
white-space: pre-line;
empty-cells: show;
}
._cell_header {
background-color: #EEE;
}
._cell_Default {
background-color: #FFF;
text-align: left;
}
.excel_cell div {
width: 30px;
height: 20px;
}
.modal {
padding-right: 30% ! important;
}
.fht-table th:nth-child(1),
.fht-table th:nth-child(2),
.fht-table th:nth-child(3)
{
position: sticky;
left: 0;
top: 0;
background-color: #00a65a;
z-index: 7!important;
border-right: 2px solid #ddd;
color: #ffffff;
}
.fht-table td:nth-child(1),
.fht-table td:nth-child(2),
.fht-table td:nth-child(3)
{
position: sticky;
left: 0;
background-color: #ffffff;
z-index: 2;
border-right: 2px solid #ddd;
color: #0e0b0b;
}
.table-responsive {
overflow-y: auto;
max-height: 450px;
}
.fht-table thead th {
position: sticky;
top: 0;
z-index: 5!important;
}
</style>
<div class="content-page">
<div class="content">
<!-- Start Content-->
<div class="container-fluid">
<!-- start page title -->
<div>
<div class="row">
<div class="col-6">
<div class="page-title-box page-title-box-alt">
<div class="page-title-right">
<ol class="breadcrumb mt-0.99 mb-2.5"">
<li class="breadcrumb-item"><a href="javascript: void(0);">HR</a></li>
<li class="breadcrumb-item active">
<h4 class="page-title">Attendance </h4>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<?php
$attributes = array('id' => 'atten');
echo form_open('attendance', $attributes); ?>
<div class="row">
<div class="col-2">
<?php $today = date('M-Y'); ?>
<input type="text" name="month" id="month" value="<?php echo $datefordropdown; ?>" class="form-control" data-provide="datepicker" data-date-format="M-yyyy" data-date-min-view-mode="1">
</div>
<div class="col-1">
<input type="submit" value="Change Month" class="btn btn-success"
title='click here for load attendance for specified month' style="margin-top:0px;">
</div>
<div class="col-1 text-right">
<i id="exportButton" class="fas fa-download download-icon" style="font-size: x-large; margin-top:12px;" title="Export Excel"></i>
</div>
<div class="col-8 text-right">
<input type="button" class="btn btn-success" id="c" value="save" style="margin-top:0px;">
</div>
</div>
<?php echo form_close(); ?>
<?php
$testarray = array();
$finalarray = array();
if (!empty($attendance)) {
foreach ($attendance as $record) {
//$index++;
if (in_array($record->EmpID, $testarray)) {
//$index--;
} else {
array_push($testarray, $record->EmpID);
array_push($finalarray, $record);
}
}
}
?>
<!-- Add table-responsive for horizontal scroll -->
<div class="table-responsive">
<table id="attendance" class="fht-table table table-striped" style="font-size: small;">
<thead>
<tr>
<th class="celda_encabezado_general">S.NO</th>
<th class="celda_encabezado_general" >EmpID</th>
<th class="celda_encabezado_general">Employee Name</th>
<?php
for ($col = 1; $col <= $monthdays; $col++) {
$flag = 0;
$flag2 = 0;
$todayflag = 0;
if ($col == $currentday) {
$todayflag = 1;
}
foreach ($sundayarray as $in) //For Find out Sundays($ind) from $monthdays array
{
if ($in == $col) {
$flag = 1;
}
}
$title = '';
foreach ($publicholidaysarray as $h) //For Find out public holidays from $monthdays array
{
$temp = $h->H_Date;
$temp = substr($temp, 8);
if ($temp == $col) {
$flag2 = 1;
//$title ="Public Holiday-" . str_replace(" ","_",$h->H_Name);
$title = str_replace(" ", "_", $h->H_Name);
//echo $title;
}
}
?>
<th <?php if ($flag2 == 1) { ?> title=" <?php echo $title; ?> "
<?php } else if ($flag == 1) { ?> title="sunday" <?php } ?>
class="celda_encabezado_general" <?php if ($flag == 1 or $flag2 == 1) {
echo "style='background: #f0898a ;'";
} else if ($todayflag == 1) {
echo "style='background: #00a65a ;'";
} ?>>
<?php if ($flag == 1 or $flag2 == 1) {
echo "<font style='color:#fff;'>" . $col . "W<font>";
} else {
echo $col . "W";
} ?></th>
<th <?php if ($flag2 == 1) { ?> title=" <?php echo $title; ?> "
<?php } else if ($flag == 1) { ?> title="sunday" <?php } ?>
class="celda_encabezado_general"
<?php if ($flag == 1 or $flag2 == 1) {
echo "style='background: #f0898a ;'"; //#f39c12 old color
} else if ($todayflag == 1) {
echo "style='background: #00a65a;'";
} ?>>
<?php if ($flag == 1 or $flag2 == 1) {
echo "<font style='color:#fff;'>" . $col . "OT<font>";
} else {
echo $col . "OT";
} ?>
</th>
<?php
//echo $flag2;
$flag = 0;
$flag2 = 0;
$todayflag = 0;
} ?>
<th class="celda_encabezado_general">Days Worked</th>
<th class="celda_encabezado_general">Absent</th>
<th class="celda_encabezado_general">Paid Leave</th>
<th class="celda_encabezado_general"> Sunday</th>
<th class="celda_encabezado_general">Worked Hrs</th>
<th class="celda_encabezado_general">OT Hrs</th>
</tr>
</thead>
<tbody style="background-color: #fff;">
<?php $index = 0;
$row = 0;
foreach ($finalarray as $a) {
$row++;
$index++; ?>
<tr id="<?php echo $row; ?>">
<td width="45" height="45" class="celda_normal"><?php echo $index; ?>
</td>
<td width="79" height="45" class="celda_normal"><?php echo $a->EmpID; ?>
</td>
<td width="80" height="45" class="celda_normal" style="text-align: left;">
<?php echo $a->FirstName; ?></td>
<?php for ($col = 1; $col <= $monthdays; $col++) {
$flag = 0;
$flag2 = 0;
if ($col == $currentday) {
$todayflag = 1;
}
foreach ($sundayarray as $in) {
if ($in == $col) {
$flag = 1;
}
}
foreach ($publicholidaysarray as $h) //For Find out public holidays from $monthdays array
{
$temp = $h->H_Date;
$temp = substr($temp, 8);
$title = '';
//echo $temp.'-'.$col.'/';
if ($temp == $col) {
$flag2 = 1;
//$title ="Public_Holiday-" . str_replace(" ","_",$h->H_Name);
$title = str_replace(" ", "_", $h->H_Name);
//echo $title;
}
}
$WH = 'WH' . $col;
$OT = 'OT' . $col;
?>
<td <?php if ($flag2 == 1) { ?> title=" <?php echo $title; ?> "
<?php } else if ($flag == 1) { ?> title="sunday" <?php } ?>
class="celda_normal"
onkeyup="myFunction(this.parentNode.id,this.id,this.textContent);"
id="<?php echo $row . 'row' . $col . 'W'; ?>"
<?php if ($flag == 1 or $flag2 == 1) {
echo "style='background: #f5a6a7 ;'";
} else if ($todayflag == 1) {
echo "style='background: #cef0ad ;'";
} ?>
contenteditable="true" tabindex="<?php echo $col; ?>">
<?php if (!empty($a->$WH)) {
echo $a->$WH;
} else {
echo '';
} ?></td>
<td <?php if ($flag2 == 1) { ?> title=" <?php echo $title; ?> "
<?php } else if ($flag == 1) { ?> title="sunday" <?php } ?>
class="celda_normal"
onkeyup="myFunction(this.parentNode.id,this.id,this.textContent);"
id="<?php echo $row . 'row' . $col . 'OT'; ?>"
<?php if ($flag == 1 or $flag2 == 1) {
echo "style='background: #f5a6a7 ;'";
} else if ($todayflag == 1) {
echo "style='background: #cef0ad ;'";
} ?>
contenteditable="true" tabindex="<?php echo $col; ?>">
<?php if (!empty($a->$OT)) {
echo $a->$OT;
} else {
echo '';
} ?></td>
<?php $flag = 0;
$flag2 = 0;
$todayflag = 0;
} ?>
<td class="celda_normal summary" id="<?php echo $row . 'DW'; ?>">
<?php if (!empty($a->Days_Worked)) {
echo $a->Days_Worked;
} else {
echo "0.00";
} ?>
</td>
<td class="celda_normal summary" id="<?php echo $row . 'AB'; ?>">
<?php if (!empty($a->Absent)) {
echo $a->Absent;
} else {
echo "0.00";
} ?>
</td>
<td class="celda_normal summary" id="<?php echo $row . 'PL'; ?>">
<?php if (!empty($noofpublicholidays)) {
echo number_format($noofpublicholidays, 2, '.', '.');
} else {
echo "0.00";
} ?>
</td>
<td class="celda_normal summary" id="<?php echo $row . 'TS'; ?>">
<?php if (!empty($noofsundays)) {
echo $noofsundays;
} else {
echo "0";
} ?>
</td>
<td class="celda_normal summary" id="<?php echo $row . 'TH'; ?>">
<?php if (!empty($a->Total_WHrs)) {
echo $a->Total_WHrs;
} else {
echo "0.00";
} ?>
</td>
<td class="celda_normal summary" id="<?php echo $row . 'OTH'; ?>">
<?php if (!empty($a->Total_OTHrs)) {
echo $a->Total_OTHrs;
} else {
echo "0.00";
} ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div><!-- End table-responsive -->
<!-- <div class="row">
<div class="col-md-12 text-right">
<input type="button" class="btn btn-success" id="c" value="save">
</div>
</div> -->
</div>
</div> <!-- End card-body -->
</div> <!-- End card -->
</div> <!-- End col -->
</div> <!-- End row -->
</div>
</div> <!-- End container-fluid -->
</div>
</div>
<!-- <script type="text/javascript" src="<?php echo base_url(); ?>public/assets/js/common.js" charset="utf-8"></script> -->
<script type="text/javascript">
$(document).ready(function() {
// Click event for the button
$('#c').click(function() {
var s = findInvalidData();
//alert(s);
if (s == 0) {
resetFinalValues();
var Totalnoofdays = <?php echo $monthdays ?>;
var alldata = $("#attendance").tableToJSON();
alldata = JSON.stringify(alldata);
var month = $('#month').val();
var currentmonth = month.substr(0, 3);
var currentyear = month.substr(4, 4);
var montharray = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var currentmonth = jQuery.inArray(currentmonth, montharray); //!== -1
currentmonth++;
var currentdate = '01-' + currentmonth + '-' + currentyear;
var totaldata = 0;
$('#loader').show();
$.ajax({
data: {
param1: alldata,
param2: currentdate,
param3: Totalnoofdays
},
//dataType:"json",
type: "POST",
url: "<?php echo base_url() ?>monthlypay/saveAttendance",
success: function(data) {
if (data) {
$('#loader').hide();
alert(data);
//totaldata = totaldata + parseFloat(data);
//console.log(data);
}
}
});
} else {
alert('Plesae Provide Working Hrs and OT Hrs Correctly..!');
}
}); });
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// function exportTableToExcel(tableId, filename = 'attendance.xlsx') {
// var table = document.getElementById(tableId);
// var rows = table.rows;
// var csv = [];
// // Loop through table rows and cells
// for (var i = 0; i < rows.length; i++) {
// var row = rows[i];
// var cols = row.querySelectorAll('td, th');
// var rowData = [];
// // Loop through each cell in the row
// for (var j = 0; j < cols.length; j++) {
// rowData.push(cols[j].innerText);
// }
// csv.push(rowData.join('\t'));
// }
// // Create a Blob from the CSV data
// var blob = new Blob([csv.join('\n')], { type: 'application/vnd.ms-excel' });
// var link = document.createElement('a');
// link.href = URL.createObjectURL(blob);
// link.download = filename;
// // Trigger download
// link.click();
// }
function exportTableToExcel(tableId, filename = 'attendance.xlsx') {
var table = document.getElementById(tableId);
var rows = table.rows;
var data = [];
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var cols = row.querySelectorAll('td, th');
var rowData = [];
for (var j = 0; j < cols.length; j++) {
rowData.push(cols[j].innerText);
}
data.push(rowData);
}
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
XLSX.writeFile(wb, filename);
}
// Add click event listener to the export button
document.getElementById('exportButton').addEventListener('click', function () {
exportTableToExcel('attendance');
});
});
$(document).ready(function() {
// $("#attendance").CongelarFilaColumna({
// lboHoverTr: true
// });
$('html').bind('keypress', function(e) {
if (((e.which || e.keyCode) == 8) || ((e.which || e.keyCode) == 9) || ((e.which || e.keyCode) ==
46) || ((e.which || e.keyCode) == 37) || ((e.which || e.keyCode) == 39)) {
return true;
}
if (e.keyCode == 13) {
return false;
}
if (((e.which || e.keyCode) < 48) || ((e.which || e.keyCode) > 57)) {
return false;
}
});
$('td').focus(function(e) {
var id = e.target.id;
var val = document.getElementById(id).textContent
//console.log(val);
if (val == 0) {
window.setTimeout(function() {
document.getElementById(id).textContent = '';
}, 0);
}
});
$('td').focusout(function(e) {
var id = e.target.id;
var val = document.getElementById(id).textContent
if (val == '') {
window.setTimeout(function() {
document.getElementById(id).textContent = '0';
}, 0);
}
//console.log(val);
});
var d = new Date().getFullYear() + '' + (new Date().getMonth() + 1) + '' + new Date().getDate();
//alert(d);
var str = $('#month').val();
var monthname = str.substr(0, 3);
var monthyear = str.substr(4);
monthno = new Date(Date.parse(monthname + " 1, 2012")).getMonth() + 1;
var n = monthyear + '' + monthno + '01';
if (d < n) {
$('#c').hide();
} else {
$('#c').show();
}
});
</script>
<script>
function myFunction(p, i, v) {
var v = v;
var i = i;
var id = i.substr(-1);
var len = i.length;
var nxtid = 0;
var nxtvalue = 0;
var curvalue = 0;
var curid = 0;
if (v > 24) {
alert('Working Hrs Do Not Exceed 24 HRs');
$(i).focus();
document.getElementById(i).textContent = '';
return false;
}
if (id == 'W' && v > 8) { // checking working hrs vallue is more than 8, if it is set as OT Hrs more than 8
var j = '#' + i;
var nextid = $(j).closest('td').next('td');
nxtid = nextid[0].attributes[2].value;
nxtvalue = v - 8;
curvalue = 8;
curid = i;
document.getElementById(i).innerHTML = parseFloat(curvalue)
if (document.getElementById(nxtid)) {
document.getElementById(nxtid).innerHTML = parseFloat(nxtvalue)
} else {
nxtid = nextid[0].attributes[3].value;
document.getElementById(nxtid).innerHTML = parseFloat(nxtvalue)
}
} else if (id == 'T' && v > 16) {
alert("OT Should not exceed 16 Hrs");
$(i).focus();
document.getElementById(i).innerHTML = '';
} else if (id == 'S' && v > 16) {
var j = '#' + i;
//console.log(i);
//console.log('********************************************');
var nextid = $(j).closest('td').next('td');
//console.log(nextid);
//console.log('********************************************');
nxtid = nextid[0].attributes[3].value;
//console.log('********************************************');
//console.log(nxtid);
//console.log(nextid[0].attributes[2].value);
nxtvalue = v - 16;
curvalue = 16;
curid = i;
document.getElementById(i).innerHTML = parseFloat(curvalue)
document.getElementById(nxtid).innerHTML = parseFloat(nxtvalue)
}
var totalworkingHrs = 0;
var sundayWorkingHr = 0;
var totalOTHrs = 0;
var paidleave = 0;
var totalDaysWorked = 0;
var absent = 0;
var sundays = <?php echo $noofsundays ?>;
var sundaysArray = <?php echo json_encode($sundayarray); ?>;
var publicholidays = <?php echo $noofpublicholidays ?>;
var totaldays = <?php echo $monthdays ?>;
totaldays = (totaldays * 2) + 3;
//console.log(totaldays);
var totalhrsid = p + 'TH';
var totalothrsid = p + 'OTH';
var paidleaveid = p + 'PL';
var daysworkedid = p + 'DW';
var absentid = p + 'AB';
//document.getElementById(i).textContent = v;
//alert('Total Hrs-'+document.getElementById(i).textContent);
var Row = $('#attendance').find('tr').eq(p).find('td');
// console.log(Row);
$.each(Row, function(index, value) {
cal: {
if (index >= totaldays) {
break cal;
}
if ((index != 0) && (index != 1) && (index != 2)) // && (index > totaldays))
{
var str = value.id;
var str1 = str.substr(-1);
var str2 = str.substr(-2);
var str3 = str.substr(-3);
if (str1 == 'W') {
// sundayValidation = false;
// let dateInt = +str3.replace(/\D/g, '');
// sundaysArray.forEach(element => {
// if (+element == dateInt) {
// sundayValidation = true;
// var text = value.textContent.trim();
// var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
// sundayWorkingHr += current;
// }
// });
// if (sundayValidation == false) {
// var text = value.textContent.trim();
// var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
// totalworkingHrs += current;
// }
var text = value.textContent.trim();
var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
totalworkingHrs += current;
if (current == 0) {
absent++;
}
} else {
var text = value.textContent.trim();
var current = (text === '' || isNaN(parseFloat(text))) ? 0 : parseFloat(value.textContent);
totalOTHrs = totalOTHrs + current;
}
}
}
// break;
});
// if(paidleave == 1 )
// {
// absent = 0;
// alert('if');
// }
// if(paidleave == 0)
// {
// absent = 0;
// alert('else if');
// }
// else
// {
// // absent = paidleave-0;
// // paidleave = 0;
// absent = paidleave;
// paidleave = 0;
// alert('else');
// }
// TotalOT = totalOTHrs + sundayWorkingHr;
TotalOT = totalOTHrs;
TotalWH = totalworkingHrs;
document.getElementById(totalhrsid).textContent = parseFloat(TotalWH).toFixed(2); // == ''?0:parseFloat(totalworkingHrs));
document.getElementById(totalothrsid).textContent = parseFloat(TotalOT).toFixed(2); // == ''?0:parseFloat(totalOTHrs));
document.getElementById(paidleaveid).textContent = parseFloat(publicholidays).toFixed(2);
document.getElementById(daysworkedid).textContent = parseFloat((TotalWH / 8)).toFixed(2);
absent = (absent) ? (absent - publicholidays) : 0;
document.getElementById(absentid).textContent = parseFloat(absent).toFixed(2);
}
function findInvalidData() {
var flag = 0;
//totaldays = (totaldays * 2);
var Row = $('#attendance').find('tr');
$.each(Row, function(index, value) {
//console.log(index+'-'+value);
var td = $(value).find('td');
$.each(td, function(iter, val) {
//console.log(iter+'-'+val.id+'-'+val.textContent);
if ((val.id).substr(-1) == 'W' && (val.id).substr(-2) != 'DW') {
if (parseFloat(val.textContent) > 8) {
//alert('more than 8');
var ide = '#' + (val.id);
var p = $(ide).css("background-color", "red");
p.hide(1000).show(1000);
p.queue(function() {
p.css({
"background-color": "white"
});
$(ide).mouseover(function() {
$(this).css({
"background-color": " #00a65a;"
})
}).mouseout(function() {
$(this).css({
"background-color": "white"
});
});
});
flag++;
return false;
}
} else if ((val.id).substr(-1) == 'T') {
if (parseFloat(val.textContent) > 16) {
var ide = '#' + (val.id);
var p = $(ide).css("background-color", "red");
p.hide(1000).show(1000);
p.queue(function() {
p.css({
"background-color": "white"
});
$(ide).mouseover(function() {
$(this).css({
"background-color": " #00a65a;"
})
}).mouseout(function() {
$(this).css({
"background-color": "white"
});
});
});
flag++;
return false;
}
}
});
});
//for Reset WH, OT, PL, AB to zero if all days entries are zero
//alert('before for');
return flag;
}
function resetFinalValues() {
var Row = $('#attendance').find('tr');
var totalrowcount = Row.length;
totalrowcount = totalrowcount - 1;
var totaldays = <?php echo $monthdays ?>;
console.log(totalrowcount);
for (i = 1; i <= totalrowcount; i++) {
//alert('inside for');
// var a = parseFloat(document.getElementById(i+'PL').textContent);
var b = parseFloat(document.getElementById(i + 'AB').textContent);
//alert(a+'-'+b+'-'+totaldays);
if (totaldays == (b)) {
//document.getElementById(i+'PL').textContent = '0.00';
document.getElementById(i + 'AB').textContent = '0.00';
}
}
}
</script>