style: Laravel Pint 코드 포맷팅 적용
- PSR-12 스타일 가이드 준수 - 302개 파일 스타일 이슈 자동 수정 - 코드 로직 변경 없음 (포맷팅만)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user