HEX
Server: LiteSpeed
System: Linux server214.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: bigisxfd (746)
PHP: 8.4.15
Disabled: NONE
Upload Files
File: /home/bigisxfd/public_html/cowork/daily_sales_report.php
<?php
// Include necessary files
include_once("header.php");
include_once("sidebar.php");

?>

<section>
    <div class="column">
        <h2>Daily Sales Report</h2>

<?php 


// Get selected month or use the current month as default
$selectedMonth = isset($_GET['month']) ? $_GET['month'] : date("m");

// Query to retrieve daily sales per mode of payment for the selected month
$sql = "SELECT DATE(date) as sale_date, 
               SUM(CASE WHEN mode = 'Gcash' THEN amount ELSE 0 END) as gcash_sales,
               SUM(CASE WHEN mode = 'Cash' THEN amount ELSE 0 END) as cash_sales,
               SUM(amount) as total_sales
        FROM Payments 
        WHERE MONTH(date) = $selectedMonth 
        GROUP BY sale_date 
        ORDER BY sale_date";

$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // Output month filter dropdown
    echo '<form method="get" action="">';
    echo 'Select Month: <select name="month" onchange="this.form.submit()">';

    for ($i = 1; $i <= 12; $i++) {
        $monthName = date('F', mktime(0, 0, 0, $i, 1));
        $selected = ($i == $selectedMonth) ? 'selected' : '';
        echo "<option value=\"$i\" $selected>$monthName</option>";
    }

    echo '</select></form>';

    // Output table header
    echo "<table border='1'>
            <tr>
                <th>Date</th>
                <th>Gcash</th>
                <th>Cash</th>
                <th>Total</th>
                <th>Actions</th>
            </tr>";

    // Initialize overall totals
    $overallGcashTotal = 0;
    $overallCashTotal = 0;
    $overallGrandTotal = 0;

// Output data
while ($row = mysqli_fetch_assoc($result)) {
    echo "<tr>
            <td>" . $row['sale_date'] . "</td>
            <td class='hidden-sales' data-date='" . $row['sale_date'] . "'>&#8369; " . number_format($row['gcash_sales']) . "</td>
            <td class='hidden-sales' data-date='" . $row['sale_date'] . "'>&#8369; " . number_format($row['cash_sales']) . "</td>
            <td class='hidden-sales' data-date='" . $row['sale_date'] . "'>&#8369; " . number_format($row['total_sales']) . "</td>
            <td><button class='reconcile-btn' data-date='" . $row['sale_date'] . "'>Reconcile</button></td>
          </tr>";

    // Update overall totals
    $overallGcashTotal += $row['gcash_sales'];
    $overallCashTotal += $row['cash_sales'];
    $overallGrandTotal += $row['total_sales'];
}

// Output total row with formatted numbers and Philippine Peso sign
echo "<tr>
        <td><strong>Total</strong></td>
        <td class='hidden-sales' data-date='total'><strong>&#8369; " . number_format($overallGcashTotal) . "</strong></td>
        <td class='hidden-sales' data-date='total'><strong>&#8369; " . number_format($overallCashTotal) . "</strong></td>
        <td class='hidden-sales' data-date='total'><strong>&#8369; " . number_format($overallGrandTotal) . "</strong></td>
        <td></td>
      </tr>";

echo "</table>";

echo "<script>
        document.addEventListener('DOMContentLoaded', function() {
            var reconcileButtons = document.querySelectorAll('.reconcile-btn');
            reconcileButtons.forEach(function(button) {
                button.addEventListener('click', function() {
                    var row = this.closest('tr');
                    var salesCells = row.querySelectorAll('.hidden-sales');
                    salesCells.forEach(function(cell) {
                        cell.classList.toggle('hidden');
                    });
                });
            });
        });
      </script>";

} else {
    echo "No records found";
}
?>

    </div>
</section>

</body>
</html>