- bom_group_key 컬럼 추가 마이그레이션 (work_order_material_inputs) - WorkOrderMaterialInput 모델 fillable에 bom_group_key 추가 - MaterialInputForItemRequest에 bom_group_key 검증 + replace 옵션 추가 - WorkOrderService.getMaterialsForItem: stock_lot_id+bom_group_key 복합키 기투입 조회 (하위호환) - WorkOrderService.registerMaterialInputForItem: bom_group_key 저장 + replace 모드 (기존 삭제→재등록) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
105 lines
2.7 KiB
PHP
105 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Production;
|
|
|
|
use App\Models\Items\Item;
|
|
use App\Models\Members\User;
|
|
use App\Models\Tenants\StockLot;
|
|
use App\Traits\Auditable;
|
|
use App\Traits\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* 개소별 자재 투입 이력 모델
|
|
*
|
|
* 작업지시 품목(개소)별 자재 투입을 추적
|
|
*/
|
|
class WorkOrderMaterialInput extends Model
|
|
{
|
|
use Auditable, BelongsToTenant;
|
|
|
|
protected $table = 'work_order_material_inputs';
|
|
|
|
protected $fillable = [
|
|
'tenant_id',
|
|
'work_order_id',
|
|
'work_order_item_id',
|
|
'stock_lot_id',
|
|
'item_id',
|
|
'bom_group_key',
|
|
'qty',
|
|
'input_by',
|
|
'input_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'qty' => 'decimal:3',
|
|
'input_at' => 'datetime',
|
|
];
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// 관계
|
|
// ──────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* 작업지시
|
|
*/
|
|
public function workOrder(): BelongsTo
|
|
{
|
|
return $this->belongsTo(WorkOrder::class);
|
|
}
|
|
|
|
/**
|
|
* 작업지시 품목 (개소)
|
|
*/
|
|
public function workOrderItem(): BelongsTo
|
|
{
|
|
return $this->belongsTo(WorkOrderItem::class);
|
|
}
|
|
|
|
/**
|
|
* 투입 로트
|
|
*/
|
|
public function stockLot(): BelongsTo
|
|
{
|
|
return $this->belongsTo(StockLot::class);
|
|
}
|
|
|
|
/**
|
|
* 자재 품목
|
|
*/
|
|
public function item(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Item::class);
|
|
}
|
|
|
|
/**
|
|
* 투입자
|
|
*/
|
|
public function inputBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'input_by');
|
|
}
|
|
|
|
// ──────────────────────────────────────────────────────────────
|
|
// 스코프
|
|
// ──────────────────────────────────────────────────────────────
|
|
|
|
/**
|
|
* 특정 개소의 투입 이력
|
|
*/
|
|
public function scopeForItem($query, int $workOrderItemId)
|
|
{
|
|
return $query->where('work_order_item_id', $workOrderItemId);
|
|
}
|
|
|
|
/**
|
|
* 특정 자재의 투입 이력
|
|
*/
|
|
public function scopeForMaterial($query, int $itemId)
|
|
{
|
|
return $query->where('item_id', $itemId);
|
|
}
|
|
}
|