fix: [bending] 원자재 LOT 조회 재질 검색 개선
- status 필터 확장: completed → completed + inspection_completed - 재질 키워드 분해 검색: "EGI 1.55T" → "EGI" AND "1.55" (공백/T 무관) - 기존: LIKE "%EGI 1.55T%" → 매칭 실패 (실제 데이터: "EGI1.55")
This commit is contained in:
@@ -58,24 +58,33 @@ public function resolveItem(Request $request): JsonResponse
|
||||
}
|
||||
|
||||
/**
|
||||
* 원자재 LOT 목록 조회 (수입검사 완료 입고 기준)
|
||||
* 원자재 LOT 목록 조회 (입고 + 수입검사 완료 기준)
|
||||
*
|
||||
* 재질(material)이 일치하는 입고 LOT 목록 반환
|
||||
* 재질(material) 키워드를 분해하여 유연 검색
|
||||
* 예: "EGI 1.55T" → "EGI" AND "1.55" 로 검색 (공백/T 무관)
|
||||
*/
|
||||
public function materialLots(Request $request): JsonResponse
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request) {
|
||||
$material = $request->query('material');
|
||||
|
||||
$query = Receiving::where('status', 'completed')
|
||||
$query = Receiving::whereIn('status', ['completed', 'inspection_completed'])
|
||||
->whereNotNull('lot_no')
|
||||
->where('lot_no', '!=', '');
|
||||
|
||||
// 재질(item_name 또는 specification)으로 필터링
|
||||
// 재질 키워드 분해 검색 (공백/T 접미사 무관)
|
||||
if ($material) {
|
||||
$query->where(function ($q) use ($material) {
|
||||
$q->where('item_name', 'LIKE', "%{$material}%")
|
||||
->orWhere('specification', 'LIKE', "%{$material}%");
|
||||
// "EGI 1.55T" → ["EGI", "1.55"], "SUS 1.2T" → ["SUS", "1.2"]
|
||||
$keywords = preg_split('/[\s]+/', preg_replace('/T$/i', '', trim($material)));
|
||||
$keywords = array_filter($keywords);
|
||||
|
||||
$query->where(function ($q) use ($keywords) {
|
||||
foreach ($keywords as $kw) {
|
||||
$q->where(function ($sub) use ($kw) {
|
||||
$sub->where('item_name', 'LIKE', "%{$kw}%")
|
||||
->orWhere('specification', 'LIKE', "%{$kw}%");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user