71 lines
3.0 KiB
PHP
71 lines
3.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Requests\Quote;
|
||
|
|
|
||
|
|
use Illuminate\Foundation\Http\FormRequest;
|
||
|
|
|
||
|
|
class StoreQuoteFormulaRequest extends FormRequest
|
||
|
|
{
|
||
|
|
public function authorize(): bool
|
||
|
|
{
|
||
|
|
return auth()->check();
|
||
|
|
}
|
||
|
|
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'category_id' => 'required|integer|exists:quote_formula_categories,id',
|
||
|
|
'product_id' => 'nullable|integer',
|
||
|
|
'name' => 'required|string|max:200',
|
||
|
|
'variable' => 'required|string|max:50|regex:/^[A-Z][A-Z0-9_]*$/',
|
||
|
|
'type' => 'required|in:input,calculation,range,mapping',
|
||
|
|
'formula' => 'nullable|string|max:2000',
|
||
|
|
'output_type' => 'in:variable,item',
|
||
|
|
'description' => 'nullable|string|max:500',
|
||
|
|
'sort_order' => 'nullable|integer|min:1',
|
||
|
|
'is_active' => 'boolean',
|
||
|
|
|
||
|
|
// 범위 규칙
|
||
|
|
'ranges' => 'array',
|
||
|
|
'ranges.*.min_value' => 'nullable|numeric',
|
||
|
|
'ranges.*.max_value' => 'nullable|numeric',
|
||
|
|
'ranges.*.condition_variable' => 'required_with:ranges|string|max:50',
|
||
|
|
'ranges.*.result_value' => 'required_with:ranges|string|max:500',
|
||
|
|
'ranges.*.result_type' => 'in:fixed,formula',
|
||
|
|
|
||
|
|
// 매핑 규칙
|
||
|
|
'mappings' => 'array',
|
||
|
|
'mappings.*.source_variable' => 'required_with:mappings|string|max:50',
|
||
|
|
'mappings.*.source_value' => 'required_with:mappings|string|max:200',
|
||
|
|
'mappings.*.result_value' => 'required_with:mappings|string|max:500',
|
||
|
|
'mappings.*.result_type' => 'in:fixed,formula',
|
||
|
|
|
||
|
|
// 품목 출력
|
||
|
|
'items' => 'array',
|
||
|
|
'items.*.item_code' => 'required_with:items|string|max:50',
|
||
|
|
'items.*.item_name' => 'required_with:items|string|max:200',
|
||
|
|
'items.*.specification' => 'nullable|string|max:100',
|
||
|
|
'items.*.unit' => 'required_with:items|string|max:20',
|
||
|
|
'items.*.quantity_formula' => 'required_with:items|string|max:500',
|
||
|
|
'items.*.unit_price_formula' => 'nullable|string|max:500',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function messages(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'category_id.required' => '카테고리를 선택해주세요.',
|
||
|
|
'category_id.exists' => '유효하지 않은 카테고리입니다.',
|
||
|
|
'name.required' => '수식 이름은 필수입니다.',
|
||
|
|
'name.max' => '수식 이름은 200자 이하로 입력해주세요.',
|
||
|
|
'variable.required' => '변수명은 필수입니다.',
|
||
|
|
'variable.regex' => '변수명은 대문자로 시작하고 대문자, 숫자, 언더스코어만 사용할 수 있습니다.',
|
||
|
|
'variable.max' => '변수명은 50자 이하로 입력해주세요.',
|
||
|
|
'type.required' => '수식 유형을 선택해주세요.',
|
||
|
|
'type.in' => '유효하지 않은 수식 유형입니다.',
|
||
|
|
'formula.max' => '수식은 2000자 이하로 입력해주세요.',
|
||
|
|
'output_type.in' => '유효하지 않은 출력 유형입니다.',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|