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

203 lines
8.0 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
$sub_center = $_POST['shgsub_center'];
$beneficiry = $_POST['shgbeneficiary'];
$startDate = date('Y-m-d', strtotime($_POST['startDate_shg']));
$endDate = date('Y-m-d', strtotime($_POST['endDate_shg']));
// Log the dates
error_log("Ohc Name: " . $ohc);
error_log("Sub Center Name: " . $sub_center);
?>
<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 include('pdf_current_ohc_header.php'); ?>
<table width="100%">
<tr>
<td style="font-size: 15px;"><strong style="margin-left: 610px">SHG Beneficiaries Report</strong></td>
</tr>
<tr>
<td align="left" style="font-size: 12px">
<strong>Sub Center Name: <?php echo getFieldFromTable('sub_center_name', 'sub_center', 'id', $sub_center); ?></strong>
</td>
<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 border="1" width="100%" cellspacing="0" class="table-fixed">
<tr bgcolor="#eeeeee">
<td style="width: 5%;">Sr.</td>
<td style="width: 15%; font-size: 10px;">Farmers Name</td>
<td style="width: 10%; font-size: 10px;">Aadhar Card</td>
<td style="width: 10%; font-size: 10px;">Gender</td>
<td style="width: 10%; font-size: 10px;">DOB</td>
<td style="width: 10%; font-size: 10px;">Mobile No</td>
<td style="width: 10%; font-size: 10px;">Village</td>
<td style="width: 10%; font-size: 10px;">Taluka</td>
<td style="width: 10%; font-size: 10px;">District</td>
<td style="width: 10%; font-size: 10px;">State</td>
<td style="width: 10%; font-size: 10px;">Pin Code</td>
<td style="width: 10%; font-size: 10px;">NO of Animal</td>
<?php
$sql2 = "SELECT * FROM tbl_items WHERE ohc_type_id = '27' ";
error_log("Check_selecting_query : " . $sql2);
$result2 = mysqli_query($conn, $sql2);
while ($row2 = mysqli_fetch_assoc($result2)) {
?>
<td style="width: 10%; font-size: 10px;"><?= $row2['item_name'] ?></td>
<?php
}
?>
<td style="width: 15%; font-size: 15px;">Farmers Contribution</td>
<td style="width: 15%; font-size: 15px;">GHCLFT Contribution</td>
<td style="width: 15%; font-size: 15px;">Total</td>
</tr>
<?php
$count = 1;
if ($beneficiry == 'all') {
$sql1 = "SELECT * FROM hari_sub_center_issue WHERE DATE(issue_date) BETWEEN '$startDate' AND '$endDate' AND sub_center = '$sub_center'";
} else {
$sql1 = "SELECT * FROM hari_sub_center_issue WHERE DATE(issue_date) BETWEEN '$startDate' AND '$endDate' AND sub_center = '$sub_center' AND beneficiary = '$beneficiry'";
}
error_log("Check_condtion-Query : ".$sql1);
$result1 = mysqli_query($conn, $sql1);
while ($row1 = mysqli_fetch_assoc($result1)) {
$sql2 = "SELECT * FROM patient_master WHERE id = '" . $row1['beneficiary'] . "'";
$result2 = mysqli_query($conn, $sql2);
$row2 = mysqli_fetch_assoc($result2)
?>
<tr>
<td style="font-size: 10px;"><?php echo $count ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars($row2['patient_name']) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars($row2['aadhar_card']) ?></td>
<td style="font-size: 10px;"><?php echo $row2['gender'] === 'M' ? 'Male' : 'Female'; ?></td>
<td style="font-size: 10px;"><?php echo date('d-m-Y', strtotime($row2['dob'])) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars($row2['aadhar_phone']) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars(getFieldFromTable('village', 'village', 'id', $row2['village'])) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars(getFieldFromTable('name', 'tehsils', 'id', $row2['tehsil'])) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars(getFieldFromTable('name', 'states', 'id', $row2['state'])) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars(getFieldFromTable('name', 'districts', 'id', $row2['district'])) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars($row2['pin_code']) ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 5) ?></td>
<?php
$sql3 = "SELECT * FROM tbl_items WHERE ohc_type_id = '27' ";
error_log("Check_selecting_query : " . $sql3);
$result3 = mysqli_query($conn, $sql3);
$total_cast = 0;
while ($row3 = mysqli_fetch_assoc($result3)) {
$sql4 = "SELECT * FROM hari_sub_center_issue_items WHERE stock_issue_id = '" . $row1['stock_issue_id'] . "' AND item_id = '" . $row3['item_id'] . "'";
$result4 = mysqli_query($conn, $sql4);
$row4 = mysqli_fetch_assoc($result4);
$total = $row4['per_unit_rate'] * $row4['issue_qty'];
$tenPercent = ($total * 10) / 100;
$total_cast += $tenPercent + $total;
?>
<td style="width: 10%; font-size: 10px;"><?= $row4['issue_qty'] ?></td>
<?php
}
?>
<td><?php $twentyPer = ($total_cast * 20) / 100;
echo $twentyPer;
?></td>
<td><?php echo $total_cast - $twentyPer;
?></td>
<td><?php echo $total_cast;
?></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>
<?php
function getValue($id, $key)
{
global $conn; // Access the global $conn variable
// Escape input parameters to prevent SQL injection
$id = mysqli_real_escape_string($conn, $id);
$key = mysqli_real_escape_string($conn, $key);
// Correct SQL query with directly inserted sanitized values
$sql = "SELECT checkup_form_value FROM beneficiary_form_key_value WHERE bene_detail_id = '$id' AND bene_form_key = '$key'";
// Log the query for debugging (optional)
error_log("Executing query: " . $sql);
// Execute the query
$result = mysqli_query($conn, $sql);
// Check for query success and fetch the result
if ($result) {
if ($row = mysqli_fetch_assoc($result)) {
error_log("Check_key+value : " . $row['checkup_form_value']);
return $row['checkup_form_value'];
} else {
return 'NA';
}
} else {
error_log("Error executing query: " . mysqli_error($conn));
return false; // Or handle this case more appropriately
}
}
?>