'datetime', 'subtotal' => 'decimal:2', 'tax_total' => 'decimal:2', 'shipping_cost' => 'decimal:2', 'total' => 'decimal:2', ]; public static array $statusLabels = [ 'new' => 'Neu', 'payment_received' => 'Zahlung eingegangen', 'processing' => 'In Bearbeitung', 'shipped' => 'Versendet', 'completed' => 'Abgeschlossen', 'cancelled' => 'Storniert', ]; public static array $paymentLabels = [ 'prepayment' => 'Vorkasse', 'invoice' => 'Rechnung', ]; public function user(): BelongsTo { return $this->belongsTo(User::class); } public function items(): HasMany { return $this->hasMany(OrderItem::class); } public function addresses(): HasMany { return $this->hasMany(OrderAddress::class); } public function billingAddress() { return $this->addresses()->where('type', 'billing')->first(); } public function shippingAddress() { return $this->addresses()->where('type', 'shipping')->first(); } public function getStatusLabelAttribute(): string { return self::$statusLabels[$this->status] ?? $this->status; } public function getPaymentLabelAttribute(): string { return self::$paymentLabels[$this->payment_method] ?? $this->payment_method; } public static function generateOrderNumber(): string { return 'ORD-' . date('Ymd') . '-' . strtoupper(substr(uniqid(), -5)); } }