query('SELECT count(*) FROM loads')->fetchColumn();
$total_drivers = $pdo->query('SELECT count(*) FROM drivers')->fetchColumn();
$in_transit_loads = $pdo->query('SELECT count(*) FROM loads WHERE status = "In-Transit"')->fetchColumn();
$delivered_loads = $pdo->query('SELECT count(*) FROM loads WHERE status = "Delivered"')->fetchColumn();
// Pie Chart: Loads by Status
$loads_by_status_stmt = $pdo->query('SELECT status, count(*) as count FROM loads GROUP BY status');
$loads_by_status = $loads_by_status_stmt->fetchAll(PDO::FETCH_ASSOC);
$status_labels = [];
$status_counts = [];
foreach ($loads_by_status as $row) {
$status_labels[] = $row['status'];
$status_counts[] = $row['count'];
}
// Bar Chart: Loads per month
// Using a default of 0 for all months of the current year
$monthly_counts = array_fill(1, 12, 0);
$loads_by_month_stmt = $pdo->query("
SELECT
CAST(strftime('%m', pickup_date) AS INTEGER) as month,
count(*) as count
FROM loads
WHERE strftime('%Y', pickup_date) = strftime('%Y', 'now')
GROUP BY month
");
$loads_by_month = $loads_by_month_stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($loads_by_month as $row) {
$monthly_counts[$row['month']] = $row['count'];
}
$monthly_labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
$monthly_values = array_values($monthly_counts);
include 'includes/header.php';
include 'includes/sidebar.php';
?>