diff --git a/includes/lang.php b/includes/lang.php index 818505e..b670c1a 100644 --- a/includes/lang.php +++ b/includes/lang.php @@ -66,7 +66,7 @@ $translations = [ 'received' => 'Received', 'processing' => 'Processing', 'ready' => 'Ready', - 'delivered' => 'Delivered', + 'delivered' => 'تم التسليم', 'cancelled' => 'Cancelled', 'unpaid' => 'Unpaid', 'partially_paid' => 'Partially Paid', @@ -236,6 +236,17 @@ $translations = [ 'loyalty' => 'Loyalty Points', 'loyalty_discount' => 'Loyalty Discount', 'final_total' => 'Final Total', + 'set_prices_for' => 'Set Prices for', + 'prices_saved_automatically' => 'Prices are saved automatically', + 'done' => 'Done', + 'uncategorized' => 'Uncategorized', + 'manage_items_categories_services' => 'Manage Items, Categories & Services', + 'manage_categories' => 'Manage Categories', + 'search_items' => 'Search Items', + 'filter' => 'Filter', + 'all_categories' => 'All Categories', + 'upload_image' => 'Upload Image', + 'confirm_delete' => 'Are you sure you want to delete this?', ], 'ar' => [ 'dashboard' => 'لوحة القيادة', @@ -458,6 +469,17 @@ $translations = [ 'loyalty' => 'نقاط الولاء', 'loyalty_discount' => 'خصم الولاء', 'final_total' => 'الإجمالي النهائي', + 'set_prices_for' => 'تحديد الأسعار لـ', + 'prices_saved_automatically' => 'يتم حفظ الأسعار تلقائياً', + 'done' => 'تم', + 'uncategorized' => 'غير مصنف', + 'manage_items_categories_services' => 'إدارة الأصناف والفئات والخدمات', + 'manage_categories' => 'إدارة الفئات', + 'search_items' => 'بحث عن أصناف', + 'filter' => 'تصفية', + 'all_categories' => 'جميع الفئات', + 'upload_image' => 'رفع صورة', + 'confirm_delete' => 'هل أنت متأكد من الحذف؟', ] ]; diff --git a/items.php b/items.php index 60b26aa..95292d0 100644 --- a/items.php +++ b/items.php @@ -186,11 +186,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $item_id = $_POST['item_id']; $service_id = $_POST['service_id']; $price = $_POST['price']; - - // Handle empty/invalid price - if ($price === '') $price = 0; - $price = str_replace(',', '.', $price); // Handle comma as decimal separator - $price = (float)$price; // Determine branch_id from session (if available) $branch_id = $_SESSION['branch_id'] ?? null; @@ -203,6 +198,38 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { if (!$chk->fetch()) $branch_id = null; } + // Handle deletion if price is empty + if ($price === '') { + try { + if ($branch_id) { + $stmt = db()->prepare("DELETE FROM prices WHERE item_id = ? AND service_id = ? AND branch_id = ?"); + $stmt->execute([$item_id, $service_id, $branch_id]); + } else { + $stmt = db()->prepare("DELETE FROM prices WHERE item_id = ? AND service_id = ? AND branch_id IS NULL"); + $stmt->execute([$item_id, $service_id]); + } + + if ($isAjax) { + header('Content-Type: application/json'); + echo json_encode(['success' => true]); + exit; + } + header('Location: items.php?success=price_deleted'); + exit; + } catch (Exception $e) { + if ($isAjax) { + header('Content-Type: application/json'); + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + exit; + } + header('Location: items.php?error=delete_failed'); + exit; + } + } + + $price = str_replace(',', '.', $price); // Handle comma as decimal separator + $price = (float)$price; + try { if ($branch_id) { $stmt = db()->prepare("INSERT INTO prices (item_id, service_id, price, branch_id) @@ -619,7 +646,7 @@ function renderServiceList($lang) {
-
+
- + +
@@ -804,6 +834,34 @@ document.querySelectorAll('.price-input').forEach(input => { }); }); +async function removePrice(btn, itemId, serviceId) { + if (confirm('')) { + const input = btn.parentElement.querySelector('.price-input'); + const formData = new FormData(); + formData.append('action', 'update_price'); + formData.append('ajax', '1'); + formData.append('item_id', itemId); + formData.append('service_id', serviceId); + formData.append('price', ''); // Empty price triggers deletion + + try { + const response = await fetch('items.php', { + method: 'POST', + body: formData + }); + const data = await response.json(); + if (data.success) { + input.value = ''; + showIndicator(input); + } else { + alert(data.error || 'Failed to remove price'); + } + } catch (error) { + console.error('Error removing price:', error); + } + } +} + function showIndicator(input) { const indicator = input.parentElement.querySelector('.success-indicator'); if (indicator) { @@ -828,4 +886,4 @@ document.getElementById('itemImageFile').addEventListener('change', function(e) }); - \ No newline at end of file +