File "monthly_harvest_report.php"
Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/monthly_harvest_report.php
File size: 5.84 KB
MIME-type: text/x-php
Charset: utf-8
<?php
// Database connection
$conn = new mysqli("server329", "leadltht_prazey1982", "prazey1982123456", "leadltht_fastlinkinternet");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$current_month = date('m');
$current_year = date('Y');
if (isset($_GET['month'])) {
$month_year = explode('-', $_GET['month']);
$current_month = $month_year[1]; // Month should be the second part
$current_year = $month_year[0]; // Year should be the first part
}
// Fetch harvest records for the selected month and year, including client_share and owner_share
$query = "SELECT hc.id, c.name as client_name, hc.harvested_date, hc.harvested_amount,
hc.less_deductions,
(hc.less_deductions * (c.client_share / 100)) as client_share_amount,
(hc.less_deductions - (hc.less_deductions * (c.client_share / 100))) as owner_share_amount
FROM harvest_collection hc
JOIN clients c ON hc.client_id = c.id
WHERE MONTH(hc.harvested_date) = ? AND YEAR(hc.harvested_date) = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $current_month, $current_year);
$stmt->execute();
$result = $stmt->get_result();
// Initialize total amount
$total_amount = 0;
$total_client_share = 0;
$total_owner_share = 0;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Monthly Harvest Report</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.action-buttons {
display: flex;
gap: 10px;
}
.table-controls {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
/* Hide elements during print */
@media print {
.table-controls button,
.table-controls a,
h1 {
display: none;
}
#monthPicker {
display: inline-block;
}
}
</style>
</head>
<body>
<div class="container mt-5">
<div style="text-align: center;">
<img src="https://fastlinkinternet.com/administrator/data-provider/uploads/fastlink.png" alt="Logo" style="max-width: 120px;">
</div>
<h1 class="mb-4" style="text-align: center;">FASTLINK INTERNET</h1>
<h3 class="text-center mb-4">Monthly Harvest Report - September 2024</h3>
<div class="table-controls">
<div>
<input type="month" id="monthPicker" value="<?php echo $current_year . '-' . str_pad($current_month, 2, '0', STR_PAD_LEFT); ?>">
<button onclick="filterByMonth()" class="btn btn-primary">Filter</button>
<button onclick="window.print()" class="btn btn-secondary">Print</button>
<a href="https://fastlinkinternet.com/administrator/data-provider/admin/?page=piso_wifi_homepage" class="btn btn-secondary">Back</a>
</div>
</div>
<table id="harvestTable" class="table">
<thead>
<tr>
<th>#</th>
<th>Client Name</th>
<th>Harvested Date</th>
<th>Harvested Amount</th>
<th>Less Deductions</th>
<th>Client Share</th>
<th>Owner Share</th>
</tr>
</thead>
<tbody>
<?php
$counter = 1;
while ($row = $result->fetch_assoc()) {
$client_share_amount = $row['client_share_amount'];
$owner_share_amount = $row['owner_share_amount'];
echo "<tr>";
echo "<td>" . $counter++ . "</td>";
echo "<td>" . htmlspecialchars($row['client_name']) . "</td>";
echo "<td>" . htmlspecialchars($row['harvested_date']) . "</td>";
echo "<td>₱" . number_format($row['harvested_amount'], 2) . "</td>";
echo "<td>₱" . number_format($row['less_deductions'], 2) . "</td>";
echo "<td>₱" . number_format($client_share_amount, 2) . "</td>";
echo "<td>₱" . number_format($owner_share_amount, 2) . "</td>";
echo "</tr>";
// Accumulate totals
$total_amount += $row['harvested_amount'];
$total_less_deductions += $row['less_deductions'];
$total_client_share += $client_share_amount;
$total_owner_share += $owner_share_amount;
}
?>
</tbody>
<tfoot>
<tr>
<th colspan="3">Total</th>
<th>₱<?php echo number_format($total_amount, 2); ?></th>
<th>₱<?php echo number_format($total_less_deductions, 2); ?></th>
<th>₱<?php echo number_format($total_client_share, 2); ?></th>
<th>₱<?php echo number_format($total_owner_share, 2); ?></th>
</tr>
</tfoot>
</table>
</div>
<script>
function filterByMonth() {
const monthPicker = document.getElementById('monthPicker').value;
window.location.href = `monthly_harvest_report.php?month=${monthPicker}`;
}
</script>
</body>
</html>
<?php
$stmt->close();
$conn->close();
?>