68 lines
1.8 KiB
PHP
68 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services;
|
||
|
|
|
||
|
|
use App\Models\Documents\DocumentTemplate;
|
||
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||
|
|
|
||
|
|
class DocumentTemplateService extends Service
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* 양식 목록 조회
|
||
|
|
*/
|
||
|
|
public function list(array $params): LengthAwarePaginator
|
||
|
|
{
|
||
|
|
$tenantId = $this->tenantId();
|
||
|
|
|
||
|
|
$query = DocumentTemplate::query()
|
||
|
|
->where('tenant_id', $tenantId)
|
||
|
|
->with(['approvalLines', 'basicFields']);
|
||
|
|
|
||
|
|
// 활성 상태 필터
|
||
|
|
if (isset($params['is_active'])) {
|
||
|
|
$query->where('is_active', filter_var($params['is_active'], FILTER_VALIDATE_BOOLEAN));
|
||
|
|
}
|
||
|
|
|
||
|
|
// 카테고리 필터
|
||
|
|
if (! empty($params['category'])) {
|
||
|
|
$query->where('category', $params['category']);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 검색 (양식명)
|
||
|
|
if (! empty($params['search'])) {
|
||
|
|
$search = $params['search'];
|
||
|
|
$query->where(function ($q) use ($search) {
|
||
|
|
$q->where('name', 'like', "%{$search}%")
|
||
|
|
->orWhere('title', 'like', "%{$search}%");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// 정렬
|
||
|
|
$sortBy = $params['sort_by'] ?? 'created_at';
|
||
|
|
$sortDir = $params['sort_dir'] ?? 'desc';
|
||
|
|
$query->orderBy($sortBy, $sortDir);
|
||
|
|
|
||
|
|
$perPage = $params['per_page'] ?? 20;
|
||
|
|
|
||
|
|
return $query->paginate($perPage);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 양식 상세 조회 (전체 관계 포함)
|
||
|
|
*/
|
||
|
|
public function show(int $id): DocumentTemplate
|
||
|
|
{
|
||
|
|
$tenantId = $this->tenantId();
|
||
|
|
|
||
|
|
return DocumentTemplate::query()
|
||
|
|
->where('tenant_id', $tenantId)
|
||
|
|
->with([
|
||
|
|
'approvalLines',
|
||
|
|
'basicFields',
|
||
|
|
'sections.items',
|
||
|
|
'columns',
|
||
|
|
])
|
||
|
|
->findOrFail($id);
|
||
|
|
}
|
||
|
|
}
|