[FEAT] 實作跨倉庫及時庫存批號搜尋與 Debounce 搜尋體驗
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 56s

This commit is contained in:
2026-03-05 11:51:13 +08:00
parent 7c395c89b5
commit f4ed358393
5 changed files with 119 additions and 29 deletions

View File

@@ -57,9 +57,31 @@ class InventoryController extends Controller
->pluck('safety_stock', 'product_id')
->mapWithKeys(fn($val, $key) => [(string)$key => (float)$val]);
$items = $warehouse->inventories()
->with(['product.baseUnit', 'lastIncomingTransaction', 'lastOutgoingTransaction'])
->get();
$query = $warehouse->inventories()
->with(['product.baseUnit', 'lastIncomingTransaction', 'lastOutgoingTransaction']);
// 加入搜尋過濾
if ($request->filled('search')) {
$search = $request->input('search');
$query->where(function ($q) use ($search) {
$q->where('batch_number', 'like', "%{$search}%")
->orWhere(\Illuminate\Support\Facades\DB::raw("CONCAT('BATCH-', inventories.id)"), 'like', "%{$search}%")
->orWhereHas('product', function ($pq) use ($search) {
$pq->where('name', 'like', "%{$search}%")
->orWhere('code', 'like', "%{$search}%");
});
});
}
// 加入類型過濾
if ($request->filled('type') && $request->input('type') !== 'all') {
$type = $request->input('type');
$query->whereHas('product.category', function ($cq) use ($type) {
$cq->where('name', $type);
});
}
$items = $query->get();
// 判斷是否為販賣機並調整分組
$isVending = $warehouse->type === 'vending';

View File

@@ -58,7 +58,9 @@ class StockQueryExport implements FromCollection, WithHeadings, WithMapping, Sho
$search = $this->filters['search'];
$query->where(function ($q) use ($search) {
$q->where('products.code', 'like', "%{$search}%")
->orWhere('products.name', 'like', "%{$search}%");
->orWhere('products.name', 'like', "%{$search}%")
->orWhere('inventories.batch_number', 'like', "%{$search}%")
->orWhere(\Illuminate\Support\Facades\DB::raw("CONCAT('BATCH-', inventories.id)"), 'like', "%{$search}%");
});
}
if (!empty($this->filters['status'])) {

View File

@@ -303,12 +303,14 @@ class InventoryService implements InventoryServiceInterface
$query->where('products.category_id', $filters['category_id']);
}
// 篩選:關鍵字(商品代碼或名稱)
// 篩選:關鍵字(商品代碼或名稱或批號
if (!empty($filters['search'])) {
$search = $filters['search'];
$query->where(function ($q) use ($search) {
$q->where('products.code', 'like', "%{$search}%")
->orWhere('products.name', 'like', "%{$search}%");
->orWhere('products.name', 'like', "%{$search}%")
->orWhere('inventories.batch_number', 'like', "%{$search}%")
->orWhere(\Illuminate\Support\Facades\DB::raw("CONCAT('BATCH-', inventories.id)"), 'like', "%{$search}%");
});
}