ifnex/04_Laravel/app/Models/Shipment.php
Kazem Alghasi b051ce4496 feat(shipment): expand schema and enhance PDF generation
Extend the shipment database schema to support additional tracking fields,
state information, and financial data. This update also transitions
shipment documentation from RTL/Persian to LTR/English layouts and
integrates barcode generation for AWB and labels.

- feat(db): add migration for missing shipment fields (state, cod_amount,
  declared_value, etc.)
- feat(shipment): update Shipment model with new casts and helper methods
- feat(ui): refactor Filament resource to use ShipmentStatus enum and
  add new input fields
- feat(pdf): implement barcode generation using picqer/php-barcode-generator
- feat(pdf): redesign AWB, Invoice, and Label templates for LTR/English
  support
- refactor(enum): simplify ShipmentStatus enum and update labels/colors
- chore(deps): add picqer/php-barcode-generator dependency
2026-08-23 22:31:58 +03:30

94 lines
3.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Shipment extends Model
{
protected $fillable = [
'user_id', 'awb_no', 'forwarder', 'direction', 'type', 'status', 'reason_for_export',
'weight', 'volumetric_weight', 'chargeable_weight', 'dimensions',
'shipping_price', 'extra_service', 'packing_cost', 'domestic_pickup', 'domestic_delivery',
'warehousing_cost', 'vat_amount', 'discount', 'total_fee', 'net_dirham', 'net_rial',
'from_country_id', 'to_country_id',
'sender_name', 'sender_company', 'sender_phone', 'sender_email',
'sender_address', 'sender_city', 'sender_state', 'sender_zip', 'sender_id_number',
'receiver_name', 'receiver_company', 'receiver_phone', 'receiver_email',
'receiver_address', 'receiver_city', 'receiver_state', 'receiver_zip', 'receiver_id_number',
'customer_notes', 'cod_amount', 'declared_value', 'content_description',
];
protected function casts(): array
{
return [
'direction' => \App\Enums\ShipmentDirection::class,
'type' => \App\Enums\ShipmentType::class,
'status' => \App\Enums\ShipmentStatus::class,
'weight' => 'decimal:2',
'volumetric_weight' => 'decimal:2',
'chargeable_weight' => 'decimal:2',
'shipping_price' => 'decimal:2',
'extra_service' => 'decimal:2',
'packing_cost' => 'decimal:2',
'domestic_pickup' => 'decimal:2',
'domestic_delivery' => 'decimal:2',
'warehousing_cost' => 'decimal:2',
'vat_amount' => 'decimal:2',
'discount' => 'decimal:2',
'total_fee' => 'decimal:2',
'net_dirham' => 'decimal:2',
'net_rial' => 'decimal:2',
'cod_amount' => 'decimal:2',
'declared_value' => 'decimal:2',
];
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
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);
}
public function isParcel(): bool
{
return $this->type === \App\Enums\ShipmentType::Parcel;
}
public function isDocument(): bool
{
return $this->type !== \App\Enums\ShipmentType::Parcel;
}
public function getInvoiceTotalUsdAttribute(): float
{
return $this->items->sum('total_usd');
}
}