37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?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,
|
|
], 'أُلغيت القسيمة وعاد المبلغ إلى سقفك');
|