Eight queries across the v2 modules counted only status = 'Finished' and so reported zero on live data, where the current ride pipeline writes 'completed': realtime revenue for today and yesterday, financial stats, settlements, driver scorecard, driver ranking, and both revenue queries. All now match either spelling. Growth and Advanced Analytics rendered through the generic shape-detecting renderer, which produced raw tables that said little. Both now have purpose- built views: - Growth: totals, 30-day joins, and a two-series daily chart. growth.php only returns days that had signups, so the series is expanded to a continuous 30-day axis with explicit zeros — plotting the returned rows directly would hide the gaps and make a quiet month look like steady growth. A caption states how many days actually had a signup. - Analytics: revenue summary tiles, a daily revenue trend, and the captain ranking, with a note explaining that platform share is what remains after the captain's cut. Null aggregates render as "—" rather than 0.00, and markers are drawn only on days with a value so a flat zero line stays readable. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
// Admin/v2/analytics/revenue.php
|
|
require_once __DIR__ . '/../../../connect.php';
|
|
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
http_response_code(403);
|
|
echo json_encode(['error' => 'Unauthorized access.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
// إحصائيات الإيرادات لآخر 30 يوم
|
|
$stmt = $con->prepare("
|
|
SELECT
|
|
DATE(created_at) as date,
|
|
SUM(price) as total_revenue,
|
|
SUM(price - price_for_driver) as company_profit,
|
|
COUNT(*) as total_rides
|
|
FROM ride
|
|
WHERE LOWER(status) IN ('finished','completed')
|
|
AND created_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
|
GROUP BY DATE(created_at)
|
|
ORDER BY date ASC
|
|
");
|
|
$stmt->execute();
|
|
$daily_stats = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// ملخص عام
|
|
$stmt = $con->prepare("
|
|
SELECT
|
|
SUM(price) as total_revenue_all,
|
|
SUM(price - price_for_driver) as total_profit_all,
|
|
AVG(price) as avg_ride_price
|
|
FROM ride
|
|
WHERE LOWER(status) IN ('finished','completed')
|
|
AND created_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
|
");
|
|
$stmt->execute();
|
|
$summary = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'data' => [
|
|
'daily' => $daily_stats,
|
|
'summary' => $summary
|
|
]
|
|
]);
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
error_log("[revenue.php] " . $e->getMessage());
|
|
echo json_encode(['status' => 'error', 'message' => 'An internal error occurred']);
|
|
}
|
|
?>
|