Files
fewo-stommer/app/Filament/Resources/Bookings/RelationManagers/PaymentsRelationManager.php
T
Lars StommerandClaude Opus 5.5 0bf302fcf9 Phase 3: Zahlungen, Mietvertrag, Erinnerungen, Anreiseinformationen
- Zahlungen erfassen (inkl. Erstattungen), Status automatisch: Bestätigt → Anzahlung erhalten → Bezahlt → Abgeschlossen
- Anzahlungsfrist bei Bestätigung; kurzfristige Buchungen: Gesamtbetrag sofort
- Mietvertrag als PDF (dompdf, Font-Subsetting), bei Bestätigung gespeichert und angehängt; Texte im Admin (Muster)
- Täglich: Zahlungserinnerungen (Anzahlung/Rest überfällig, Kopie an Vermieter), Zahlungsaufforderung Rest 7 Tage vorher, Anreiseinfos 7 Tage vorher, Abschluss nach Abreise
- Admin: Zahlungen je Buchung, offene Beträge, Vertrag herunterladen/neu erzeugen

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 13:29:41 +02:00

82 lines
3.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Filament\Resources\Bookings\RelationManagers;
use App\Actions\RecordPayment;
use App\Enums\PaymentMethod;
use App\Filament\Forms\Components\EuroInput;
use App\Models\Booking;
use App\Models\Payment;
use App\Support\Money;
use Carbon\CarbonImmutable;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
/**
* @property Booking $ownerRecord
*/
class PaymentsRelationManager extends RelationManager
{
protected static string $relationship = 'payments';
protected static ?string $title = 'Zahlungen';
public function isReadOnly(): bool
{
return false;
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('amount')
->description(fn (): string => 'Bezahlt: '.Money::format($this->ownerRecord->paidAmount()).' · offen: '.Money::format($this->ownerRecord->openAmount()))
->columns([
TextColumn::make('paid_on')->label('Eingang')->date('d.m.Y'),
TextColumn::make('amount')->label('Betrag')->money('EUR', divideBy: 100, locale: 'de'),
TextColumn::make('method')->label('Art'),
TextColumn::make('note')->label('Notiz')->placeholder('–'),
TextColumn::make('recorded_by')->label('Erfasst von')->placeholder('–'),
])
->headerActions([
Action::make('record')
->label('Zahlung erfassen')
->icon(Heroicon::OutlinedBanknotes)
->fillForm(fn (): array => [
'amount' => number_format(($this->ownerRecord->openDeposit() ?: $this->ownerRecord->openAmount()) / 100, 2, '.', ''),
'paid_on' => today(),
'method' => PaymentMethod::Transfer,
])
->schema([
EuroInput::make('amount')->label('Betrag')->helperText('Erstattungen mit Minus erfassen.')->minValue(null)->required(),
DatePicker::make('paid_on')->label('Zahlungseingang')->required(),
Select::make('method')->label('Art')->options(PaymentMethod::class)->required(),
TextInput::make('note')->label('Notiz')->maxLength(255),
])
->action(function (array $data, RecordPayment $recordPayment): void {
$recordPayment->handle(
$this->ownerRecord,
(int) $data['amount'],
CarbonImmutable::parse($data['paid_on']),
$data['method'] instanceof PaymentMethod ? $data['method'] : PaymentMethod::from($data['method']),
$data['note'] ?: null,
auth()->user()?->name,
);
Notification::make()->title('Zahlung erfasst – Status: '.$this->ownerRecord->fresh()->status->getLabel())->success()->send();
}),
])
->recordActions([
DeleteAction::make()->after(fn (Payment $record) => app(RecordPayment::class)->updateStatus($this->ownerRecord->fresh())),
]);
}
}