20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:55:06 +01:00
parent a8b395e20d
commit a00c42e770
252 changed files with 28785 additions and 8907 deletions

View file

@ -34,6 +34,7 @@ class DhlShipment extends Model
'recipient',
'tracking_status',
'last_tracked_at',
'tracking_completed_at',
'tracking_email_sent_at',
'tracking_email_type',
'api_response_data',
@ -43,6 +44,7 @@ class DhlShipment extends Model
'recipient' => 'array',
'api_response_data' => 'array',
'last_tracked_at' => 'datetime',
'tracking_completed_at' => 'datetime',
'tracking_email_sent_at' => 'datetime',
'weight_kg' => 'decimal:3',
];
@ -162,7 +164,7 @@ class DhlShipment extends Model
*/
public function getStatusTranslation(): string
{
return __('dhl.status.' . $this->status, [], $this->status);
return __('dhl.status.'.$this->status, [], $this->status);
}
/**
@ -170,7 +172,7 @@ class DhlShipment extends Model
*/
public static function getStatusTranslationFor(string $status): string
{
return __('dhl.status.' . $status, [], $status);
return __('dhl.status.'.$status, [], $status);
}
/**
@ -178,7 +180,7 @@ class DhlShipment extends Model
*/
public function getTypeTranslation(): string
{
return __('dhl.type.' . $this->type, [], $this->type);
return __('dhl.type.'.$this->type, [], $this->type);
}
/**
@ -186,7 +188,7 @@ class DhlShipment extends Model
*/
public function getProductCodeTranslation(): string
{
return __('dhl.product_codes.' . $this->product_code, [], $this->product_code);
return __('dhl.product_codes.'.$this->product_code, [], $this->product_code);
}
/**
@ -194,7 +196,7 @@ class DhlShipment extends Model
*/
public function getTrackingUrl(): string
{
return 'https://www.dhl.de/de/privatkunden/pakete-empfangen/verfolgen.html?piececode=' . $this->dhl_shipment_no;
return 'https://www.dhl.de/de/privatkunden/pakete-empfangen/verfolgen.html?piececode='.$this->dhl_shipment_no;
}
/**
@ -267,6 +269,77 @@ class DhlShipment extends Model
return $query->whereNotIn('status', ['delivered', 'canceled', 'returned', 'failed']);
}
/**
* Terminal statuses where tracking is considered complete
*/
public const TERMINAL_STATUSES = ['delivered', 'canceled', 'returned', 'failed'];
/**
* Tracking interval per status (in hours).
* Determines how often each status should be re-checked via the DHL API.
*/
public const TRACKING_INTERVALS = [
'out_for_delivery' => 1,
'in_transit' => 2,
'exception' => 4,
'unknown' => 4,
'created' => 6,
];
/**
* Default tracking interval in hours for statuses not explicitly listed
*/
public const DEFAULT_TRACKING_INTERVAL = 4;
/**
* Scope for shipments that need a tracking update based on status-dependent intervals.
* Skips shipments that are already completed or were recently tracked.
*/
public function scopeNeedsTrackingUpdate($query)
{
return $query
->whereNull('tracking_completed_at')
->whereNotNull('dhl_shipment_no')
->where(function ($q) {
$q->whereNull('last_tracked_at') // Noch nie getrackt → sofort
->orWhere(function ($q2) {
// Status-abhängige Intervalle
$q2->where(function ($q3) {
$q3->where('status', 'out_for_delivery')
->where('last_tracked_at', '<', now()->subHours(self::TRACKING_INTERVALS['out_for_delivery']));
})->orWhere(function ($q3) {
$q3->where('status', 'in_transit')
->where('last_tracked_at', '<', now()->subHours(self::TRACKING_INTERVALS['in_transit']));
})->orWhere(function ($q3) {
$q3->whereIn('status', ['exception', 'unknown'])
->where('last_tracked_at', '<', now()->subHours(self::TRACKING_INTERVALS['exception']));
})->orWhere(function ($q3) {
$q3->where('status', 'created')
->where('last_tracked_at', '<', now()->subHours(self::TRACKING_INTERVALS['created']));
});
});
});
}
/**
* Check if tracking for this shipment is in a terminal state
*/
public function isTrackingComplete(): bool
{
return $this->tracking_completed_at !== null
|| in_array($this->status, self::TERMINAL_STATUSES);
}
/**
* Mark tracking as completed
*/
public function markTrackingCompleted(): void
{
if ($this->tracking_completed_at === null) {
$this->update(['tracking_completed_at' => now()]);
}
}
/**
* Scope for shipments that need tracking email
*/