Files
Siro/backend/serviceapp/getEmployeeDriverAfterCallingRegister.php
Hamza-Ayed 72eeb24cd7 Fix #18: Exception leak remediation across 87 PHP files
- 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
2026-06-17 07:48:31 +03:00

61 lines
2.3 KiB
PHP

<?php
require_once __DIR__ . '/../connect.php';
/**
* منطق تحديد التواريخ:
* 1. إذا تم إرسال start_date و end_date في الطلب، سيتم استخدامهما (للبحث في رينج مخصص).
* 2. إذا لم يتم إرسالهما، سيتم الاعتماد على month و year (للبحث في شهر كامل).
* 3. إذا لم يتم إرسال أي شيء، سيتم استخدام الشهر الحالي كافتراضي.
*/
if (isset($_POST['start_date']) && isset($_POST['end_date'])) {
// الحالة الأولى: البحث بنطاق تاريخ محدد (من يوم كذا إلى يوم كذا)
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
} else {
// الحالة الثانية: البحث بالشهر (مثل السكربت القديم)
$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));
}
$sql = "SELECT
employmentType,
COUNT(*) AS `count`
FROM
`driver`
WHERE
DATE(created_at) >= :start_date
AND DATE(created_at) <= :end_date
GROUP BY
employmentType";
try {
$stmt = $con->prepare($sql);
$stmt->execute([':start_date' => $start_date, ':end_date' => $end_date]);
$stats_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($stats_data) {
// طباعة البيانات كـ JSON مع إضافة التواريخ المستخدمة للعلم
printSuccess([
"data" => $stats_data,
"period" => [
"start" => $start_date,
"end" => $end_date
]
]);
} else {
jsonError("No data found for the selected period");
}
} catch (PDOException $e) {
// في حال حدوث خطأ في قاعدة البيانات
jsonError("An internal error occurred. Please try again later.");
}
?>