diff --git a/includes/sale_form.php b/includes/sale_form.php index d02d028..971af87 100644 --- a/includes/sale_form.php +++ b/includes/sale_form.php @@ -44,7 +44,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { continue; } $product = $catalog[$sku]; - $price = (float) $product['price']; + $editedName = trim((string) ($item['name'] ?? '')); + $finalName = $editedName !== '' + ? $editedName + : trim((string) ($product['name_' . current_lang()] ?? '')); + if ($finalName === '') { + $finalName = trim((string) ($product['name_ar'] ?? '')); + } + if ($finalName === '') { + $finalName = trim((string) ($product['name_en'] ?? '')); + } + if ($finalName === '') { + $finalName = $sku; + } + + $price = isset($item['price']) && is_numeric($item['price']) + ? max(0, (float) $item['price']) + : (float) $product['price']; $lineTotal = $price * $qty; $vatPercent = (float) ($product['vat'] ?? 0); @@ -54,8 +70,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $normalized[] = [ 'sku' => $sku, - 'name_ar' => $product['name_ar'], - 'name_en' => $product['name_en'], + 'name_ar' => $finalName, + 'name_en' => $finalName, 'qty' => $qty, 'price' => $price, 'line_total' => $lineTotal, @@ -260,6 +276,12 @@ require __DIR__ . '/header.php'; color: #212529; margin-bottom: 0; } +.line-input { + min-width: 0; +} +.line-price-input { + min-width: 96px; +}
@@ -600,6 +622,29 @@ function addItemToInvoice(sku) { renderInvoice(); } +function changeItemName(sku, newName) { + if (!invoiceItems[sku]) { + return; + } + const fallbackName = '' === 'ar' + ? (catalogData[sku].name_ar || catalogData[sku].name_en || sku) + : (catalogData[sku].name_en || catalogData[sku].name_ar || sku); + const nextName = String(newName || '').trim(); + invoiceItems[sku].name = nextName !== '' ? nextName : fallbackName; + renderInvoice(); +} + +function changeItemPrice(sku, newPrice) { + if (!invoiceItems[sku]) { + return; + } + const parsed = parseFloat(newPrice); + invoiceItems[sku].price = Number.isFinite(parsed) && parsed >= 0 + ? Math.round(parsed * 1000) / 1000 + : (parseFloat(catalogData[sku].price) || 0); + renderInvoice(); +} + function changeQty(sku, newQty) { const qty = parseInt(newQty); if (isNaN(qty) || qty < 1) { @@ -615,6 +660,12 @@ function removeItem(sku) { renderInvoice(); } +function escapeHtml(value) { + return String(value ?? '').replace(/[&<>"']/g, function(char) { + return ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''})[char] || char; + }); +} + function renderInvoice() { const skus = Object.keys(invoiceItems); if (skus.length === 0) { @@ -639,15 +690,20 @@ function renderInvoice() { totalVat += itemVat; totalAmount += lineTotal; - cartData.push({ sku: item.sku, qty: item.qty }); + cartData.push({ sku: item.sku, name: item.name, price: item.price, qty: item.qty }); + + const safeSku = escapeHtml(item.sku); + const safeName = escapeHtml(item.name); const tr = document.createElement('tr'); tr.innerHTML = ` -
${item.name}
-
SKU: ${item.sku}
+ +
SKU: ${safeSku}
+ + + - ${item.price.toFixed(3)} diff --git a/pos.php b/pos.php index 7a9c5d5..041318e 100644 --- a/pos.php +++ b/pos.php @@ -312,6 +312,12 @@ require __DIR__ . '/includes/header.php'; .cart-item-info { flex: 1; padding-right: 1rem; + text-align: right; +} +.cart-items, +.cart-footer, +.cart-header h5 { + text-align: right; } .cart-item-title { font-weight: 600;