ohctech_p8/attendence_short_report_pdf.php
Dushant Mali 899fb3e65a Upgrade 7 to 8
Upgrade 7 to 8
2024-11-02 18:03:13 +05:30

549 lines
22 KiB
PHP

<?php
// include('pdf_header.php');
include('includes/config/config.php');
include('includes/functions.php');
// include('pop_up_top.php');
if ($_REQUEST['excel'] == 'YES') {
header('Content-Type: application/force-download');
header('Content-disposition: attachment; filename=AttendanceReport.xls');
}
?>
<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('new_pdf_header.php') ?>
<br>
<br>
<br>
<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;
}
function getShiftStatus($i, $id, $ohc_idd, $year)
{
$sql_attendance = "SELECT ar.shift as shift 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['shift']);
$shiftName = getFieldFromTable('status_name', 'shift_status', 'shift_status_id', $row_att['shift']);
error_log("SHIFT NAME : " . $shiftName);
$ot = $shiftName;
return strtoupper($ot);
}
function getTotalShiftCount($emp_id , $ohc_id, $month , $year , $shiftquery){
// $shift_id = getFieldFromTable('shift_status_id', 'shift_status', 'status_name', $shiftName);
$sql = "SELECT COUNT(shift) as total FROM attendance_detail a INNER JOIN shift_status b ON a.shift = b.shift_status_id WHERE staff_id = '$emp_id' AND staff_deploy_ohc = '$ohc_id' AND month(in_time) = '$month' AND year(in_time) = '$year' $shiftquery";
error_log("TOTAL SHIFT ::" . $sql);
$query = mysqli_query($GLOBALS['conn'], $sql);
$row = mysqli_fetch_array($query);
return $row['total'];
}
function getTotalHourOt($emp_id , $ohc_id, $month , $year){
$sqlTotalOT = "SELECT SUM(ot) as ot from attendance_detail where staff_deploy_ohc = '$ohc_id' AND staff_id = '$emp_id' AND month(in_time) = '$month' AND year(in_time) = '$year'";
$queryTotalOT = mysqli_query($GLOBALS['conn'], $sqlTotalOT);
$rowTotalOT = mysqli_fetch_array($queryTotalOT);
return $rowTotalOT['ot'];
}
$TotalDaysInThisMonth = cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year);
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="">Sr.</th>
<th rowspan="" width="5%">Emp Code</th>
<th rowspan="" width="5%">Name</th>
<?php for ($i = 1; $i <= cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year); $i++) { ?>
<th width="2%">
<?php $dateDM = $i . "-" . $_POST['attend_month'] . "-" . $year;
// echo date("D", strtotime($dateDM)) . " " . date("d-m-Y", strtotime($dateDM));
echo $i
?>
</th>
<?php } ?>
<th rowspan="" style="background-color: black; color: white;">P</th>
<th rowspan="" style="background-color: black; color: white;">A</th>
<th rowspan="" style="background-color: black; color: white;">CL</th>
<th rowspan="" style="background-color: black; color: white;">H</th>
<th rowspan="" style="background-color: black; color: white;">HP</th>
<th rowspan="" style="background-color: black; color: white;">HD</th>
<th rowspan="" style="background-color: black; color: white;">WO</th>
<th rowspan="" style="background-color: black; color: white;">WOP</th>
<th rowspan="" style="background-color: black; color: white;">TOTAL</th>
<th rowspan="" style="background-color: black; color: white;">OT</th>
</tr>
<?php $sql_attend = "SELECT distinct(s.staff_id) as staff_id, s.staff_name as staff_name , s.emp_code 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['emp_code'] ?></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 = "";
$ShiftStatus = "";
$in_time = getInTime($i, $row_attend['staff_id'], $ohc_id, $year);
$ShiftStatus = getShiftStatus($i, $row_attend['staff_id'], $ohc_id, $year);
error_log("SHIFT : " . $ShiftStatus);
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 width="2%">
<?php
// if ($in_time != "" && $out_time != "") {
// echo 'P';
// }else{
// echo 'A';
// }
echo $ShiftStatus;
?>
</td>
<?php
}
$count++;
?>
<td style="background-color: black; color: white;">
<?php
$totalHDPresent05 = "";
$totalHDPresent05 = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('HD') ");
$HDCount=0;
for ($i=0; $i < $totalHDPresent05 ; $i++) {
$HDCount +=0.5;
}
// echo $dayWork = getNoOfDays($row_attend['staff_id'], $ohc_id, $year)
$totalPresentDay = "";
echo $totalPresentDay = (getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('A1' , 'A2' , 'A3' , 'B' , 'C' )")+$HDCount);
?>
</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:black; color: white;">
<?php
// echo convertMinutesToHoursAndMinutes($total_hours[$count - 1]);
$totalAbsentDay= "";
$totalPresent = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('A1' , 'A2' , 'A3' , 'B' , 'C' , 'WOP' , 'WO' , 'H' , 'HD' , 'CL') ");
echo $totalAbsentDay = ($TotalDaysInThisMonth-$totalPresent);
?>
</td>
<td style="background-color: black; color: white;">
<?php
// echo $totalWo = getWo($row_attend['staff_id'], $ohc_id, $year);
$totalCLPresent="";
echo $totalCLPresent = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('CL') ");
?>
</td>
<td style="background-color: black; color: white;">
<?php
// echo cal_days_in_month(CAL_GREGORIAN, $_POST['attend_month'], $year) - $dayWork - $totalWo ;
$totalHPresent = "";
echo $totalHPresent = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('H') ");
?>
</td>
<td style="background-color: black; color: white;">
<?php
$totalHPPresent = "";
echo $totalHPPresent = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('HP') ");
?>
</td>
<td style="background-color: black; color: white;">
<?php
$totalHDPresent = "";
$totalHDPresent = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('HD') ");
echo $HDCount;
?>
</td>
<td style="background-color: black; color: white;">
<?php
$totalWOPresent = "";
echo $totalWOPresent = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('WO') ");
?>
</td>
<td style="background-color: black; color: white;">
<?php
$totalWOPPresent = "";
echo $totalWOPPresent = getTotalShiftCount($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year ,"AND b.status_name IN ('WOP') ");
?>
</td>
<td style="background-color: black; color: white;">
<?php
echo ($totalPresentDay+$totalAbsentDay+$totalCLPresent+$totalHPresent+$totalHPPresent+$HDCount+$totalWOPresent+$totalWOPPresent);
?>
</td>
<td style="background-color: black; color: white;">
<?php
echo $totalPresentOT = getTotalHourOt($row_attend['staff_id'], $ohc_id, $_POST['attend_month'], $year);
?>
</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));
if ($_REQUEST['excel'] != 'YES') {
?>
<div align="center">
<button align="center" id="printPageButton" class="btn btn-success" onClick="window.print();">Print</button>
</div>
<?php } ?>
</body>
<script>
$(document).ready(function() {
window.print();
});
</script>