Files
sam-api/app/Models/Tenants/ShipmentItem.php
권혁성 d7c096b615 feat: [shipment] MES 데이터 정합성 개선 — can_ship 검증, ShipmentItem FK, 재고차감 비활성화
- ShipmentService::updateStatus()에 can_ship 검증 추가 (ready/shipping/completed 전환 시)
- shipment_items에 order_item_id, work_order_item_id 컬럼+인덱스 추가 (마이그레이션)
- ShipmentItem 모델에 orderItem(), workOrderItem() 관계 추가
- createShipmentFromOrder()에서 order_item_id, work_order_item_id 자동 매핑
- decreaseStockForShipment() 호출 비활성화 (수주생산=재고 미경유, 선생산=자재 투입 시 차감)
2026-03-13 22:45:43 +09:00

85 lines
1.8 KiB
PHP

<?php
namespace App\Models\Tenants;
use App\Traits\Auditable;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class ShipmentItem extends Model
{
use Auditable, BelongsToTenant, SoftDeletes;
protected $fillable = [
'tenant_id',
'shipment_id',
'seq',
'item_id',
'item_code',
'item_name',
'floor_unit',
'specification',
'quantity',
'unit',
'lot_no',
'stock_lot_id',
'order_item_id',
'work_order_item_id',
'remarks',
];
protected $casts = [
'seq' => 'integer',
'item_id' => 'integer',
'quantity' => 'decimal:2',
'shipment_id' => 'integer',
'stock_lot_id' => 'integer',
'order_item_id' => 'integer',
'work_order_item_id' => 'integer',
];
/**
* 출하 관계
*/
public function shipment(): BelongsTo
{
return $this->belongsTo(Shipment::class);
}
/**
* 재고 LOT 관계
*/
public function stockLot(): BelongsTo
{
return $this->belongsTo(StockLot::class);
}
/**
* 수주 품목 관계
*/
public function orderItem(): BelongsTo
{
return $this->belongsTo(\App\Models\Orders\OrderItem::class);
}
/**
* 작업지시 품목 관계
*/
public function workOrderItem(): BelongsTo
{
return $this->belongsTo(\App\Models\WorkOrders\WorkOrderItem::class);
}
/**
* 다음 순번 가져오기
*/
public static function getNextSeq(int $shipmentId): int
{
$maxSeq = static::where('shipment_id', $shipmentId)->max('seq');
return ($maxSeq ?? 0) + 1;
}
}