418 lines
16 KiB
PHP
418 lines
16 KiB
PHP
<?php
|
|
// include('pdf_header.php');
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
// include('pop_up_top.php');
|
|
|
|
?>
|
|
|
|
<style type="text/css">
|
|
.btn {
|
|
background-color: #4CAF50;
|
|
border-radius: 5%;
|
|
/* Green */
|
|
border: none;
|
|
color: white;
|
|
padding: 15px 32px;
|
|
text-align: center;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
font-size: 16px;
|
|
margin: 4px 2px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
@media print {
|
|
#printPageButton {
|
|
display: none;
|
|
}
|
|
}
|
|
|
|
.table,
|
|
.th,
|
|
.td {
|
|
border: 1px solid black;
|
|
text-align: center;
|
|
border-collapse: collapse;
|
|
}
|
|
|
|
|
|
p {
|
|
font-weight: bold;
|
|
}
|
|
</style>
|
|
|
|
<body>
|
|
|
|
<?php include('pdf_ohc_header.php') ?>
|
|
<p align="center" style="font-size:20px"><strong> ATTENDANCE REPORT </strong></p>
|
|
|
|
|
|
<table>
|
|
<td style="font-size: 15px;"><strong>For:</strong>
|
|
<?php echo $month_name = date("F", mktime(0, 0, 0, $_POST['attend_month'], 10)) . " " . $_POST['yearAtt'];
|
|
|
|
$ohc_id = $_REQUEST['ohc_attend'];
|
|
|
|
?></td>
|
|
|
|
|
|
</table>
|
|
<br>
|
|
<td style="font-size: 15px;">
|
|
<strong>OHC Name: </strong>
|
|
<?php echo getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $ohc_id); ?>
|
|
</td>
|
|
|
|
|
|
<?php
|
|
|
|
$year = $_POST['yearAtt'];
|
|
|
|
function getInTime($i, $id, $ohc_idd, $year)
|
|
{
|
|
|
|
$sql_attendance = "SELECT ar.in_time as in_time FROM `attendance_detail` ar LEFT JOIN `attendance_master` a ON a.attendance_id = ar.attendance_id where ar.staff_id = '$id' AND ar.staff_deploy_ohc = '" . $ohc_idd . "' and day(ar.in_time)='$i' and month(a.attendance_date) = '" . $_POST['attend_month'] . "' and year(a.attendance_date)='" . $year . "'";
|
|
error_log("QUERY INTIME::" . $sql_attendance);
|
|
$query_attendance = mysqli_query($GLOBALS['conn'], $sql_attendance);
|
|
$row_att = mysqli_fetch_array($query_attendance);
|
|
error_log("INTIME::" . $row_att['in_time']);
|
|
$inTime = $row_att['in_time'];
|
|
if ($inTime == "") {
|
|
$inTime = "";
|
|
} else {
|
|
$date = date_create($inTime);
|
|
// echo date_format($date,"Y/m/d H:i:s");
|
|
$time = date_format($date, "d-m-Y h:i:sa");
|
|
$inTime = $time;
|
|
}
|
|
return $inTime;
|
|
}
|
|
|
|
function getOutTime($i, $id, $ohc_idd, $month, $year)
|
|
{
|
|
|
|
$sql_attendance = "SELECT ar.out_time as out_time FROM `attendance_detail` ar RIGHT JOIN `attendance_master` a ON a.attendance_id = ar.attendance_id where ar.staff_id = '$id' AND ar.staff_deploy_ohc = '" . $ohc_idd . "' and day(ar.out_time)='$i' and month(ar.out_time) = '" . $month . "' and year(a.attendance_date)='" . $year . "' ";
|
|
error_log("QUERY OUTTIME::" . $sql_attendance);
|
|
$query_attendance = mysqli_query($GLOBALS['conn'], $sql_attendance);
|
|
$row_att = mysqli_fetch_array($query_attendance);
|
|
error_log("OUTTIME::" . $row_att['out_time']);
|
|
|
|
$outTime = $row_att['out_time'];
|
|
if ($outTime == "") {
|
|
$outTime = "";
|
|
} else {
|
|
$date = date_create($outTime);
|
|
$time = date_format($date, "d-m-Y h:i:sa");
|
|
// $time = date_format( $date , "h:i:sa");
|
|
$outTime = $time;
|
|
}
|
|
return $outTime;
|
|
}
|
|
|
|
|
|
function getOutTimeGreater($i, $id, $ohc_idd, $month, $year, $in_time)
|
|
{
|
|
$indate = DateTime::createFromFormat('d-m-Y h:i:sA', $in_time);
|
|
$indate_formatted = $indate->format('Y-m-d H:i:s');
|
|
$sql_attendance = "SELECT ar.out_time as out_time FROM `attendance_detail` ar RIGHT JOIN `attendance_master` a ON a.attendance_id = ar.attendance_id where ar.staff_id = '$id' AND ar.staff_deploy_ohc = '" . $ohc_idd . "' and ar.out_time>'$indate_formatted' and day(ar.out_time)='$i' and month(ar.out_time) = '" . $month . "' and year(a.attendance_date)='" . $year . "' ";
|
|
error_log("QUERY OUTTIME greater::" . $sql_attendance);
|
|
$query_attendance = mysqli_query($GLOBALS['conn'], $sql_attendance);
|
|
$row_att = mysqli_fetch_array($query_attendance);
|
|
error_log("OUTTIME Greater::" . $row_att['out_time']);
|
|
|
|
$outTime = $row_att['out_time'];
|
|
if ($outTime == "") {
|
|
$outTime = "";
|
|
} else {
|
|
$date = date_create($outTime);
|
|
$time = date_format($date, "d-m-Y h:i:sa");
|
|
// $time = date_format( $date , "h:i:sa");
|
|
$outTime = $time;
|
|
}
|
|
return $outTime;
|
|
}
|
|
|
|
|
|
function getOt($i, $id, $ohc_idd, $year)
|
|
{
|
|
|
|
$sql_attendance = "SELECT ar.ot as ot FROM `attendance_detail` ar RIGHT JOIN `attendance_master` a ON a.attendance_id = ar.attendance_id where ar.staff_id = '$id' AND ar.staff_deploy_ohc = '" . $ohc_idd . "' and day(ar.in_time)='$i' and month(a.attendance_date) = '" . $_POST['attend_month'] . "' and year(a.attendance_date)='" . $year . "' ";
|
|
error_log("QUERY ot::" . $sql_attendance);
|
|
$query_attendance = mysqli_query($GLOBALS['conn'], $sql_attendance);
|
|
$row_att = mysqli_fetch_array($query_attendance);
|
|
error_log("ot::" . $row_att['ot']);
|
|
$ot = $row_att['ot'];
|
|
return strtoupper($ot);
|
|
}
|
|
|
|
|
|
function getRemarks($i, $id, $ohc_idd, $year)
|
|
{
|
|
$sql_attendance = "SELECT ar.remark as remarks FROM `attendance_detail` ar RIGHT JOIN `attendance_master` a ON a.attendance_id = ar.attendance_id where ar.staff_id = '$id' AND ar.staff_deploy_ohc = '" . $ohc_idd . "' and day(ar.in_time)='$i' and month(a.attendance_date) = '" . $_POST['attend_month'] . "' and year(a.attendance_date)='" . $year . "'";
|
|
|
|
error_log("REMARKS" . $sql_attendance);
|
|
$query_attendance = mysqli_query($GLOBALS['conn'], $sql_attendance);
|
|
$row_att = mysqli_fetch_array($query_attendance);
|
|
return $row_att['remarks'];
|
|
}
|
|
|
|
function getRelay($id)
|
|
{
|
|
|
|
$sql_attendance = "SELECT a.relay_set_work FROM `attendance_detail` ar RIGHT JOIN `attendance_master` a ON a.attendance_id = ar.attendance_id where ar.staff_id = '$id' ";
|
|
error_log("REMARKS" . $sql_attendance);
|
|
$query_attendance = mysqli_query($GLOBALS['conn'], $sql_attendance);
|
|
$row_att = mysqli_fetch_array($query_attendance);
|
|
|
|
|
|
if ($row_att['relay_set_work'] == 'G') {
|
|
return 'GENERAL';
|
|
} else {
|
|
return $row_att['relay_set_work'];
|
|
}
|
|
}
|
|
|
|
|
|
function getNoOfDays($id, $ohc_idd, $year)
|
|
{
|
|
|
|
$sql_days = "SELECT in_time , out_time from attendance_detail a left join attendance_master b on a.attendance_id = b.attendance_id where a.staff_id='$id' AND a.staff_deploy_ohc = '" . $ohc_idd . "' and month(b.attendance_date) = '" . $_POST['attend_month'] . "' and a.wo!='W' and year(b.attendance_date)='" . $year . "'";
|
|
|
|
error_log("NO. OF DAYS::" . $sql_days);
|
|
|
|
$result_days = mysqli_query($GLOBALS['conn'], $sql_days);
|
|
$numDay = 0;
|
|
while ($row_days = mysqli_fetch_assoc($result_days)) {
|
|
if ($row_days['in_time'] == "00:00:00" && $row_days['out_time'] == "00:00:00") {
|
|
if (empty($row_days['out_time']) && empty($row_days['in_time'])) {
|
|
}
|
|
} else {
|
|
$numDay++;
|
|
}
|
|
}
|
|
|
|
|
|
return $numDay;
|
|
}
|
|
|
|
|
|
function getWo($id, $ohc_idd, $year)
|
|
{
|
|
|
|
$sql_days = "SELECT count(*) as total from attendance_detail a left join attendance_master b on a.attendance_id = b.attendance_id where a.staff_id='$id' AND a.staff_deploy_ohc = '" . $ohc_idd . "' and month(b.attendance_date) = '" . $_POST['attend_month'] . "' and a.wo='W' and year(a.attendance_date)='" . $year . "'";
|
|
|
|
error_log("NO. OF DAYS::" . $sql_days);
|
|
|
|
$result_days = mysqli_query($GLOBALS['conn'], $sql_days);
|
|
$woDay = 0;
|
|
if ($row_days = mysqli_fetch_assoc($result_days)) {
|
|
$woDay = $row_days['total'];
|
|
}
|
|
|
|
|
|
return $woDay;
|
|
}
|
|
|
|
function getNoOfHours($intime, $outtime)
|
|
{
|
|
|
|
$diff = strtotime($outtime) - strtotime($intime);
|
|
|
|
if ($diff < 0) return 0;
|
|
// $hours = floor($diff / 3600);
|
|
$minutes = floor($diff / 60);
|
|
|
|
// error_log("DIFFERENCE::" . $hours . " --- " . $minutes);
|
|
return $minutes;
|
|
}
|
|
|
|
function convertMinutesToHoursAndMinutes($minutes)
|
|
{
|
|
$hours = floor($minutes / 60);
|
|
$remainingMinutes = $minutes % 60;
|
|
|
|
$result = $hours . " hour" . ($hours == 1 ? "" : "s");
|
|
|
|
if ($remainingMinutes > 0) {
|
|
$result .= " and " . $remainingMinutes . " minute" . ($remainingMinutes == 1 ? "" : "s");
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
error_log('tt'.cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year));
|
|
?>
|
|
|
|
<table border="1" cellspacing="0" style="text-align: center;font-size: 12px;" width="100%">
|
|
|
|
|
|
<tr>
|
|
<th rowspan="2">Sr.</th>
|
|
<th rowspan="2" width="5%">Name</th>
|
|
<?php for ($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year); $i++) { ?>
|
|
<th colspan="5" width="8%">
|
|
<?php $dateDM = $i . "-" . $_POST['attend_month'] . "-" . $year;
|
|
echo date("D", strtotime($dateDM)) . " " . date("d-m-Y", strtotime($dateDM));
|
|
?></th>
|
|
<?php } ?>
|
|
<th rowspan="2" style="background-color: green; color: white;">No. of Days Worked</th>
|
|
<th rowspan="2" style="background-color:darkcyan; color: white;">No. of Hours Worked</th>
|
|
<th style="background-color: yellow; color:black;" rowspan="2">W/O</th>
|
|
<th style="background-color: red; color: white;" rowspan="2">Absent</th>
|
|
<!-- <th rowspan="2">Remarks</th> -->
|
|
</tr>
|
|
|
|
<tr>
|
|
<?php for ($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year); $i++) { ?>
|
|
<th width="5%">In</th>
|
|
<th width="5%">Out</th>
|
|
<th width="5%">Worked Hrs</th>
|
|
<th width="5%">O/T</th>
|
|
<th width="10%">Remark</th>
|
|
<?php } ?>
|
|
</tr>
|
|
<?php $sql_attend = "SELECT distinct(s.staff_id) as staff_id, s.staff_name as staff_name from `staff_master` s left join attendance_detail a ON s.staff_id = a.staff_id WHERE a.staff_deploy_ohc = '" . $ohc_id . "'";
|
|
$result_attend = mysqli_query($GLOBALS['conn'], $sql_attend);
|
|
error_log("SQL ATTENDANCE : " . $sql_attend);
|
|
if (!$result_attend) {
|
|
echo "Something Went Wrong";
|
|
die;
|
|
}
|
|
$j = 0;
|
|
$sr = 1;
|
|
$total_hours = array();
|
|
$count = 0;
|
|
while ($row_attend = mysqli_fetch_assoc($result_attend)) {
|
|
|
|
?>
|
|
|
|
<tr>
|
|
<td><?php echo $sr ?></td>
|
|
<td><?= $row_attend['staff_name'] ?></td>
|
|
|
|
<?php
|
|
$total = 0;
|
|
for ($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year); $i++) {
|
|
|
|
$in_time = "";
|
|
$out_time = "";
|
|
|
|
$in_time = getInTime($i, $row_attend['staff_id'], $ohc_id, $year);
|
|
error_log("in time " . $in_time);
|
|
error_log("attend month " . $_POST['attend_month']);
|
|
if ($in_time == "") {
|
|
} else {
|
|
if (cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year) == $i) {
|
|
$out_time = getOutTime(1, $row_attend['staff_id'], $ohc_id, $_POST['attend_month'] + 1, $year);
|
|
} else {
|
|
$out_time = getOutTime($i, $row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year);
|
|
error_log("out time " . $out_time);
|
|
if ($out_time == "") {
|
|
$out_time = getOutTime($i + 1, $row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year);
|
|
error_log("out time " . $out_time);
|
|
}
|
|
}
|
|
}
|
|
$format = 'd-m-Y H:i:sa';
|
|
$datetimeObjIn = DateTime::createFromFormat($format, $in_time);
|
|
if ($out_time != "") {
|
|
$datetimeObjOut = DateTime::createFromFormat($format, $out_time);
|
|
|
|
if ($datetimeObjIn->getTimestamp() > $datetimeObjOut->getTimestamp()) {
|
|
|
|
$out_time = getOutTimeGreater($i, $row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year, $in_time);
|
|
|
|
if ($out_time == "") {
|
|
$out_time = getOutTime($i + 1, $row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year);
|
|
}
|
|
}
|
|
}
|
|
|
|
$total += getNoOfHours($in_time, $out_time);
|
|
$total_hours[$count] = $total;
|
|
error_log("out time " . $out_time);
|
|
?>
|
|
<td><?php echo $in_time ?></td>
|
|
<td><?php echo $out_time ?></td>
|
|
<td><?php
|
|
if($in_time!='' && $out_time!=''){
|
|
$dateTimeObject1 = date_create($in_time);
|
|
$dateTimeObject2 = date_create($out_time);
|
|
|
|
$interval = date_diff($dateTimeObject1, $dateTimeObject2);
|
|
|
|
|
|
echo $interval->h.' Hrs '.$interval->i.' min '; }
|
|
?></td>
|
|
<td><?php echo getOt($i, $row_attend['staff_id'], $ohc_id, $year) ?></td>
|
|
<td><?php echo getRemarks($i, $row_attend['staff_id'], $ohc_id, $year) ?></td>
|
|
<?php }
|
|
$count++;
|
|
?>
|
|
|
|
<td style="background-color: green; color: white;">
|
|
<?php echo $dayWork = getNoOfDays($row_attend['staff_id'], $ohc_id, $year) ?></td>
|
|
|
|
<?php
|
|
// $total = 0;
|
|
// for ($j = 1; $j <= cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year); $j++) {
|
|
// $hours = getNoOfHours(getInTime($j, $row_attend['staff_id'], $ohc_id), getOutTime($j, $row_attend['staff_id'], $ohc_id));
|
|
|
|
// $total = $total + $hours;
|
|
|
|
// error_log("TOTAL HOURS::" . $total);
|
|
// }
|
|
?>
|
|
<td style="background-color:darkcyan; color: white;">
|
|
<?php echo convertMinutesToHoursAndMinutes($total_hours[$count - 1]); ?></td>
|
|
|
|
<td style="background-color: yellow; color: black;">
|
|
<?php echo $totalWo = getWo($row_attend['staff_id'], $ohc_id, $year); ?></td>
|
|
<td style="background-color: red; color: white;">
|
|
<?php echo cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year) - $dayWork - $totalWo ?></td>
|
|
</tr>
|
|
|
|
|
|
<?php
|
|
$sr++;
|
|
} ?>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<br>
|
|
<br>
|
|
<br>
|
|
<?php
|
|
$sql_sign_rk = "select a.*,d.emp_sign as empSign,d.image_type from attendance_master a left join attendance_detail b on a.attendance_id = b.attendance_id left join tbl_users c on a.approval_user=c.user_id left join employee_signature d on c.staff_id=d.staff_id where a.mine_name='" . $_SESSION['current_mine'] . "'";
|
|
|
|
|
|
error_log("SIGN QUERY::" . $sql_sign_rk);
|
|
$result_sign_rk = mysqli_query($conn, $sql_sign_rk);
|
|
$row_sign_rk = mysqli_fetch_assoc($result_sign_rk); ?>
|
|
|
|
|
|
<?php
|
|
$sql_sign = "select a.*,d.emp_sign as empSign,d.image_type from attendance_master a left join attendance_detail b on a.attendance_id = b.attendance_id left join tbl_users c on a.created_by=c.user_id left join employee_signature d on c.staff_id=d.staff_id where a.mine_name='" . $_SESSION['current_mine'] . "'";
|
|
|
|
|
|
error_log("SIGN QUERY::" . $sql_sign);
|
|
$result_sign = mysqli_query($conn, $sql_sign);
|
|
$row_sign = mysqli_fetch_assoc($result_sign);
|
|
|
|
error_log("total worked array" . print_r($total_hours, true));
|
|
?>
|
|
|
|
|
|
<div align="center">
|
|
|
|
<button align="center" id="printPageButton" class="btn btn-success" onClick="window.print();">Print</button>
|
|
</div>
|
|
</body>
|
|
<script>
|
|
$(document).ready(function() {
|
|
window.print();
|
|
|
|
});
|
|
</script>
|