'int', 'month' => 'int', 'year' => 'int', 'number' => 'int', 'net' => 'float', 'tax_rate' => 'float', 'tax' => 'float', 'taxable' => 'int', 'total' => 'float', 'paid_out' => 'bool', 'cancellation' => 'bool', 'cancellation_id' => 'int', 'status' => 'int', 'infos' => 'array', ]; protected $dates = [ 'date', 'paid_out_date', 'cancellation_date', ]; protected $fillable = [ 'user_id', 'month', 'year', 'date', 'full_number', 'number', 'net', 'tax_rate', 'tax', 'total', 'taxable', 'filename', 'dir', 'disk', 'infos', 'paid_out', 'paid_out_date', 'cancellation', 'cancellation_id', 'cancellation_date', 'status', ]; public static $statusTypes = [ 0 => 'open', 1 => 'paid', 2 => 'check', 10 => 'cancelled', ]; public static $statusColors = [ 0 => 'warning', 1 => 'success', 2 => 'secondary', 10 => 'danger', ]; public static $taxableTypes = [ 0 => '', 1 => 'umsatzsteuerpflichtig / DE', // payment.to_sales_tax_de 2 => 'nicht umsatzsteuerpflichtig / DE', // payment.not_to_sales_tax_de 3 => 'nicht umsatzsteuerpflichtig / Ausland', // payment.not_to_sales_tax_foreign ]; public function user() { return $this->belongsTo(User::class); } public function user_credit_items() { return $this->hasMany(UserCreditItem::class); } public function isCredit() { return $this->filename ? true : false; } public function getDateAttribute($value) { return $value ? Carbon::parse($value)->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 getFormattedTax() { return formatNumber($this->attributes['tax']); } public function getFormattedNet() { return formatNumber($this->attributes['net']); } public function getFormattedTotal() { return formatNumber($this->attributes['total']); } public function getStatusType() { // trans('payment.cancelled') return isset(self::$statusTypes[$this->status]) ? __('payment.'.self::$statusTypes[$this->status]) : ''; } public function getStatusColor() { return isset(self::$statusColors[$this->status]) ? self::$statusColors[$this->status] : 'default'; } public static function getTransStatusType() { $ret = []; foreach (self::$statusTypes as $key => $val) { $ret[$key] = trans('payment.'.$val); } return $ret; } public function getDownloadPath($full = false) { if (! $full) { return $this->dir.$this->filename; } return \Storage::disk($this->disk)->path($this->dir.$this->filename); } /** * Gibt den Download-Pfad für die lokalisierte Gutschrift 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 lokalisierten Dateinamen für die Gutschrift 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 Gutschrift 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); } }