diff --git a/eid_orders.php b/eid_orders.php index 82ffdbe..8d7d766 100644 --- a/eid_orders.php +++ b/eid_orders.php @@ -34,6 +34,28 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' redirect_to('eid_orders.php', $_GET); } +$canDeleteEidOrders = $user['role'] === 'owner' || has_permission('sales', 'del'); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete_eid_order') { + if (!$canDeleteEidOrders) { + set_flash('danger', tr('ليس لديك صلاحية حذف الفواتير.', 'You do not have permission to delete invoices.')); + redirect_to('eid_orders.php', $_GET); + } + + $id = (int)($_POST['id'] ?? 0); + try { + $sale = fetch_sale($id); + if (!$sale || ($sale['order_type'] ?? '') !== 'eid') { + set_flash('warning', tr('فاتورة العيد غير موجودة.', 'Eid invoice was not found.')); + } else { + $stmt = db()->prepare("DELETE FROM sales_orders WHERE id = :id AND order_type = 'eid'"); + $stmt->execute([':id' => $id]); + set_flash('success', tr('تم حذف فاتورة العيد بنجاح.', 'Eid invoice deleted successfully.')); + } + } catch (Throwable $e) { + set_flash('danger', tr('تعذر حذف فاتورة العيد.', 'Failed to delete Eid invoice.')); + } + redirect_to('eid_orders.php', $_GET); +} $activeNav = 'eid_orders'; $pageTitle = tr('طلبات العيد', 'Eid Orders'); @@ -505,6 +527,15 @@ require __DIR__ . '/includes/header.php'; + +
+ + + +
+ @@ -620,5 +651,21 @@ async function receivePayment(id, totalAmount, paidAmount, dueAmount, completeOr Swal.fire({ icon: 'error', text: data.error || '' }); } } + +function confirmDeleteEidOrder(form) { + Swal.fire({ + title: '', + text: '', + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#dc3545', + cancelButtonText: '', + confirmButtonText: '' + }).then((result) => { + if (result.isConfirmed) { + form.submit(); + } + }); +}