fix: Filter POS items by outlet and fix item name display fallback

This commit is contained in:
Flatlogic Bot 2026-03-19 16:52:53 +00:00
parent 443ae2521f
commit aca3dd49a3
2 changed files with 17 additions and 15 deletions

View File

@ -458,9 +458,10 @@ if (isset($_GET['action']) || isset($_POST['action'])) {
$q = $_GET['q'] ?? '';
$searchTerm = "%$q%";
$sql = "SELECT * FROM stock_items WHERE (name_en LIKE ? OR name_ar LIKE ? OR sku LIKE ?) ORDER BY name_en ASC LIMIT 100";
$oid = current_outlet_id();
$sql = "SELECT * FROM stock_items WHERE outlet_id = ? AND (name_en LIKE ? OR name_ar LIKE ? OR sku LIKE ?) ORDER BY name_en ASC LIMIT 100";
$products_raw = db()->prepare($sql);
$products_raw->execute([$searchTerm, $searchTerm, $searchTerm]);
$products_raw->execute([$oid, $searchTerm, $searchTerm, $searchTerm]);
while($p = $products_raw->fetch(PDO::FETCH_ASSOC)) {
$p['original_price'] = (float)$p['sale_price'];
$p['sale_price'] = getPromotionalPrice($p);
@ -475,7 +476,7 @@ if (isset($_GET['action']) || isset($_POST['action'])) {
<i class="bi bi-box-seam text-muted" style="font-size: 3rem;"></i>
</div>
<?php endif; ?>
<div class="fw-bold mb-1 product-name" data-en="<?= htmlspecialchars($p['name_en']) ?>" data-ar="<?= htmlspecialchars($p['name_ar']) ?>"><?= htmlspecialchars($p['name_en']) ?></div>
<div class="fw-bold mb-1 product-name" data-en="<?= htmlspecialchars($p['name_en']) ?>" data-ar="<?= htmlspecialchars($p['name_ar']) ?>"><?= htmlspecialchars($p['name_en'] ?: $p['name_ar']) ?></div>
<div class="small text-muted mb-2"><?= htmlspecialchars($p['sku']) ?></div>
<div class="d-flex justify-content-between align-items-center mt-auto">
<div class="d-flex flex-column">
@ -497,8 +498,9 @@ if (isset($_GET['action']) || isset($_POST['action'])) {
$sku = $_GET['sku'] ?? '';
if (!$sku) { echo json_encode(null); exit; }
$stmt = db()->prepare("SELECT * FROM stock_items WHERE sku = ? LIMIT 1");
$stmt->execute([$sku]);
$oid = current_outlet_id();
$stmt = db()->prepare("SELECT * FROM stock_items WHERE sku = ? AND outlet_id = ? LIMIT 1");
$stmt->execute([$sku, $oid]);
$p = $stmt->fetch(PDO::FETCH_ASSOC);
if ($p) {
@ -5372,7 +5374,8 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
$registers = db()->query("SELECT * FROM cash_registers WHERE status = 'active'")->fetchAll();
$allow_zero_stock_sell = ($data['settings']['allow_zero_stock_sell'] ?? '1') === '1';
$sql = "SELECT * FROM stock_items ORDER BY name_en ASC LIMIT 100";
$oid = current_outlet_id();
$sql = "SELECT * FROM stock_items WHERE outlet_id = $oid ORDER BY name_en ASC LIMIT 100";
$products_raw = db()->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$products = [];
foreach ($products_raw as $p) {
@ -5408,7 +5411,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
<i class="bi bi-box-seam text-muted" style="font-size: 3rem;"></i>
</div>
<?php endif; ?>
<div class="fw-bold mb-1 product-name" data-en="<?= htmlspecialchars($p['name_en']) ?>" data-ar="<?= htmlspecialchars($p['name_ar']) ?>"><?= htmlspecialchars($p['name_en']) ?></div>
<div class="fw-bold mb-1 product-name" data-en="<?= htmlspecialchars($p['name_en']) ?>" data-ar="<?= htmlspecialchars($p['name_ar']) ?>"><?= htmlspecialchars($p['name_en'] ?: $p['name_ar']) ?></div>
<div class="small text-muted mb-2"><?= htmlspecialchars($p['sku']) ?></div>
<div class="d-flex justify-content-between align-items-center mt-auto">
<div class="d-flex flex-column">

View File

@ -1,14 +1,13 @@
Plan:
- Update `index.php` to use a dynamic page title (`__($page)`) instead of the hardcoded "Accounting".
- Add "Copy Outlet Data" to `includes/lang.php` (both English and Arabic) to ensure the title displays correctly without hyphens.
1. **Filter by Outlet:** Updated POS item queries (initial load, search, SKU lookup) to filter by the current `outlet_id`.
2. **Fix Name Display:** Updated the item card rendering to show `name_ar` if `name_en` is empty, fixing the issue where items appeared with only SKU.
3. **Data Fix:** Ran a one-time update to assign all existing unassigned items to Outlet 1.
Changed:
- `index.php`: Changed `<title>` tag to use `__($page)`.
- `includes/lang.php`: Added `'copy_outlet_data' => 'Copy Outlet Data'` (and Arabic equivalent).
* `index.php`: Added `WHERE outlet_id = ?` to POS queries and updated item name display logic.
Notes:
- This change also fixes a bug where *every* page was previously titled "Accounting - Admin Panel". Now all pages will show their correct titles (e.g., "Dashboard", "Sales", "POS").
* POS now correctly shows only items for the selected outlet.
* Items without an English name will now display their Arabic name instead of a blank space (or appearing as just SKU).
Next:
- Refresh the "Copy/Sync Outlet Data" page to see the new title "Copy Outlet Data - Admin Panel".
- Reminder: click Save in the editor to sync changes.
Next: Verify that switching outlets changes the POS items and that all items display a name.