47 lines
937 B
PHP
47 lines
937 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
class ShipmentItem extends Model
|
||
|
|
{
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'shipment_id',
|
||
|
|
'order_id',
|
||
|
|
'order_ctn',
|
||
|
|
'order_qty',
|
||
|
|
'order_ttl_qty',
|
||
|
|
'order_ttl_amount',
|
||
|
|
'order_ttl_kg',
|
||
|
|
];
|
||
|
|
|
||
|
|
// ---------------------------
|
||
|
|
// RELATIONSHIPS
|
||
|
|
// ---------------------------
|
||
|
|
|
||
|
|
public function shipment()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Shipment::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function order()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Order::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Helper: return order data with fallback to snapshot
|
||
|
|
public function getDisplayQty()
|
||
|
|
{
|
||
|
|
return $this->order->qty ?? $this->order_qty;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getDisplayAmount()
|
||
|
|
{
|
||
|
|
return $this->order->ttl_amount ?? $this->order_ttl_amount;
|
||
|
|
}
|
||
|
|
}
|