rate; $irrAmount = $this->exchangeRate->convertToIrr($aedAmount, 'AED'); $irrAmount = (int) round($irrAmount / 1000) * 1000; // round to nearest 1000 IRR return [ 'aed' => $aedAmount, 'irr' => $irrAmount, 'currency' => 'IRR', 'rate' => $rateEntry, ]; } /** * Convenience: calculate from a Shipment model. */ public function calculateForShipment($shipment): array { $direction = $shipment->direction === ShipmentDirection::Export->value || $shipment->direction === 'export' ? 'export' : 'import'; $serviceType = $shipment->type === ShipmentType::Document->value || $shipment->type === 'document' ? 'document' : 'parcel'; $weight = (float) ($shipment->total_weight ?? $shipment->weight ?? 0); $country = $shipment->toCountry?->name ?? $shipment->receiver_country ?? $shipment->destination_country; return $this->calculate($direction, $serviceType, $weight, $country); } }