2026-02-19 21:18:31 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Barobill;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 거래처 모델 (검색용)
|
|
|
|
|
* clients 테이블은 API 프로젝트에서 관리하며, MNG에서는 검색 조회만 수행
|
|
|
|
|
*/
|
|
|
|
|
class Client extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $table = 'clients';
|
|
|
|
|
|
|
|
|
|
/**
|
2026-02-19 21:25:08 +09:00
|
|
|
* 고유번호(id) 또는 거래처명으로 검색
|
2026-02-19 21:18:31 +09:00
|
|
|
*/
|
2026-02-19 21:25:08 +09:00
|
|
|
public static function searchByIdOrName(int $tenantId, string $keyword, int $limit = 20)
|
2026-02-19 21:18:31 +09:00
|
|
|
{
|
|
|
|
|
return self::where('tenant_id', $tenantId)
|
|
|
|
|
->where('is_active', true)
|
|
|
|
|
->where(function ($query) use ($keyword) {
|
2026-02-19 21:25:08 +09:00
|
|
|
if (is_numeric($keyword)) {
|
|
|
|
|
$query->where('id', $keyword);
|
|
|
|
|
}
|
|
|
|
|
$query->orWhere('name', 'like', "%{$keyword}%");
|
2026-02-19 21:18:31 +09:00
|
|
|
})
|
2026-02-19 21:25:08 +09:00
|
|
|
->select('id', 'name')
|
|
|
|
|
->orderBy('id')
|
2026-02-19 21:18:31 +09:00
|
|
|
->limit($limit)
|
|
|
|
|
->get();
|
|
|
|
|
}
|
|
|
|
|
}
|