Files
sam-manage/database/seeders/ProductInspectionRequestTemplateSeeder.php
권혁성 9e69c64024 feat: [품질검사] 제품검사 요청서 템플릿 시더 + Pretendard 폰트
- ProductInspectionRequestTemplateSeeder (template ID 66)
- Pretendard 폰트 + TCPDF 폰트 파일 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 03:05:14 +09:00

189 lines
8.5 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\DocumentTemplate;
use App\Models\DocumentTemplateApprovalLine;
use App\Models\DocumentTemplateBasicField;
use App\Models\DocumentTemplateColumn;
use App\Models\DocumentTemplateSection;
use App\Models\DocumentTemplateSectionItem;
use Illuminate\Database\Seeder;
class ProductInspectionRequestTemplateSeeder extends Seeder
{
private int $tenantId = 287;
private int $templateId = 66;
public function run(): void
{
$def = $this->getTemplateDefinition();
$template = DocumentTemplate::updateOrCreate(
['id' => $this->templateId, 'tenant_id' => $this->tenantId],
[
'name' => $def['name'],
'category' => '품질/제품검사',
'title' => $def['title'],
'company_name' => '케이디산업',
'is_active' => true,
]
);
$this->cleanupRelations($template->id);
$this->createApprovalLines($template->id);
$this->createBasicFields($template->id);
foreach ($def['sections'] as $i => $sectionDef) {
$this->createSection($template->id, $sectionDef, $i + 1);
}
$this->createColumns($template->id, $def['columns']);
$this->command->info("제품검사 요청서 (ID: {$template->id})");
}
private function getTemplateDefinition(): array
{
return [
'name' => '제품검사 요청서',
'title' => '제 품 검 사 요 청 서',
'sections' => [
[
'title' => '건축공사장 정보',
'items' => [
['item' => '현장명', 'measurement_type' => 'text_input'],
['item' => '대지위치', 'measurement_type' => 'text_input'],
['item' => '지번', 'measurement_type' => 'text_input'],
],
],
[
'title' => '자재유통업자 정보',
'items' => [
['item' => '회사명', 'measurement_type' => 'text_input'],
['item' => '주소', 'measurement_type' => 'text_input'],
['item' => '대표자', 'measurement_type' => 'text_input'],
['item' => '전화번호', 'measurement_type' => 'text_input'],
],
],
[
'title' => '공사시공자 정보',
'items' => [
['item' => '회사명', 'measurement_type' => 'text_input'],
['item' => '주소', 'measurement_type' => 'text_input'],
['item' => '성명', 'measurement_type' => 'text_input'],
['item' => '전화번호', 'measurement_type' => 'text_input'],
],
],
[
'title' => '공사감리자 정보',
'items' => [
['item' => '사무소명', 'measurement_type' => 'text_input'],
['item' => '주소', 'measurement_type' => 'text_input'],
['item' => '성명', 'measurement_type' => 'text_input'],
['item' => '전화번호', 'measurement_type' => 'text_input'],
],
],
[
'title' => '검사대상 사전 고지 정보',
'description' => '발주 사이즈와 시공 완료된 사이즈가 다를 시, 일정 범위를 벗어날 경우 인정마크를 부착할 수 없습니다. 제품검사를 위한 방문 전 미리 변경사항을 고지해주셔야 인정마크를 부착할 수 있습니다. (사전고지를 하지 않음으로 발생하는 문제의 귀책은 신청업체에 있습니다.)',
'items' => [],
],
],
// 사전 고지 정보 테이블 컬럼
'columns' => [
['label' => 'No.', 'column_type' => 'text', 'width' => '40px', 'sort_order' => 1],
['label' => '층수', 'column_type' => 'text', 'width' => '60px', 'sort_order' => 2],
['label' => '부호', 'column_type' => 'text', 'width' => '60px', 'sort_order' => 3],
['label' => '발주 가로', 'column_type' => 'text', 'width' => '70px', 'sort_order' => 4, 'group_name' => '오픈사이즈(발주규격)'],
['label' => '발주 세로', 'column_type' => 'text', 'width' => '70px', 'sort_order' => 5, 'group_name' => '오픈사이즈(발주규격)'],
['label' => '시공 가로', 'column_type' => 'text', 'width' => '70px', 'sort_order' => 6, 'group_name' => '오픈사이즈(시공후규격)'],
['label' => '시공 세로', 'column_type' => 'text', 'width' => '70px', 'sort_order' => 7, 'group_name' => '오픈사이즈(시공후규격)'],
['label' => '변경사유', 'column_type' => 'text', 'width' => '1fr', 'sort_order' => 8],
],
];
}
private function createApprovalLines(int $templateId): void
{
$lines = [
['name' => '작성', 'dept' => '품질', 'role' => '담당자', 'sort_order' => 1],
['name' => '승인', 'dept' => '경영', 'role' => '대표', 'sort_order' => 2],
];
foreach ($lines as $line) {
DocumentTemplateApprovalLine::create(array_merge(
['template_id' => $templateId],
$line,
));
}
}
private function createBasicFields(int $templateId): void
{
$fields = [
['label' => '수주처', 'field_key' => 'client', 'field_type' => 'text', 'sort_order' => 1],
['label' => '업체명', 'field_key' => 'company_name', 'field_type' => 'text', 'sort_order' => 2],
['label' => '담당자', 'field_key' => 'manager', 'field_type' => 'text', 'sort_order' => 3],
['label' => '수주번호', 'field_key' => 'order_number', 'field_type' => 'text', 'sort_order' => 4],
['label' => '담당자 연락처', 'field_key' => 'manager_contact', 'field_type' => 'text', 'sort_order' => 5],
['label' => '현장명', 'field_key' => 'site_name', 'field_type' => 'text', 'sort_order' => 6],
['label' => '납품일', 'field_key' => 'delivery_date', 'field_type' => 'date', 'sort_order' => 7],
['label' => '현장 주소', 'field_key' => 'site_address', 'field_type' => 'text', 'sort_order' => 8],
['label' => '총 개소', 'field_key' => 'total_locations', 'field_type' => 'number', 'sort_order' => 9],
['label' => '접수일', 'field_key' => 'receipt_date', 'field_type' => 'date', 'sort_order' => 10],
['label' => '검사방문요청일', 'field_key' => 'inspection_request_date', 'field_type' => 'date', 'sort_order' => 11],
];
foreach ($fields as $field) {
DocumentTemplateBasicField::create(array_merge(
['template_id' => $templateId],
$field,
));
}
}
private function createSection(int $templateId, array $sectionDef, int $sortOrder): void
{
$section = DocumentTemplateSection::create([
'template_id' => $templateId,
'title' => $sectionDef['title'],
'description' => $sectionDef['description'] ?? null,
'sort_order' => $sortOrder,
]);
foreach ($sectionDef['items'] as $i => $item) {
DocumentTemplateSectionItem::create(array_merge(
['section_id' => $section->id, 'sort_order' => $i + 1],
$item,
));
}
}
private function createColumns(int $templateId, array $columns): void
{
foreach ($columns as $col) {
DocumentTemplateColumn::create(array_merge(
['template_id' => $templateId],
$col,
));
}
}
private function cleanupRelations(int $templateId): void
{
DocumentTemplateColumn::where('template_id', $templateId)->delete();
$sections = DocumentTemplateSection::where('template_id', $templateId)->get();
foreach ($sections as $section) {
DocumentTemplateSectionItem::where('section_id', $section->id)->delete();
}
DocumentTemplateSection::where('template_id', $templateId)->delete();
DocumentTemplateBasicField::where('template_id', $templateId)->delete();
DocumentTemplateApprovalLine::where('template_id', $templateId)->delete();
}
}