159 lines
5.3 KiB
PHP
159 lines
5.3 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
|
|
$ohcid = $_REQUEST['ohc_id10'];
|
|
$batch_id = $_REQUEST['batch_name10'];
|
|
$startDate = date('Y-m-d', strtotime($_REQUEST['startdate10']));
|
|
$endDate = date('Y-m-d', strtotime($_REQUEST['enddate10']));
|
|
|
|
if ($type === 'excel') {
|
|
header("Content-Type: application/vnd.ms-excel");
|
|
header("Content-Disposition: attachment; filename=batch_attendence_report.xls");
|
|
header("Pragma: no-cache");
|
|
header("Expires: 0");
|
|
}
|
|
|
|
error_log("OHC ID " . $ohcid);
|
|
error_log("BATCH ID " . $batch_id);
|
|
error_log("Start Date " . $startDate);
|
|
error_log("End Date " . $endDate);
|
|
?>
|
|
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />
|
|
<style>
|
|
@page {
|
|
margin: 15px;
|
|
}
|
|
.btn {
|
|
background-color: #4CAF50;
|
|
border-radius: 5%;
|
|
border: none;
|
|
color: white;
|
|
padding: 5px 8px;
|
|
text-align: center;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
font-size: 12px;
|
|
margin: 4px 2px;
|
|
cursor: pointer;
|
|
}
|
|
@media print {
|
|
#printPageButton {
|
|
display: none;
|
|
}
|
|
}
|
|
#test table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
}
|
|
#test th, #test td {
|
|
/* border: 1px solid #000; */
|
|
padding: 8px;
|
|
text-align: center;
|
|
}
|
|
|
|
#test th {
|
|
background-color: #f2f2f2;
|
|
font-size: 15px;
|
|
font-weight: bold;
|
|
padding: 10px;
|
|
}
|
|
</style>
|
|
|
|
<?php
|
|
|
|
if ($type === 'excel') {
|
|
|
|
}else{
|
|
include('pdf_current_ohc_header.php');
|
|
}
|
|
?>
|
|
<body style="padding: 10px;">
|
|
<table width="100%" style="border-collapse: collapse;">
|
|
<tr>
|
|
<td align="center" style="font-size: 15px; padding: 10px; padding-left: 350px;"><strong>Batch Attendance</strong></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="left" style="font-size: 12px; padding: 10px;"><strong>Duration: <?php echo date("d-M-Y", strtotime($startDate)); ?> to <?php echo date("d-M-Y", strtotime($endDate)); ?></strong></td>
|
|
<td align="right" style="font-size: 12px; padding: 10px;"><strong>Selected Location : <?= getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $ohcid) ?></strong></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" style="font-size: 12px; padding: 20px 10px;"><strong>Batch Name: </strong><?= getFieldFromTable('batch_name', 'training_batch_master', 'batch_id', $batch_id) ?></td>
|
|
</tr>
|
|
</table>
|
|
|
|
|
|
<br>
|
|
<table border="1" id="test" width="100%">
|
|
<tr>
|
|
<th>Beneficiary Name</th>
|
|
<th>Total Present</th>
|
|
<th>Total Absent</th>
|
|
<th>Total Leave</th>
|
|
<th>Total Present %</th>
|
|
<th>Total Absent %</th>
|
|
<th>Total Leave %</th>
|
|
</tr>
|
|
|
|
<?php
|
|
$sql2 = "SELECT * FROM training_batch_enrollment_beneficiary WHERE batch_id = '$batch_id'";
|
|
$result1 = mysqli_query($conn, $sql2);
|
|
|
|
while ($row1 = mysqli_fetch_assoc($result1)) {
|
|
$beneficiary_id = intval($row1['beneficiary_id']);
|
|
$beneficiary_name = getFieldFromTable('patient_name', 'patient_master', 'id', $beneficiary_id);
|
|
|
|
// Counts
|
|
$total_present = get_count('Present', $startDate, $endDate, $batch_id, $beneficiary_id);
|
|
$total_absent = get_count('Absent', $startDate, $endDate, $batch_id, $beneficiary_id);
|
|
$total_leave = get_count('Leave', $startDate, $endDate, $batch_id, $beneficiary_id);
|
|
|
|
// Overall Count
|
|
$total_days = $total_present + $total_absent + $total_leave;
|
|
$present_percentage = ($total_days > 0) ? round(($total_present / $total_days) * 100, 2) : 0;
|
|
$absent_percentage = ($total_days > 0) ? round(($total_absent / $total_days) * 100, 2) : 0;
|
|
$leave_percentage = ($total_days > 0) ? round(($total_leave / $total_days) * 100, 2) : 0;
|
|
?>
|
|
<tr>
|
|
<td><?php echo $beneficiary_name; ?></td>
|
|
<td><?php echo $total_present; ?></td>
|
|
<td><?php echo $total_absent; ?></td>
|
|
<td><?php echo $total_leave; ?></td>
|
|
<td><?php echo $present_percentage . '%'; ?></td>
|
|
<td><?php echo $absent_percentage . '%'; ?></td>
|
|
<td><?php echo $leave_percentage . '%'; ?></td>
|
|
</tr>
|
|
<?php } ?>
|
|
</table>
|
|
</body>
|
|
<?php
|
|
function get_count($status, $start_date, $end_date, $batch_id, $beneficiary_id) {
|
|
global $conn; // Access the global $conn variable
|
|
|
|
$sql = "SELECT COUNT(*) AS count
|
|
FROM beneficiary_attendence a
|
|
LEFT JOIN attendance_batch b ON a.pti_id = b.id
|
|
WHERE b.attendence_date >= '$start_date'
|
|
AND b.attendence_date <= '$end_date'
|
|
AND b.batch_id = '$batch_id'
|
|
AND a.beneficiary_id = '$beneficiary_id'
|
|
AND a.status = '$status'";
|
|
|
|
error_log("Check_sql_query: " . $sql);
|
|
$result = mysqli_query($conn, $sql);
|
|
|
|
if ($result) {
|
|
$row = mysqli_fetch_assoc($result);
|
|
return $row['count']; // Return the count from the associative array
|
|
} else {
|
|
return 0; // Handle query error
|
|
}
|
|
}
|
|
?>
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
window.print();
|
|
});
|
|
</script>
|