2025-08-22 15:57:14 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Products;
|
|
|
|
|
|
2025-08-29 16:22:05 +09:00
|
|
|
use App\Models\Materials\Material;
|
2025-11-06 17:45:49 +09:00
|
|
|
use App\Traits\BelongsToTenant;
|
|
|
|
|
use App\Traits\ModelTrait;
|
2025-08-22 15:57:14 +09:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
|
|
class ProductComponent extends Model
|
|
|
|
|
{
|
2025-11-06 17:45:49 +09:00
|
|
|
use BelongsToTenant, ModelTrait, SoftDeletes;
|
2025-08-22 15:57:14 +09:00
|
|
|
|
|
|
|
|
protected $table = 'product_components';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
2025-08-25 17:46:34 +09:00
|
|
|
'tenant_id',
|
|
|
|
|
'parent_product_id',
|
2025-08-29 16:22:05 +09:00
|
|
|
'category_id',
|
|
|
|
|
'category_name',
|
2025-08-25 17:46:34 +09:00
|
|
|
'ref_type',
|
2025-08-29 16:22:05 +09:00
|
|
|
'ref_id',
|
2025-08-25 17:46:34 +09:00
|
|
|
'quantity',
|
|
|
|
|
'sort_order',
|
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
|
|
|
// 하이브리드 구조: 고정 필드 (범용 BOM 계산)
|
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
|
|
|
'quantity_formula',
|
|
|
|
|
'condition',
|
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',
|
2025-08-25 17:46:34 +09:00
|
|
|
'created_by',
|
|
|
|
|
'updated_by',
|
2025-08-22 15:57:14 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
2025-11-06 17:45:49 +09:00
|
|
|
'quantity' => 'decimal:6',
|
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' => 'array',
|
2025-08-25 17:46:34 +09:00
|
|
|
'created_at' => 'datetime',
|
|
|
|
|
'updated_at' => 'datetime',
|
|
|
|
|
'deleted_at' => 'datetime',
|
2025-08-22 15:57:14 +09:00
|
|
|
];
|
|
|
|
|
|
2025-08-25 17:46:34 +09:00
|
|
|
protected $hidden = [
|
|
|
|
|
'deleted_at',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 상위 제품 (모델/제품)
|
|
|
|
|
*/
|
|
|
|
|
public function parentProduct()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Product::class, 'parent_product_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-30 14:35:26 +09:00
|
|
|
* 참조된 제품 또는 자재를 동적으로 가져오기
|
|
|
|
|
* ref_type에 따라 Product 또는 Material을 반환
|
|
|
|
|
*/
|
|
|
|
|
public function referencedItem()
|
|
|
|
|
{
|
|
|
|
|
if ($this->ref_type === 'PRODUCT') {
|
|
|
|
|
return $this->belongsTo(Product::class, 'ref_id');
|
|
|
|
|
} elseif ($this->ref_type === 'MATERIAL') {
|
|
|
|
|
return $this->belongsTo(Material::class, 'ref_id');
|
|
|
|
|
}
|
2025-11-06 17:45:49 +09:00
|
|
|
|
2025-09-30 14:35:26 +09:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 하위 제품 (ref_type = PRODUCT일 때만)
|
2025-08-25 17:46:34 +09:00
|
|
|
*/
|
2025-09-30 14:35:26 +09:00
|
|
|
public function product()
|
2025-08-25 17:46:34 +09:00
|
|
|
{
|
2025-09-30 14:35:26 +09:00
|
|
|
return $this->belongsTo(Product::class, 'ref_id')
|
|
|
|
|
->where('ref_type', 'PRODUCT');
|
2025-08-25 17:46:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-30 14:35:26 +09:00
|
|
|
* 하위 자재 (ref_type = MATERIAL일 때만)
|
2025-08-25 17:46:34 +09:00
|
|
|
*/
|
|
|
|
|
public function material()
|
|
|
|
|
{
|
2025-09-30 14:35:26 +09:00
|
|
|
return $this->belongsTo(Material::class, 'ref_id')
|
|
|
|
|
->where('ref_type', 'MATERIAL');
|
2025-08-25 17:46:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
// 🔎 Query Scopes
|
|
|
|
|
// ---------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 제품 BOM 아이템만
|
|
|
|
|
*/
|
|
|
|
|
public function scopeProducts($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('ref_type', 'PRODUCT');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 자재 BOM 아이템만
|
|
|
|
|
*/
|
|
|
|
|
public function scopeMaterials($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('ref_type', 'MATERIAL');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 특정 상위 제품의 BOM
|
|
|
|
|
*/
|
|
|
|
|
public function scopeForParent($query, int $parentProductId)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('parent_product_id', $parentProductId);
|
|
|
|
|
}
|
2025-08-22 15:57:14 +09:00
|
|
|
}
|