csrtechnew.ohctech.in/sub_center_item_issue_report.php

221 lines
7.5 KiB
PHP
Raw Permalink Normal View History

2025-04-14 13:28:09 +05:30
<?php
include('includes/config/config.php');
include('includes/functions.php');
// Get and sanitize input
$ohc = $_POST['scohc'];
2025-10-16 15:19:10 +05:30
$vehicle = $_POST['vehicle'];
2025-04-14 13:28:09 +05:30
$sub_center = $_POST['sc'];
$startDate = date('Y-m-d', strtotime($_POST['startDate_sc']));
$endDate = date('Y-m-d', strtotime($_POST['endDate_sc']));
// Log the dates
error_log("Ohc Name: " . $ohc);
error_log("sub center Name: " . $sub_center);
error_log("Start date: " . $startDate);
error_log("End date: " . $endDate);
$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");
}
2025-10-16 15:19:10 +05:30
$vehicleCondition = "";
if ($vehicle != 'all') {
$vehicleCondition = " AND a.vehicle = '$vehicle'";
}
2025-04-14 13:28:09 +05:30
2025-10-16 15:19:10 +05:30
if ($sub_center == 'all') {
2025-04-14 13:28:09 +05:30
$sql = "SELECT *
2025-10-16 15:19:10 +05:30
FROM stock_issue a
LEFT JOIN stock_issue_items b ON a.stock_issue_id = b.stock_issue_id
WHERE DATE(a.issue_date) BETWEEN '$startDate' AND '$endDate'
AND a.issue_ohc_type_id = '$ohc'
AND a.sub_center > 0
$vehicleCondition";
} else {
$sql = "SELECT *
FROM stock_issue a
LEFT JOIN stock_issue_items b ON a.stock_issue_id = b.stock_issue_id
WHERE DATE(a.issue_date) BETWEEN '$startDate' AND '$endDate'
AND a.issue_ohc_type_id = '$ohc'
AND a.sub_center = '$sub_center'
$vehicleCondition";
2025-04-14 13:28:09 +05:30
}
2025-10-16 15:19:10 +05:30
2025-04-14 13:28:09 +05:30
error_log("Check_query : " . $sql);
$result = mysqli_query($conn, $sql);
?>
<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 style="margin: 20px;">
<?php
if ($type === 'excel') {
} else {
include('pdf_current_ohc_header.php');
}
?>
2025-10-16 15:19:10 +05:30
<table width="100%">
2025-04-14 13:28:09 +05:30
<!-- 1st Row: Left Aligned -->
<tr align="left">
<td align="left" style="font-size: 12px">
<strong>Duration: <?php echo date("d-M-Y", strtotime($startDate)); ?> To <?php echo date("d-M-Y", strtotime($endDate)); ?></strong>
</td>
</tr>
<!-- 2nd Row: Center Aligned -->
<tr align="center">
<td style="font-size: 15px;">
<strong>
Item Issue Report
</br>(
<?php
2025-10-16 15:19:10 +05:30
if ($sub_center == 'all') {
2025-04-14 13:28:09 +05:30
echo 'All Center Report';
2025-10-16 15:19:10 +05:30
} else {
echo getFieldFromTable('sub_center_name', 'sub_center', 'id', $sub_center);
2025-04-14 13:28:09 +05:30
}
?> )
</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 border="1" width="100%" cellspacing="0" class="table-fixed">
<tr>
<td style="width: 3%;font-size: 15px;font-weight: bold;background-color: gainsboro;">Sr.</td>
<td style="width: 10%; font-size: 15px;font-weight: bold;background-color: gainsboro;">Date</td>
<td style="width: 10%; font-size: 15px;font-weight: bold;background-color: gainsboro;">Rec. No.</td>
<td style="width: 15%; font-size: 15px;font-weight: bold;background-color: gainsboro;">Item Name</td>
2025-10-16 15:19:10 +05:30
<?php if ($vehicle != 'all') { ?>
<td style="width: 10%; font-size: 15px;font-weight: bold;background-color: gainsboro;">Transportation vehicle</td>
<?php } ?>
2025-04-14 13:28:09 +05:30
<td style="width: 5%;font-size: 15px;font-weight: bold;background-color: gainsboro;">Quantity</td>
<td style="width: 5%;font-size: 15px;font-weight: bold;background-color: gainsboro;">Per Unit Rate</td>
<td style="width: 5%;font-size: 15px;font-weight: bold;background-color: gainsboro;">Total</td>
</tr>
<?php
$count = 1;
$total = 0;
while ($row1 = mysqli_fetch_assoc($result)) {
?>
<tr>
<td style="font-size: 10px;"><?php echo $count++ ?></td>
<td style="font-size: 10px;"><?php echo date("d/m/Y", strtotime($row1['issue_date'])); ?></td>
<td style="font-size: 10px;"><?php echo $row1['issue_ref_no'] ?></td>
<td style="font-size: 10px;"><?php echo getFieldFromTable('item_name', 'tbl_items', 'item_id', $row1['item_id']) ?></td>
2025-10-16 15:19:10 +05:30
<?php if ($vehicle != 'all') { ?>
<td style="font-size: 10px;"><?php echo getFieldFromTable('Driver_name', 'vehicle', 'Vehicle_id', $row1['vehicle']) . " (" . getFieldFromTable('Vehicle_number', 'vehicle', 'Vehicle_id', $row1['vehicle']) . ")"; ?></td>
<?php } ?>
2025-04-14 13:28:09 +05:30
<td style="font-size: 10px;"><?php echo $row1['issue_qty'] ?></td>
<td style="font-size: 10px;"><?php echo $row1['per_unit_rate'] ?></td>
<td style="font-size: 10px;"><?php $total += $row1['total_rate'];
echo $row1['total_rate'] ?></td>
</tr>
<?php
} ?>
<tr style="background-color: #4CAF50;">
2025-10-16 15:19:10 +05:30
<td <?php if ($vehicle == 'all') { ?> colspan="6" align="right" <?php } ?> colspan="7" align="right">Grand Total :- </td>
2025-04-14 13:28:09 +05:30
<td><?= $total ?></td>
</tr>
</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
}
}
?>