2026-01-07 09:12:10 +05:30

270 lines
13 KiB
PHP

<?php
include('includes/config/config.php');
include('includes/functions.php');
// Get and sanitize input
$startDate = date('Y-m-d', strtotime($_POST['startDate_di']));
$endDate = date('Y-m-d', strtotime($_POST['endDate_di']));
$ohc = $_POST['ohcid'];
// Log the dates
error_log("Start date: " . $startDate);
error_log("End date: " . $endDate);
// Construct the SQL query directly, with the sanitized variables
$sql = "SELECT * FROM beneficiary_drip_add_details WHERE DATE(drip_date) BETWEEN '$startDate' AND '$endDate' AND ohc_type_id = '$ohc'";
error_log("Check_sql : " . $sql);
// Execute the query
$result = mysqli_query($conn, $sql);
// Check for query errors
if (!$result) {
die("Error executing query: " . mysqli_error($conn));
}
// Check for errors
if (!$result) {
error_log("Error executing query: " . mysqli_error($conn));
die("Error executing query");
}
// Initialize total variables
$total_mis_cost = 0;
$total_ggrc_contribution = 0;
$total_ghcl_ft_contribution = 0;
$total_farmers_contribution = 0;
$total_amount = 0;
$total_amount_to_deposit = 0;
$total_difference = 0;
$total_amount_rs = 0;
?>
<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;
}
.total-row {
background-color: #f0f0f0;
font-weight: bold;
}
</style>
<body>
<?php include('pdf_ohc_header.php'); ?>
<table width="100%">
<tr>
<td style="font-size: 15px;"><strong style="margin-left: 670px">Drip Irrigation Report</strong></td>
</tr>
<tr>
<td align="left" style="font-size: 12px">
<strong>From Date: <?php echo date("d-M-Y", strtotime($startDate)); ?> To <?php echo date("d-M-Y", strtotime($endDate)); ?></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 rowspan="2" style="width: 3%;font-size: 10px;">Sr.</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">W/O Date</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">GHCLFT Reg Nos</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">GGRC Reg.Nos</td>
<td rowspan="2" style="width: 17%; font-size: 10px;">Benificiaries Name</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Subsidy rate</td>
<td rowspan="2" style="width: 12%; font-size: 10px;">Mobile No</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Village</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Taluka</td>
<td rowspan="2" style="width: 8%; font-size: 10px;">Suvey No</td>
<td rowspan="2" style="width: 8%; font-size: 10px;">Area Ha.</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Total MIS Cost</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">GGRC Contribution</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">GHCL FT Contribution</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Farmers Contribution</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Company</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Dealer</td>
<td colspan="3" style="width: 50%; font-size: 10px;text-align: center;">Detail of payment</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Amt to be Deposit</td>
<td rowspan="2" style="width: 9%; font-size: 10px;">Difference</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Payment From GHCLFT</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Cheque Nos</td>
<td rowspan="2" style="width: 10%; font-size: 10px;">Amount Rs.</td>
<!-- <td style="width: 10%; font-size: 10px;">Cheque Sr.no</td> -->
</tr>
<tr>
<td style=" font-size: 10px;">Date</td>
<td style=" font-size: 10px;">Bank</td>
<td style=" font-size: 10px;">Amount</td>
</tr>
<?php
$count = 1;
while ($row1 = $result->fetch_assoc()) {
// Get values
$mis_cost = getValue($row1['id'], 'total_mis_cost');
$ggrc_contribution = getValue($row1['id'], 'ggrc_contribution');
$ghcl_ft_contribution = getValue($row1['id'], 'ghcl_ft_contribution');
$farmers_contribution = getValue($row1['id'], 'farmers_contribution');
$amount = getValue($row1['id'], 'amount');
$amount_to_deposit = getValue($row1['id'], 'amountt_to_be_deposit');
$difference = getValue($row1['id'], 'difference');
$amount_rs = getValue($row1['id'], 'amount_rs');
// Convert to float and add to totals
$mis_cost_float = floatval($mis_cost);
$ggrc_contribution_float = floatval($ggrc_contribution);
$ghcl_ft_contribution_float = floatval($ghcl_ft_contribution);
$farmers_contribution_float = floatval($farmers_contribution);
$amount_float = floatval($amount);
$amount_to_deposit_float = floatval($amount_to_deposit);
$difference_float = floatval($difference);
$amount_rs_float = floatval($amount_rs);
// Add to totals
$total_mis_cost += $mis_cost_float;
$total_ggrc_contribution += $ggrc_contribution_float;
$total_ghcl_ft_contribution += $ghcl_ft_contribution_float;
$total_farmers_contribution += $farmers_contribution_float;
$total_amount += $amount_float;
$total_amount_to_deposit += $amount_to_deposit_float;
$total_difference += $difference_float;
$total_amount_rs += $amount_rs_float;
?>
<tr>
<td style="font-size: 10px;"><?php echo $count ?></td>
<td style="font-size: 10px;"><?php echo date("d/m/Y", strtotime($row1['drip_date'])); ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 'ghcl_ft_reg_nos') ?></td>
<td style="font-size: 10px;"><?php echo $row1['ggrc_no'] ?></td>
<td style="font-size: 10px;"><?php echo getfieldFromTable('patient_name', 'patient_master', 'id', $row1['beneficiary']) ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 'subsidy_rate') ?></td>
<td style="font-size: 10px;"><?php echo getfieldFromTable('aadhar_phone', 'patient_master', 'id', $row1['beneficiary']); ?></td>
<td style="font-size: 10px;"><?php
$village_id = getfieldFromTable('village', 'patient_master', 'id', $row1['beneficiary']);
echo htmlspecialchars(getFieldFromTable('village', 'village', 'id', $village_id)) ?></td>
<td style="font-size: 10px;"><?php
$tehsil = getfieldFromTable('tehsil', 'patient_master', 'id', $row1['beneficiary']);
echo htmlspecialchars(getFieldFromTable('name', 'tehsils', 'id', $tehsil)) ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 'survey_no') ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 'area_hechter') ?></td>
<td style="font-size: 10px;"><?php echo number_format($mis_cost_float, 2, '.', '') ?></td>
<td style="font-size: 10px;"><?php echo number_format($ggrc_contribution_float, 2, '.', '') ?></td>
<td style="font-size: 10px;"><?php echo number_format($ghcl_ft_contribution_float, 2, '.', '') ?></td>
<td style="font-size: 10px;"><?php echo number_format($farmers_contribution_float, 2, '.', '') ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars(getFieldFromTable('parameter_value_name', 'checkup_parameter_value', 'parameter_value_id', getValue($row1['id'], 'company'))) ?></td>
<td style="font-size: 10px;"><?php echo htmlspecialchars(getFieldFromTable('parameter_value_name', 'checkup_parameter_value', 'parameter_value_id', getValue($row1['id'], 'dealer'))) ?></td>
<td style="font-size: 10px;"><?php echo date("d/m/Y", strtotime(getValue($row1['id'], 'payment_date'))); ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 'bank_name') ?></td>
<td style="font-size: 10px;"><?php echo number_format($amount_float, 2, '.', '') ?></td>
<td style="font-size: 10px;"><?php echo number_format($amount_to_deposit_float, 2, '.', '') ?></td>
<td style="font-size: 10px;"><?php echo number_format($difference_float, 2, '.', '') ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 'payment_from_ghcl_ft') ?></td>
<td style="font-size: 10px;"><?php echo getValue($row1['id'], 'cheque_nos') ?></td>
<td style="font-size: 10px;"><?php echo number_format($amount_rs_float, 2, '.', '') ?></td>
</tr>
<?php
$count++;
}
// Reset result pointer to beginning for any further operations
mysqli_data_seek($result, 0);
// Add total row
if ($count > 1) {
?>
<tr class="total-row">
<td colspan="11" style="font-size: 10px; text-align: center; font-weight: bold;">TOTAL :</td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_mis_cost, 2, '.', '') ?></td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_ggrc_contribution, 2, '.', '') ?></td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_ghcl_ft_contribution, 2, '.', '') ?></td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_farmers_contribution, 2, '.', '') ?></td>
<td style="font-size: 10px; font-weight: bold;" colspan="4"></td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_amount, 2, '.', '') ?></td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_amount_to_deposit, 2, '.', '') ?></td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_difference, 2, '.', '') ?></td>
<td style="font-size: 10px; font-weight: bold;" colspan="2"></td>
<td style="font-size: 10px; font-weight: bold;"><?php echo number_format($total_amount_rs, 2, '.', '') ?></td>
</tr>
<?php
}
?>
</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_drip_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 '0'; // Return 0 instead of 'NA' for calculations
}
} else {
error_log("Error executing query: " . mysqli_error($conn));
return '0'; // Return 0 for calculations
}
}
?>