csrtechnew.ohctech.in/rrwhs_report_pdf.php
2025-04-14 13:28:09 +05:30

204 lines
6.8 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
// Get and sanitize input
$ohc_type_id = $_POST['pohcid'];
$program_name = $_POST['program_name'];
$activity_name = $_POST['activity_name'];
$from_date1 = date('Y-m-d', strtotime($_POST['procurement_date1']));
$from_date2 = date('Y-m-d', strtotime($_POST['procurement_date2']));
$type = isset($_GET['type']) ? $_GET['type'] : ''; // Get the type parameter
error_log("Check_type : " . $type);
if ($type === 'excel') {
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=beneficiry_report_excel.xls");
header("Pragma: no-cache");
header("Expires: 0");
}
// Construct the SQL query directly, with the sanitized variables
$sql = "SELECT * FROM stock_issue WHERE DATE(issue_date) BETWEEN ? AND ? AND activity_name = ? AND issue_ohc_type_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssss", $startDate, $endDate, $activity_name, $ohc);
$stmt->execute();
$result = $stmt->get_result();
// Ensure query was successful
if (!$result) {
die("Error executing query: " . mysqli_error($conn));
}
?>
<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-fixed {
table-layout: fixed;
width: 100%;
}
.table-fixed td {
word-wrap: break-word;
}
</style>
<body>
<?php
if ($type === 'excel') {
} else {
include('pdf_current_ohc_header.php');
}
?>
<table width="100%">
<tr align="center">
<td style="font-size: 15px;">
<strong>
<?php
echo getFieldFromTable('program_name', 'csr_program', 'csr_id', $program_name) . '-' .
getFieldFromTable('program_name', 'program_master', 'program_id', $activity_name);
?>
</strong>
</td>
</tr>
<!-- 3rd Row: Right Aligned -->
<tr align="right">
<td align="right" style="font-size: 12px">
<strong>Selected Location: <?= htmlspecialchars(getFieldFromTable('ohc_type_name', 'ohc_type', 'ohc_type_id', $ohc)) ?></strong>
</td>
</tr>
</table>
<br>
<table width="100%">
<tr>
<td style="font-size: 15px;">
<strong style="margin-left: 600px">
RRWHS Report
<?php if (isset($only_referral) && $only_referral == 'Y') {
echo "(Referral)";
} ?>
</strong>
</td>
</tr>
<tr>
<td align="left" style="font-size: 12px">
<strong>
From Date: <?php echo date("d-M-Y", strtotime($from_date1)); ?>
&nbsp;&nbsp;&nbsp;To Date: <?php echo date("d-M-Y", strtotime($from_date2)); ?>
</strong>
</td>
<td align="right" style="font-size: 15px">
<button align="center" id="printPageButton" class="btn btn-success" onClick="window.print();">Print</button>
</td>
</tr>
</table>
<br>
<table border="1" width="100%" cellspacing="0">
<tr bgcolor="#eeeeee">
<td style="width:5%;">Sr.</td>
<td style="width:8%;">Date</td>
<td style="width:8%;">Center Location</td>
<td style="width:15%;">Name</td>
<td style="width:8%;" >Village</td>
<td style="width:8%;" >Taluka</td>
<td style="width:5%;" >Length</td>
<td style="width:5%;" >Width</td>
<td style="width:5%;" >Depth</td>
<td style="width:8%;" >Capacity</td>
<td style="width:8%;" >Tank No</td>
<td style="width:10%;" >Status</td>
</tr>
<?php
// Fetch data from the database
$sql = "SELECT * FROM rrwhs_activity
WHERE ohc_type_id = '" . $ohc_type_id . "'
AND STR_TO_DATE('$from_date1', '%Y-%m-%d') <= date(rrwhs_date)
AND date(rrwhs_date) <= STR_TO_DATE('$from_date2', '%Y-%m-%d')
ORDER BY rrwhs_date DESC";
error_log($sql); // Log the SQL query for debugging
$result = mysqli_query($conn, $sql);
$count = 1; // Initialize the row counter
while ($row1 = mysqli_fetch_assoc($result)) {
?>
<tr>
<?php
if($row1['progress_status'] == 'first_stage'){
$status = 'First Stage Complate';
}else if($row1['progress_status'] == 'second_stage'){
$status = 'Second Stage Complate';
}else if($row1['progress_status'] == 'complete'){
$status = 'Final Stage Complate';
}
?>
<td><?php echo $count; ?></td>
<td><?php echo date_format(date_create($row1['rrwhs_date']), "d-m-Y"); ?></td>
<td><?php echo getFieldFromTable('ohc_type_name','ohc_type','ohc_type_id',$row1['ohc_type_id']); ?></td>
<td><?php echo $beneficiary = getFieldFromTable('patient_name','patient_master','id',$row1['beneficiary']); ?></td>
<?php
$village = getFieldFromTable('village','patient_master','id',$row1['beneficiary']);
$tehsil = getFieldFromTable('tehsil','patient_master','id',$row1['beneficiary']);
?>
<td><?php echo getFieldFromTable('village','village','id',$village); ?></td>
<td><?php echo getFieldFromTable('name','tehsils','id',$tehsil); ?></td>
<td><?php echo htmlspecialchars($row1['length']); ?></td>
<td><?php echo htmlspecialchars($row1['width']); ?></td>
<td><?php echo htmlspecialchars($row1['depth']); ?></td>
<td><?php echo htmlspecialchars($row1['capacity']); ?></td>
<td><?php echo htmlspecialchars($row1['tank_no']); ?></td>
<td><?php echo $status; ?></td>
</tr>
<?php
$count++;
}
?>
</table>
<div style="text-align: center; margin-top: 20px;">
<button id="printPageButton" class="btn" onClick="window.print();">Print</button>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Uncomment below to enable print on load
// window.print();
});
</script>