query($query); if ($result === false) { throw new Exception("Query failed: " . $conn->error); } return $result; } try { // Get total sales value $result = executeQuery($conn, "SELECT SUM(final_amount) as total FROM sales"); $totalSales = $result->fetch_assoc()['total'] ?? 0; // Get total expense value $result = executeQuery($conn, "SELECT SUM(amount) as total FROM expenses"); $totalExpenses = $result->fetch_assoc()['total'] ?? 0; // Get total payments value $result = executeQuery($conn, "SELECT SUM(amount_paid) as total FROM payments"); $totalPayments = $result->fetch_assoc()['total'] ?? 0; // Get total weight harvested $result = executeQuery($conn, "SELECT SUM(weight_tilapia + weight_small_fish + weight_big_fish) as total FROM sales"); $totalWeightHarvested = $result->fetch_assoc()['total'] ?? 0; // Get average rate per kg $result = executeQuery($conn, "SELECT SUM(final_amount) / SUM(weight_tilapia + weight_small_fish + weight_big_fish) as avg_rate FROM sales"); $averageRatePerKg = $result->fetch_assoc()['avg_rate'] ?? 0; // Get initial values $result = executeQuery($conn, "SELECT * FROM initial_values LIMIT 1"); $initialValues = $result->fetch_assoc(); // Calculate cash in hand $cashInHand = ($initialValues['cash_in_hand'] ?? 0) + $totalPayments - $totalExpenses; // Start outputting content ob_start(); ?>

Dashboard

Export to CSV

Total Sales Value

Total Expense Value

Total Payments Value

Cash in Hand

Total Weight Harvested

kg

Average Rate/Kg

Fortnightly Harvest Charges

0 ORDER BY start_date"; $result = executeQuery($conn, $query); while ($row = $result->fetch_assoc()) { // Format the start and end dates $startDate = date('Y-m-d', strtotime($row['start_date'])); $endDate = date('Y-m-d', strtotime($row['end_date'])); // Create a descriptive fortnight name if ($row['half_month'] == 'First Half') { $fortnightName = date('M d', strtotime($startDate)) . " - " . date('M d', strtotime($row['month_year'] . '-15')); } else { $fortnightName = date('M d', strtotime($row['month_year'] . '-16')) . " - " . date('M d', strtotime($endDate)); } echo ""; } ?>
Fortnight Tilapia (kg) Small Fish (kg) Big Fish (kg) Harvest Charges
{$fortnightName} " . number_format($row['total_tilapia'], 2) . " " . number_format($row['total_small_fish'], 2) . " " . number_format($row['total_big_fish'], 2) . " " . formatCurrency($row['total_charges']) . "

Buyer Data

fetch_assoc()) { echo ""; } ?>
Buyer Total Sales Total Payments Balance
{$row['buyer_name']} " . formatCurrency($row['total_sales']) . " " . formatCurrency($row['total_payments']) . " " . formatCurrency($row['balance']) . "

Monthly Sales Data (Oct 2024 - Sep 2025)

fetch_assoc()) { echo ""; } ?>
Month Sales Value Expense Value Payments Value Harvested Weight Rate/Kg
{$row['month']} " . formatCurrency($row['sales_value']) . " " . formatCurrency($row['expense_value']) . " " . formatCurrency($row['payments_value']) . " " . number_format($row['harvested_weight'], 2) . " kg " . formatCurrency($row['rate_per_kg']) . "
An error occurred: " . htmlspecialchars($e->getMessage()) . "

"; } include 'main_layout.php'; ?>