diff --git a/app/Http/Views/MemberView.php b/app/Http/Views/MemberView.php index bc4be28a..26a2cea6 100644 --- a/app/Http/Views/MemberView.php +++ b/app/Http/Views/MemberView.php @@ -2,6 +2,7 @@ namespace App\Http\Views; +use App\Activity; use App\Member\Member; use App\Member\MemberResource; use App\Payment\ActionFactory; @@ -12,10 +13,12 @@ use Illuminate\Http\Request; class MemberView { public function index(Request $request, array $filter) { + $activities = Activity::with('subactivities')->get(); + return [ 'data' => MemberResource::collection(Member::select('*') ->filter($filter)->search($request->query('search', null)) - ->with('billKind')->with('payments') + ->with('billKind')->with('payments')->with('memberships') ->withSubscriptionName()->withIsConfirmed()->withPendingPayment()->withAgeGroup() ->orderByRaw('lastname, firstname') ->paginate(15) @@ -24,6 +27,10 @@ class MemberView { 'paymentDefaults' => ['nr' => date('Y')], 'subscriptions' => Subscription::get()->pluck('name', 'id'), 'statuses' => Status::get()->pluck('name', 'id'), + 'activities' => $activities->pluck('name', 'id'), + 'subactivities' => $activities->map(function(Activity $activity) { + return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id]; + })->pluck('subactivities', 'id'), ]; } diff --git a/app/Member/MemberResource.php b/app/Member/MemberResource.php index 36ab2cd9..167c2cbb 100644 --- a/app/Member/MemberResource.php +++ b/app/Member/MemberResource.php @@ -2,6 +2,7 @@ namespace App\Member; +use App\Membership\MembershipResource; use App\Payment\PaymentResource; use Illuminate\Http\Resources\Json\JsonResource; @@ -49,6 +50,7 @@ class MemberResource extends JsonResource 'is_confirmed' => $this->is_confirmed, 'children_phone' => $this->children_phone, 'payments' => PaymentResource::collection($this->whenLoaded('payments')), + 'memberships' => MembershipResource::collection($this->whenLoaded('memberships')), 'pending_payment' => $this->pending_payment ? number_format($this->pending_payment / 100, 2, ',', '.').' €' : null, 'first_activity_id' => $this->first_activity_id, 'first_subactivity_id' => $this->first_subactivity_id, diff --git a/app/Member/Membership.php b/app/Member/Membership.php index 339667dd..fb3d6af2 100644 --- a/app/Member/Membership.php +++ b/app/Member/Membership.php @@ -2,12 +2,26 @@ namespace App\Member; +use App\Activity; +use App\Subactivity; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Membership extends Model { use HasFactory; public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'created_at']; + + public function activity(): BelongsTo + { + return $this->belongsTo(Activity::class); + } + + public function subactivity(): BelongsTo + { + return $this->belongsTo(Subactivity::class); + } + } diff --git a/app/Membership/MembershipController.php b/app/Membership/MembershipController.php new file mode 100644 index 00000000..0dd057e7 --- /dev/null +++ b/app/Membership/MembershipController.php @@ -0,0 +1,18 @@ +memberships()->create($request->input()); + + return redirect()->back(); + } +} diff --git a/app/Membership/MembershipResource.php b/app/Membership/MembershipResource.php new file mode 100644 index 00000000..8cd6d01d --- /dev/null +++ b/app/Membership/MembershipResource.php @@ -0,0 +1,26 @@ + $this->id, + 'activity_id' => $this->activity_id, + 'activity_name' => $this->activity->name, + 'subactivity_id' => $this->subactivity_id, + 'subactivity_name' => optional($this->subactivity)->name, + 'human_date' => $this->created_at->format('d.m.Y'), + ]; + } +} diff --git a/resources/js/views/member/Index.vue b/resources/js/views/member/Index.vue index 77f365e3..5a469174 100644 --- a/resources/js/views/member/Index.vue +++ b/resources/js/views/member/Index.vue @@ -53,6 +53,7 @@ + @@ -65,6 +66,7 @@ + @@ -72,6 +74,7 @@ diff --git a/resources/js/views/member/Memberships.vue b/resources/js/views/member/Memberships.vue new file mode 100644 index 00000000..b9c2ce6c --- /dev/null +++ b/resources/js/views/member/Memberships.vue @@ -0,0 +1,87 @@ + + + diff --git a/routes/web.php b/routes/web.php index d128bac2..1325ee2b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ use App\Http\Controllers\HomeController; use App\Initialize\InitializeController; use App\Member\MemberConfirmController; use App\Member\MemberController; +use App\Membership\MembershipController; use App\Payment\AllpaymentController; use App\Payment\PaymentController; use App\Payment\SendpaymentController; @@ -26,4 +27,5 @@ Route::group(['middleware' => 'auth:web'], function (): void { ->name('member.singlepdf'); Route::get('/sendpayment', [SendpaymentController::class, 'create'])->name('sendpayment.create'); Route::get('/sendpayment/pdf', [SendpaymentController::class, 'send'])->name('sendpayment.pdf'); + Route::apiResource('member.membership', MembershipController::class); });