60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
|
|
include "../../connect.php";
|
|
$driverID = filterRequest("driverID");
|
|
|
|
// الخطوة 1: جلب كل سجلات الدفع لليوم الحالي
|
|
$sql_records = "SELECT
|
|
id,
|
|
amount,
|
|
payment_method,
|
|
isGiven,
|
|
passengerID,
|
|
rideId,
|
|
created_at
|
|
FROM
|
|
payments
|
|
WHERE
|
|
driverID = ?
|
|
AND DATE(created_at) = CURDATE()
|
|
";
|
|
|
|
$stmt_records = $con->prepare($sql_records);
|
|
$stmt_records->execute([$driverID]);
|
|
$records = $stmt_records->fetchAll(PDO::FETCH_ASSOC);
|
|
$count = $stmt_records->rowCount();
|
|
|
|
if ($count > 0) {
|
|
// الخطوة 2: حساب المجموع اليومي في استعلام منفصل وآمن
|
|
$sql_sum = "SELECT
|
|
COALESCE(SUM(amount), 0) AS todayAmount
|
|
FROM
|
|
payments
|
|
WHERE
|
|
driverID = ?
|
|
AND DATE(created_at) = CURDATE()
|
|
-- AND isGiven !='waiting'";
|
|
|
|
$stmt_sum = $con->prepare($sql_sum);
|
|
$stmt_sum->execute([$driverID]);
|
|
$total_row = $stmt_sum->fetch(PDO::FETCH_ASSOC);
|
|
$todayAmount = $total_row['todayAmount'];
|
|
|
|
// الخطوة 3: إضافة المجموع الكلي لكل سجل في القائمة
|
|
$response_data = [];
|
|
foreach ($records as $record) {
|
|
$record['todayAmount'] = $todayAmount; // أضف المجموع هنا
|
|
$response_data[] = $record;
|
|
}
|
|
|
|
// إرسال البيانات بالهيكلية التي يتوقعها التطبيق
|
|
printSuccess( $response_data);
|
|
|
|
} else {
|
|
// في حالة عدم وجود أي دفعات اليوم
|
|
printFailure($message = "No wallet record found");
|
|
}
|
|
|
|
|
|
?>
|