Files
sam-api/app/Services/ItemMaster/ItemMasterService.php

65 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Services\ItemMaster;
use App\Models\ItemMaster\CustomTab;
use App\Models\ItemMaster\ItemMasterField;
use App\Models\ItemMaster\ItemPage;
use App\Models\ItemMaster\SectionTemplate;
use App\Models\ItemMaster\UnitOption;
use App\Services\Service;
class ItemMasterService extends Service
{
/**
* 초기화 데이터 로드
*
* - pages (섹션/필드 중첩)
* - sectionTemplates
* - masterFields
* - customTabs (columnSetting 포함)
* - unitOptions
*/
public function init(): array
{
$tenantId = $this->tenantId();
// 1. 페이지 (섹션 → 필드 중첩)
$pages = ItemPage::with([
'sections' => function ($query) {
$query->orderBy('order_no');
},
'sections.fields' => function ($query) {
$query->orderBy('order_no');
},
'sections.bomItems',
])
->where('tenant_id', $tenantId)
->where('is_active', 1)
->get();
// 2. 섹션 템플릿
$sectionTemplates = SectionTemplate::where('tenant_id', $tenantId)->get();
// 3. 마스터 필드
$masterFields = ItemMasterField::where('tenant_id', $tenantId)->get();
// 4. 커스텀 탭 (컬럼 설정 포함)
$customTabs = CustomTab::with('columnSetting')
->where('tenant_id', $tenantId)
->orderBy('order_no')
->get();
// 5. 단위 옵션
$unitOptions = UnitOption::where('tenant_id', $tenantId)->get();
return [
'pages' => $pages,
'sectionTemplates' => $sectionTemplates,
'masterFields' => $masterFields,
'customTabs' => $customTabs,
'unitOptions' => $unitOptions,
];
}
}