diff --git a/app/Services/ItemService.php b/app/Services/ItemService.php index 1f56075..9ab0168 100644 --- a/app/Services/ItemService.php +++ b/app/Services/ItemService.php @@ -7,6 +7,8 @@ use App\Models\ItemMaster\ItemPage; use App\Models\Items\Item; use App\Models\Items\ItemDetail; +use App\Models\Products\CommonCode; +use App\Models\Scopes\TenantScope; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Database\Eloquent\Model; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -425,7 +427,18 @@ public function index(array $params): LengthAwarePaginator } } - $paginator = $query->orderBy('id', 'desc')->paginate($size); + // common_codes에서 item_type 한글명 조회 (서브쿼리로 컬럼 충돌 방지) + $tableName = $query->getModel()->getTable(); + $query->addSelect([ + 'item_type_name' => CommonCode::withoutGlobalScope(TenantScope::class) + ->select('name') + ->whereColumn('code', "{$tableName}.item_type") + ->where('code_group', 'item_type') + ->where('is_active', true) + ->limit(1), + ]); + + $paginator = $query->orderBy("{$tableName}.id", 'desc')->paginate($size); // 날짜 형식 변환, files 그룹화, options 펼침, code → item_code $paginator->setCollection( @@ -702,6 +715,12 @@ public function update(int $id, array $data): Model $this->validateBom($data['bom'], $id); } + // attributes 병합 (기존 값 보존, 새 값으로 덮어쓰기) + if (isset($data['attributes']) && is_array($data['attributes'])) { + $existingAttributes = is_array($item->attributes) ? $item->attributes : []; + $data['attributes'] = array_merge($existingAttributes, $data['attributes']); + } + // 테이블 업데이트 $itemData = array_intersect_key($data, array_flip([ 'item_type', 'code', 'name', 'unit', 'category_id', diff --git a/database/migrations/2026_02_02_103000_add_gcs_uri_to_sales_consultations.php b/database/migrations/2026_02_02_103000_add_gcs_uri_to_sales_consultations.php deleted file mode 100644 index cf5248d..0000000 --- a/database/migrations/2026_02_02_103000_add_gcs_uri_to_sales_consultations.php +++ /dev/null @@ -1,31 +0,0 @@ -string('gcs_uri', 500)->nullable()->after('duration')->comment('GCS 저장 URI'); - }); - } - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('sales_consultations', function (Blueprint $table) { - $table->dropColumn('gcs_uri'); - }); - } -};