- Replaced all client-facing $e->getMessage() with generic error messages - Added error_log() with filename prefix to all catch blocks - Covered jsonError(), echo, and json_encode() response patterns - Also fixed 2 remaining display_errors=1 and add_invoice.php leak - Script-assisted fix for 75 files, manual fix for 12 remaining edge cases
36 lines
1009 B
PHP
36 lines
1009 B
PHP
<?php
|
|
// Admin/v2/financial/stats.php
|
|
require_once __DIR__ . '/../../../connect.php';
|
|
|
|
if ($role !== 'admin' && $role !== 'super_admin') {
|
|
http_response_code(403);
|
|
echo json_encode(['error' => 'Unauthorized access.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
// إحصائيات مالية عامة
|
|
$stmt = $con->prepare("
|
|
SELECT
|
|
SUM(price_for_passenger) as total_revenue,
|
|
SUM(price_for_driver) as total_driver_pay,
|
|
SUM(price_for_passenger - price_for_driver) as total_platform_commission,
|
|
0 as cash_payments,
|
|
0 as digital_payments
|
|
FROM ride
|
|
WHERE status = 'Finished'
|
|
");
|
|
$stmt->execute();
|
|
$stats = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'data' => $stats
|
|
]);
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
error_log("[stats.php] " . $e->getMessage());
|
|
echo json_encode(['status' => 'error', 'message' => 'An internal error occurred']);
|
|
}
|
|
?>
|