diff --git a/app/Member/Membership.php b/app/Member/Membership.php index 48df23cd..6dd09dab 100644 --- a/app/Member/Membership.php +++ b/app/Member/Membership.php @@ -44,6 +44,16 @@ class Membership extends Model return $this->belongsTo(Subactivity::class); } + /** + * @param Builder $query + * + * @return Builder + */ + public function scopeActive(Builder $query): Builder + { + return $query->whereNull('to'); + } + /** * @param Builder $query * diff --git a/app/Membership/AgeGroupCountBlock.php b/app/Membership/AgeGroupCountBlock.php index d7e7542a..d0fc7e56 100644 --- a/app/Membership/AgeGroupCountBlock.php +++ b/app/Membership/AgeGroupCountBlock.php @@ -19,6 +19,7 @@ class AgeGroupCountBlock extends Block ->join('subactivities', 'memberships.subactivity_id', 'subactivities.id') ->isAgeGroup() ->isMember() + ->active() ->groupBy('subactivities.slug', 'subactivities.name') ->orderBy('subactivity_id'); } @@ -31,6 +32,7 @@ class AgeGroupCountBlock extends Block return Membership::selectRaw('"leiter" AS slug, "Leiter" AS name, COUNT(member_id) AS count') ->join('activities', 'memberships.activity_id', 'activities.id') ->join('subactivities', 'memberships.subactivity_id', 'subactivities.id') + ->active() ->isLeader(); } diff --git a/database/factories/Member/MembershipFactory.php b/database/factories/Member/MembershipFactory.php index 46c6434b..bf3e1b54 100644 --- a/database/factories/Member/MembershipFactory.php +++ b/database/factories/Member/MembershipFactory.php @@ -51,6 +51,11 @@ class MembershipFactory extends Factory return $instance; } + public function ended(): self + { + return $this->state(['to' => now()->subDays(2)]); + } + public function in(string $activity, int $activityNamiId, ?string $subactivity = null, ?int $subactivityNamiId = null): self { $instance = $this->for(Activity::factory()->name($activity)->inNami($activityNamiId)); diff --git a/tests/Feature/Membership/AgeGroupCountBlockTest.php b/tests/Feature/Membership/AgeGroupCountBlockTest.php index 05a1ff71..45ba040f 100644 --- a/tests/Feature/Membership/AgeGroupCountBlockTest.php +++ b/tests/Feature/Membership/AgeGroupCountBlockTest.php @@ -26,7 +26,10 @@ class AgeGroupCountBlockTest extends TestCase Member::factory()->count(2)->has(Membership::factory()->in('€ LeiterIn', 2, 'Wölfling', 3)) ->defaults() ->create(); - Member::factory()->count(2)->has(Membership::factory()->in('€ LeiterIn', 2, 'Jungpfadfinder', 3)) + Member::factory()->count(2) + ->has(Membership::factory()->in('€ LeiterIn', 2, 'Jungpfadfinder', 3)) + ->has(Membership::factory()->ended()->in('€ LeiterIn', 2, 'Pfadfinder', 3)) + ->has(Membership::factory()->ended()->in('€ Mitglied', 2, 'Jungpfadfinder', 3)) ->defaults() ->create();