From 21bb6aadf6aa4e0d0bc3e733931e46a3c33078bf Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 17 Jul 2021 18:10:13 +0200 Subject: [PATCH] Fixed: dont group by firstname --- app/Pdf/PdfRepositoryFactory.php | 12 ++++----- tests/Feature/Pdf/GenerateTest.php | 41 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/app/Pdf/PdfRepositoryFactory.php b/app/Pdf/PdfRepositoryFactory.php index cbb6ce11..b320a787 100644 --- a/app/Pdf/PdfRepositoryFactory.php +++ b/app/Pdf/PdfRepositoryFactory.php @@ -20,7 +20,7 @@ class PdfRepositoryFactory public function fromSingleRequest(string $type, Member $member): ?PdfRepository { - $members = $this->singleMemberCollection($member); + $members = $this->singleMemberCollection($member, $type); if ($members->isEmpty()) { return null; @@ -34,11 +34,11 @@ class PdfRepositoryFactory ); } - public function singleMemberCollection(Member $member): Collection + public function singleMemberCollection(Member $member, string $type): Collection { - $members = Member::where($member->only(['firstname', 'lastname', 'address', 'zip', 'location'])) - ->whereHas('payments', fn ($q) => $q->whereNeedsPayment()) - ->get(); + $members = Member::where($member->only(['lastname', 'address', 'zip', 'location'])) + ->get() + ->filter(fn (Member $member) => app($type)->createable($member)); return $this->toMemberGroup($members); } @@ -52,7 +52,7 @@ class PdfRepositoryFactory { return $members->groupBy( fn ($member) => Str::slug( - "{$member->firstname}{$member->lastname}{$member->address}{$member->zip}{$member->location}", + "{$member->lastname}{$member->address}{$member->zip}{$member->location}", ), ); } diff --git a/tests/Feature/Pdf/GenerateTest.php b/tests/Feature/Pdf/GenerateTest.php index c83d759f..073efd9e 100644 --- a/tests/Feature/Pdf/GenerateTest.php +++ b/tests/Feature/Pdf/GenerateTest.php @@ -98,6 +98,47 @@ class GenerateTest extends TestCase '29.04.2021', ], ], + 'families' => [ + 'members' => [ + [ + 'factory' => fn (MemberFactory $member): MemberFactory => $member + ->state([ + 'firstname' => '::firstname1::', + 'lastname' => '::lastname::', + 'address' => '::address::', + 'zip' => '12345', + 'location' => '::location::', + ]), + 'payments' => [ + fn (PaymentFactory $payment): PaymentFactory => $payment + ->nr('::nr::')->notPaid()->subscription('::subName::', 1500), + ], + ], + [ + 'factory' => fn (MemberFactory $member): MemberFactory => $member + ->state([ + 'firstname' => '::firstname2::', + 'lastname' => '::lastname::', + 'address' => '::address::', + 'zip' => '12345', + 'location' => '::location::', + ]), + 'payments' => [ + fn (PaymentFactory $payment): PaymentFactory => $payment + ->nr('::nr2::')->notPaid()->subscription('::subName2::', 1600), + ], + ], + ], + 'urlCallable' => fn (Collection $members): int => $members->first()->id, + 'type' => BillType::class, + 'filename' => 'rechnung-fur-lastname.pdf', + 'output' => [ + '::nr::', + '::nr2::', + '::subName::', + '::subName2::', + ], + ], ]; }