adrema/app/Contribution/Documents/CityFrankfurtMainDocument.php

94 lines
2.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
2024-12-13 11:56:02 +01:00
use App\Contribution\Traits\FormatsDates;
2024-12-13 02:33:12 +01:00
use App\Contribution\Traits\HasPdfBackground;
use App\Country;
2024-03-12 13:52:10 +01:00
use App\Invoice\InvoiceSettings;
use Illuminate\Support\Collection;
class CityFrankfurtMainDocument extends ContributionDocument
{
2024-12-13 02:33:12 +01:00
use HasPdfBackground;
2024-12-13 11:56:02 +01:00
use FormatsDates;
2024-12-13 02:33:12 +01:00
2024-03-12 13:52:10 +01:00
public string $fromName;
/**
* @param Collection<int, Collection<int, MemberData>> $members
*/
public function __construct(
public string $dateFrom,
public string $dateUntil,
public string $zipLocation,
public ?Country $country,
public Collection $members,
2024-03-12 13:52:10 +01:00
public string $eventName,
public ?string $filename = '',
public string $type = 'F',
) {
2024-12-13 02:28:41 +01:00
$this->setEventName($eventName);
2024-03-12 13:52:10 +01:00
$this->fromName = app(InvoiceSettings::class)->from_long;
}
/**
* {@inheritdoc}
*/
public static function fromRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromModels($request['members'])->chunk(15),
2024-03-12 13:52:10 +01:00
eventName: $request['eventName'],
);
}
/**
* {@inheritdoc}
*/
public static function fromApiRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromApi($request['member_data'])->chunk(15),
2024-03-12 13:52:10 +01:00
eventName: $request['eventName'],
);
}
public function countryName(): string
{
return $this->country->name;
}
public function pages(): int
{
return count($this->members);
}
public static function getName(): string
{
2024-12-13 02:16:09 +01:00
return 'Frankfurt';
}
/**
* @return array<string, mixed>
*/
public static function rules(): array
{
return [
'dateFrom' => 'required|string|date_format:Y-m-d',
'dateUntil' => 'required|string|date_format:Y-m-d',
'country' => 'required|integer|exists:countries,id',
'zipLocation' => 'required|string',
];
}
}