adrema/app/Contribution/Documents/RemscheidDocument.php

102 lines
2.6 KiB
PHP
Raw Normal View History

2022-11-17 22:59:16 +01:00
<?php
namespace App\Contribution\Documents;
use App\Country;
use App\Member\Member;
use Carbon\Carbon;
2023-02-17 18:57:11 +01:00
use Illuminate\Support\Collection;
2022-11-17 22:59:16 +01:00
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
class RemscheidDocument extends ContributionDocument
{
2023-02-17 18:57:11 +01:00
/**
* @param Collection<int, Collection<int, Member>> $leaders
* @param Collection<int, Collection<int, Member>> $children
*/
2022-11-17 22:59:16 +01:00
public function __construct(
public string $dateFrom,
public string $dateUntil,
public string $zipLocation,
public ?Country $country,
public Collection $leaders,
public Collection $children,
public ?string $filename = '',
public string $type = 'F',
) {
}
public function niceDateFrom(): string
{
return Carbon::parse($this->dateFrom)->format('d.m.Y');
}
public function niceDateUntil(): string
{
return Carbon::parse($this->dateUntil)->format('d.m.Y');
}
2023-03-09 02:14:24 +01:00
/**
* @param array<string, string|int> $request
*/
public static function fromRequest(array $request): self
2022-11-17 22:59:16 +01:00
{
2023-03-09 02:14:24 +01:00
[$leaders, $children] = Member::whereIn('id', $request['members'])->orderByRaw('lastname, firstname')->get()->partition(fn ($member) => $member->isLeader());
2022-11-17 22:59:16 +01:00
return new self(
2023-03-09 02:14:24 +01:00
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
2023-02-17 18:57:11 +01:00
leaders: $leaders->values()->toBase()->chunk(6),
children: $children->values()->toBase()->chunk(20),
2022-11-17 22:59:16 +01:00
);
}
public function basename(): string
{
return 'zuschuesse-remscheid';
}
public function view(): string
{
return 'tex.zuschuss-remscheid';
}
public function template(): Template
{
return Template::make('tex.templates.contribution');
}
public function setFilename(string $filename): static
{
$this->filename = $filename;
return $this;
}
public function getEngine(): Engine
{
return Engine::PDFLATEX;
}
public static function getName(): string
{
return 'Für Remscheid erstellen';
}
/**
* @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',
'country' => 'required|integer|exists:countries,id',
];
}
2022-11-17 22:59:16 +01:00
}