Fixed: dont group by firstname

This commit is contained in:
philipp lang 2021-07-17 18:10:13 +02:00
parent 1c0a68d4c6
commit 21bb6aadf6
2 changed files with 47 additions and 6 deletions

View File

@ -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}",
),
);
}

View File

@ -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::',
],
],
];
}