Update: 2026-08-08 12:58:16

This commit is contained in:
Hamza-Ayed
2026-08-08 12:58:17 +03:00
parent 611b5e616d
commit fae0e4a38a
55 changed files with 5771 additions and 1820 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
/**
* fuel/cancel_voucher.php — إلغاء قسيمة لم تُصرف
*
* ‏يحرّر المبلغ المحجوز فوراً. بدونه ينتظر السائق انتهاء الصلاحية ليعود
* ‏سقفه — وهو ينتظر عند مضخة ليتزوّد بمبلغ آخر.
*/
require_once __DIR__ . '/../connect.php';
require_once __DIR__ . '/functions.php';
$driverId = $user_id ?? '';
if (empty($driverId) || ($role ?? '') !== 'driver') {
jsonError('Unauthorized', 401);
}
// ‏الشرط على driver_id إلى جانب الحالة: الرمز وحده يكفي للعثور على
// ‏قسيمة، ولا يجوز أن يُلغي سائقٌ قسيمة غيره برمز وقع بيده.
$st = $con->prepare("
UPDATE fuel_vouchers
SET status = 'cancelled'
WHERE driver_id = ? AND status = 'issued'
");
$st->execute([$driverId]);
if ($st->rowCount() === 0) {
jsonError('لا توجد قسيمة قابلة للإلغاء');
}
$obligation = fuelObligation($con, $driverId);
$state = $obligation ? fuelCreditState($con, $obligation) : null;
jsonSuccess([
'cancelled' => true,
'available' => $state['available'] ?? null,
], 'أُلغيت القسيمة وعاد المبلغ إلى سقفك');