style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -2,15 +2,15 @@
|
||||
|
||||
namespace App\Services\Calculation;
|
||||
|
||||
use App\Models\Design\BomTemplate;
|
||||
use App\Models\Design\BomTemplateItem;
|
||||
use App\Models\Calculation\CalculationConfig;
|
||||
use App\Models\Design\BomTemplate;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CalculationEngine
|
||||
{
|
||||
protected FormulaParser $parser;
|
||||
|
||||
protected ParameterValidator $validator;
|
||||
|
||||
public function __construct(FormulaParser $parser, ParameterValidator $validator)
|
||||
@@ -21,9 +21,10 @@ public function __construct(FormulaParser $parser, ParameterValidator $validator
|
||||
|
||||
/**
|
||||
* BOM 계산 실행
|
||||
* @param int $bomTemplateId BOM 템플릿 ID
|
||||
* @param array $parameters 입력 파라미터
|
||||
* @param string|null $companyName 업체명 (null시 기본값 사용)
|
||||
*
|
||||
* @param int $bomTemplateId BOM 템플릿 ID
|
||||
* @param array $parameters 입력 파라미터
|
||||
* @param string|null $companyName 업체명 (null시 기본값 사용)
|
||||
* @return array 계산 결과
|
||||
*/
|
||||
public function calculateBOM(int $bomTemplateId, array $parameters, ?string $companyName = null): array
|
||||
@@ -48,32 +49,33 @@ public function calculateBOM(int $bomTemplateId, array $parameters, ?string $com
|
||||
'id' => $bomTemplate->id,
|
||||
'name' => $bomTemplate->name,
|
||||
'company_type' => $bomTemplate->company_type,
|
||||
'formula_version' => $bomTemplate->formula_version
|
||||
'formula_version' => $bomTemplate->formula_version,
|
||||
],
|
||||
'input_parameters' => $parameters,
|
||||
'calculated_values' => $calculatedValues,
|
||||
'bom_items' => $bomItems,
|
||||
'calculation_timestamp' => now()
|
||||
'calculation_timestamp' => now(),
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('BOM 계산 실패', [
|
||||
'bom_template_id' => $bomTemplateId,
|
||||
'parameters' => $parameters,
|
||||
'error' => $e->getMessage()
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => $e->getMessage(),
|
||||
'bom_template_id' => $bomTemplateId
|
||||
'bom_template_id' => $bomTemplateId,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 견적시 필요한 파라미터 스키마 추출
|
||||
* @param int $bomTemplateId BOM 템플릿 ID
|
||||
*
|
||||
* @param int $bomTemplateId BOM 템플릿 ID
|
||||
* @return array 파라미터 스키마
|
||||
*/
|
||||
public function getRequiredParameters(int $bomTemplateId): array
|
||||
@@ -81,7 +83,7 @@ public function getRequiredParameters(int $bomTemplateId): array
|
||||
$bomTemplate = BomTemplate::findOrFail($bomTemplateId);
|
||||
|
||||
$schema = $bomTemplate->calculation_schema;
|
||||
if (!$schema) {
|
||||
if (! $schema) {
|
||||
return $this->getDefaultParameterSchema($bomTemplate);
|
||||
}
|
||||
|
||||
@@ -107,7 +109,7 @@ protected function calculateIntermediateValues(BomTemplate $bomTemplate, array $
|
||||
$calculated = array_merge($calculated, $this->parser->execute($sizeFormula->formula_expression, [
|
||||
'W0' => $W0,
|
||||
'H0' => $H0,
|
||||
'product_type' => $productType
|
||||
'product_type' => $productType,
|
||||
]));
|
||||
} else {
|
||||
// 기본 공식 (경동기업 기준)
|
||||
@@ -148,7 +150,7 @@ protected function calculateBomItems(Collection $bomItems, array $calculatedValu
|
||||
$results = [];
|
||||
|
||||
foreach ($bomItems as $item) {
|
||||
if (!$item->is_calculated) {
|
||||
if (! $item->is_calculated) {
|
||||
// 고정 수량 아이템
|
||||
$results[] = [
|
||||
'item_id' => $item->id,
|
||||
@@ -157,8 +159,9 @@ protected function calculateBomItems(Collection $bomItems, array $calculatedValu
|
||||
'original_qty' => $item->qty,
|
||||
'calculated_qty' => $item->qty,
|
||||
'is_calculated' => false,
|
||||
'calculation_formula' => null
|
||||
'calculation_formula' => null,
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -175,13 +178,13 @@ protected function calculateBomItems(Collection $bomItems, array $calculatedValu
|
||||
'calculated_qty' => $calculatedQty['result'] ?? $item->qty,
|
||||
'is_calculated' => true,
|
||||
'calculation_formula' => $item->calculation_formula,
|
||||
'depends_on' => $item->depends_on
|
||||
'depends_on' => $item->depends_on,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Log::warning('BOM 아이템 계산 실패', [
|
||||
'item_id' => $item->id,
|
||||
'formula' => $item->calculation_formula,
|
||||
'error' => $e->getMessage()
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
// 계산 실패시 원래 수량 사용
|
||||
@@ -192,7 +195,7 @@ protected function calculateBomItems(Collection $bomItems, array $calculatedValu
|
||||
'original_qty' => $item->qty,
|
||||
'calculated_qty' => $item->qty,
|
||||
'is_calculated' => false,
|
||||
'calculation_error' => $e->getMessage()
|
||||
'calculation_error' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -206,7 +209,9 @@ protected function calculateBomItems(Collection $bomItems, array $calculatedValu
|
||||
protected function validateParameters(BomTemplate $bomTemplate, array $parameters): void
|
||||
{
|
||||
$schema = $bomTemplate->calculation_schema;
|
||||
if (!$schema) return;
|
||||
if (! $schema) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->validator->validate($schema, $parameters);
|
||||
}
|
||||
@@ -236,7 +241,7 @@ protected function getDefaultParameterSchema(BomTemplate $bomTemplate): array
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'min' => 500,
|
||||
'max' => 15000
|
||||
'max' => 15000,
|
||||
],
|
||||
[
|
||||
'key' => 'H0',
|
||||
@@ -244,25 +249,25 @@ protected function getDefaultParameterSchema(BomTemplate $bomTemplate): array
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'min' => 500,
|
||||
'max' => 5000
|
||||
'max' => 5000,
|
||||
],
|
||||
[
|
||||
'key' => 'product_type',
|
||||
'label' => '제품타입',
|
||||
'type' => 'select',
|
||||
'options' => ['screen' => '스크린', 'steel' => '철재'],
|
||||
'required' => true
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'key' => 'installation_type',
|
||||
'label' => '설치방식',
|
||||
'type' => 'select',
|
||||
'options' => ['wall' => '벽면형', 'side' => '측면형', 'mixed' => '혼합형'],
|
||||
'required' => false
|
||||
]
|
||||
'required' => false,
|
||||
],
|
||||
],
|
||||
'company_type' => $bomTemplate->company_type ?: 'default',
|
||||
'formula_version' => $bomTemplate->formula_version ?: 'v1.0'
|
||||
'formula_version' => $bomTemplate->formula_version ?: 'v1.0',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user