Zeige im Zahlungsjournal die Zahlungen je gekauftem Angebot

Filter nach Angebot mit dem Anteil des Angebots an der Bestellung (Preis nach Rabatt), damit eine
Bestellung mit mehreren Angeboten den Umsatz des einzelnen nicht überzeichnet. Zusätzliche CSV-Spalte,
Link von der Angebotsseite.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-23 08:16:13 +01:00
1 parent 32272e8e40
commit dd3cc83057
5 files changed
+183 -16

No files matched your search

+20 -6
View File
@@ -2,6 +2,7 @@
namespace App\Filament\Pages;
use App\Domain\Catalog\Offer;
use App\Domain\Commerce\LedgerEntry;
use App\Domain\Commerce\PaymentJournal;
use App\Filament\Support\ShopAccess;
@@ -50,6 +51,10 @@ class Zahlungsjournal extends Page
#[Url(as: 'betrieb')]
public string $betrieb = 'echt';
/** Kennung eines Angebots oder leer für alle (Zeichenkette, damit die Auswahl „Alle“ leer sein kann). */
#[Url(as: 'angebot')]
public string $angebot = '';
public static function canAccess(): bool
{
return ShopAccess::allowed();
@@ -95,6 +100,7 @@ private function normalize(): void
$this->art = in_array($this->art, ['alle', LedgerEntry::KIND_PAYMENT, LedgerEntry::KIND_REFUND], true) ? $this->art : 'alle';
$this->weg = in_array($this->weg, ['alle', 'stripe', 'ueberweisung', 'test'], true) ? $this->weg : 'alle';
$this->betrieb = in_array($this->betrieb, ['echt', 'test', 'alle'], true) ? $this->betrieb : 'echt';
$this->angebot = ctype_digit($this->angebot) && Offer::query()->whereKey((int) $this->angebot)->exists() ? $this->angebot : '';
$this->jahr = max(2020, min((int) CarbonImmutable::now(PaymentJournal::TIMEZONE)->year + 1, (int) ($this->jahr ?? 2026)));
$max = $this->modus === 'quartal' ? 4 : 12;
$this->nr = max(1, min($max, (int) ($this->nr ?? 1)));
@@ -126,13 +132,18 @@ public function daten(): array
{
[$from, $to] = $this->range();
$journal = app(PaymentJournal::class);
$entries = $journal->entries($from, $to, $this->art, $this->weg, $this->betrieb);
$offerId = $this->angebot === '' ? null : (int) $this->angebot;
$entries = $journal->entries($from, $to, $this->art, $this->weg, $this->betrieb, $offerId);
$shares = $offerId === null ? null : $journal->shares($entries, $offerId);
return [
'zeitraum' => $this->zeitraumName(),
'eintraege' => $entries->take(PaymentJournal::DISPLAY_LIMIT),
'anzahl' => $entries->count(),
'summen' => PaymentJournal::totals($entries),
'angebote' => Offer::query()->orderBy('name')->pluck('name', 'id')->all(),
'angebotName' => $offerId === null ? null : Offer::query()->find($offerId)?->name,
'anteile' => $shares,
'summen' => PaymentJournal::totals($entries, $shares),
'nachBetrieb' => $journal->countByOperation($from, $to),
'ohneAdresse' => $entries->filter(fn (LedgerEntry $entry): bool => $entry->kind === LedgerEntry::KIND_PAYMENT && empty(($entry->payer ?? [])['billing']))->count(),
'nachgetragen' => $entries->where('derived', true)->count(),
@@ -144,17 +155,20 @@ public function exportieren(): StreamedResponse
abort_unless(ShopAccess::allowed(), 403);
[$from, $to] = $this->range();
$entries = app(PaymentJournal::class)->entries($from, $to, $this->art, $this->weg, $this->betrieb);
$journal = app(PaymentJournal::class);
$offerId = $this->angebot === '' ? null : (int) $this->angebot;
$entries = $journal->entries($from, $to, $this->art, $this->weg, $this->betrieb, $offerId);
$shares = $offerId === null ? null : $journal->shares($entries, $offerId);
$name = 'zahlungsjournal-'.match ($this->modus) {
'monat' => $this->jahr.'-'.str_pad((string) $this->nr, 2, '0', STR_PAD_LEFT),
'quartal' => $this->jahr.'-Q'.$this->nr,
default => (string) $this->jahr,
}.'-'.match ($this->betrieb) {
'echt' => 'echt', 'test' => 'test', default => 'alle'
}.'.csv';
}.($offerId === null ? '' : '-angebot-'.$offerId).'.csv';
return response()->streamDownload(function () use ($entries): void {
echo PaymentJournal::csv($entries);
return response()->streamDownload(function () use ($entries, $shares): void {
echo PaymentJournal::csv($entries, $shares);
}, $name, ['Content-Type' => 'text/csv; charset=UTF-8']);
}
}