Implement a comprehensive notification system using Kavenegar SMS
gateway and enhance system traceability through audit logging and
detailed shipment status history.
- SMS Integration:
- Add Kavenegar SMS service with configurable API keys and sender
numbers via system settings.
- Implement automated SMS notifications for shipment approval,
rejection, successful payments, and tracking updates.
- Add administrative UI in Filament to manage SMS gateway settings
and toggle specific notification types.
- Audit & Tracking:
- Apply `Auditable` trait to core models (User, Shipment, Wallet,
etc.) to track changes.
- Refactor `ShipmentStatusHistory` to include status transitions
(`from_status` to `to_status`) and specific reasons for changes.
- Implement `ShipmentObserver` to automate notification triggers
on status changes.
- Database & Config:
- Add migrations for enhanced shipment status history tracking.
- Update `.env.example` and `config/ifnex.php` with Kavenegar
configuration parameters.
66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
use App\Traits\Auditable;
|
||
|
||
class ShipmentPackage extends Model
|
||
{
|
||
use Auditable;
|
||
protected $fillable = [
|
||
'shipment_id',
|
||
'package_no',
|
||
'weight',
|
||
'volumetric_weight',
|
||
'chargeable_weight',
|
||
'dimensions',
|
||
'content_description',
|
||
];
|
||
|
||
protected $casts = [
|
||
'weight' => 'decimal:3',
|
||
'volumetric_weight' => 'decimal:3',
|
||
'chargeable_weight' => 'decimal:3',
|
||
];
|
||
|
||
/**
|
||
* رابطه با Shipment
|
||
*/
|
||
public function shipment(): BelongsTo
|
||
{
|
||
return $this->belongsTo(Shipment::class);
|
||
}
|
||
|
||
/**
|
||
* محاسبه وزن قابل محاسبه (ماکزیمم وزن واقعی و حجمی)
|
||
*/
|
||
public function calculateChargeableWeight(): float
|
||
{
|
||
return max((float) $this->weight, (float) $this->volumetric_weight);
|
||
}
|
||
|
||
/**
|
||
* محاسبه وزن حجمی از ابعاد
|
||
* فرمول: (طول × عرض × ارتفاع) / 5000
|
||
*/
|
||
public static function calculateVolumetricWeight(?string $dimensions): float
|
||
{
|
||
if (!$dimensions) return 0;
|
||
|
||
// پارس کردن ابعاد - فرمتهای ممکن: "25*15*3" یا "25x15x3" یا "25,15,3"
|
||
$parts = preg_split('/[\*xX,]/', trim($dimensions));
|
||
if (count($parts) !== 3) return 0;
|
||
|
||
$length = (float) trim($parts[0]);
|
||
$width = (float) trim($parts[1]);
|
||
$height = (float) trim($parts[2]);
|
||
|
||
if ($length <= 0 || $width <= 0 || $height <= 0) return 0;
|
||
|
||
// فرمول استاندارد IATA: (L × W × H) / 5000
|
||
return round(($length * $width * $height) / 5000, 3);
|
||
}
|
||
}
|