another update for eid sales
This commit is contained in:
parent
ea4bf1e47f
commit
680965e7e9
@ -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';
|
||||
</div>
|
||||
<a class="btn btn-sm btn-light border text-primary" href="<?= h(url_for('sale.php', ['id' => $order['id']])) ?>" title="<?= h(tr('تفاصيل', 'Detail')) ?>"><i class="bi bi-eye"></i></a>
|
||||
<a class="btn btn-sm btn-outline-secondary" href="<?= h(url_for('edit_sale.php', ['id' => $order['id']])) ?>" title="<?= h(tr('تعديل', 'Edit')) ?>"><i class="bi bi-pencil"></i></a>
|
||||
<?php if ($canDeleteEidOrders): ?>
|
||||
<form method="post" action="" class="d-inline-block js-eid-delete-form">
|
||||
<input type="hidden" name="action" value="delete_eid_order">
|
||||
<input type="hidden" name="id" value="<?= h($order['id']) ?>">
|
||||
<button type="button" class="btn btn-sm btn-outline-danger" onclick="confirmDeleteEidOrder(this.form)" title="<?= h(tr('حذف', 'Delete')) ?>">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@ -620,5 +651,21 @@ async function receivePayment(id, totalAmount, paidAmount, dueAmount, completeOr
|
||||
Swal.fire({ icon: 'error', text: data.error || '<?= h(tr('تعذر تسجيل الدفعة.', 'Could not record the payment.')) ?>' });
|
||||
}
|
||||
}
|
||||
|
||||
function confirmDeleteEidOrder(form) {
|
||||
Swal.fire({
|
||||
title: '<?= h(tr('هل أنت متأكد من حذف الفاتورة؟', 'Are you sure you want to delete this invoice?')) ?>',
|
||||
text: '<?= h(tr('سيتم حذف فاتورة العيد نهائياً من النظام. استخدم هذا الخيار فقط عند الضرورة.', 'This will permanently delete the Eid invoice from the system. Use this only when necessary.')) ?>',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#dc3545',
|
||||
cancelButtonText: '<?= h(tr('إلغاء', 'Cancel')) ?>',
|
||||
confirmButtonText: '<?= h(tr('نعم، احذف', 'Yes, delete it')) ?>'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php require __DIR__ . '/includes/footer.php'; ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user