fix:거래처코드 검색을 고유번호(id) 기반으로 변경
- Client::searchByCodeOrName → searchByIdOrName으로 변경 - 검색 기준: id(숫자일 때 정확 매칭) + name(LIKE 검색) - 반환값: client_code 대신 id를 code로 반환 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -951,12 +951,12 @@ public function searchClients(Request $request): JsonResponse
|
||||
]);
|
||||
}
|
||||
|
||||
$clients = Client::searchByCodeOrName($tenantId, $keyword);
|
||||
$clients = Client::searchByIdOrName($tenantId, $keyword);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $clients->map(fn($c) => [
|
||||
'code' => $c->client_code,
|
||||
'code' => (string) $c->id,
|
||||
'name' => $c->name,
|
||||
])
|
||||
]);
|
||||
|
||||
@@ -13,18 +13,20 @@ class Client extends Model
|
||||
protected $table = 'clients';
|
||||
|
||||
/**
|
||||
* 거래처코드 또는 거래처명으로 검색
|
||||
* 고유번호(id) 또는 거래처명으로 검색
|
||||
*/
|
||||
public static function searchByCodeOrName(int $tenantId, string $keyword, int $limit = 20)
|
||||
public static function searchByIdOrName(int $tenantId, string $keyword, int $limit = 20)
|
||||
{
|
||||
return self::where('tenant_id', $tenantId)
|
||||
->where('is_active', true)
|
||||
->where(function ($query) use ($keyword) {
|
||||
$query->where('client_code', 'like', "%{$keyword}%")
|
||||
->orWhere('name', 'like', "%{$keyword}%");
|
||||
if (is_numeric($keyword)) {
|
||||
$query->where('id', $keyword);
|
||||
}
|
||||
$query->orWhere('name', 'like', "%{$keyword}%");
|
||||
})
|
||||
->select('client_code', 'name')
|
||||
->orderBy('client_code')
|
||||
->select('id', 'name')
|
||||
->orderBy('id')
|
||||
->limit($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user