Files
sam-api/app/Http/Requests/Quote/QuoteBomBulkCalculateRequest.php
권혁성 5448f0e57d deploy: 2026-03-12 배포
- feat: [barobill] 바로빌 카드/은행/홈택스 REST API 구현
- feat: [equipment] 설비관리 API 백엔드 구현
- feat: [payroll] 급여관리 계산 엔진 및 일괄 처리 API
- feat: [QMS] 점검표 템플릿 관리 + 로트심사 개선
- feat: [생산/출하] 수주 단위 출하 자동생성 + 상태 흐름 개선
- feat: [receiving] 입고 성적서 파일 연결
- feat: [견적] 제어기 타입 체계 변경
- feat: [email] 테넌트 메일 설정 마이그레이션 및 모델
- feat: [pmis] 시공관리 테이블 마이그레이션
- feat: [R2] 파일 업로드 커맨드 + filesystems 설정
- feat: [배포] Jenkinsfile 롤백 기능 추가
- fix: [approval] SAM API 규칙 준수 코드 개선
- fix: [account-codes] 계정과목 중복 데이터 정리
- fix: [payroll] 일괄 생성 시 삭제된 사용자 건너뛰기
- fix: [db] codebridge DB 분리 후 깨진 FK 제약조건 제거
- refactor: [barobill] 바로빌 연동 코드 전면 개선
2026-03-12 15:20:20 +09:00

169 lines
6.4 KiB
PHP

<?php
namespace App\Http\Requests\Quote;
use Illuminate\Foundation\Http\FormRequest;
/**
* 다건 BOM 기반 견적 산출 요청
*
* React 견적등록 화면에서 여러 품목의 자동 견적 산출 시 사용됩니다.
* React QuoteFormItem 인터페이스의 필드명(camelCase)과
* API 입력 변수(W0, H0 등)를 모두 지원합니다.
*/
class QuoteBomBulkCalculateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
// 품목 배열 (최소 1개, 최대 100개)
'items' => 'required|array|min:1|max:100',
// 각 품목별 필수 입력
'items.*.finished_goods_code' => 'required|string|max:50',
// React 필드명 (camelCase) - 우선 적용
'items.*.openWidth' => 'nullable|numeric|min:100|max:20000',
'items.*.openHeight' => 'nullable|numeric|min:100|max:20000',
'items.*.quantity' => 'nullable|integer|min:1',
'items.*.productCategory' => 'nullable|string|in:SCREEN,STEEL',
'items.*.guideRailType' => 'nullable|string|in:wall,ceiling,floor,mixed',
'items.*.motorPower' => 'nullable|string|in:single,three',
'items.*.controller' => 'nullable|string|in:exposed,embedded,embedded_no_box',
'items.*.wingSize' => 'nullable|numeric|min:0|max:500',
'items.*.inspectionFee' => 'nullable|numeric|min:0',
// API 변수명 (약어) - React 필드명이 없을 때 사용
'items.*.W0' => 'nullable|numeric|min:100|max:20000',
'items.*.H0' => 'nullable|numeric|min:100|max:20000',
'items.*.QTY' => 'nullable|integer|min:1',
'items.*.PC' => 'nullable|string|in:SCREEN,STEEL',
'items.*.GT' => 'nullable|string|in:wall,ceiling,floor,mixed',
'items.*.MP' => 'nullable|string|in:single,three',
'items.*.CT' => 'nullable|string|in:exposed,embedded,embedded_no_box',
'items.*.WS' => 'nullable|numeric|min:0|max:500',
'items.*.INSP' => 'nullable|numeric|min:0',
// 디버그 모드 (개발용)
'debug' => 'nullable|boolean',
];
}
public function attributes(): array
{
return [
'items' => __('validation.attributes.items'),
'items.*.finished_goods_code' => __('validation.attributes.finished_goods_code'),
'items.*.openWidth' => __('validation.attributes.open_width'),
'items.*.openHeight' => __('validation.attributes.open_height'),
'items.*.quantity' => __('validation.attributes.quantity'),
'items.*.productCategory' => __('validation.attributes.product_category'),
'items.*.guideRailType' => __('validation.attributes.guide_rail_type'),
'items.*.motorPower' => __('validation.attributes.motor_power'),
'items.*.controller' => __('validation.attributes.controller'),
'items.*.wingSize' => __('validation.attributes.wing_size'),
'items.*.inspectionFee' => __('validation.attributes.inspection_fee'),
];
}
public function messages(): array
{
return [
'items.required' => __('error.items_required'),
'items.min' => __('error.items_min'),
'items.max' => __('error.items_max'),
'items.*.finished_goods_code.required' => __('error.finished_goods_code_required'),
];
}
/**
* 입력 품목 배열 반환 (FormulaEvaluatorService용)
*
* React 필드명(camelCase)과 API 변수명(약어) 모두 지원
* React 필드명 우선, 없으면 API 변수명 사용
*
* @return array<int, array{finished_goods_code: string, inputs: array}>
*/
public function getInputItems(): array
{
$validated = $this->validated();
$result = [];
foreach ($validated['items'] as $index => $item) {
$result[] = [
'index' => $index,
'finished_goods_code' => $item['finished_goods_code'],
'inputs' => $this->normalizeInputVariables($item),
];
}
return $result;
}
/**
* 단일 품목의 입력 변수 정규화
*
* React 필드명 → API 변수명 매핑
* - openWidth → W0
* - openHeight → H0
* - quantity → QTY
* - productCategory → PC
* - guideRailType → GT
* - motorPower → MP
* - controller → CT
* - wingSize → WS
* - inspectionFee → INSP
*/
private function normalizeInputVariables(array $item): array
{
return [
'W0' => (float) ($item['openWidth'] ?? $item['W0'] ?? 0),
'H0' => (float) ($item['openHeight'] ?? $item['H0'] ?? 0),
'QTY' => (int) ($item['quantity'] ?? $item['QTY'] ?? 1),
'PC' => $item['productCategory'] ?? $item['PC'] ?? 'SCREEN',
'GT' => $item['guideRailType'] ?? $item['GT'] ?? 'wall',
'MP' => $item['motorPower'] ?? $item['MP'] ?? 'single',
'CT' => $item['controller'] ?? $item['CT'] ?? 'exposed',
'WS' => (float) ($item['wingSize'] ?? $item['WS'] ?? 50),
'INSP' => (float) ($item['inspectionFee'] ?? $item['INSP'] ?? 50000),
];
}
/**
* 필수 입력 검증 (W0, H0)
*
* React 필드명이든 API 변수명이든 둘 중 하나는 있어야 함
*/
public function withValidator($validator): void
{
$validator->after(function ($validator) {
$items = $this->input('items', []);
foreach ($items as $index => $item) {
// W0 (openWidth 또는 W0) 검증
$w0 = $item['openWidth'] ?? $item['W0'] ?? null;
if ($w0 === null || $w0 === '') {
$validator->errors()->add(
"items.{$index}.openWidth",
__('error.open_width_required')
);
}
// H0 (openHeight 또는 H0) 검증
$h0 = $item['openHeight'] ?? $item['H0'] ?? null;
if ($h0 === null || $h0 === '') {
$validator->errors()->add(
"items.{$index}.openHeight",
__('error.open_height_required')
);
}
}
});
}
}