93 lines
2.1 KiB
PHP
93 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Tms\Models;
|
|
|
|
use App\BusinessLocation;
|
|
use App\Contact;
|
|
use App\Transaction;
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Shipment extends Model
|
|
{
|
|
protected $table = 'tms_shipments';
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
public function customsClearance()
|
|
{
|
|
return $this->hasOne(CustomsClearance::class, 'shipment_id');
|
|
}
|
|
|
|
protected $casts = [
|
|
'scheduled_at' => 'datetime',
|
|
'pickup_at' => 'datetime',
|
|
'delivered_at' => 'datetime',
|
|
'freight_cost' => 'decimal:4',
|
|
'weight' => 'decimal:2',
|
|
'volume' => 'decimal:2',
|
|
'destination_latitude' => 'decimal:7',
|
|
'destination_longitude' => 'decimal:7',
|
|
];
|
|
|
|
public function transaction()
|
|
{
|
|
return $this->belongsTo(Transaction::class, 'transaction_id');
|
|
}
|
|
|
|
public function project()
|
|
{
|
|
return $this->belongsTo(\Modules\Project\Entities\Project::class, 'pjt_project_id');
|
|
}
|
|
|
|
public function fieldMission()
|
|
{
|
|
return $this->belongsTo(\Modules\Maintenance\Models\FieldMission::class, 'source_id');
|
|
}
|
|
|
|
public function isFieldMissionShipment(): bool
|
|
{
|
|
return $this->source_type === 'field_mission' && ! empty($this->source_id);
|
|
}
|
|
|
|
public function contact()
|
|
{
|
|
return $this->belongsTo(Contact::class, 'contact_id');
|
|
}
|
|
|
|
public function carrier()
|
|
{
|
|
return $this->belongsTo(Carrier::class, 'carrier_id');
|
|
}
|
|
|
|
public function route()
|
|
{
|
|
return $this->belongsTo(RoutePlan::class, 'route_id');
|
|
}
|
|
|
|
public function vehicle()
|
|
{
|
|
return $this->belongsTo(Vehicle::class, 'vehicle_id');
|
|
}
|
|
|
|
public function driver()
|
|
{
|
|
return $this->belongsTo(Driver::class, 'driver_id');
|
|
}
|
|
|
|
public function originLocation()
|
|
{
|
|
return $this->belongsTo(BusinessLocation::class, 'origin_location_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function statusLogs()
|
|
{
|
|
return $this->hasMany(ShipmentStatusLog::class, 'shipment_id')->orderByDesc('logged_at');
|
|
}
|
|
}
|