2022-08-23 23:49:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Contribution;
|
|
|
|
|
|
|
|
use App\Country;
|
|
|
|
use App\Member\Member;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use Illuminate\Http\Request;
|
2022-11-07 16:18:11 +01:00
|
|
|
use Zoomyboy\Tex\Document;
|
|
|
|
use Zoomyboy\Tex\Engine;
|
|
|
|
use Zoomyboy\Tex\Template;
|
2022-08-23 23:49:19 +02:00
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
class DvDocument extends Document
|
2022-08-23 23:49:19 +02:00
|
|
|
{
|
|
|
|
public function __construct(
|
|
|
|
public string $dateFrom,
|
|
|
|
public string $dateUntil,
|
|
|
|
public string $zipLocation,
|
|
|
|
public ?Country $country,
|
2022-11-07 16:18:11 +01:00
|
|
|
public Collection $members,
|
2022-08-23 23:49:19 +02:00
|
|
|
public ?string $filename = '',
|
2022-10-30 16:27:51 +01:00
|
|
|
public string $type = 'F',
|
2022-08-23 23:49:19 +02:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function dateRange(): string
|
|
|
|
{
|
|
|
|
return Carbon::parse($this->dateFrom)->format('d.m.Y')
|
|
|
|
.' - '
|
|
|
|
.Carbon::parse($this->dateUntil)->format('d.m.Y');
|
|
|
|
}
|
|
|
|
|
2022-08-23 23:49:19 +02:00
|
|
|
public static function fromRequest(Request $request): self
|
|
|
|
{
|
|
|
|
return new self(
|
|
|
|
dateFrom: $request->dateFrom,
|
|
|
|
dateUntil: $request->dateUntil,
|
|
|
|
zipLocation: $request->zipLocation,
|
|
|
|
country: Country::findOrFail($request->country),
|
2022-11-07 16:18:11 +01:00
|
|
|
members: Member::whereIn('id', $request->members)->orderByRaw('lastname, firstname')->get()->chunk(17),
|
2022-08-23 23:49:19 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function countryName(): string
|
2022-08-23 23:49:19 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return $this->country->name;
|
2022-08-23 23:49:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function memberShort(Member $member): string
|
|
|
|
{
|
|
|
|
return $member->isLeader() ? 'L' : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberName(Member $member): string
|
|
|
|
{
|
|
|
|
return $member->lastname.', '.$member->firstname;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberAddress(Member $member): string
|
|
|
|
{
|
|
|
|
return $member->fullAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberGender(Member $member): string
|
|
|
|
{
|
|
|
|
if (!$member->gender) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return strtolower(substr($member->gender->name, 0, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function memberAge(Member $member): string
|
|
|
|
{
|
|
|
|
return (string) $member->getAge();
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function basename(): string
|
2022-08-23 23:49:19 +02:00
|
|
|
{
|
|
|
|
return 'zuschuesse-dv';
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function view(): string
|
2022-08-23 23:49:19 +02:00
|
|
|
{
|
|
|
|
return 'tex.zuschuss-dv';
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function template(): Template
|
2022-08-23 23:49:19 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return Template::make('tex.templates.contribution');
|
2022-08-23 23:49:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setFilename(string $filename): static
|
|
|
|
{
|
|
|
|
$this->filename = $filename;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function getEngine(): Engine
|
2022-08-23 23:49:19 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return Engine::PDFLATEX;
|
2022-08-23 23:49:19 +02:00
|
|
|
}
|
|
|
|
}
|