diff --git a/app/Activity.php b/app/Activity.php index b19dac9d..c6e28c4e 100644 --- a/app/Activity.php +++ b/app/Activity.php @@ -11,7 +11,7 @@ class Activity extends Model use HasNamiField; - public $fillable = ['is_member', 'name', 'is_filterable', 'nami_id']; + public $fillable = ['is_try', 'is_member', 'name', 'is_filterable', 'nami_id']; public $timestamps = false; public $casts = [ diff --git a/app/Http/Views/HomeView.php b/app/Http/Views/HomeView.php index 6ccf0b28..3c5da304 100644 --- a/app/Http/Views/HomeView.php +++ b/app/Http/Views/HomeView.php @@ -15,7 +15,6 @@ class HomeView { $amount = Payment::whereNeedsPayment()->selectRaw('sum(subscriptions.amount) AS a')->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')->first()->a; $members = Member::whereHasPendingPayment()->count(); - return [ 'data' => [ 'payments' => [ @@ -30,7 +29,8 @@ class HomeView { ->where('activities.is_member', true) ->groupBy('subactivities.name', 'subactivities.slug') ->orderBy('subactivities.id') - ->get() + ->get(), + 'ending_tries' => MemberTriesResource::collection(Member::endingTries()->get()), ] ]; } diff --git a/app/Http/Views/MemberTriesResource.php b/app/Http/Views/MemberTriesResource.php new file mode 100644 index 00000000..cb3676c8 --- /dev/null +++ b/app/Http/Views/MemberTriesResource.php @@ -0,0 +1,23 @@ +<?php + +namespace App\Http\Views; + +use App\Member\MemberResource; +use Illuminate\Http\Resources\Json\JsonResource; + +class MemberTriesResource extends MemberResource +{ + /** + * Transform the resource into an array. + * + * @param \Illuminate\Http\Request $request + * @return array + */ + public function toArray($request) + { + return array_merge(parent::toArray($request), [ + 'try_ends_at' => $this->getModel()->try_created_at->addWeeks(8)->format('d.m.Y'), + 'try_ends_at_human' => $this->getModel()->try_created_at->addWeeks(8)->diffForHumans(), + ]); + } +} diff --git a/app/Member/Member.php b/app/Member/Member.php index 02e1356f..24c0e2da 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -27,7 +27,7 @@ class Member extends Model public $fillable = ['firstname', 'lastname', 'nickname', 'other_country', 'birthday', 'joined_at', 'send_newspaper', 'address', 'further_address', 'zip', 'location', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'nami_id', 'group_id', 'letter_address', 'country_id', 'way_id', 'nationality_id', 'subscription_id', 'region_id', 'gender_id', 'confession_id', 'letter_address', 'bill_kind_id', 'version', 'first_subactivity_id', 'first_activity_id', 'confirmed_at', 'children_phone']; - public $dates = ['joined_at', 'birthday']; + public $dates = ['try_created_at', 'joined_at', 'birthday']; public $casts = [ 'pending_payment' => 'integer', @@ -218,4 +218,17 @@ class Member extends Model return $q; } + public function scopeEndingTries(Builder $q): Builder + { + return $q->whereHas('memberships', fn ($q) => $q + ->where('created_at', '<=', now()->subWeeks(7)) + ->whereHas('activity', fn ($q) => $q->where('is_try', true))) + ->addSelect([ + 'try_created_at' => Membership::select('created_at') + ->whereColumn('memberships.member_id', 'members.id') + ->join('activities', 'activities.id', 'memberships.activity_id') + ->where('activities.is_try', true) + ]); + } + } diff --git a/database/migrations/2021_08_22_231629_create_activities_is_member_column.php b/database/migrations/2021_08_22_231629_create_activities_is_member_column.php index 47b87623..4f915783 100644 --- a/database/migrations/2021_08_22_231629_create_activities_is_member_column.php +++ b/database/migrations/2021_08_22_231629_create_activities_is_member_column.php @@ -17,6 +17,10 @@ class CreateActivitiesIsMemberColumn extends Migration Schema::table('activities', function (Blueprint $table) { $table->boolean('is_member')->default(false); }); + Schema::table('activities', function (Blueprint $table) { + $table->boolean('is_try')->default(false); + }); + Activity::firstWhere('name', 'Schnuppermitgliedschaft')->update(['is_try' => true]); Activity::whereIn('name', ['€ Mitglied', 'Schnuppermitgliedschaft'])->update(['is_member' => true]); } diff --git a/resources/js/views/home/Index.vue b/resources/js/views/home/Index.vue index 903ca804..77ef080e 100644 --- a/resources/js/views/home/Index.vue +++ b/resources/js/views/home/Index.vue @@ -13,6 +13,13 @@ <span v-text="group.count"></span> </div> </block> + <block title="Endende Schhnupperzeiten"> + <div v-for="member in data.ending_tries" class="flex mt-2 items-center leading-none text-gray-100"> + <span class="flex-grow" v-text="`${member.firstname} ${member.lastname}`"></span> + <span class="mr-2 text-sm tex-gray-600" v-text="`${member.try_ends_at}`"></span> + <span class="text-xs tex-gray-600" v-text="`${member.try_ends_at_human}`"></span> + </div> + </block> </div> </template>