diff --git a/app/Models/Materials/Material.php b/app/Models/Materials/Material.php index 8d81e07..63d267f 100644 --- a/app/Models/Materials/Material.php +++ b/app/Models/Materials/Material.php @@ -18,6 +18,23 @@ class Material extends Model { use SoftDeletes, ModelTrait, BelongsToTenant; + protected $fillable = [ + 'tenant_id', + 'category_id', + 'name', + 'item_name', + 'specification', + 'material_code', + 'unit', + 'is_inspection', + 'search_tag', + 'remarks', + 'attributes', + 'options', + 'created_by', + 'updated_by', + ]; + protected $casts = [ 'attributes' => 'array', 'options' => 'array', diff --git a/app/Models/Members/User.php b/app/Models/Members/User.php index 33499b6..916455d 100644 --- a/app/Models/Members/User.php +++ b/app/Models/Members/User.php @@ -5,6 +5,7 @@ use App\Models\Commons\File; use App\Models\Tenants\Tenant; use App\Traits\ModelTrait; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; diff --git a/app/Models/Products/Product.php b/app/Models/Products/Product.php index daafe17..bee1269 100644 --- a/app/Models/Products/Product.php +++ b/app/Models/Products/Product.php @@ -15,19 +15,19 @@ class Product extends Model use SoftDeletes, BelongsToTenant, ModelTrait; protected $fillable = [ - 'tenant_id','code','name','category_id', + 'tenant_id','code','name','unit','category_id', 'product_type', // 라벨/분류용 - 'attributes','description','is_active', - 'is_sellable','is_purchasable','is_producible', + 'attributes','description', + 'is_sellable','is_purchasable','is_producible','is_active', 'created_by','updated_by' ]; protected $casts = [ 'attributes' => 'array', - 'is_active' => 'boolean', 'is_sellable' => 'boolean', 'is_purchasable' => 'boolean', 'is_producible' => 'boolean', + 'is_active' => 'boolean', ]; protected $hidden = [ diff --git a/app/Models/Products/ProductComponent.php b/app/Models/Products/ProductComponent.php index 00ccbc2..8c1ff90 100644 --- a/app/Models/Products/ProductComponent.php +++ b/app/Models/Products/ProductComponent.php @@ -28,8 +28,7 @@ class ProductComponent extends Model ]; protected $casts = [ - 'quantity' => 'decimal:4', - 'is_default' => 'boolean', + 'quantity' => 'decimal:6', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', @@ -39,7 +38,6 @@ class ProductComponent extends Model 'deleted_at', ]; - /** * 상위 제품 (모델/제품) */ @@ -49,19 +47,35 @@ public function parentProduct() } /** - * 하위 제품 (ref_type = PRODUCT일 때만 의미 있음) + * 참조된 제품 또는 자재를 동적으로 가져오기 + * ref_type에 따라 Product 또는 Material을 반환 */ - public function childProduct() + public function referencedItem() { - return $this->belongsTo(Product::class, 'child_product_id'); + if ($this->ref_type === 'PRODUCT') { + return $this->belongsTo(Product::class, 'ref_id'); + } elseif ($this->ref_type === 'MATERIAL') { + return $this->belongsTo(Material::class, 'ref_id'); + } + return null; } /** - * 하위 자재 (ref_type = MATERIAL일 때만 의미 있음) + * 하위 제품 (ref_type = PRODUCT일 때만) + */ + public function product() + { + return $this->belongsTo(Product::class, 'ref_id') + ->where('ref_type', 'PRODUCT'); + } + + /** + * 하위 자재 (ref_type = MATERIAL일 때만) */ public function material() { - return $this->belongsTo(Material::class, 'material_id'); + return $this->belongsTo(Material::class, 'ref_id') + ->where('ref_type', 'MATERIAL'); } // --------------------------------------------------- diff --git a/app/Models/Tenants/Tenant.php b/app/Models/Tenants/Tenant.php index 50b7f31..b2a73c5 100644 --- a/app/Models/Tenants/Tenant.php +++ b/app/Models/Tenants/Tenant.php @@ -50,6 +50,7 @@ class Tenant extends Model 'expires_at' => 'datetime', 'last_paid_at' => 'datetime', 'max_users' => 'integer', + 'options' => 'array', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', @@ -59,6 +60,30 @@ class Tenant extends Model 'deleted_at', ]; + /** + * 활성화된 테넌트만 조회하는 스코프 + */ + public function scopeActive($query) + { + return $query->whereIn('tenant_st_code', ['trial', 'active']); + } + + /** + * 테넌트가 활성 상태인지 확인 + */ + public function isActive(): bool + { + return in_array($this->tenant_st_code, ['trial', 'active']); + } + + /** + * 테넌트가 트라이얼 상태인지 확인 + */ + public function isTrial(): bool + { + return $this->tenant_st_code === 'trial'; + } + // 관계 정의 (예시) public function plan() {