getMessage(); } $categories = []; $suppliers = []; try { $pdo = db(); $categories = $pdo->query('SELECT id, name_ar, name_en FROM categories ORDER BY name_ar ASC')->fetchAll(); $suppliers = $pdo->query('SELECT id, name FROM suppliers ORDER BY name ASC')->fetchAll(); } catch (Throwable $e) { // Ignore if not present } // Search and filter logic $search = $_GET['q'] ?? ''; $catFilter = $_GET['category'] ?? ''; $supFilter = $_GET['supplier'] ?? ''; $filteredStock = []; if (empty($dbError)) { $lowerSearch = strtolower($search); foreach ($allStock as $key => $row) { $matchSearch = !$search || str_contains(strtolower((string)$row['sku']), $lowerSearch) || str_contains(strtolower((string)$row['name']), $lowerSearch); $matchCat = !$catFilter || (isset($row['category_id']) && $row['category_id'] == $catFilter); $matchSup = !$supFilter || (isset($row['supplier_id']) && $row['supplier_id'] == $supFilter); if ($matchSearch && $matchCat && $matchSup) { $filteredStock[$key] = $row; } } } // Pagination logic $page = max(1, (int)($_GET['p'] ?? 1)); $limit = 10; $total = count($filteredStock); $totalPages = max(1, ceil($total / $limit)); $offset = ($page - 1) * $limit; $stockRows = array_slice($filteredStock, $offset, $limit, true); require __DIR__ . '/includes/header.php'; ?>

SKU
1): ?>