- 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
103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../connect.php';
|
|
|
|
// منع الأخطاء النصية وضبط الترويسة
|
|
error_reporting(0);
|
|
header('Content-Type: application/json');
|
|
|
|
// 1. استقبال التواريخ
|
|
if (isset($_POST['start_date']) && isset($_POST['end_date'])) {
|
|
$start_date = $_POST['start_date'];
|
|
$end_date = $_POST['end_date'];
|
|
} else {
|
|
// Fallback
|
|
$current_month = isset($_POST['month']) ? str_pad($_POST['month'], 2, "0", STR_PAD_LEFT) : date('m');
|
|
$current_year = isset($_POST['year']) ? $_POST['year'] : date('Y');
|
|
|
|
$start_date = date('Y-m-d', strtotime("$current_year-$current_month-01"));
|
|
$end_date = date('Y-m-t', strtotime($start_date));
|
|
}
|
|
|
|
$end_date_full = $end_date . ' 23:59:59';
|
|
|
|
$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,
|
|
|
|
(SELECT COUNT(*) FROM driver) AS totalDrivers,
|
|
|
|
(
|
|
SELECT COUNT(*)
|
|
FROM driver
|
|
WHERE DATE(driver.created_at) = date_series.date
|
|
) AS dailyTotalDrivers,
|
|
|
|
(
|
|
SELECT COUNT(*)
|
|
FROM notesForDriverService
|
|
WHERE DATE(notesForDriverService.createdAt) = date_series.date
|
|
) AS dailyTotalCallingDrivers,
|
|
|
|
(
|
|
SELECT COUNT(*)
|
|
FROM notesForDriverService n
|
|
JOIN driver d ON n.phone = d.phone
|
|
WHERE DATE(n.createdAt) = date_series.date
|
|
) AS dailyMatchingNotes,
|
|
|
|
(
|
|
SELECT COUNT(*)
|
|
FROM driver
|
|
WHERE driver.created_at BETWEEN :start_date1 AND :end_date1
|
|
) AS totalMonthlyDrivers,
|
|
|
|
(
|
|
SELECT COUNT(*)
|
|
FROM notesForDriverService
|
|
WHERE notesForDriverService.createdAt BETWEEN :start_date2 AND :end_date2
|
|
) AS totalMonthlyCallingDrivers,
|
|
|
|
(
|
|
SELECT COUNT(*)
|
|
FROM notesForDriverService n
|
|
JOIN driver d ON n.phone = d.phone
|
|
WHERE n.createdAt BETWEEN :start_date3 AND :end_date3
|
|
) AS totalMonthlyMatchingNotes
|
|
|
|
FROM
|
|
date_series
|
|
GROUP BY
|
|
date_series.date
|
|
ORDER BY
|
|
date_series.date ASC";
|
|
|
|
try {
|
|
$stmt = $con->prepare($sql);
|
|
$stmt->execute([
|
|
':start_date' => $start_date,
|
|
':end_date' => $end_date,
|
|
':start_date1' => $start_date,
|
|
':end_date1' => $end_date_full,
|
|
':start_date2' => $start_date,
|
|
':end_date2' => $end_date_full,
|
|
':start_date3' => $start_date,
|
|
':end_date3' => $end_date_full
|
|
]);
|
|
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($data) {
|
|
echo json_encode(array("status" => "success", "message" => $data));
|
|
} else {
|
|
echo json_encode(array("status" => "success", "message" => []));
|
|
}
|
|
} catch (PDOException $e) {
|
|
echo json_encode(array("status" => "failure", "message" => "An internal error occurred"));
|
|
}
|
|
?>
|