23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace Acme\Dhl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use App\Models\ShoppingOrder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* DHL Shipment Model for both outbound shipments and returns
|
||||
|
|
@ -29,17 +29,22 @@ class DhlShipment extends Model
|
|||
'firstname',
|
||||
'lastname',
|
||||
'company',
|
||||
'email',
|
||||
'postnumber',
|
||||
'recipient',
|
||||
'tracking_status',
|
||||
'last_tracked_at',
|
||||
'api_response_data'
|
||||
'tracking_email_sent_at',
|
||||
'tracking_email_type',
|
||||
'api_response_data',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'recipient' => 'array',
|
||||
'api_response_data' => 'array',
|
||||
'last_tracked_at' => 'datetime',
|
||||
'weight_kg' => 'decimal:3'
|
||||
'tracking_email_sent_at' => 'datetime',
|
||||
'weight_kg' => 'decimal:3',
|
||||
];
|
||||
|
||||
public const STATUS_MAP = [
|
||||
|
|
@ -50,10 +55,9 @@ class DhlShipment extends Model
|
|||
'exception' => 'exception',
|
||||
'returned' => 'returned',
|
||||
'failed' => 'failed',
|
||||
'unknown' => 'unknown'
|
||||
'unknown' => 'unknown',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Get the tracking events for this shipment
|
||||
*/
|
||||
|
|
@ -184,4 +188,91 @@ class DhlShipment extends Model
|
|||
{
|
||||
return __('dhl.product_codes.' . $this->product_code, [], $this->product_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get DHL tracking URL for this shipment
|
||||
*/
|
||||
public function getTrackingUrl(): string
|
||||
{
|
||||
return 'https://www.dhl.de/de/privatkunden/pakete-empfangen/verfolgen.html?piececode=' . $this->dhl_shipment_no;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if tracking email can be sent
|
||||
*/
|
||||
public function canSendTrackingEmail(): bool
|
||||
{
|
||||
if (empty($this->dhl_shipment_no)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->shoppingOrder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if email is available in shipment record (new field)
|
||||
if (! empty($this->email)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fallback: check shopping user email
|
||||
$shoppingUser = $this->shoppingOrder->shopping_user;
|
||||
if (! $shoppingUser || empty($shoppingUser->email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if tracking email was already sent
|
||||
*/
|
||||
public function wasTrackingEmailSent(): bool
|
||||
{
|
||||
return $this->tracking_email_sent_at !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark tracking email as sent
|
||||
*/
|
||||
public function markTrackingEmailSent(string $type = 'manual'): void
|
||||
{
|
||||
$this->update([
|
||||
'tracking_email_sent_at' => now(),
|
||||
'tracking_email_type' => $type,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status badge class for Bootstrap
|
||||
*/
|
||||
public function getStatusBadgeClass(): string
|
||||
{
|
||||
return match ($this->status) {
|
||||
'created', 'pending' => 'secondary',
|
||||
'in_transit' => 'info',
|
||||
'out_for_delivery' => 'primary',
|
||||
'delivered' => 'success',
|
||||
'exception', 'failed' => 'danger',
|
||||
'returned', 'canceled' => 'warning',
|
||||
default => 'secondary'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for active shipments (not delivered or canceled)
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->whereNotIn('status', ['delivered', 'canceled', 'returned', 'failed']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for shipments that need tracking email
|
||||
*/
|
||||
public function scopeNeedsTrackingEmail($query)
|
||||
{
|
||||
return $query->where('status', 'in_transit')
|
||||
->whereNull('tracking_email_sent_at');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue