2025-07-23 15:41:01 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Products;
|
|
|
|
|
|
2025-08-22 15:57:14 +09:00
|
|
|
use App\Models\Commons\Category;
|
2025-07-29 17:20:44 +09:00
|
|
|
use App\Models\Commons\File;
|
|
|
|
|
use App\Models\Commons\Tag;
|
2025-08-22 15:57:14 +09:00
|
|
|
use App\Traits\BelongsToTenant;
|
|
|
|
|
use App\Traits\ModelTrait;
|
2025-07-23 15:41:01 +09:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
|
|
class Product extends Model
|
|
|
|
|
{
|
2025-11-06 17:45:49 +09:00
|
|
|
use BelongsToTenant, ModelTrait, SoftDeletes;
|
2025-07-23 15:41:01 +09:00
|
|
|
|
2025-08-22 15:57:14 +09:00
|
|
|
protected $fillable = [
|
2025-11-06 17:45:49 +09:00
|
|
|
'tenant_id', 'code', 'name', 'unit', 'category_id',
|
2025-08-27 18:13:49 +09:00
|
|
|
'product_type', // 라벨/분류용
|
2025-11-06 17:45:49 +09:00
|
|
|
'attributes', 'description',
|
feat: BP-MES Phase 1 모델 업데이트 및 Seeder 실행
[모델 업데이트]
- Product 모델: 하이브리드 구조 필드로 fillable/casts 간소화
- 고정 필드: safety_stock, lead_time, is_variable_size, product_category, part_type, attributes_archive
- 동적 필드: attributes JSON (category_fields로 관리)
- 제거: BP-MES 전용 33개 필드 (이제 attributes에 저장)
- ProductComponent 모델: BOM 계산 필드 + 동적 필드
- 고정 필드: quantity_formula, condition
- 동적 필드: attributes JSON
- 제거: is_bending, bending_diagram, bending_details (이제 attributes에 저장)
[Seeder 실행]
- BpMesCategoryFieldsSeeder: FG/PT/절곡품 카테고리 및 필드 생성
- BpMesTenantStatFieldsSeeder: 통계 필드 설정 (마진율, 가공비, 인건비, 설치비 등)
[검증 완료]
- Tinker 모델 테스트 통과
- Pint 코드 포맷팅 검사 통과
2025-11-14 11:11:55 +09:00
|
|
|
'is_sellable', 'is_purchasable', 'is_producible',
|
|
|
|
|
// 하이브리드 구조: 최소 고정 필드
|
feat: BP-MES Phase 1 - products/product_components 테이블 확장
- products 테이블에 33개 필드 추가
- 공통: is_active, margin_rate, costs, safety_stock, lead_time, is_variable_size
- FG 전용: product_category, lot_abbreviation, note
- PT 전용: part_type, part_usage, installation_type, assembly_type,
side_spec_width, side_spec_height, assembly_length,
guide_rail_model_type, guide_rail_model
- 절곡품: bending_diagram, bending_details, material, length, bending_length
- 인증: certification_number, start/end_date, specification/certification files
- 동적 확장: options (JSON)
- product_components 테이블에 5개 필드 추가
- 수식 계산: quantity_formula
- 조건부 BOM: condition
- 절곡품: is_bending, bending_diagram, bending_details
- Product/ProductComponent 모델 fillable/casts 업데이트
- 인덱스 추가: is_active, product_category, part_type, part_usage, is_bending
2025-11-14 09:07:33 +09:00
|
|
|
'safety_stock', 'lead_time', 'is_variable_size',
|
feat: BP-MES Phase 1 모델 업데이트 및 Seeder 실행
[모델 업데이트]
- Product 모델: 하이브리드 구조 필드로 fillable/casts 간소화
- 고정 필드: safety_stock, lead_time, is_variable_size, product_category, part_type, attributes_archive
- 동적 필드: attributes JSON (category_fields로 관리)
- 제거: BP-MES 전용 33개 필드 (이제 attributes에 저장)
- ProductComponent 모델: BOM 계산 필드 + 동적 필드
- 고정 필드: quantity_formula, condition
- 동적 필드: attributes JSON
- 제거: is_bending, bending_diagram, bending_details (이제 attributes에 저장)
[Seeder 실행]
- BpMesCategoryFieldsSeeder: FG/PT/절곡품 카테고리 및 필드 생성
- BpMesTenantStatFieldsSeeder: 통계 필드 설정 (마진율, 가공비, 인건비, 설치비 등)
[검증 완료]
- Tinker 모델 테스트 통과
- Pint 코드 포맷팅 검사 통과
2025-11-14 11:11:55 +09:00
|
|
|
'product_category', 'part_type',
|
|
|
|
|
'attributes_archive',
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
// 파일 필드
|
|
|
|
|
'bending_diagram', 'bending_details',
|
|
|
|
|
'specification_file', 'specification_file_name',
|
|
|
|
|
'certification_file', 'certification_file_name',
|
|
|
|
|
'certification_number', 'certification_start_date', 'certification_end_date',
|
2025-11-17 14:55:31 +09:00
|
|
|
'created_by', 'updated_by', 'is_active',
|
2025-08-22 15:57:14 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
2025-11-06 17:45:49 +09:00
|
|
|
'attributes' => 'array',
|
feat: BP-MES Phase 1 모델 업데이트 및 Seeder 실행
[모델 업데이트]
- Product 모델: 하이브리드 구조 필드로 fillable/casts 간소화
- 고정 필드: safety_stock, lead_time, is_variable_size, product_category, part_type, attributes_archive
- 동적 필드: attributes JSON (category_fields로 관리)
- 제거: BP-MES 전용 33개 필드 (이제 attributes에 저장)
- ProductComponent 모델: BOM 계산 필드 + 동적 필드
- 고정 필드: quantity_formula, condition
- 동적 필드: attributes JSON
- 제거: is_bending, bending_diagram, bending_details (이제 attributes에 저장)
[Seeder 실행]
- BpMesCategoryFieldsSeeder: FG/PT/절곡품 카테고리 및 필드 생성
- BpMesTenantStatFieldsSeeder: 통계 필드 설정 (마진율, 가공비, 인건비, 설치비 등)
[검증 완료]
- Tinker 모델 테스트 통과
- Pint 코드 포맷팅 검사 통과
2025-11-14 11:11:55 +09:00
|
|
|
'attributes_archive' => 'array',
|
feat: 품목 파일 업로드 API 구현 (절곡도, 시방서, 인정서)
- Products 테이블에 9개 파일 관련 필드 추가
- bending_diagram, bending_details (JSON)
- specification_file, specification_file_name
- certification_file, certification_file_name
- certification_number, certification_start_date, certification_end_date
- ItemsFileController 구현 (Code-based API)
- POST /items/{code}/files - 파일 업로드
- DELETE /items/{code}/files/{type} - 파일 삭제
- 파일 타입: bending_diagram, specification, certification
- ItemsFileUploadRequest 검증
- 파일 타입별 MIME 검증 (이미지/문서)
- 파일 크기 제한 (10MB/20MB)
- 인증 정보 및 절곡 상세 정보 검증
- Swagger 문서 작성 (ItemsFileApi.php)
- 업로드/삭제 API 스펙
- 스키마: ItemFileUploadResponse, ItemFileDeleteResponse
2025-11-17 13:40:07 +09:00
|
|
|
'bending_details' => 'array',
|
|
|
|
|
'certification_start_date' => 'date',
|
|
|
|
|
'certification_end_date' => 'date',
|
2025-11-06 17:45:49 +09:00
|
|
|
'is_sellable' => 'boolean',
|
2025-08-22 15:57:14 +09:00
|
|
|
'is_purchasable' => 'boolean',
|
2025-11-06 17:45:49 +09:00
|
|
|
'is_producible' => 'boolean',
|
feat: BP-MES Phase 1 - products/product_components 테이블 확장
- products 테이블에 33개 필드 추가
- 공통: is_active, margin_rate, costs, safety_stock, lead_time, is_variable_size
- FG 전용: product_category, lot_abbreviation, note
- PT 전용: part_type, part_usage, installation_type, assembly_type,
side_spec_width, side_spec_height, assembly_length,
guide_rail_model_type, guide_rail_model
- 절곡품: bending_diagram, bending_details, material, length, bending_length
- 인증: certification_number, start/end_date, specification/certification files
- 동적 확장: options (JSON)
- product_components 테이블에 5개 필드 추가
- 수식 계산: quantity_formula
- 조건부 BOM: condition
- 절곡품: is_bending, bending_diagram, bending_details
- Product/ProductComponent 모델 fillable/casts 업데이트
- 인덱스 추가: is_active, product_category, part_type, part_usage, is_bending
2025-11-14 09:07:33 +09:00
|
|
|
'is_variable_size' => 'boolean',
|
2025-11-17 14:55:31 +09:00
|
|
|
'is_active' => 'boolean',
|
2025-08-22 15:57:14 +09:00
|
|
|
];
|
|
|
|
|
|
2025-08-27 18:13:49 +09:00
|
|
|
protected $hidden = [
|
|
|
|
|
'deleted_at',
|
|
|
|
|
];
|
|
|
|
|
|
2025-08-22 15:57:14 +09:00
|
|
|
// 분류
|
2025-11-06 17:45:49 +09:00
|
|
|
public function category()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Category::class, 'category_id');
|
|
|
|
|
}
|
2025-07-29 13:00:25 +09:00
|
|
|
|
2025-08-22 15:57:14 +09:00
|
|
|
// BOM (자기참조) — 라인 모델 경유
|
2025-08-29 16:22:05 +09:00
|
|
|
public function componentLines()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(ProductComponent::class, 'parent_product_id')->orderBy('sort_order');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 라인들
|
|
|
|
|
public function parentLines()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(ProductComponent::class, 'child_product_id');
|
|
|
|
|
} // 나를 쓰는 상위 라인들
|
2025-08-22 15:57:14 +09:00
|
|
|
|
|
|
|
|
// 편의: 직접 children/parents 제품에 접근
|
|
|
|
|
public function children()
|
2025-07-29 13:00:25 +09:00
|
|
|
{
|
2025-08-22 15:57:14 +09:00
|
|
|
return $this->belongsToMany(
|
|
|
|
|
self::class, 'product_components', 'parent_product_id', 'child_product_id'
|
2025-11-06 17:45:49 +09:00
|
|
|
)->withPivot(['quantity', 'sort_order', 'is_default'])
|
2025-08-22 15:57:14 +09:00
|
|
|
->withTimestamps();
|
2025-07-29 13:00:25 +09:00
|
|
|
}
|
2025-07-29 17:20:44 +09:00
|
|
|
|
2025-08-22 15:57:14 +09:00
|
|
|
public function parents()
|
2025-07-29 17:20:44 +09:00
|
|
|
{
|
2025-08-22 15:57:14 +09:00
|
|
|
return $this->belongsToMany(
|
|
|
|
|
self::class, 'product_components', 'child_product_id', 'parent_product_id'
|
2025-11-06 17:45:49 +09:00
|
|
|
)->withPivot(['quantity', 'sort_order', 'is_default'])
|
2025-08-22 15:57:14 +09:00
|
|
|
->withTimestamps();
|
2025-07-29 17:20:44 +09:00
|
|
|
}
|
2025-08-22 15:57:14 +09:00
|
|
|
|
|
|
|
|
// 파일 / 태그 (폴리모픽)
|
2025-11-06 17:45:49 +09:00
|
|
|
public function files()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphMany(File::class, 'fileable');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function tags()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphToMany(Tag::class, 'taggable');
|
|
|
|
|
}
|
2025-08-22 15:57:14 +09:00
|
|
|
|
|
|
|
|
// 스코프
|
2025-11-06 17:45:49 +09:00
|
|
|
public function scopeType($q, string $type)
|
|
|
|
|
{
|
|
|
|
|
return $q->where('product_type', $type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeSellable($q)
|
|
|
|
|
{
|
|
|
|
|
return $q->where('is_sellable', 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopePurchasable($q)
|
|
|
|
|
{
|
|
|
|
|
return $q->where('is_purchasable', 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function scopeProducible($q)
|
|
|
|
|
{
|
|
|
|
|
return $q->where('is_producible', 1);
|
|
|
|
|
}
|
2025-07-23 15:41:01 +09:00
|
|
|
}
|