'decimal:3', 'volumetric_weight' => 'decimal:3', 'chargeable_weight' => 'decimal:3', 'status' => \App\Enums\ShipmentStatus::class, 'direction' => \App\Enums\ShipmentDirection::class, 'type' => \App\Enums\ShipmentType::class, ]; // === Relationships === public function fromCountry(): BelongsTo { return $this->belongsTo(Country::class, 'from_country_id'); } public function toCountry(): BelongsTo { return $this->belongsTo(Country::class, 'to_country_id'); } public function items(): HasMany { return $this->hasMany(ShipmentItem::class); } public function carrierMappings(): HasMany { return $this->hasMany(ShipmentCarrierMapping::class); } public function trackingEvents(): HasMany { return $this->hasMany(ShipmentTrackingEvent::class); } /** * بسته‌های مرسوله (Multi-Package) */ public function packages(): HasMany { return $this->hasMany(ShipmentPackage::class); } // === Scopes === public function scopeByAwb($query, string $awbNo) { return $query->where('awb_no', $awbNo); } public function scopeExport($query) { return $query->where('direction', 'export'); } public function scopeImport($query) { return $query->where('direction', 'import'); } // === Helpers === /** * دریافت آخرین رویداد ترکینگ */ public function latestTrackingEvent() { return $this->trackingEvents() ->orderBy('event_date', 'desc') ->orderBy('event_time', 'desc') ->first(); } /** * آیا مرسوله تحویل داده شده؟ */ public function isDelivered(): bool { return $this->status === 'delivered'; } }