Files
Kent-logistics-Laravel/app/Models/Shipment.php

92 lines
2.6 KiB
PHP
Raw Normal View History

2025-11-14 13:55:01 +05:30
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Shipment extends Model
{
use HasFactory;
protected $fillable = [
'shipment_id',
'origin',
'destination',
'total_ctn',
'total_qty',
'total_ttl_qty',
'total_amount',
'total_cbm',
'total_ttl_cbm',
'total_kg',
'total_ttl_kg',
'status',
'shipment_date',
'meta',
];
protected $casts = [
'meta' => 'array',
'shipment_date' => 'date',
];
// ---------------------------
// RELATIONSHIPS
// ---------------------------
public function items()
{
return $this->hasMany(ShipmentItem::class);
}
public function orders()
{
return $this->belongsToMany(Order::class, 'shipment_items', 'shipment_id', 'order_id');
}
// ---------------------------
2025-12-23 00:36:15 +05:30
// HELPERS
2025-11-14 13:55:01 +05:30
// ---------------------------
2025-12-23 00:36:15 +05:30
public function totalOrdersCount()
2025-11-14 13:55:01 +05:30
{
2025-12-23 00:36:15 +05:30
return $this->items()->count();
2025-11-14 13:55:01 +05:30
}
2025-12-23 00:36:15 +05:30
// ---------------------------
// STATUS CONSTANTS (LOGISTICS FLOW)
2025-11-14 13:55:01 +05:30
// ---------------------------
2025-12-23 00:36:15 +05:30
const STATUS_SHIPMENT_READY = 'shipment_ready';
const STATUS_EXPORT_CUSTOM = 'export_custom';
const STATUS_INTERNATIONAL_TRANSIT= 'international_transit';
const STATUS_ARRIVED_INDIA = 'arrived_india';
const STATUS_IMPORT_CUSTOM = 'import_custom';
const STATUS_WAREHOUSE = 'warehouse';
const STATUS_DOMESTIC_DISTRIBUTION= 'domestic_distribution';
const STATUS_OUT_FOR_DELIVERY = 'out_for_delivery';
const STATUS_DELIVERED = 'delivered';
2025-11-14 13:55:01 +05:30
2025-12-23 00:36:15 +05:30
public static function statusOptions()
2025-11-14 13:55:01 +05:30
{
2025-12-23 00:36:15 +05:30
return [
self::STATUS_SHIPMENT_READY => 'Shipment Ready',
self::STATUS_EXPORT_CUSTOM => 'Export Custom',
self::STATUS_INTERNATIONAL_TRANSIT => 'International Transit',
self::STATUS_ARRIVED_INDIA => 'Arrived at India',
self::STATUS_IMPORT_CUSTOM => 'Import Custom',
self::STATUS_WAREHOUSE => 'Warehouse',
self::STATUS_DOMESTIC_DISTRIBUTION => 'Domestic Distribution',
self::STATUS_OUT_FOR_DELIVERY => 'Out for Delivery',
self::STATUS_DELIVERED => 'Delivered',
];
2025-11-14 13:55:01 +05:30
}
public function statusLabel()
{
2025-12-23 00:36:15 +05:30
return self::statusOptions()[$this->status]
?? ucfirst(str_replace('_', ' ', $this->status));
2025-11-14 13:55:01 +05:30
}
2025-12-23 00:36:15 +05:30
2025-11-14 13:55:01 +05:30
}