File "view_harvests.php"
Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/view_harvests.php
File size: 9.42 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start(); // Start the session
include 'header.php'; // Include the header file which includes the navigation
// Database connection
$conn = new mysqli("server329", "leadltht_prazey1982", "prazey1982123456", "leadltht_fastlinkinternet");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch all harvest records along with less_deductions, client_share, owner_share, and remarks
$query = "SELECT hc.id, c.name as client_name, hc.harvested_date, hc.harvested_amount, hc.less_deductions,
c.client_share,
(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,
hc.remarks
FROM harvest_collection hc
JOIN clients c ON hc.client_id = c.id";
$result = $conn->query($query);
if ($result === false) {
die("Error in query: " . $conn->error);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Harvest Collection</title>
<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;
}
.btn-back, .btn-show, .btn-print {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-right: 10px;
}
.pagination {
display: flex;
justify-content: center;
margin-top: 20px;
}
.pagination button {
padding: 10px 20px;
margin: 0 5px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
/* Hide elements during print */
@media print {
.table-controls,
.pagination,
.btn-back,
.btn-show,
.btn-print,
#showing-entries {
display: none;
}
.action-buttons,
th:last-child, /* Hide the last column header */
td:last-child { /* Hide the last column cells */
display: none;
}
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function () {
const rows = Array.from(document.querySelector("tbody").children);
const searchInput = document.getElementById("search");
const entriesSelect = document.getElementById("entries");
const fromDateInput = document.getElementById("from-date");
const toDateInput = document.getElementById("to-date");
const showReportButton = document.querySelector(".btn-show");
let currentPage = 1;
let entriesPerPage = parseInt(entriesSelect.value);
let filteredRows = rows.slice();
function renderTable() {
const start = (currentPage - 1) * entriesPerPage;
const end = start + entriesPerPage;
rows.forEach(row => row.style.display = "none");
filteredRows.slice(start, end).forEach(row => row.style.display = "");
const totalEntries = filteredRows.length;
document.getElementById("showing-entries").textContent = `Showing ${Math.min(end, totalEntries)} of ${totalEntries} entries`;
document.getElementById("prevPage").disabled = currentPage === 1;
document.getElementById("nextPage").disabled = end >= filteredRows.length;
}
function filterRows() {
const query = searchInput.value.toLowerCase();
filteredRows = rows.filter(row => {
return Array.from(row.children).some(cell => cell.textContent.toLowerCase().includes(query));
});
currentPage = 1;
renderTable();
}
function filterByDateRange() {
const fromDate = new Date(fromDateInput.value);
const toDate = new Date(toDateInput.value);
filteredRows = rows.filter(row => {
const harvestedDate = new Date(row.children[2].textContent);
return harvestedDate >= fromDate && harvestedDate <= toDate;
});
currentPage = 1;
renderTable();
}
function showPreviousPage() {
if (currentPage > 1) {
currentPage--;
renderTable();
}
}
function showNextPage() {
if (currentPage * entriesPerPage < filteredRows.length) {
currentPage++;
renderTable();
}
}
searchInput.addEventListener("input", filterRows);
entriesSelect.addEventListener("change", function () {
entriesPerPage = parseInt(this.value);
renderTable();
});
showReportButton.addEventListener("click", filterByDateRange);
document.getElementById("prevPage").addEventListener("click", showPreviousPage);
document.getElementById("nextPage").addEventListener("click", showNextPage);
renderTable();
});
function printPage() {
window.print();
}
</script>
</head>
<body>
<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>
<h4 class="mb-4" style="text-align: center;">Harvest Collection as of <?= date('F Y'); ?> </h4>
<div class="table-controls">
<div>
Show
<select id="entries">
<option value="25">25</option>
<option value="50">50</option>
</select>
entries
</div>
<div>
Search: <input type="text" id="search">
</div>
<div>
<label for="from-date">From: </label>
<input type="date" id="from-date" name="from-date">
<label for="to-date">To: </label>
<input type="date" id="to-date" name="to-date">
<button class="btn-show" type="button">Show Report</button>
<button class="btn-print" onclick="printPage()">Print</button>
</div>
</div>
<table>
<thead>
<tr>
<th>#</th>
<th>Client Name</th>
<th>Harvested Date</th>
<th>Harvested Amount</th>
<th>Less Deductions</th>
<th>Owner Share</th>
<th>Client Share</th>
<th>Remarks</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$counter = 1;
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $counter++ . "</td>";
echo "<td>" . htmlspecialchars($row['client_name']) . "</td>";
echo "<td>" . htmlspecialchars($row['harvested_date']) . "</td>";
echo "<td>" . htmlspecialchars($row['harvested_amount']) . "</td>";
echo "<td>" . htmlspecialchars($row['less_deductions']) . "</td>";
echo "<td>" . number_format($row['owner_share_amount'], 2) . "</td>";
echo "<td>" . number_format($row['client_share_amount'], 2) . "</td>";
echo "<td>" . htmlspecialchars($row['remarks']) . "</td>";
echo "<td>";
echo "<div class='action-buttons'>";
echo "<a href='edit_harvest.php?id=" . $row['id'] . "'><button>Edit</button></a>";
echo "<a href='delete_harvest.php?id=" . $row['id'] . "' onclick='return confirm(\"Are you sure you want to delete this record?\");'><button>Delete</button></a>";
echo "</div>";
echo "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='9'>No records found.</td></tr>";
}
?>
</tbody>
</table>
<div id="showing-entries"></div>
<div class="pagination">
<button id="prevPage">Previous</button>
<button id="nextPage">Next</button>
</div>
<div>
<a href="javascript:history.back()">
<button type="button" class="btn-back">Back</button>
</a>
</div>
</body>
</html>
<?php
$result->free();
$conn->close();
?>