update pos 4

This commit is contained in:
Flatlogic Bot 2026-04-20 16:02:36 +00:00
parent 4ca9818d92
commit 52c9aed760

31
pos.php
View File

@ -448,13 +448,13 @@ require __DIR__ . '/includes/header.php';
<!-- Grid -->
<div class="products-grid" id="productsGrid">
<?php foreach ($catalog as $sku => $item):
<?php $productIndex = 0; foreach ($catalog as $sku => $item):
$itemSkuRaw = (string) $sku;
$primaryNameRaw = trim((string) (current_lang() === 'ar' ? ($item['name_ar'] ?? '') : ($item['name_en'] ?? '')));
$fallbackNameRaw = trim((string) (current_lang() === 'ar' ? ($item['name_en'] ?? '') : ($item['name_ar'] ?? '')));
$itemNameRaw = $primaryNameRaw !== ''
? $primaryNameRaw
: ($fallbackNameRaw !== '' ? $fallbackNameRaw : ('SKU ' . $itemSkuRaw));
: ($fallbackNameRaw !== '' ? $fallbackNameRaw : (tr('صنف ' . $itemSkuRaw, 'Item ' . $itemSkuRaw)));
$searchBits = [
(string) ($item['name_ar'] ?? ''),
(string) ($item['name_en'] ?? ''),
@ -474,7 +474,7 @@ require __DIR__ . '/includes/header.php';
$isRecentlyAdded = $createdAtStamp && $createdAtStamp >= strtotime('-7 days');
$createdLabel = $createdAtStamp ? date('Y-m-d', $createdAtStamp) : '';
?>
<div class="product-card" data-sku="<?= $itemSku ?>" data-name="<?= $itemName ?>" data-price="<?= $itemPrice ?>" data-cat="<?= $itemCat ?>" data-search="<?= h($searchText) ?>" data-created="<?= h($createdAtRaw) ?>" onclick="addToCart('<?= $itemSku ?>')">
<div class="product-card" data-sku="<?= $itemSku ?>" data-name="<?= $itemName ?>" data-price="<?= $itemPrice ?>" data-cat="<?= $itemCat ?>" data-search="<?= h($searchText) ?>" data-created="<?= h($createdAtRaw) ?>" data-index="<?= $productIndex++ ?>" onclick="addToCart('<?= $itemSku ?>')">
<div class="product-img-wrapper">
<?php if (!empty($imageUrl)):
$imgAlt = $itemName;
@ -497,12 +497,6 @@ require __DIR__ . '/includes/header.php';
<?php endif; ?>
</div>
<div class="product-title" title="<?= $itemName ?>"><?= $itemName ?></div>
<div class="product-meta">
<div class="product-sku" title="<?= $itemSku ?>">SKU: <?= $itemSku ?></div>
<?php if ($createdLabel !== ''): ?>
<div class="product-created"><?= h(tr('أضيف', 'Added')) ?>: <?= h($createdLabel) ?></div>
<?php endif; ?>
</div>
<div class="product-price"><?= h(currency((float)$item['price'])) ?></div>
</div>
</div>
@ -769,21 +763,32 @@ document.getElementById('posBarcode').addEventListener('keypress', function(e) {
}
});
const INITIAL_PRODUCT_LIMIT = 100;
function applyFilters() {
const q = document.getElementById('posSearch').value.toLowerCase().trim();
const activeCat = document.querySelector('.cat-btn.active').dataset.cat;
let visibleCount = 0;
document.querySelectorAll('.product-card').forEach(card => {
const searchable = (card.dataset.search || card.dataset.name || '').toLowerCase();
const cat = card.dataset.cat;
const matchesSearch = q === '' || searchable.includes(q);
const matchesCat = (activeCat === 'all' || cat === activeCat);
card.hidden = !(matchesSearch && matchesCat);
const matches = matchesSearch && matchesCat;
const withinInitialLimit = q !== '' || visibleCount < INITIAL_PRODUCT_LIMIT;
card.hidden = !(matches && withinInitialLimit);
if (matches) {
visibleCount += 1;
}
});
}
applyFilters();
// Cart Logic
function addToCart(sku) {
if (!catalogData[sku]) return;