File "for_harvest.php"

Full Path: /home/leadltht/fastlinkinternet.com/administrator/data-provider/admin/for_harvest.php
File size: 9.73 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);
}
// Get current month and year
$current_month = date('m');
$current_year = date('Y');

// Fetch clients for harvest
$query = "SELECT * FROM clients WHERE MONTH(last_harvested_date) != ? OR YEAR(last_harvested_date) != ? OR last_harvested_date IS NULL";
$stmt = $conn->prepare($query);
$stmt->bind_param("ii", $current_month, $current_year);
$stmt->execute();
$result = $stmt->get_result();

// Fetch the logged-in user's name from the session
$collected_by = $_SESSION['username']; // Make sure 'username' is set in the session when the user logs in
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>For Harvest</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;
            cursor: pointer;
        }
        th.sortable::after {
            content: ' \25B2\25BC';
            font-size: 0.8em;
            color: #aaa;
            padding-left: 5px;
        }
        th.sort-asc::after {
            content: ' \25B2';
        }
        th.sort-desc::after {
            content: ' \25BC';
        }
        .harvest-button {
            margin-bottom: 20px;
        }
        .search-container {
            margin-bottom: 20px;
        }
        .deduction-input {
            width: 100px;
            margin-left: 5px;
        }
        .deduction-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .print-button {
            margin-bottom: 20px;
        }

        /* Hide elements during print */
        @media print {
            .search-container,
            .print-button,
            .harvest-button,
            a[href*="for_harvest"],
            th:last-child,
            td:last-child {
                display: none;
            }
        }
    </style>
    <script>
        function calculateDeductions(rowId) {
            const harvestedAmountField = document.getElementById(`harvested_amount_${rowId}`);
            const lessDeductionsField = document.getElementById(`less_deductions_${rowId}`);

            const deductionCheckboxes = document.querySelectorAll(`.deduction-row input[type="checkbox"][data-row-id="${rowId}"]`);
            let totalDeductions = 0;

            deductionCheckboxes.forEach(checkbox => {
                if (checkbox.checked) {
                    const deductionValue = parseFloat(checkbox.closest('.deduction-row').querySelector('.deduction-input').value) || 0;
                    totalDeductions += deductionValue;
                }
            });

            const harvestedAmount = parseFloat(harvestedAmountField.value) || 0;
            const lessDeductions = harvestedAmount - totalDeductions;

            lessDeductionsField.value = lessDeductions.toFixed(2);
        }

        function sortTable(n) {
            // Sorting logic here...
        }

        function searchTable() {
            var input, filter, table, tr, td, i, j, txtValue;
            input = document.getElementById("searchInput");
            filter = input.value.toLowerCase();
            table = document.getElementById("clientTable");
            tr = table.getElementsByTagName("tr");

            for (i = 1; i < tr.length; i++) { // Skip the header row
                tr[i].style.display = "none"; // Hide all rows initially
                td = tr[i].getElementsByTagName("td");
                for (j = 0; j < td.length; j++) { // Loop through each cell in the row
                    if (td[j]) {
                        txtValue = td[j].textContent || td[j].innerText;
                        if (txtValue.toLowerCase().indexOf(filter) > -1) {
                            tr[i].style.display = ""; // Show the row if a match is found
                            break; // Exit the loop early if a match is found in any cell
                        }
                    }
                }
            }
        }

        function resetRowNumbers() {
            // Row numbering logic here...
        }

        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;">Clients for Harvest as of <?= date('F Y'); ?> </h4>
    <div class="search-container">
        <input type="text" id="searchInput" onkeyup="searchTable()" placeholder="Search for clients..">
    </div>
    <div class="print-button">
        <button onclick="printPage()">Print</button>
    </div>
    <form action="mark_harvested.php" method="post">
        <table id="clientTable">
            <thead>
                <tr>
                    <th>#</th>
                    <th class="sortable" onclick="sortTable(1)">Client Name</th>
                    <th class="sortable" onclick="sortTable(2)">Area</th>
                    <th class="sortable" onclick="sortTable(3)">Harvest Day</th>
                    <th>Harvested Amount</th>
                    <th>Deductions</th>
                    <th>Less Deductions</th>
                    <th>Remarks</th>
                    <th>Select</th>
                </tr>
            </thead>
            <tbody>
                <?php 
                $counter = 1;
                while ($row = $result->fetch_assoc()) { 
                    $rowId = $row['id']; ?>
                    <tr>
                        <td><?php echo $counter++; ?></td>
                        <td><?php echo htmlspecialchars($row['name']); ?></td>
                        <td><?php echo htmlspecialchars($row['area']); ?></td>
                        <td><?php echo htmlspecialchars($row['cutoff_day']); ?></td>
                        <td><input type="number" id="harvested_amount_<?php echo $rowId; ?>" name="harvested_amounts[<?php echo $rowId; ?>]" step="0.01" min="0" oninput="calculateDeductions(<?php echo $rowId; ?>)"></td>
                        <td>
                            <div class="deduction-row">
                                <input type="checkbox" id="deduction_internet_<?php echo $rowId; ?>" name="deductions[<?php echo $rowId; ?>][internet]" value="internet" onclick="calculateDeductions(<?php echo $rowId; ?>)" data-row-id="<?php echo $rowId; ?>">
                                <label for="deduction_internet_<?php echo $rowId; ?>">Internet</label>
                                <input type="number" class="deduction-input deduction-amount" data-row-id="<?php echo $rowId; ?>" step="0.01" min="0" oninput="calculateDeductions(<?php echo $rowId; ?>)">
                            </div>
                            <div class="deduction-row">
                                <input type="checkbox" id="deduction_electricity_<?php echo $rowId; ?>" name="deductions[<?php echo $rowId; ?>][electricity]" value="electricity" onclick="calculateDeductions(<?php echo $rowId; ?>)" data-row-id="<?php echo $rowId; ?>">
                                <label for="deduction_electricity_<?php echo $rowId; ?>">Electricity</label>
                                <input type="number" class="deduction-input deduction-amount" data-row-id="<?php echo $rowId; ?>" step="0.01" min="0" oninput="calculateDeductions(<?php echo $rowId; ?>)">
                            </div>
                            <div class="deduction-row">
                                <input type="checkbox" id="deduction_other_<?php echo $rowId; ?>" name="deductions[<?php echo $rowId; ?>][other]" value="other" onclick="calculateDeductions(<?php echo $rowId; ?>)" data-row-id="<?php echo $rowId; ?>">
                                <label for="deduction_other_<?php echo $rowId; ?>">Other</label>
                                <input type="number" class="deduction-input deduction-amount" data-row-id="<?php echo $rowId; ?>" step="0.01" min="0" oninput="calculateDeductions(<?php echo $rowId; ?>)">
                            </div>
                        </td>
                        <td><input type="number" id="less_deductions_<?php echo $rowId; ?>" name="less_deductions[<?php echo $rowId; ?>]" step="0.01" readonly></td>
                        <td><input type="text" name="remarks[<?php echo $rowId; ?>]" placeholder=""></td>
                        <td><input type="checkbox" name="harvested_clients[]" value="<?php echo $rowId; ?>"></td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
        <div class="harvest-button">
            <input type="submit" value="Mark as Harvested">
        </div>
    </form>
    <div style="margin-top: 20px;">
        <a href="https://fastlinkinternet.com/administrator/data-provider/admin/?page=for_harvest">
            <button type="button" style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer;">Back to Piso WiFi Client Lists</button>
        </a>
    </div>
</body>
</html>

<?php
$stmt->close();
$conn->close();
include 'footer.php'; // Include the footer file
?>