update items filter
This commit is contained in:
parent
b12231e100
commit
4f16b7540a
69
index.php
69
index.php
@ -4731,12 +4731,26 @@ if ($page === 'export') {
|
||||
$headers = ['ID', 'Name', 'Email', 'Phone', 'Tax ID', 'Balance', 'Created At'];
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) $rows[] = $row;
|
||||
} elseif ($type === 'items') {
|
||||
$where = ["1=1"];
|
||||
$params = [];
|
||||
if (!empty($_GET['search'])) { $where[] = "(i.name_en LIKE ? OR i.name_ar LIKE ? OR i.sku LIKE ?)"; $params[] = "%{$_GET['search']}%"; $params[] = "%{$_GET['search']}%"; $params[] = "%{$_GET['search']}%"; }
|
||||
$where = ["i.outlet_id = ?"];
|
||||
$params = [current_outlet_id()];
|
||||
if (!empty($_GET['search'])) {
|
||||
$where[] = "(i.name_en LIKE ? OR i.name_ar LIKE ? OR i.sku LIKE ?)";
|
||||
$params[] = "%{$_GET['search']}%";
|
||||
$params[] = "%{$_GET['search']}%";
|
||||
$params[] = "%{$_GET['search']}%";
|
||||
}
|
||||
if (!empty($_GET['category_id'])) {
|
||||
$where[] = "i.category_id = ?";
|
||||
$params[] = (int)$_GET['category_id'];
|
||||
}
|
||||
if (!empty($_GET['supplier_id'])) {
|
||||
$where[] = "i.supplier_id = ?";
|
||||
$params[] = (int)$_GET['supplier_id'];
|
||||
}
|
||||
$whereSql = implode(" AND ", $where);
|
||||
$stmt = db()->prepare("SELECT i.sku, i.name_en, i.name_ar, c.name_en as category, i.purchase_price, i.sale_price, i.stock_quantity, i.vat_rate
|
||||
FROM stock_items i LEFT JOIN stock_categories c ON i.category_id = c.id
|
||||
LEFT JOIN suppliers s ON i.supplier_id = s.id
|
||||
WHERE $whereSql ORDER BY i.id DESC");
|
||||
$stmt->execute($params);
|
||||
$headers = ['SKU', 'Name (EN)', 'Name (AR)', 'Category', 'Purchase Price', 'Sale Price', 'Quantity', 'VAT %'];
|
||||
@ -4940,14 +4954,22 @@ switch ($page) {
|
||||
break;
|
||||
case 'items':
|
||||
app_debug_file_log('debug.log', date('Y-m-d H:i:s') . " - Items case hit");
|
||||
$where = ["i.outlet_id = " . current_outlet_id()];
|
||||
$params = [];
|
||||
$where = ["i.outlet_id = ?"];
|
||||
$params = [current_outlet_id()];
|
||||
if (!empty($_GET['search'])) {
|
||||
$where[] = "(i.name_en LIKE ? OR i.name_ar LIKE ? OR i.sku LIKE ?)";
|
||||
$params[] = "%{$_GET['search']}%";
|
||||
$params[] = "%{$_GET['search']}%";
|
||||
$params[] = "%{$_GET['search']}%";
|
||||
}
|
||||
if (!empty($_GET['category_id'])) {
|
||||
$where[] = "i.category_id = ?";
|
||||
$params[] = (int)$_GET['category_id'];
|
||||
}
|
||||
if (!empty($_GET['supplier_id'])) {
|
||||
$where[] = "i.supplier_id = ?";
|
||||
$params[] = (int)$_GET['supplier_id'];
|
||||
}
|
||||
$whereSql = implode(" AND ", $where);
|
||||
|
||||
$countStmt = db()->prepare("SELECT COUNT(*) FROM stock_items i
|
||||
@ -7185,16 +7207,35 @@ runtime_debug_mark('page:rendering', ['page' => (string)$page]);
|
||||
</div>
|
||||
|
||||
<!-- Search Bar -->
|
||||
<?php $hasItemFilters = !empty($_GET['search']) || !empty($_GET['category_id']) || !empty($_GET['supplier_id']); ?>
|
||||
<div class="bg-light p-3 rounded mb-4">
|
||||
<form method="GET" class="row g-2 align-items-end">
|
||||
<input type="hidden" name="page" value="items">
|
||||
<div class="col-md-7">
|
||||
<div class="col-lg-4 col-md-12">
|
||||
<label class="form-label small" data-en="Search" data-ar="بحث">Search</label>
|
||||
<input type="text" name="search" class="form-control" value="<?= htmlspecialchars($_GET['search'] ?? '') ?>" placeholder="Name or SKU..." data-en="Name or SKU..." data-ar="الاسم أو الباركود...">
|
||||
</div>
|
||||
<div class="col-md-5 d-flex gap-1">
|
||||
<div class="col-lg-3 col-md-6">
|
||||
<label class="form-label small" data-en="Category" data-ar="الفئة">Category</label>
|
||||
<select name="category_id" class="form-select">
|
||||
<option value="" data-en="All Categories" data-ar="كل الفئات">All Categories</option>
|
||||
<?php foreach ($data['categories'] ?? [] as $category): ?>
|
||||
<option value="<?= $category['id'] ?>" <?= (string)($category['id'] ?? '') === (string)($_GET['category_id'] ?? '') ? 'selected' : '' ?> data-en="<?= htmlspecialchars(localized_option_label($category, 'en')) ?>" data-ar="<?= htmlspecialchars(localized_option_label($category, 'ar')) ?>"><?= htmlspecialchars(localized_option_label($category)) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6">
|
||||
<label class="form-label small" data-en="Supplier" data-ar="المورد">Supplier</label>
|
||||
<select name="supplier_id" class="form-select">
|
||||
<option value="" data-en="All Suppliers" data-ar="كل الموردين">All Suppliers</option>
|
||||
<?php foreach ($data['suppliers'] ?? [] as $supplier): ?>
|
||||
<option value="<?= $supplier['id'] ?>" <?= (string)($supplier['id'] ?? '') === (string)($_GET['supplier_id'] ?? '') ? 'selected' : '' ?>><?= htmlspecialchars((string)($supplier['name'] ?? '')) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-2 col-md-12 d-flex gap-1">
|
||||
<button type="submit" class="btn btn-primary flex-grow-1">
|
||||
<i class="bi bi-search"></i> <span data-en="Search" data-ar="بحث">Search</span>
|
||||
<i class="bi bi-search"></i> <span data-en="Filter" data-ar="تصفية">Filter</span>
|
||||
</button>
|
||||
<div class="dropdown d-inline-block">
|
||||
<button class="btn btn-outline-success dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
@ -7205,13 +7246,12 @@ runtime_debug_mark('page:rendering', ['page' => (string)$page]);
|
||||
<li><a class="dropdown-item" href="index.php?<?= http_build_query(array_merge($_GET, ['page' => 'export', 'type' => 'items', 'format' => 'excel'])) ?>"><i class="bi bi-file-earmark-excel me-2"></i> Excel</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php if (!empty($_GET['search'])): ?>
|
||||
<a href="<?= htmlspecialchars(page_url('items')) ?>" class="btn btn-outline-secondary">
|
||||
<?php if ($hasItemFilters): ?>
|
||||
<a href="<?= htmlspecialchars(page_url('items', ['limit' => (int)($_GET['limit'] ?? 20)])) ?>" class="btn btn-outline-secondary" title="Clear filters">
|
||||
<i class="bi bi-x-lg"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="col-md-auto ms-auto d-flex align-items-end mt-2 mt-md-0">
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<span class="input-group-text" data-en="Limit" data-ar="الحد">Limit</span>
|
||||
@ -7235,6 +7275,7 @@ runtime_debug_mark('page:rendering', ['page' => (string)$page]);
|
||||
<th data-en="Name" data-ar="الاسم">Name</th>
|
||||
<th data-en="Category" data-ar="الفئة">Category</th>
|
||||
<th data-en="Supplier" data-ar="المورد">Supplier</th>
|
||||
<th data-en="Sale Price" data-ar="سعر البيع">Sale Price</th>
|
||||
<th data-en="Stock Level" data-ar="المخزون">Stock Level</th>
|
||||
<th data-en="Expiry" data-ar="تاريخ الانتهاء">Expiry</th>
|
||||
<th data-en="VAT" data-ar="الضريبة">VAT</th>
|
||||
@ -7269,6 +7310,12 @@ runtime_debug_mark('page:rendering', ['page' => (string)$page]);
|
||||
</td>
|
||||
<td><span data-en="<?= htmlspecialchars((string)($item['cat_en'] ?? '')) ?>" data-ar="<?= htmlspecialchars((string)($item['cat_ar'] ?? '')) ?>"><?= htmlspecialchars((string)($item['cat_en'] ?? '')) ?></span></td>
|
||||
<td><?= htmlspecialchars((string)($item['supplier_name'] ?? '---')) ?></td>
|
||||
<td>
|
||||
<div class="text-end">
|
||||
<strong><?= number_format((float)$item['sale_price'], 3) ?></strong>
|
||||
<div class="small text-muted" data-en="Incl. VAT: <?= number_format((float)$itemBarcodePrice, 3) ?>" data-ar="شامل الضريبة: <?= number_format((float)$itemBarcodePrice, 3) ?>">Incl. VAT: <?= number_format((float)$itemBarcodePrice, 3) ?></div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="text-end">
|
||||
<strong><?= number_format((float)$item['stock_quantity'], 3) ?></strong>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user