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

324 lines
10 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
$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");
?>
<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;
}
td {
text-align: center;
}
@media print {
.print {
display: none;
}
}
body {
border: 1px solid black;
padding: 10px;
}
</style>
<center>
<?php
if ($_REQUEST['excel'] == 'NO') {
echo "<button class='btn btn-success print' onclick='window.print();'>Print</button>";
include("new_pdf_header.php");
} else {
header('Content-Type: application/force-download');
header('Content-disposition: attachment; filename=excel_oxy_report_' . $oxyDate1_formate . '_to_' . $oxyDate2_formate . '.xls');
}
?>
<h3 style="font-size: medium; text-align: center;background-color: #243557;color: white">Oxygen Cylinder Checklist</h3>
</center>
</table>
<h4>Date : <?php echo $oxyDate1_formate . " To " . $oxyDate2_formate ?></h4>
<table border="1" width="100%" cellspacing="0">
<?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); // Assuming check_date is a string
$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);
?>
<strong>
<tr style="background-color: #e1e1e1;font-size: 12px;
font-style: bold;
vertical-align: center;" bgcolor="#eeeeee">
<td rowspan="2" style="height: 30px;" align="left" width="2%">SN</td>
<td rowspan="2" style="height: 30px;" align="left" width="10%">Date</td>
<td rowspan="2" style="height: 30px;" align="left" width="10%">Cylinder No</td>
<?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) { ?>
<td rowspan="2" style="height: 30px;" style="width:<?= $wid ?>%; font-size: 12px;"><strong><?= $name ?><br><?php echo getFieldFromTable('loc', 'oxygen_cylinder', 'oxygen_kit_no', $name) ?> </strong></td>
<?php } ?>
<th rowspan="2" align="center" width="10%">Checked By (Nursing Staff)</th>
<th rowspan="2" align="center" width="10%">Remarks</th>
</tr>
<tr>
<!-- <td style="height: 40px;" ></td> -->
<!-- <td style="height: 40px;" style="text-align: center;" colspan="<?php echo $count_oxy ?>">PRESSURE</td> -->
<!-- <td style="height: 40px;" >Checked By (Nursing Staff)</td>
<td style="height: 40px;" >Remarks</td> -->
</tr>
<tr>
</tr>
<?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);
error_log(print_r($result_details, true) . " DMDMDM");
$any_leakage = array_column($result_details, 'any_leakage');
error_log(print_r($any_leakage, true) . " DMDMDM");
$any_leakage = implode(",", $any_leakage);
error_log("ANY LEAKAGE" . $any_leakage);
if (trim($any_leakage) == 'Y') {
echo 'Yes';
} else if (trim($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++;
}
?>
</table>
</body>
<?php
$sql_doc_details = "select * from employee_signature where emp_id='" . $_SESSION['logged_user_empid'] . "'";
$result_doc_details = mysqli_query($conn, $sql_doc_details);
$row_doc_details = mysqli_fetch_array($result_doc_details);
$doc_id = $_SESSION['user_id'];
$doc_id = getFieldFromTable('emp_id', 'tbl_users', 'user_id', $doc_id);
$doc_name = getFieldFromTable('patient_name', 'patient_master', 'id', $doc_id);
?>
<table width="100%">
<tr>
<td style="width: 80%;"></td>
<td style="width: 20%;"><img src="data:<?php echo $row_doc_details['image_type'] ?>;base64,<?php echo base64_encode($row_doc_details['emp_sign']) ?>" style="width: 120px; height: 80px;float: right" /></td>
</tr>
</table>
<table>
<tr>
<td style="font-size: 12px;">
Date:<?= date_format(date_create($s), "d-M-Y ") ?>
</td>
<td style="text-align:right;font-size:12px; width: 20%; ">
<strong></strong>
</td>
</tr>
</table>
<table width="100%">
<tr>
<!-- <td><span style="float: right; font-size: 12px;">Date</span></td> -->
<td><span style="float: right; font-size: 12px;">Sign & Stamp of Factory Medical Officer</span></td>
</tr>
</table>
<br>
<table width="100%">
<tr>
<td><span style="float: right;">
<?php
echo $doc_name . " ," . $row_doc_details['qualification'];
?>
</span></td>
</tr>
</table>
<br>
<table width="100%">
<tr>
<td><span style="float: right;">KMC Reg No:
<?php echo $row_doc_details['registration_no'] ?>
</span>
</td>
</tr>
</table>
<br><br>
<span style="font-size: medium; 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>
<script>
$(document).ready(function() {
window.print();
});
</script>