update normal sale
This commit is contained in:
parent
52c9aed760
commit
b6bf7b7b5e
@ -44,7 +44,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$product = $catalog[$sku];
|
$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;
|
$lineTotal = $price * $qty;
|
||||||
|
|
||||||
$vatPercent = (float) ($product['vat'] ?? 0);
|
$vatPercent = (float) ($product['vat'] ?? 0);
|
||||||
@ -54,8 +70,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
$normalized[] = [
|
$normalized[] = [
|
||||||
'sku' => $sku,
|
'sku' => $sku,
|
||||||
'name_ar' => $product['name_ar'],
|
'name_ar' => $finalName,
|
||||||
'name_en' => $product['name_en'],
|
'name_en' => $finalName,
|
||||||
'qty' => $qty,
|
'qty' => $qty,
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
'line_total' => $lineTotal,
|
'line_total' => $lineTotal,
|
||||||
@ -260,6 +276,12 @@ require __DIR__ . '/header.php';
|
|||||||
color: #212529;
|
color: #212529;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
.line-input {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
.line-price-input {
|
||||||
|
min-width: 96px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="container-fluid py-4">
|
<div class="container-fluid py-4">
|
||||||
@ -600,6 +622,29 @@ function addItemToInvoice(sku) {
|
|||||||
renderInvoice();
|
renderInvoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeItemName(sku, newName) {
|
||||||
|
if (!invoiceItems[sku]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fallbackName = '<?= current_lang() ?>' === '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) {
|
function changeQty(sku, newQty) {
|
||||||
const qty = parseInt(newQty);
|
const qty = parseInt(newQty);
|
||||||
if (isNaN(qty) || qty < 1) {
|
if (isNaN(qty) || qty < 1) {
|
||||||
@ -615,6 +660,12 @@ function removeItem(sku) {
|
|||||||
renderInvoice();
|
renderInvoice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHtml(value) {
|
||||||
|
return String(value ?? '').replace(/[&<>"']/g, function(char) {
|
||||||
|
return ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''})[char] || char;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function renderInvoice() {
|
function renderInvoice() {
|
||||||
const skus = Object.keys(invoiceItems);
|
const skus = Object.keys(invoiceItems);
|
||||||
if (skus.length === 0) {
|
if (skus.length === 0) {
|
||||||
@ -639,15 +690,20 @@ function renderInvoice() {
|
|||||||
totalVat += itemVat;
|
totalVat += itemVat;
|
||||||
|
|
||||||
totalAmount += lineTotal;
|
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');
|
const tr = document.createElement('tr');
|
||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
<td>
|
<td>
|
||||||
<div class="fw-medium text-dark">${item.name}</div>
|
<input type="text" class="form-control form-control-sm line-input fw-medium mb-2" value="${safeName}" onchange="changeItemName('${sku}', this.value)" onkeyup="if(event.key==='Enter') changeItemName('${sku}', this.value)">
|
||||||
<div class="text-muted small">SKU: ${item.sku}</div>
|
<div class="text-muted small">SKU: ${safeSku}</div>
|
||||||
|
</td>
|
||||||
|
<td class="text-center align-middle">
|
||||||
|
<input type="number" class="form-control form-control-sm text-center line-input line-price-input mx-auto" min="0" step="0.001" value="${item.price.toFixed(3)}" onchange="changeItemPrice('${sku}', this.value)" onkeyup="if(event.key==='Enter') changeItemPrice('${sku}', this.value)">
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center text-muted align-middle">${item.price.toFixed(3)}</td>
|
|
||||||
<td class="text-center align-middle">
|
<td class="text-center align-middle">
|
||||||
<input type="number" class="qty-control mx-auto fw-medium" min="1" value="${item.qty}" onchange="changeQty('${sku}', this.value)" onkeyup="if(event.key==='Enter') changeQty('${sku}', this.value)">
|
<input type="number" class="qty-control mx-auto fw-medium" min="1" value="${item.qty}" onchange="changeQty('${sku}', this.value)" onkeyup="if(event.key==='Enter') changeQty('${sku}', this.value)">
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
6
pos.php
6
pos.php
@ -312,6 +312,12 @@ require __DIR__ . '/includes/header.php';
|
|||||||
.cart-item-info {
|
.cart-item-info {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding-right: 1rem;
|
padding-right: 1rem;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.cart-items,
|
||||||
|
.cart-footer,
|
||||||
|
.cart-header h5 {
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
.cart-item-title {
|
.cart-item-title {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user