- 품목관리 3-Panel 레이아웃 (좌:목록, 중:BOM/수식산출, 우:상세) - FormulaApiService로 API 견적수식 엔진 연동 - FG 품목 선택 시 기본값(W:1000, H:1000, QTY:1) 자동 산출 - 수식 산출 결과 트리 렌더링 (그룹별/소계/합계) - 중앙 패널 클릭 시 우측 상세만 변경 (skipCenterUpdate) - API 인증 버튼 전역 헤더로 이동 (모든 페이지에서 사용 가능) - FormulaApiService에 Bearer 토큰 지원 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
86 lines
2.3 KiB
PHP
86 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Items\Item;
|
|
use App\Services\FormulaApiService;
|
|
use App\Services\ItemManagementService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class ItemManagementApiController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly ItemManagementService $service
|
|
) {}
|
|
|
|
/**
|
|
* 품목 목록 (HTML partial - 좌측 패널)
|
|
*/
|
|
public function index(Request $request): View
|
|
{
|
|
$items = $this->service->getItemList([
|
|
'search' => $request->input('search'),
|
|
'item_type' => $request->input('item_type'),
|
|
'per_page' => $request->input('per_page', 50),
|
|
]);
|
|
|
|
return view('item-management.partials.item-list', compact('items'));
|
|
}
|
|
|
|
/**
|
|
* BOM 재귀 트리 (JSON - 중앙 패널, JS 렌더링)
|
|
*/
|
|
public function bomTree(int $id, Request $request): JsonResponse
|
|
{
|
|
$maxDepth = $request->input('max_depth', 10);
|
|
$tree = $this->service->getBomTree($id, $maxDepth);
|
|
|
|
return response()->json($tree);
|
|
}
|
|
|
|
/**
|
|
* 품목 상세 (HTML partial - 우측 패널)
|
|
*/
|
|
public function detail(int $id): View
|
|
{
|
|
$data = $this->service->getItemDetail($id);
|
|
|
|
return view('item-management.partials.item-detail', [
|
|
'item' => $data['item'],
|
|
'bomChildren' => $data['bom_children'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 수식 기반 BOM 산출 (API 서버의 FormulaEvaluatorService HTTP 호출)
|
|
*/
|
|
public function calculateFormula(Request $request, int $id): JsonResponse
|
|
{
|
|
$item = Item::withoutGlobalScopes()
|
|
->where('tenant_id', session('selected_tenant_id'))
|
|
->findOrFail($id);
|
|
|
|
$width = (int) $request->input('width', 1000);
|
|
$height = (int) $request->input('height', 1000);
|
|
$qty = (int) $request->input('qty', 1);
|
|
|
|
$variables = [
|
|
'W0' => $width,
|
|
'H0' => $height,
|
|
'QTY' => $qty,
|
|
];
|
|
|
|
$formulaService = new FormulaApiService();
|
|
$result = $formulaService->calculateBom(
|
|
$item->code,
|
|
$variables,
|
|
(int) session('selected_tenant_id')
|
|
);
|
|
|
|
return response()->json($result);
|
|
}
|
|
}
|