adrema/app/Contribution/Documents/GallierDocument.php

89 lines
2.3 KiB
PHP
Raw Normal View History

2024-12-13 00:58:44 +01:00
<?php
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
2024-12-13 02:33:12 +01:00
use App\Contribution\Traits\HasPdfBackground;
2024-12-13 00:58:44 +01:00
use App\Country;
use Carbon\Carbon;
use Illuminate\Support\Collection;
class GallierDocument extends ContributionDocument
{
2024-12-13 02:33:12 +01:00
use HasPdfBackground;
2024-12-13 00:58:44 +01:00
/**
* @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,
public ?string $filename = '',
public string $type = 'F',
2024-12-13 02:16:09 +01:00
public string $eventName = '',
2024-12-13 00:58:44 +01:00
) {
2024-12-13 02:16:09 +01:00
$this->setEventName($eventName);
2024-12-13 00:58:44 +01:00
}
2024-12-13 01:59:09 +01:00
public function dateFromHuman(): string
2024-12-13 00:58:44 +01:00
{
2024-12-13 01:59:09 +01:00
return Carbon::parse($this->dateFrom)->format('d.m.Y');
}
public function dateUntilHuman(): string
{
return Carbon::parse($this->dateUntil)->format('d.m.Y');
2024-12-13 00:58:44 +01:00
}
/**
* {@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(14),
2024-12-13 02:16:09 +01:00
eventName: $request['eventName'],
2024-12-13 00:58:44 +01:00
);
}
/**
* {@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(14),
2024-12-13 02:16:09 +01:00
eventName: $request['eventName'],
2024-12-13 00:58:44 +01:00
);
}
public static function getName(): string
{
2024-12-13 02:16:09 +01:00
return 'Gallier';
2024-12-13 00:58:44 +01:00
}
/**
* @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',
'zipLocation' => 'required|string',
];
}
}