Initial commit with updated Auth and media ignored
This commit is contained in:
64
serviceapp/getRidesStatic.php
Executable file
64
serviceapp/getRidesStatic.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../connect.php';
|
||||
|
||||
// 1. استقبال تواريخ البداية والنهاية بدلاً من الشهر والسنة فقط
|
||||
if (isset($_POST['start_date']) && isset($_POST['end_date'])) {
|
||||
// إذا أرسل التطبيق تواريخ محددة (الوضع الجديد)
|
||||
$start_date = $_POST['start_date']; // Format: YYYY-MM-DD
|
||||
$end_date = $_POST['end_date']; // Format: YYYY-MM-DD
|
||||
} else {
|
||||
// (Fallback) إذا لم يرسل تواريخ، نستخدم منطق الشهر والسنة القديم
|
||||
$current_month = isset($_POST['month']) ? $_POST['month'] : date('m');
|
||||
$current_year = isset($_POST['year']) ? $_POST['year'] : date('Y');
|
||||
|
||||
// التأكد من أن صيغة الشهر خانتين
|
||||
$current_month = str_pad($current_month, 2, "0", STR_PAD_LEFT);
|
||||
|
||||
$start_date = date('Y-m-d', strtotime($current_year . '-' . $current_month . '-01'));
|
||||
$end_date = date('Y-m-t', strtotime($start_date));
|
||||
}
|
||||
|
||||
// 2. جملة الـ SQL المعدلة لتعمل مع النطاق الزمني
|
||||
$sql = "
|
||||
WITH RECURSIVE date_series AS (
|
||||
SELECT '$start_date' AS date
|
||||
UNION ALL
|
||||
SELECT DATE_ADD(date, INTERVAL 1 DAY)
|
||||
FROM date_series
|
||||
WHERE date < '$end_date'
|
||||
)
|
||||
SELECT
|
||||
date_series.date AS day,
|
||||
-- حساب الرحلات المنتهية في هذا اليوم
|
||||
COALESCE(SUM(ride.status = 'Finished'), 0) AS totalRides,
|
||||
|
||||
-- حساب الإجمالي للفترة المحددة كاملة (وليس للشهر فقط)
|
||||
(SELECT COUNT(*) FROM ride
|
||||
WHERE ride.created_at >= '$start_date'
|
||||
AND ride.created_at <= '$end_date 23:59:59'
|
||||
AND ride.status = 'Finished') AS totalMonthly
|
||||
|
||||
FROM
|
||||
date_series
|
||||
LEFT JOIN
|
||||
ride ON DATE(ride.created_at) = date_series.date
|
||||
AND ride.status = 'Finished'
|
||||
WHERE
|
||||
date_series.date >= '$start_date'
|
||||
AND date_series.date <= '$end_date'
|
||||
GROUP BY
|
||||
date_series.date
|
||||
ORDER BY
|
||||
date_series.date ASC;
|
||||
";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($data) {
|
||||
jsonSuccess($data);
|
||||
} else {
|
||||
jsonError("No data found");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user