first commit
This commit is contained in:
34
backend/Admin/v2/financial/stats.php
Normal file
34
backend/Admin/v2/financial/stats.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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,
|
||||
(SELECT SUM(amount) FROM payments WHERE payment_method = 'Cash') as cash_payments,
|
||||
(SELECT SUM(amount) FROM payments WHERE payment_method != 'Cash') 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);
|
||||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user