2023-09-07 13:03:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Contribution\Documents;
|
|
|
|
|
|
|
|
use App\Contribution\Data\MemberData;
|
|
|
|
use App\Country;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Support\Collection;
|
2024-03-12 14:04:34 +01:00
|
|
|
use Illuminate\Support\Str;
|
2023-09-07 13:03:15 +02:00
|
|
|
use Zoomyboy\Tex\Engine;
|
|
|
|
use Zoomyboy\Tex\Template;
|
|
|
|
|
|
|
|
class BdkjHesse extends ContributionDocument
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @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 14:04:34 +01:00
|
|
|
public string $eventName,
|
2023-09-07 13:03:15 +02:00
|
|
|
public ?string $filename = '',
|
|
|
|
public string $type = 'F',
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dateFrom(): string
|
|
|
|
{
|
|
|
|
return Carbon::parse($this->dateFrom)->format('d.m.Y');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dateUntil(): string
|
|
|
|
{
|
|
|
|
return Carbon::parse($this->dateUntil)->format('d.m.Y');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@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(20),
|
2024-03-12 14:04:34 +01:00
|
|
|
eventName: $request['eventName'],
|
2023-09-07 13:03:15 +02: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(20),
|
2024-03-12 14:04:34 +01:00
|
|
|
eventName: $request['eventName'],
|
2023-09-07 13:03:15 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function countryName(): string
|
|
|
|
{
|
|
|
|
return $this->country->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function durationDays(): int
|
|
|
|
{
|
2024-09-22 17:32:29 +02:00
|
|
|
return intVal(Carbon::parse($this->dateUntil)->diffInDays(Carbon::parse($this->dateFrom))) + 1;
|
2023-09-07 13:03:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Collection<int, MemberData> $chunk
|
|
|
|
*/
|
|
|
|
public function membersDays(Collection $chunk): int
|
|
|
|
{
|
|
|
|
return $this->durationDays() * $chunk->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function pages(): int
|
|
|
|
{
|
|
|
|
return count($this->members);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberName(MemberData $member): string
|
|
|
|
{
|
|
|
|
return $member->separatedName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberCity(MemberData $member): string
|
|
|
|
{
|
|
|
|
return $member->city();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberGender(MemberData $member): string
|
|
|
|
{
|
|
|
|
if (!$member->gender) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return strtolower(substr($member->gender->name, 0, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberBirthYear(MemberData $member): string
|
|
|
|
{
|
|
|
|
return $member->birthYear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function basename(): string
|
|
|
|
{
|
2024-03-12 14:04:34 +01:00
|
|
|
return 'zuschuesse-bdkj-hessen' . Str::slug($this->eventName);
|
2023-09-07 13:03:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function view(): string
|
|
|
|
{
|
|
|
|
return 'tex.contribution.bdkj-hesse';
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2024-12-13 02:16:09 +01:00
|
|
|
return 'BDKJ Hessen';
|
2023-09-07 13:03:15 +02: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',
|
|
|
|
'country' => 'required|integer|exists:countries,id',
|
|
|
|
'zipLocation' => 'required|string',
|
|
|
|
'eventName' => 'required|string',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|