ifnex/04_Laravel/test_pricing3.php
Kazem Alghasi 3aaa9a5481 refactor(api): improve shipping rate import and pricing logic
Refactor the shipping rate import process to support bidirectional
data handling (import/export) and implement currency conversion using
system settings. Update the price calculator to ensure valid zone
data is retrieved.

- Update `ShippingRatesImport` to handle both import and export
  directions via `SimpleRateSheetImport`.
- Implement AED to IRR conversion during rate importation using
  `SystemSetting`.
- Add validation for zone numbers and rate values during import.
- Enhance `PriceCalculatorService` to filter for non-zero zone values.
- Add various debug and testing scripts for pricing and data
  structure verification.
2026-08-04 07:24:23 +03:30

94 lines
3.0 KiB
PHP

<?php
require 'vendor/autoload.php';
$app = require_once 'bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
$service = new App\Services\PriceCalculatorService();
$testCases = [
[
'name' => 'DOC_NORMAL Export to DE 1kg',
'data' => [
'type' => 'DOC_NORMAL',
'direction' => 'Outbound',
'country_iso' => 'DE',
'weight' => 1,
'volumetric_weight' => 1,
'extra_service' => 0,
'packing_cost' => 100000,
'domestic_pickup' => 0,
'domestic_delivery' => 0,
'warehousing_cost' => 0,
'discount' => 0,
],
],
[
'name' => 'PARCEL Export to AE 1kg',
'data' => [
'type' => 'PARCEL',
'direction' => 'Outbound',
'country_iso' => 'AE',
'weight' => 1,
'volumetric_weight' => 1,
'extra_service' => 0,
'packing_cost' => 100000,
'domestic_pickup' => 0,
'domestic_delivery' => 0,
'warehousing_cost' => 0,
'discount' => 0,
],
],
[
'name' => 'PARCEL Import from US 5kg',
'data' => [
'type' => 'PARCEL',
'direction' => 'Inbound',
'country_iso' => 'US',
'weight' => 5,
'volumetric_weight' => 5,
'extra_service' => 50000,
'packing_cost' => 150000,
'domestic_pickup' => 20000,
'domestic_delivery' => 30000,
'warehousing_cost' => 50000,
'discount' => 10000,
],
],
[
'name' => 'DOC_ECONOMY Export to US 2kg',
'data' => [
'type' => 'DOC_ECONOMY',
'direction' => 'Outbound',
'country_iso' => 'US',
'weight' => 2,
'volumetric_weight' => 2,
'extra_service' => 0,
'packing_cost' => 80000,
'domestic_pickup' => 15000,
'domestic_delivery' => 25000,
'warehousing_cost' => 0,
'discount' => 0,
],
],
];
foreach ($testCases as $case) {
echo "=== {$case['name']} ===" . PHP_EOL;
try {
$result = $service->calculate($case['data']);
echo "Base Price (AED): " . $result['base_price'] . PHP_EOL;
echo "Net Dirham: " . $result['net_dirham'] . PHP_EOL;
echo "Net Rial: " . number_format($result['net_rial'], 0) . PHP_EOL;
echo "Extra Service: " . number_format($result['extra_service'], 0) . PHP_EOL;
echo "Packing Cost: " . number_format($result['packing_cost'], 0) . PHP_EOL;
echo "VAT Amount: " . number_format($result['vat_amount'], 0) . PHP_EOL;
echo "Total Fee: " . number_format($result['total_fee'], 0) . PHP_EOL;
echo "Zone: " . $result['zone'] . PHP_EOL;
echo "Chargeable Weight: " . $result['chargeable_weight'] . PHP_EOL;
} catch (Exception $e) {
echo "ERROR: " . $e->getMessage() . PHP_EOL;
}
echo PHP_EOL;
}