From 52ac5937a4791393debda729d53481a42c613ff4 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 13 Dec 2024 01:59:09 +0100 Subject: [PATCH] Add validation --- app/Contribution/Data/MemberData.php | 10 ++++ .../Documents/GallierDocument.php | 49 +++---------------- app/Gender.php | 9 ++++ resources/views/tex/contribution/gallier.tex | 2 +- tests/Feature/Contribution/StoreTest.php | 16 ++++++ 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/app/Contribution/Data/MemberData.php b/app/Contribution/Data/MemberData.php index c7be0b80..9e44f910 100644 --- a/app/Contribution/Data/MemberData.php +++ b/app/Contribution/Data/MemberData.php @@ -81,4 +81,14 @@ class MemberData extends Data { return (string) $this->birthday->year; } + + public function birthdayHuman(): string + { + return $this->birthday->format('d.m.Y'); + } + + public function genderLetter(): string + { + return $this->gender->short; + } } diff --git a/app/Contribution/Documents/GallierDocument.php b/app/Contribution/Documents/GallierDocument.php index 520e8846..e375a60c 100644 --- a/app/Contribution/Documents/GallierDocument.php +++ b/app/Contribution/Documents/GallierDocument.php @@ -25,11 +25,14 @@ class GallierDocument extends ContributionDocument ) { } - public function dateRange(): string + public function dateFromHuman(): string { - return Carbon::parse($this->dateFrom)->format('d.m.Y') - . ' - ' - . Carbon::parse($this->dateUntil)->format('d.m.Y'); + return Carbon::parse($this->dateFrom)->format('d.m.Y'); + } + + public function dateUntilHuman(): string + { + return Carbon::parse($this->dateUntil)->format('d.m.Y'); } /** @@ -60,40 +63,6 @@ class GallierDocument extends ContributionDocument ); } - public function countryName(): string - { - return $this->country->name; - } - - public function memberShort(MemberData $member): string - { - return $member->isLeader ? 'L' : ''; - } - - public function memberName(MemberData $member): string - { - return $member->separatedName(); - } - - public function memberAddress(MemberData $member): string - { - return $member->fullAddress(); - } - - public function memberGender(MemberData $member): string - { - if (!$member->gender) { - return ''; - } - - return strtolower(substr($member->gender->name, 0, 1)); - } - - public function memberAge(MemberData $member): string - { - return $member->age(); - } - public function basename(): string { return 'zuschuesse-gallier'; @@ -123,7 +92,7 @@ class GallierDocument extends ContributionDocument public static function getName(): string { - return 'Für RdP NRW erstellen'; + return 'Für Gallier erstellen'; } /** @@ -134,9 +103,7 @@ class GallierDocument extends ContributionDocument 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', ]; } } diff --git a/app/Gender.php b/app/Gender.php index 883657fb..2d22627b 100644 --- a/app/Gender.php +++ b/app/Gender.php @@ -25,6 +25,15 @@ class Gender extends Model }; } + public function getShortAttribute(): string + { + return match ($this->name) { + 'Männlich' => 'm', + 'Weiblich' => 'w', + default => '' + }; + } + public static function fromString(string $title): self { return self::firstWhere('name', $title); diff --git a/resources/views/tex/contribution/gallier.tex b/resources/views/tex/contribution/gallier.tex index d6256f35..0fe8169c 100644 --- a/resources/views/tex/contribution/gallier.tex +++ b/resources/views/tex/contribution/gallier.tex @@ -28,7 +28,7 @@ \node[anchor=center, text width=45.75mm, align=center] at ($(135.35mm, 59.7mm + 9.2mm * <<<$i%14>>>)$) {<<<$member->address>>>}; \node[anchor=center, text width=26.75mm, align=center] at ($(174.35mm, 59.7mm + 9.2mm * <<<$i%14>>>)$) {<<<$member->city()>>>}; \node[anchor=center, text width=19.75mm, align=center] at ($(199.35mm, 59.7mm + 9.2mm * <<<$i%14>>>)$) {<<<$member->birthdayHuman()>>>}; - \node[anchor=center, text width=7.75mm, align=center] at ($(216.35mm, 59.7mm + 9.2mm * <<<$i%14>>>)$) {<<<$member->gender?->short>>>}; + \node[anchor=center, text width=7.75mm, align=center] at ($(216.35mm, 59.7mm + 9.2mm * <<<$i%14>>>)$) {<<<$member->genderLetter()>>>}; \node[anchor=center, text width=7.75mm, align=center] at ($(276.35mm, 59.7mm + 9.2mm * <<<$i%14>>>)$) {<<<$member->isLeader ? 'GL' : 'T'>>>}; @endforeach diff --git a/tests/Feature/Contribution/StoreTest.php b/tests/Feature/Contribution/StoreTest.php index 9b139d15..cce1ec27 100644 --- a/tests/Feature/Contribution/StoreTest.php +++ b/tests/Feature/Contribution/StoreTest.php @@ -5,6 +5,7 @@ namespace Tests\Feature\Contribution; use App\Contribution\Documents\ContributionDocument; use App\Contribution\Documents\RdpNrwDocument; use App\Contribution\Documents\CitySolingenDocument; +use App\Contribution\Documents\GallierDocument; use App\Country; use App\Gender; use App\Invoice\InvoiceSettings; @@ -89,6 +90,21 @@ dataset('validation', function () { CitySolingenDocument::class, 'zipLocation', ], + [ + ['zipLocation' => ''], + GallierDocument::class, + 'zipLocation', + ], + [ + ['dateFrom' => ''], + GallierDocument::class, + 'dateFrom', + ], + [ + ['dateUntil' => ''], + GallierDocument::class, + 'dateUntil', + ], ]; });