ohctech_p8/oxy_report_excel.php
2024-10-16 19:18:52 +05:30

237 lines
7.3 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
header('Content-Type: application/force-download');
header('Content-disposition: attachment; filename=Oxygen_Cylinder_Report.xls');
error_reporting(E_ERROR | E_PARSE);
$date1 = date_create($_POST['oxyDate1']);
$oxyDate1 = date_format($date1, "Y-m-d");
$oxyDate1_formate = date_format($date1, "d-m-Y");
$date2 = date_create($_POST['oxyDate2']);
$oxyDate2 = date_format($date2, "Y-m-d");
$oxyDate2_formate = date_format($date2, "d-m-Y");
?>
<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;
}
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 5px;
text-align: center;
}
th {
background-color: #e1e1e1;
}
</style>
<body>
<?php include('excel_ohc_header.php'); ?>
<h4>QHSE En / OHC / F / 19</h4>
<h3>Oxygen Cylinder Checklist</h3>
<h4>Date: <?php echo $oxyDate1_formate . " To " . $oxyDate2_formate ?></h4>
<table>
<?php
function getOxygenCylinderDetails($conn, $oxygen_cylinder_id, $check_date) {
$sql = "SELECT pressure_reading, any_leakage, water_humidifier_date, valve_closed, checked_by, remarks_t
FROM oxygen_cylinder_checklist
WHERE oxygen_cylinder_id = ? AND check_date = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("is", $oxygen_cylinder_id, $check_date);
$stmt->execute();
$result = $stmt->get_result();
$details = [];
while ($row = $result->fetch_assoc()) {
$details[] = $row;
}
$stmt->close();
return $details;
}
function getAllRemarks($conn, $check_date) {
$sql = "SELECT remarks FROM oxygen_cylinder_checklist WHERE check_date = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $check_date);
$stmt->execute();
$result = $stmt->get_result();
$remarksArray = [];
while ($row = $result->fetch_assoc()) {
$remarksArray[] = $row['remarks'];
}
$stmt->close();
if (!empty($remarksArray)) {
return implode(", ", $remarksArray);
} else {
return null;
}
}
$ohc_type = $_SESSION['current_ohcttype'];
$primary_ohc_type = getFieldFromTable('primary_ohc_id', 'ohc_type', 'ohc_type_id', $ohc_type);
if ($primary_ohc_type) {
$ohc_type = $primary_ohc_type;
} else {
$ohc_type = $_SESSION['current_ohcttype'];
}
$child_ohcs = "SELECT ohc_type_id FROM ohc_type WHERE primary_ohc_id = '$ohc_type'";
$child_ohcs_query = mysqli_query($conn, $child_ohcs);
$child_ids = array();
while ($childs_ohcs = mysqli_fetch_array($child_ohcs_query)) {
array_push($child_ids, $childs_ohcs['ohc_type_id']);
}
$all_ohc_ids = array_push($child_ids, $ohc_type);
$comma_separated_string = implode(",", $child_ids);
$sql = "SELECT * FROM oxygen_cylinder_checklist WHERE date(issue_date) BETWEEN '$oxyDate1' AND '$oxyDate2' AND ohc_type_id IN($comma_separated_string)";
$result = mysqli_query($conn, $sql);
?>
<thead>
<tr>
<th rowspan="2">SN</th>
<th rowspan="2">Date</th>
<th rowspan="2">Cylinder No</th>
<?php
$sql_procurement = "SELECT * FROM oxygen_cylinder";
$result_procurement = mysqli_query($conn, $sql_procurement);
$items_name = array();
while ($row_procurement = mysqli_fetch_assoc($result_procurement)) {
array_push($items_name, $row_procurement['oxygen_kit_no']);
}
?>
<?php
$count_oxy = count($items_name);
$wid = 60 / $count_oxy;
foreach ($items_name as $name) { ?>
<th rowspan="2" style="width:<?= $wid ?>%; font-size: 12px;"><strong><?= $name ?><br><?php echo getFieldFromTable('loc', 'oxygen_cylinder', 'oxygen_kit_no', $name) ?> </strong></th>
<?php } ?>
<th rowspan="2">Checked By (Nursing Staff)</th>
<th rowspan="2">Remarks</th>
</tr>
<tr></tr>
</thead>
<tbody>
<?php
$sql_date = "SELECT DISTINCT date(check_date) as check_date FROM oxygen_cylinder_checklist WHERE date(check_date) BETWEEN '$oxyDate1' AND '$oxyDate2'";
$result_date = mysqli_query($conn, $sql_date);
$count = 1;
while ($row1 = mysqli_fetch_assoc($result_date)) {
$current_check_date = $row1['check_date'];
echo '<tr>';
echo '<td rowspan="4">' . $count . '</td>';
echo '<td rowspan="4">' . $current_check_date . '</td>';
echo '<td>Pressure</td>';
foreach ($items_name as $name) {
echo '<td style="width:' . $wid . '%;"><strong>';
$oxy_id = getFieldFromTable('id', 'oxygen_cylinder', 'oxygen_kit_no', $name);
$result_details = getOxygenCylinderDetails($conn, $oxy_id, $current_check_date);
$pressure_readings = array_column($result_details, 'pressure_reading');
if ($pressure_readings) {
echo implode(", ", $pressure_readings) . ' (kg/cm²)';
}
echo '</strong></td>';
}
echo '<td rowspan="4"></td>';
echo "<td rowspan='4'>" . getAllRemarks($conn, $current_check_date) . "</td>";
echo '</tr>';
echo '<tr>';
echo '<td>Any Leakage</td>';
foreach ($items_name as $name) {
echo '<td style="width:' . $wid . '%;"><strong>';
$oxy_id = getFieldFromTable('id', 'oxygen_cylinder', 'oxygen_kit_no', $name);
$result_details = getOxygenCylinderDetails($conn, $oxy_id, $current_check_date);
$any_leakage = array_column($result_details, 'any_leakage');
$any_leakage = implode(", ", $any_leakage);
if ($any_leakage == 'Y') {
echo 'Yes';
} else if ($any_leakage == 'N') {
echo 'No';
}
echo '</strong></td>';
}
echo '</tr>';
echo '<tr>';
echo '<td>Gas Mask Clean</td>';
foreach ($items_name as $name) {
echo '<td style="width:' . $wid . '%;"><strong>';
$oxy_id = getFieldFromTable('id', 'oxygen_cylinder', 'oxygen_kit_no', $name);
$result_details = getOxygenCylinderDetails($conn, $oxy_id, $current_check_date);
$valve_closed = array_column($result_details, 'valve_closed');
$valve_closed = implode(", ", $valve_closed);
if ($valve_closed == 'Y') {
echo 'Yes';
} else if ($valve_closed == 'N') {
echo 'No';
}
echo '</strong></td>';
}
echo '</tr>';
echo '<tr>';
echo '<td>Water of humidifier replaced</td>';
foreach ($items_name as $name) {
echo '<td style="width:' . $wid . '%;"><strong>';
$oxy_id = getFieldFromTable('id', 'oxygen_cylinder', 'oxygen_kit_no', $name);
$result_details = getOxygenCylinderDetails($conn, $oxy_id, $current_check_date);
$water_humidifier_date = array_column($result_details, 'water_humidifier_date');
echo implode(", ", $water_humidifier_date);
echo '</strong></td>';
}
echo '</tr>';
$count++;
}
?>
</tbody>
</table>
<br>
<br>
<span style="font-size: small; font-weight: lighter;">Remarks: If oxygen cylinder pressure noted 50 -60 kg /cm2 on checking, inform to Doctor in Charge, OHC and arrange to send the same cylinder for refilling.</span>
</body>