updating items
This commit is contained in:
parent
35d8fe23f8
commit
9060a6d586
@ -66,7 +66,7 @@ $translations = [
|
|||||||
'received' => 'Received',
|
'received' => 'Received',
|
||||||
'processing' => 'Processing',
|
'processing' => 'Processing',
|
||||||
'ready' => 'Ready',
|
'ready' => 'Ready',
|
||||||
'delivered' => 'Delivered',
|
'delivered' => 'تم التسليم',
|
||||||
'cancelled' => 'Cancelled',
|
'cancelled' => 'Cancelled',
|
||||||
'unpaid' => 'Unpaid',
|
'unpaid' => 'Unpaid',
|
||||||
'partially_paid' => 'Partially Paid',
|
'partially_paid' => 'Partially Paid',
|
||||||
@ -236,6 +236,17 @@ $translations = [
|
|||||||
'loyalty' => 'Loyalty Points',
|
'loyalty' => 'Loyalty Points',
|
||||||
'loyalty_discount' => 'Loyalty Discount',
|
'loyalty_discount' => 'Loyalty Discount',
|
||||||
'final_total' => 'Final Total',
|
'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' => [
|
'ar' => [
|
||||||
'dashboard' => 'لوحة القيادة',
|
'dashboard' => 'لوحة القيادة',
|
||||||
@ -458,6 +469,17 @@ $translations = [
|
|||||||
'loyalty' => 'نقاط الولاء',
|
'loyalty' => 'نقاط الولاء',
|
||||||
'loyalty_discount' => 'خصم الولاء',
|
'loyalty_discount' => 'خصم الولاء',
|
||||||
'final_total' => 'الإجمالي النهائي',
|
'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' => 'هل أنت متأكد من الحذف؟',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
72
items.php
72
items.php
@ -187,11 +187,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
$service_id = $_POST['service_id'];
|
$service_id = $_POST['service_id'];
|
||||||
$price = $_POST['price'];
|
$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)
|
// Determine branch_id from session (if available)
|
||||||
$branch_id = $_SESSION['branch_id'] ?? null;
|
$branch_id = $_SESSION['branch_id'] ?? null;
|
||||||
if ($branch_id === 'all') $branch_id = null;
|
if ($branch_id === 'all') $branch_id = null;
|
||||||
@ -203,6 +198,38 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
if (!$chk->fetch()) $branch_id = null;
|
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 {
|
try {
|
||||||
if ($branch_id) {
|
if ($branch_id) {
|
||||||
$stmt = db()->prepare("INSERT INTO prices (item_id, service_id, price, branch_id)
|
$stmt = db()->prepare("INSERT INTO prices (item_id, service_id, price, branch_id)
|
||||||
@ -619,7 +646,7 @@ function renderServiceList($lang) {
|
|||||||
<div class="fw-bold small">
|
<div class="fw-bold small">
|
||||||
<?= $lang === 'ar' ? $svc['name_ar'] : $svc['name_en'] ?>
|
<?= $lang === 'ar' ? $svc['name_ar'] : $svc['name_en'] ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex align-items-center" style="width: 150px;">
|
<div class="d-flex align-items-center gap-2" style="width: 200px;">
|
||||||
<input type="number" step="0.001"
|
<input type="number" step="0.001"
|
||||||
class="form-control form-control-sm border-0 bg-white price-input"
|
class="form-control form-control-sm border-0 bg-white price-input"
|
||||||
style="border-radius: 10px;"
|
style="border-radius: 10px;"
|
||||||
@ -627,7 +654,10 @@ function renderServiceList($lang) {
|
|||||||
data-service-id="<?= $svc['id'] ?>"
|
data-service-id="<?= $svc['id'] ?>"
|
||||||
value="<?= $prices[$item['id']][$svc['id']] ?? '' ?>"
|
value="<?= $prices[$item['id']][$svc['id']] ?? '' ?>"
|
||||||
placeholder="0.000">
|
placeholder="0.000">
|
||||||
<i class="bi bi-check-circle-fill text-success ms-2 success-indicator d-none"></i>
|
<button class="btn btn-sm btn-light p-1" style="border-radius: 8px;" onclick="removePrice(this, <?= $item['id'] ?>, <?= $svc['id'] ?>)">
|
||||||
|
<i class="bi bi-x-circle text-danger"></i>
|
||||||
|
</button>
|
||||||
|
<i class="bi bi-check-circle-fill text-success ms-1 success-indicator d-none"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@ -804,6 +834,34 @@ document.querySelectorAll('.price-input').forEach(input => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function removePrice(btn, itemId, serviceId) {
|
||||||
|
if (confirm('<?= __('confirm_delete') ?>')) {
|
||||||
|
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) {
|
function showIndicator(input) {
|
||||||
const indicator = input.parentElement.querySelector('.success-indicator');
|
const indicator = input.parentElement.querySelector('.success-indicator');
|
||||||
if (indicator) {
|
if (indicator) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user