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();
?>
Total Weight Harvested
kg
Fortnightly Harvest Charges
| Fortnight |
Tilapia (kg) |
Small Fish (kg) |
Big Fish (kg) |
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 "
| {$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
| Buyer |
Total Sales |
Total Payments |
Balance |
fetch_assoc()) {
echo "
| {$row['buyer_name']} |
" . formatCurrency($row['total_sales']) . " |
" . formatCurrency($row['total_payments']) . " |
" . formatCurrency($row['balance']) . " |
";
}
?>
Monthly Sales Data (Oct 2024 - Sep 2025)
| Month |
Sales Value |
Expense Value |
Payments Value |
Harvested Weight |
Rate/Kg |
fetch_assoc()) {
echo "
| {$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';
?>