92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?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');
|
|
}
|
|
|
|
// ---------------------------
|
|
// HELPERS
|
|
// ---------------------------
|
|
|
|
public function totalOrdersCount()
|
|
{
|
|
return $this->items()->count();
|
|
}
|
|
|
|
// ---------------------------
|
|
// STATUS CONSTANTS (LOGISTICS FLOW)
|
|
// ---------------------------
|
|
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';
|
|
|
|
public static function statusOptions()
|
|
{
|
|
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',
|
|
];
|
|
}
|
|
|
|
public function statusLabel()
|
|
{
|
|
return self::statusOptions()[$this->status]
|
|
?? ucfirst(str_replace('_', ' ', $this->status));
|
|
}
|
|
|
|
}
|