style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace App\Services\Design;
|
||||
|
||||
use App\Services\Service;
|
||||
use App\Services\Calculation\CalculationEngine;
|
||||
use App\Models\Design\BomTemplate;
|
||||
use App\Models\Calculation\CalculationConfig;
|
||||
use App\Models\Design\BomTemplate;
|
||||
use App\Services\Calculation\CalculationEngine;
|
||||
use App\Services\Service;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -20,9 +20,9 @@ public function __construct(CalculationEngine $calculationEngine)
|
||||
|
||||
/**
|
||||
* 견적 파라미터 조회
|
||||
* @param int $modelId 모델 ID
|
||||
* @param string|null $companyName 업체명
|
||||
* @return array
|
||||
*
|
||||
* @param int $modelId 모델 ID
|
||||
* @param string|null $companyName 업체명
|
||||
*/
|
||||
public function getEstimateParameters(int $modelId, ?string $companyName = null): array
|
||||
{
|
||||
@@ -38,7 +38,7 @@ public function getEstimateParameters(int $modelId, ?string $companyName = null)
|
||||
->where('is_primary', true)
|
||||
->first();
|
||||
|
||||
if (!$bomTemplate) {
|
||||
if (! $bomTemplate) {
|
||||
throw new \Exception("모델 ID {$modelId}에 대한 BOM 템플릿을 찾을 수 없습니다.");
|
||||
}
|
||||
|
||||
@@ -58,22 +58,22 @@ public function getEstimateParameters(int $modelId, ?string $companyName = null)
|
||||
'id' => $bomTemplate->modelVersion->model->id,
|
||||
'name' => $bomTemplate->modelVersion->model->name ?? '모델명 없음',
|
||||
'version' => $bomTemplate->modelVersion->version_no ?? 'v1.0',
|
||||
'bom_template_id' => $bomTemplate->id
|
||||
'bom_template_id' => $bomTemplate->id,
|
||||
],
|
||||
'company_info' => [
|
||||
'company_type' => $bomTemplate->company_type,
|
||||
'formula_version' => $bomTemplate->formula_version,
|
||||
'requested_company' => $companyName
|
||||
'requested_company' => $companyName,
|
||||
],
|
||||
'parameters' => $parameters,
|
||||
'calculation_preview' => true
|
||||
'calculation_preview' => true,
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('견적 파라미터 조회 실패', [
|
||||
'model_id' => $modelId,
|
||||
'company_name' => $companyName,
|
||||
'error' => $e->getMessage()
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
@@ -82,10 +82,10 @@ public function getEstimateParameters(int $modelId, ?string $companyName = null)
|
||||
|
||||
/**
|
||||
* BOM 계산 실행
|
||||
* @param int $bomTemplateId BOM 템플릿 ID
|
||||
* @param array $parameters 입력 파라미터
|
||||
* @param string|null $companyName 업체명
|
||||
* @return array
|
||||
*
|
||||
* @param int $bomTemplateId BOM 템플릿 ID
|
||||
* @param array $parameters 입력 파라미터
|
||||
* @param string|null $companyName 업체명
|
||||
*/
|
||||
public function calculateBomEstimate(int $bomTemplateId, array $parameters, ?string $companyName = null): array
|
||||
{
|
||||
@@ -112,7 +112,7 @@ public function calculateBomEstimate(int $bomTemplateId, array $parameters, ?str
|
||||
return [
|
||||
'success' => $result['success'],
|
||||
'data' => $result['success'] ? $result : null,
|
||||
'error' => $result['success'] ? null : $result['error']
|
||||
'error' => $result['success'] ? null : $result['error'],
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@@ -121,21 +121,21 @@ public function calculateBomEstimate(int $bomTemplateId, array $parameters, ?str
|
||||
'bom_template_id' => $bomTemplateId,
|
||||
'parameters' => $parameters,
|
||||
'company_name' => $companyName,
|
||||
'error' => $e->getMessage()
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'data' => null,
|
||||
'error' => $e->getMessage()
|
||||
'error' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 업체별 산출식 목록 조회
|
||||
* @param string $companyName 업체명
|
||||
* @return array
|
||||
*
|
||||
* @param string $companyName 업체명
|
||||
*/
|
||||
public function getCompanyFormulas(string $companyName): array
|
||||
{
|
||||
@@ -150,18 +150,18 @@ public function getCompanyFormulas(string $companyName): array
|
||||
'version' => $formula['version'],
|
||||
'description' => $formula['description'],
|
||||
'parameters' => $formula['parameters'],
|
||||
'updated_at' => $formula['updated_at']
|
||||
'updated_at' => $formula['updated_at'],
|
||||
];
|
||||
}, $formulas)
|
||||
}, $formulas),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 업체별 산출식 등록/수정
|
||||
* @param string $companyName 업체명
|
||||
* @param string $formulaType 산출식 타입
|
||||
* @param array $formulaData 산출식 데이터
|
||||
* @return array
|
||||
*
|
||||
* @param string $companyName 업체명
|
||||
* @param string $formulaType 산출식 타입
|
||||
* @param array $formulaData 산출식 데이터
|
||||
*/
|
||||
public function saveCompanyFormula(string $companyName, string $formulaType, array $formulaData): array
|
||||
{
|
||||
@@ -191,7 +191,7 @@ public function saveCompanyFormula(string $companyName, string $formulaType, arr
|
||||
'validation_rules' => $formulaData['validation_rules'] ?? null,
|
||||
'description' => $formulaData['description'] ?? null,
|
||||
'is_active' => true,
|
||||
'created_by' => $this->apiUserId()
|
||||
'created_by' => $this->apiUserId(),
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
@@ -202,7 +202,7 @@ public function saveCompanyFormula(string $companyName, string $formulaType, arr
|
||||
'formula_type' => $formula->formula_type,
|
||||
'version' => $formula->version,
|
||||
'is_active' => $formula->is_active,
|
||||
'created_at' => $formula->created_at
|
||||
'created_at' => $formula->created_at,
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
@@ -210,7 +210,7 @@ public function saveCompanyFormula(string $companyName, string $formulaType, arr
|
||||
Log::error('업체별 산출식 저장 실패', [
|
||||
'company_name' => $companyName,
|
||||
'formula_type' => $formulaType,
|
||||
'error' => $e->getMessage()
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
@@ -245,7 +245,7 @@ protected function logCalculationHistory(int $bomTemplateId, array $parameters,
|
||||
'parameters' => $parameters,
|
||||
'success' => $result['success'],
|
||||
'calculated_items_count' => $result['success'] ? count($result['bom_items']) : 0,
|
||||
'calculated_by' => $this->apiUserId()
|
||||
'calculated_by' => $this->apiUserId(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -255,11 +255,12 @@ protected function logCalculationHistory(int $bomTemplateId, array $parameters,
|
||||
protected function incrementVersion(string $currentVersion): string
|
||||
{
|
||||
if (preg_match('/^v(\d+)\.(\d+)$/', $currentVersion, $matches)) {
|
||||
$major = (int)$matches[1];
|
||||
$minor = (int)$matches[2];
|
||||
return "v{$major}." . ($minor + 1);
|
||||
$major = (int) $matches[1];
|
||||
$minor = (int) $matches[2];
|
||||
|
||||
return "v{$major}.".($minor + 1);
|
||||
}
|
||||
|
||||
return 'v1.0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public function upsertTemplate(int $modelVersionId, string $name = 'Main', bool
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($modelVersionId);
|
||||
|
||||
if (!$mv) {
|
||||
if (! $mv) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ public function upsertTemplate(int $modelVersionId, string $name = 'Main', bool
|
||||
$action = 'created';
|
||||
$before = null;
|
||||
|
||||
if (!$tpl) {
|
||||
if (! $tpl) {
|
||||
$tpl = BomTemplate::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'tenant_id' => $tenantId,
|
||||
'model_version_id' => $mv->id,
|
||||
'name' => $name,
|
||||
'is_primary' => $isPrimary,
|
||||
'notes' => $notes,
|
||||
'name' => $name,
|
||||
'is_primary' => $isPrimary,
|
||||
'notes' => $notes,
|
||||
]);
|
||||
} else {
|
||||
$action = 'updated';
|
||||
@@ -98,7 +98,7 @@ public function updateTemplate(int $templateId, array $data): BomTemplate
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($templateId);
|
||||
|
||||
if (!$tpl) {
|
||||
if (! $tpl) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public function deleteTemplate(int $templateId): void
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($templateId);
|
||||
|
||||
if (!$tpl) {
|
||||
if (! $tpl) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -172,11 +172,11 @@ public function show(int $templateId, bool $withItems = false): BomTemplate
|
||||
|
||||
$q = BomTemplate::query()->where('tenant_id', $tenantId);
|
||||
if ($withItems) {
|
||||
$q->with(['items' => fn($w) => $w->orderBy('sort_order')]);
|
||||
$q->with(['items' => fn ($w) => $w->orderBy('sort_order')]);
|
||||
}
|
||||
|
||||
$tpl = $q->find($templateId);
|
||||
if (!$tpl) {
|
||||
if (! $tpl) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -192,15 +192,15 @@ public function replaceItems(int $templateId, array $items): void
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($templateId);
|
||||
|
||||
if (!$tpl) {
|
||||
if (! $tpl) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
// 1차 검증
|
||||
foreach ($items as $i => $row) {
|
||||
$refType = strtoupper((string) Arr::get($row, 'ref_type'));
|
||||
$qty = (float) Arr::get($row, 'qty', 0);
|
||||
if (!in_array($refType, ['MATERIAL','PRODUCT'], true)) {
|
||||
$qty = (float) Arr::get($row, 'qty', 0);
|
||||
if (! in_array($refType, ['MATERIAL', 'PRODUCT'], true)) {
|
||||
throw ValidationException::withMessages(["items.$i.ref_type" => __('error.validation_failed')]);
|
||||
}
|
||||
if ($qty <= 0) {
|
||||
@@ -215,14 +215,14 @@ public function replaceItems(int $templateId, array $items): void
|
||||
->where('bom_template_id', $tpl->id)
|
||||
->orderBy('sort_order')
|
||||
->get()
|
||||
->map(fn($i) => [
|
||||
->map(fn ($i) => [
|
||||
'ref_type' => strtoupper($i->ref_type),
|
||||
'ref_id' => (int)$i->ref_id,
|
||||
'qty' => (float)$i->qty,
|
||||
'waste_rate' => (float)$i->waste_rate,
|
||||
'ref_id' => (int) $i->ref_id,
|
||||
'qty' => (float) $i->qty,
|
||||
'waste_rate' => (float) $i->waste_rate,
|
||||
'uom_id' => $i->uom_id,
|
||||
'notes' => $i->notes,
|
||||
'sort_order' => (int)$i->sort_order,
|
||||
'sort_order' => (int) $i->sort_order,
|
||||
])->all();
|
||||
|
||||
BomTemplateItem::query()
|
||||
@@ -234,21 +234,21 @@ public function replaceItems(int $templateId, array $items): void
|
||||
$payloads = [];
|
||||
foreach ($items as $row) {
|
||||
$payloads[] = [
|
||||
'tenant_id' => $tenantId,
|
||||
'tenant_id' => $tenantId,
|
||||
'bom_template_id' => $tpl->id,
|
||||
'ref_type' => strtoupper($row['ref_type']),
|
||||
'ref_id' => (int) $row['ref_id'],
|
||||
'qty' => (string) ($row['qty'] ?? 1),
|
||||
'waste_rate' => (string) ($row['waste_rate'] ?? 0),
|
||||
'uom_id' => $row['uom_id'] ?? null,
|
||||
'notes' => $row['notes'] ?? null,
|
||||
'sort_order' => (int) ($row['sort_order'] ?? 0),
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
'ref_type' => strtoupper($row['ref_type']),
|
||||
'ref_id' => (int) $row['ref_id'],
|
||||
'qty' => (string) ($row['qty'] ?? 1),
|
||||
'waste_rate' => (string) ($row['waste_rate'] ?? 0),
|
||||
'uom_id' => $row['uom_id'] ?? null,
|
||||
'notes' => $row['notes'] ?? null,
|
||||
'sort_order' => (int) ($row['sort_order'] ?? 0),
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($payloads)) {
|
||||
if (! empty($payloads)) {
|
||||
BomTemplateItem::insert($payloads);
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ public function listItems(int $templateId)
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($templateId);
|
||||
|
||||
if (!$tpl) {
|
||||
if (! $tpl) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ public function diffTemplates(int $leftTemplateId, int $rightTemplateId): array
|
||||
$left = BomTemplate::query()->where('tenant_id', $tenantId)->find($leftTemplateId);
|
||||
$right = BomTemplate::query()->where('tenant_id', $tenantId)->find($rightTemplateId);
|
||||
|
||||
if (!$left || !$right) {
|
||||
if (! $left || ! $right) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -310,30 +310,30 @@ public function diffTemplates(int $leftTemplateId, int $rightTemplateId): array
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('bom_template_id', $left->id)
|
||||
->get()
|
||||
->map(fn($i) => [
|
||||
'key' => strtoupper($i->ref_type) . ':' . (int)$i->ref_id,
|
||||
'ref_type' => strtoupper($i->ref_type),
|
||||
'ref_id' => (int)$i->ref_id,
|
||||
'qty' => (float)$i->qty,
|
||||
'waste_rate' => (float)$i->waste_rate,
|
||||
'uom_id' => $i->uom_id ? (int)$i->uom_id : null,
|
||||
'notes' => $i->notes,
|
||||
'sort_order' => (int)$i->sort_order,
|
||||
->map(fn ($i) => [
|
||||
'key' => strtoupper($i->ref_type).':'.(int) $i->ref_id,
|
||||
'ref_type' => strtoupper($i->ref_type),
|
||||
'ref_id' => (int) $i->ref_id,
|
||||
'qty' => (float) $i->qty,
|
||||
'waste_rate' => (float) $i->waste_rate,
|
||||
'uom_id' => $i->uom_id ? (int) $i->uom_id : null,
|
||||
'notes' => $i->notes,
|
||||
'sort_order' => (int) $i->sort_order,
|
||||
])->keyBy('key');
|
||||
|
||||
$rightItems = BomTemplateItem::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('bom_template_id', $right->id)
|
||||
->get()
|
||||
->map(fn($i) => [
|
||||
'key' => strtoupper($i->ref_type) . ':' . (int)$i->ref_id,
|
||||
'ref_type' => strtoupper($i->ref_type),
|
||||
'ref_id' => (int)$i->ref_id,
|
||||
'qty' => (float)$i->qty,
|
||||
'waste_rate' => (float)$i->waste_rate,
|
||||
'uom_id' => $i->uom_id ? (int)$i->uom_id : null,
|
||||
'notes' => $i->notes,
|
||||
'sort_order' => (int)$i->sort_order,
|
||||
->map(fn ($i) => [
|
||||
'key' => strtoupper($i->ref_type).':'.(int) $i->ref_id,
|
||||
'ref_type' => strtoupper($i->ref_type),
|
||||
'ref_id' => (int) $i->ref_id,
|
||||
'qty' => (float) $i->qty,
|
||||
'waste_rate' => (float) $i->waste_rate,
|
||||
'uom_id' => $i->uom_id ? (int) $i->uom_id : null,
|
||||
'notes' => $i->notes,
|
||||
'sort_order' => (int) $i->sort_order,
|
||||
])->keyBy('key');
|
||||
|
||||
$added = [];
|
||||
@@ -341,40 +341,40 @@ public function diffTemplates(int $leftTemplateId, int $rightTemplateId): array
|
||||
$changed = [];
|
||||
|
||||
foreach ($rightItems as $key => $ri) {
|
||||
if (!$leftItems->has($key)) {
|
||||
if (! $leftItems->has($key)) {
|
||||
$added[] = Arr::except($ri, ['key']);
|
||||
} else {
|
||||
$li = $leftItems[$key];
|
||||
$diffs = [];
|
||||
foreach (['qty','waste_rate','uom_id','notes','sort_order'] as $fld) {
|
||||
foreach (['qty', 'waste_rate', 'uom_id', 'notes', 'sort_order'] as $fld) {
|
||||
if (($li[$fld] ?? null) !== ($ri[$fld] ?? null)) {
|
||||
$diffs[$fld] = ['before' => $li[$fld] ?? null, 'after' => $ri[$fld] ?? null];
|
||||
}
|
||||
}
|
||||
if (!empty($diffs)) {
|
||||
if (! empty($diffs)) {
|
||||
$changed[] = [
|
||||
'ref_type' => $ri['ref_type'],
|
||||
'ref_id' => $ri['ref_id'],
|
||||
'changes' => $diffs,
|
||||
'ref_id' => $ri['ref_id'],
|
||||
'changes' => $diffs,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($leftItems as $key => $li) {
|
||||
if (!$rightItems->has($key)) {
|
||||
if (! $rightItems->has($key)) {
|
||||
$removed[] = Arr::except($li, ['key']);
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
'left_template_id' => $left->id,
|
||||
'left_template_id' => $left->id,
|
||||
'right_template_id' => $right->id,
|
||||
'summary' => [
|
||||
'added' => count($added),
|
||||
'added' => count($added),
|
||||
'removed' => count($removed),
|
||||
'changed' => count($changed),
|
||||
],
|
||||
'added' => $added,
|
||||
'added' => $added,
|
||||
'removed' => $removed,
|
||||
'changed' => $changed,
|
||||
];
|
||||
@@ -399,7 +399,7 @@ public function cloneTemplate(int $templateId, ?int $targetVersionId = null, ?st
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$src = BomTemplate::query()->where('tenant_id', $tenantId)->find($templateId);
|
||||
if (!$src) {
|
||||
if (! $src) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -409,29 +409,29 @@ public function cloneTemplate(int $templateId, ?int $targetVersionId = null, ?st
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($targetVersionId);
|
||||
|
||||
if (!$mv) {
|
||||
if (! $mv) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
// 이름 결정(중복 회피)
|
||||
$baseName = $name ?: ($src->name . ' Copy');
|
||||
$baseName = $name ?: ($src->name.' Copy');
|
||||
$newName = $baseName;
|
||||
$i = 2;
|
||||
while (BomTemplate::query()
|
||||
->where('model_version_id', $mv->id)
|
||||
->where('name', $newName)
|
||||
->exists()) {
|
||||
$newName = $baseName . ' ' . $i;
|
||||
$newName = $baseName.' '.$i;
|
||||
$i++;
|
||||
}
|
||||
|
||||
return DB::transaction(function () use ($tenantId, $src, $mv, $newName, $isPrimary, $notes) {
|
||||
$dest = BomTemplate::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'tenant_id' => $tenantId,
|
||||
'model_version_id' => $mv->id,
|
||||
'name' => $newName,
|
||||
'is_primary' => $isPrimary,
|
||||
'notes' => $notes ?? $src->notes,
|
||||
'name' => $newName,
|
||||
'is_primary' => $isPrimary,
|
||||
'notes' => $notes ?? $src->notes,
|
||||
]);
|
||||
|
||||
$now = now();
|
||||
@@ -439,21 +439,21 @@ public function cloneTemplate(int $templateId, ?int $targetVersionId = null, ?st
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('bom_template_id', $src->id)
|
||||
->get()
|
||||
->map(fn($i) => [
|
||||
'tenant_id' => $tenantId,
|
||||
->map(fn ($i) => [
|
||||
'tenant_id' => $tenantId,
|
||||
'bom_template_id' => $dest->id,
|
||||
'ref_type' => strtoupper($i->ref_type),
|
||||
'ref_id' => (int)$i->ref_id,
|
||||
'qty' => (string)$i->qty,
|
||||
'waste_rate' => (string)$i->waste_rate,
|
||||
'uom_id' => $i->uom_id,
|
||||
'notes' => $i->notes,
|
||||
'sort_order' => (int)$i->sort_order,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
'ref_type' => strtoupper($i->ref_type),
|
||||
'ref_id' => (int) $i->ref_id,
|
||||
'qty' => (string) $i->qty,
|
||||
'waste_rate' => (string) $i->waste_rate,
|
||||
'uom_id' => $i->uom_id,
|
||||
'notes' => $i->notes,
|
||||
'sort_order' => (int) $i->sort_order,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
])->all();
|
||||
|
||||
if (!empty($items)) {
|
||||
if (! empty($items)) {
|
||||
BomTemplateItem::insert($items);
|
||||
}
|
||||
|
||||
@@ -487,7 +487,7 @@ public function validateForRelease(int $modelVersionId): void
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($modelVersionId);
|
||||
|
||||
if (!$mv) {
|
||||
if (! $mv) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ public function validateForRelease(int $modelVersionId): void
|
||||
->where('is_primary', true)
|
||||
->first();
|
||||
|
||||
if (!$primary) {
|
||||
if (! $primary) {
|
||||
throw ValidationException::withMessages(['template' => __('error.validation_failed')]);
|
||||
}
|
||||
|
||||
@@ -515,17 +515,17 @@ public function validateForRelease(int $modelVersionId): void
|
||||
// 중복 키 및 값 검증
|
||||
$seen = [];
|
||||
foreach ($items as $idx => $it) {
|
||||
$key = strtoupper($it->ref_type) . ':' . (int)$it->ref_id;
|
||||
$key = strtoupper($it->ref_type).':'.(int) $it->ref_id;
|
||||
if (isset($seen[$key])) {
|
||||
throw ValidationException::withMessages(["items.$idx" => __('error.duplicate')]);
|
||||
}
|
||||
$seen[$key] = true;
|
||||
|
||||
// 수량/로스율
|
||||
if ((float)$it->qty <= 0) {
|
||||
if ((float) $it->qty <= 0) {
|
||||
throw ValidationException::withMessages(["items.$idx.qty" => __('error.validation_failed')]);
|
||||
}
|
||||
if ((float)$it->waste_rate < 0) {
|
||||
if ((float) $it->waste_rate < 0) {
|
||||
throw ValidationException::withMessages(["items.$idx.waste_rate" => __('error.validation_failed')]);
|
||||
}
|
||||
|
||||
@@ -536,7 +536,7 @@ public function validateForRelease(int $modelVersionId): void
|
||||
->where('id', $it->ref_id)
|
||||
->whereNull('deleted_at')
|
||||
->exists();
|
||||
if (!$exists) {
|
||||
if (! $exists) {
|
||||
throw ValidationException::withMessages(["items.$idx.ref_id" => __('error.not_found')]);
|
||||
}
|
||||
} elseif (strtoupper($it->ref_type) === 'PRODUCT') {
|
||||
@@ -545,7 +545,7 @@ public function validateForRelease(int $modelVersionId): void
|
||||
->where('id', $it->ref_id)
|
||||
->whereNull('deleted_at')
|
||||
->exists();
|
||||
if (!$exists) {
|
||||
if (! $exists) {
|
||||
throw ValidationException::withMessages(["items.$idx.ref_id" => __('error.not_found')]);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -45,6 +45,7 @@ public function create(array $data): DesignModel
|
||||
|
||||
return DB::transaction(function () use ($tenantId, $data) {
|
||||
$payload = array_merge($data, ['tenant_id' => $tenantId]);
|
||||
|
||||
return DesignModel::create($payload);
|
||||
});
|
||||
}
|
||||
@@ -55,10 +56,10 @@ public function find(int $id): DesignModel
|
||||
$tenantId = $this->tenantId();
|
||||
$model = DesignModel::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->with(['versions' => fn($q) => $q->orderBy('version_no')])
|
||||
->with(['versions' => fn ($q) => $q->orderBy('version_no')])
|
||||
->find($id);
|
||||
|
||||
if (!$model) {
|
||||
if (! $model) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ public function update(int $id, array $data): DesignModel
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($id);
|
||||
|
||||
if (!$model) {
|
||||
if (! $model) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -103,7 +104,7 @@ public function delete(int $id): void
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($id);
|
||||
|
||||
if (!$model) {
|
||||
if (! $model) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public function listByModel(int $modelId)
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($modelId);
|
||||
|
||||
if (!$model) {
|
||||
if (! $model) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public function createDraft(int $modelId, array $extra = []): ModelVersion
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($modelId);
|
||||
|
||||
if (!$model) {
|
||||
if (! $model) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public function createDraft(int $modelId, array $extra = []): ModelVersion
|
||||
$max = ModelVersion::query()
|
||||
->where('model_id', $model->id)
|
||||
->max('version_no');
|
||||
$versionNo = (int)($max ?? 0) + 1;
|
||||
$versionNo = (int) ($max ?? 0) + 1;
|
||||
} else {
|
||||
$exists = ModelVersion::query()
|
||||
->where('model_id', $model->id)
|
||||
@@ -63,14 +63,14 @@ public function createDraft(int $modelId, array $extra = []): ModelVersion
|
||||
}
|
||||
|
||||
return ModelVersion::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'model_id' => $model->id,
|
||||
'version_no' => $versionNo,
|
||||
'status' => 'DRAFT',
|
||||
'is_active' => true,
|
||||
'notes' => $extra['notes'] ?? null,
|
||||
'tenant_id' => $tenantId,
|
||||
'model_id' => $model->id,
|
||||
'version_no' => $versionNo,
|
||||
'status' => 'DRAFT',
|
||||
'is_active' => true,
|
||||
'notes' => $extra['notes'] ?? null,
|
||||
'effective_from' => $extra['effective_from'] ?? null,
|
||||
'effective_to' => $extra['effective_to'] ?? null,
|
||||
'effective_to' => $extra['effective_to'] ?? null,
|
||||
]);
|
||||
});
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public function release(int $versionId): ModelVersion
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($versionId);
|
||||
|
||||
if (!$mv) {
|
||||
if (! $mv) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user