diff --git a/app/Services/ItemMaster/ItemSectionService.php b/app/Services/ItemMaster/ItemSectionService.php index 4283a3d..b28f08f 100644 --- a/app/Services/ItemMaster/ItemSectionService.php +++ b/app/Services/ItemMaster/ItemSectionService.php @@ -3,8 +3,6 @@ namespace App\Services\ItemMaster; use App\Models\ItemMaster\EntityRelationship; -use App\Models\ItemMaster\ItemBomItem; -use App\Models\ItemMaster\ItemField; use App\Models\ItemMaster\ItemSection; use App\Services\Service; use App\Traits\LockCheckTrait; @@ -94,60 +92,28 @@ public function clone(int $id): ItemSection 'created_by' => $userId, ]); - // 필드 복제 (entity_relationships 기반) + // 기존 필드에 대한 링크만 생성 (필드는 복제하지 않음 - 링크 관계) foreach ($original->getRelation('fields') as $orderNo => $field) { - $clonedField = ItemField::create([ - 'tenant_id' => $tenantId, - 'group_id' => $field->group_id, - 'field_name' => $field->field_name, - 'field_type' => $field->field_type, - 'order_no' => $field->order_no, - 'is_required' => $field->is_required, - 'default_value' => $field->default_value, - 'placeholder' => $field->placeholder, - 'display_condition' => $field->display_condition, - 'validation_rules' => $field->validation_rules, - 'options' => $field->options, - 'properties' => $field->properties, - 'created_by' => $userId, - ]); - - // 섹션-필드 관계 생성 EntityRelationship::link( $tenantId, EntityRelationship::TYPE_SECTION, $cloned->id, EntityRelationship::TYPE_FIELD, - $clonedField->id, + $field->id, $field->order_no, null, $field->group_id ); } - // BOM 항목 복제 (entity_relationships 기반) + // 기존 BOM에 대한 링크만 생성 (BOM은 복제하지 않음 - 링크 관계) foreach ($original->getRelation('bomItems') as $orderNo => $bom) { - $clonedBom = ItemBomItem::create([ - 'tenant_id' => $tenantId, - 'group_id' => $bom->group_id, - 'item_code' => $bom->item_code, - 'item_name' => $bom->item_name, - 'quantity' => $bom->quantity, - 'unit' => $bom->unit, - 'unit_price' => $bom->unit_price, - 'total_price' => $bom->total_price, - 'spec' => $bom->spec, - 'note' => $bom->note, - 'created_by' => $userId, - ]); - - // 섹션-BOM 관계 생성 EntityRelationship::link( $tenantId, EntityRelationship::TYPE_SECTION, $cloned->id, EntityRelationship::TYPE_BOM, - $clonedBom->id, + $bom->id, $orderNo, null, $bom->group_id