'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); } }