'int', 'month' => 'int', 'year' => 'int', 'number' => 'int', 'paid' => 'bool', 'cancellation' => 'bool', 'cancellation_id' => 'int', 'status' => 'int', 'infos' => 'array', ]; protected $dates = [ 'date', 'paid_date', 'cancellation_date', ]; protected $fillable = [ 'shopping_order_id', 'month', 'year', 'date', 'full_number', 'number', 'filename', 'dir', 'delivery_filename', 'delivery_dir', 'disk', 'infos', 'paid', 'paid_date', 'cancellation', 'cancellation_id', 'cancellation_date', 'status', ]; public static $monthNames = [ 1 => 'Januar', 2 => 'Februar', 3 => 'März', 4 => 'April', 5 => 'Mai', 6 => 'Juni', 7 => 'Juli', 8 => 'August', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Dezember', ]; public static $statusTypes = [ 0 => '-', 1 => 'Bestellung', 2 => 'Shop', 11 => 'storniert B.', 12 => 'storniert Shop', ]; public static $statusColors = [ 0 => 'warning', 1 => 'success', 2 => 'secondary', 11 => 'danger', 12 => 'danger', ]; public function shopping_order() { return $this->belongsTo(ShoppingOrder::class); } public function getDateAttribute($value) { return $this->attributes['date'] ? Carbon::parse($this->attributes['date'])->format(\Util::formatDateDB()) : ''; } public function setDateAttribute($value) { $this->attributes['date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : null; } public function getDateRaw() { return isset($this->attributes['date']) ? $this->attributes['date'] : null; } public function getPaidDateAttribute($value) { return $this->attributes['paid_date'] ? Carbon::parse($this->attributes['paid_date'])->format(\Util::formatDateDB()) : ''; } public function setPaidDateAttribute($value) { $this->attributes['paid_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : null; } public function getPaidDateRaw() { return isset($this->attributes['paid_date']) ? $this->attributes['paid_date'] : null; } public function getCancellationDateAttribute($value) { return $this->attributes['cancellation_date'] ? Carbon::parse($this->attributes['cancellation_date'])->format(\Util::formatDateDB()) : ''; } public function setCancellationDateAttribute($value) { $this->attributes['cancellation_date'] = isset($value) ? (new Carbon($value))->format('Y-m-d') : null; } public function getCancellationDateRaw() { return isset($this->attributes['cancellation_date']) ? $this->attributes['cancellation_date'] : null; } public static function getMonthName($month) { return isset(self::$monthNames[$month]) ? self::$monthNames[$month] : $month; } public function getStatusType() { return isset(self::$statusTypes[$this->status]) ? self::$statusTypes[$this->status] : ''; } public function getStatusColor() { return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : 'default'; } public function getDownloadPath($full = false) { if (! $full) { return $this->dir.$this->filename; } return \Storage::disk($this->disk)->path($this->dir.$this->filename); } public function getDownloadPathDelivery($full = false) { if (! $full) { return $this->delivery_dir.$this->delivery_filename; } return \Storage::disk($this->disk)->path($this->delivery_dir.$this->delivery_filename); } /** * Gibt den Download-Pfad für die lokalisierte Rechnung zurück. * Bei 'de' oder nicht vorhandener Locale-Version wird das Original zurückgegeben. * * @param string|null $locale Sprachcode (de, en, es) * @param bool $full Vollständiger Dateisystempfad oder relativer Pfad * @return string */ public function getDownloadPathLocale($locale = null, $full = false) { // Bei Deutsch oder keiner Angabe: Original zurückgeben if (! $locale || $locale === 'de') { return $this->getDownloadPath($full); } // Dateiname mit Locale-Suffix $filename = str_replace('.pdf', '-'.$locale.'.pdf', $this->filename); $path = $this->dir.$filename; // Prüfen ob Locale-Version existiert, sonst Fallback auf DE if (! \Storage::disk($this->disk)->exists($path)) { return $this->getDownloadPath($full); } return $full ? \Storage::disk($this->disk)->path($path) : $path; } /** * Gibt den Download-Pfad für den lokalisierten Lieferschein zurück. * Bei 'de' oder nicht vorhandener Locale-Version wird das Original zurückgegeben. * * @param string|null $locale Sprachcode (de, en, es) * @param bool $full Vollständiger Dateisystempfad oder relativer Pfad * @return string */ public function getDownloadPathDeliveryLocale($locale = null, $full = false) { // Bei Deutsch oder keiner Angabe: Original zurückgeben if (! $locale || $locale === 'de') { return $this->getDownloadPathDelivery($full); } // Dateiname mit Locale-Suffix $filename = str_replace('.pdf', '-'.$locale.'.pdf', $this->delivery_filename); $path = $this->delivery_dir.$filename; // Prüfen ob Locale-Version existiert, sonst Fallback auf DE if (! \Storage::disk($this->disk)->exists($path)) { return $this->getDownloadPathDelivery($full); } return $full ? \Storage::disk($this->disk)->path($path) : $path; } /** * Gibt den lokalisierten Dateinamen für die Rechnung zurück. * * @param string|null $locale * @return string */ public function getFilenameLocale($locale = null) { if (! $locale || $locale === 'de') { return $this->filename; } $filename = str_replace('.pdf', '-'.$locale.'.pdf', $this->filename); $path = $this->dir.$filename; // Fallback auf Original wenn nicht vorhanden if (! \Storage::disk($this->disk)->exists($path)) { return $this->filename; } return $filename; } /** * Gibt alle verfügbaren lokalisierten Versionen der Rechnung zurück (außer DE). * * @return array Array mit Sprachcodes, z.B. ['en', 'es'] */ public function getAvailableLocales(): array { $availableTemplates = config('localization.availableTemplates', ['de']); $locales = []; foreach ($availableTemplates as $locale) { if ($locale === 'de') { continue; } $filename = str_replace('.pdf', '-'.$locale.'.pdf', $this->filename); $path = $this->dir.$filename; if (\Storage::disk($this->disk)->exists($path)) { $locales[] = $locale; } } return $locales; } /** * Prüft ob eine lokalisierte Version für die angegebene Sprache existiert. */ public function hasLocale(string $locale): bool { if ($locale === 'de') { return true; } $filename = str_replace('.pdf', '-'.$locale.'.pdf', $this->filename); $path = $this->dir.$filename; return \Storage::disk($this->disk)->exists($path); } }