Implement a new pricing architecture based on a 4-quadrant model (Export/Import x Document/Non-Document) to replace the previous 2-zone model. This includes the ability to handle different zones for parcels and documents per country. - Add `RateEntry` and `CountryZone` models for managing complex rate matrices. - Implement `RateImportService` to parse Excel templates using PhpSpreadsheet. - Add `RateImportResource` in Filament for administrative rate uploads. - Refactor `PriceCalculatorService` to utilize the new 4-quadrant lookup logic. - Add database migrations to extend `rate_entries` and create `country_zones`. - Update `DEPLOYMENT.md` with new architectural details and deployment steps.
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* CountryZone
|
|
* -----------
|
|
* Stores the zone mapping for a country.
|
|
*
|
|
* Crucial: a country can have DIFFERENT zones for Parcel vs Document.
|
|
* Example from the customer's data:
|
|
* Afghanistan → Parcel Zone 7, Document Zone 5
|
|
* Belgium → Parcel Zone 1, Document Zone 3
|
|
* China → Parcel Zone 6, Document Zone 4
|
|
*/
|
|
class CountryZone extends Model
|
|
{
|
|
protected $table = 'country_zones';
|
|
|
|
protected $fillable = [
|
|
'country_name', 'country_iso2', 'parcel_zone', 'document_zone',
|
|
];
|
|
|
|
protected $casts = [
|
|
'parcel_zone' => 'integer',
|
|
'document_zone' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* Lookup zone for a country by service type.
|
|
* Returns null if country not found OR zone is 0 (origin country).
|
|
*/
|
|
public static function lookupZone(string $country, string $serviceType): ?int
|
|
{
|
|
$row = self::where('country_name', $country)->first();
|
|
if (! $row) return null;
|
|
|
|
$zone = $serviceType === 'document'
|
|
? $row->document_zone
|
|
: $row->parcel_zone;
|
|
|
|
return ($zone && $zone > 0) ? (int) $zone : null;
|
|
}
|
|
}
|