- Implement OfferOptionAdminTest to validate offer option management, including price display, activation, and cancellation. - Create OrganizationPurchaseTest to ensure correct handling of organization purchases, including access control and order processing. - Add ShopProductPageTest to verify shop product listings, search functionality, and product page details. - Introduce BuildsShop trait for seeding test data related to shop functionality. - Implement MoneyTest to validate money parsing and formatting, ensuring correct handling of euro amounts.
113 lines
4.4 KiB
PHP
113 lines
4.4 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Resources\Offers\Pages;
|
||
|
||
use App\Domain\Catalog\Offer;
|
||
use App\Domain\Catalog\OfferService;
|
||
use App\Domain\Catalog\OfferStatus;
|
||
use App\Domain\Catalog\StatusValue;
|
||
use App\Filament\Resources\Offers\OfferResource;
|
||
use App\Filament\Support\CatalogLabels;
|
||
use App\Filament\Support\ListsCatalog;
|
||
use App\Filament\Support\ReportsDomainRules;
|
||
use Filament\Actions\Action;
|
||
use Filament\Forms\Components\TextInput;
|
||
use Filament\Resources\Pages\ListRecords;
|
||
use Illuminate\Contracts\Support\Htmlable;
|
||
|
||
class ListOffers extends ListRecords
|
||
{
|
||
use ListsCatalog;
|
||
use ReportsDomainRules;
|
||
|
||
protected static string $resource = OfferResource::class;
|
||
|
||
public function getSubheading(): string|Htmlable|null
|
||
{
|
||
return 'Ein Angebot verbindet Artikel oder eine Paketfassung mit einem Rechteprofil. Die aufgelösten Berechtigungen stehen auf der Angebotsseite.';
|
||
}
|
||
|
||
protected function getHeaderActions(): array
|
||
{
|
||
return [
|
||
Action::make('create')->label('Angebot anlegen')
|
||
->modalHeading('Neues Angebot')
|
||
->modalDescription('Der Name genügt. Positionen, Vergabe und Preis legst du danach am Angebot fest.')
|
||
->modalSubmitActionLabel('Angebot anlegen')
|
||
->schema([
|
||
TextInput::make('name')->label('Name')->required(),
|
||
])->action(function (array $data): void {
|
||
$offer = null;
|
||
$this->report(function () use ($data, &$offer): void {
|
||
$offer = app(OfferService::class)->create($data['name']);
|
||
}, 'Das Angebot ist angelegt.');
|
||
|
||
if ($offer instanceof Offer) {
|
||
$this->redirect(OfferResource::getUrl('view', ['record' => $offer]));
|
||
}
|
||
}),
|
||
];
|
||
}
|
||
|
||
protected function catalogRows(): array
|
||
{
|
||
$rows = [];
|
||
|
||
foreach (Offer::query()->with(['versions.lines.article', 'versions.lines.bundleVersion.bundle', 'versions.lines.rights.profile'])->orderBy('name')->get() as $offer) {
|
||
$versions = $offer->versions->sortByDesc('number');
|
||
$active = $versions->first(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Aktiv->value);
|
||
$ended = $versions->filter(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Beendet->value)->count();
|
||
$chips = [];
|
||
$zustand = [];
|
||
$text = '';
|
||
|
||
if ($active !== null) {
|
||
$chips[] = ['label' => 'Fassung '.$active->number.' aktiv', 'ton' => 'gut'];
|
||
$chips[] = ['label' => CatalogLabels::vergabe($active), 'ton' => 'neutral'];
|
||
$chips[] = ['label' => $active->holder_kind === 'organisation' ? 'Für Organisationen' : 'Für Privatpersonen', 'ton' => 'neutral'];
|
||
$zustand[] = 'aktiv';
|
||
$text = $active->lines->map(fn ($line): string => ($line->article !== null
|
||
? 'Lizenzartikel '.$line->article->code
|
||
: 'Paket '.($line->bundleVersion?->bundle?->name ?? '–')).' · '.($line->rights?->profile?->name ?? ''))->implode('; ');
|
||
} else {
|
||
$chips[] = ['label' => 'Keine aktive Fassung', 'ton' => 'offen'];
|
||
$zustand[] = 'ohne';
|
||
}
|
||
|
||
if ($ended > 0) {
|
||
$chips[] = ['label' => $ended === 1 ? '1 beendete Fassung' : $ended.' beendete Fassungen', 'ton' => 'leise'];
|
||
}
|
||
|
||
$url = OfferResource::getUrl('view', ['record' => $offer]);
|
||
$rows[] = [
|
||
'schluessel' => 'o'.$offer->id,
|
||
'titel' => $offer->name,
|
||
'meta' => 'Angebot',
|
||
'text' => $text,
|
||
'symbol' => 'etikett',
|
||
'url' => $url,
|
||
'chips' => $chips,
|
||
'zustand' => $zustand,
|
||
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
|
||
];
|
||
}
|
||
|
||
return $rows;
|
||
}
|
||
|
||
protected function zustandOptionen(): array
|
||
{
|
||
return ['alle' => 'Jeder Zustand', 'aktiv' => 'Mit aktiver Fassung', 'ohne' => 'Ohne aktive Fassung'];
|
||
}
|
||
|
||
protected function einheit(): array
|
||
{
|
||
return ['Angebot', 'Angebote'];
|
||
}
|
||
|
||
protected function leer(): array
|
||
{
|
||
return ['titel' => 'Noch keine Angebote', 'text' => 'Mit „Angebot anlegen“ oben entsteht das erste Angebot.'];
|
||
}
|
||
}
|