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>
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
// Admin/v2/financial/settlements.php
|
|
require_once __DIR__ . '/../../../connect.php';
|
|
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
http_response_code(403);
|
|
echo json_encode(['error' => 'Unauthorized access.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
// جلب السائقين الذين لديهم مستحقات أو مديونية
|
|
// الحسبة: إجمالي (price_for_driver) من الرحلات المكتملة
|
|
$stmt = $con->prepare("
|
|
SELECT
|
|
d.id, d.first_name, d.last_name, d.phone,
|
|
SUM(r.price_for_driver) as total_earned,
|
|
COUNT(r.id) as total_rides
|
|
FROM driver d
|
|
LEFT JOIN ride r ON d.id = r.driver_id AND LOWER(r.status) IN ('finished','completed')
|
|
GROUP BY d.id
|
|
HAVING total_earned > 0
|
|
ORDER BY total_earned DESC
|
|
LIMIT 50
|
|
");
|
|
$stmt->execute();
|
|
$drivers = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// فك تشفير البيانات
|
|
foreach ($drivers as &$driver) {
|
|
$driver['first_name'] = $encryptionHelper->decryptData($driver['first_name']);
|
|
$driver['last_name'] = $encryptionHelper->decryptData($driver['last_name']);
|
|
$driver['phone'] = $encryptionHelper->decryptData($driver['phone']);
|
|
}
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'data' => $drivers
|
|
]);
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
error_log("[settlements.php] " . $e->getMessage());
|
|
echo json_encode(['status' => 'error', 'message' => 'An internal error occurred']);
|
|
}
|
|
?>
|