2021-07-04 16:56:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Views;
|
|
|
|
|
2021-08-22 22:23:17 +02:00
|
|
|
use App\Activity;
|
2021-11-19 22:58:27 +01:00
|
|
|
use App\Course\Models\Course;
|
2021-07-04 16:56:07 +02:00
|
|
|
use App\Member\Member;
|
2021-07-16 00:12:19 +02:00
|
|
|
use App\Member\MemberResource;
|
2021-07-17 16:57:37 +02:00
|
|
|
use App\Payment\ActionFactory;
|
2021-07-16 00:12:19 +02:00
|
|
|
use App\Payment\PaymentResource;
|
2021-07-04 16:56:07 +02:00
|
|
|
use App\Payment\Status;
|
|
|
|
use App\Payment\Subscription;
|
2021-08-23 00:46:41 +02:00
|
|
|
use App\Subactivity;
|
2021-07-16 00:12:19 +02:00
|
|
|
use Illuminate\Http\Request;
|
2021-07-04 16:56:07 +02:00
|
|
|
|
|
|
|
class MemberView {
|
2021-08-22 05:51:25 +02:00
|
|
|
public function index(Request $request, array $filter) {
|
2021-08-22 22:23:17 +02:00
|
|
|
$activities = Activity::with('subactivities')->get();
|
|
|
|
|
2021-07-04 16:56:07 +02:00
|
|
|
return [
|
2021-08-22 19:31:20 +02:00
|
|
|
'data' => MemberResource::collection(Member::select('*')
|
|
|
|
->filter($filter)->search($request->query('search', null))
|
2021-11-19 22:58:27 +01:00
|
|
|
->with('billKind')->with('payments')->with('memberships')->with('courses')
|
2021-08-22 19:31:20 +02:00
|
|
|
->withSubscriptionName()->withIsConfirmed()->withPendingPayment()->withAgeGroup()
|
|
|
|
->orderByRaw('lastname, firstname')
|
|
|
|
->paginate(15)
|
|
|
|
),
|
2021-11-19 22:58:27 +01:00
|
|
|
'filterActivities' => Activity::where('is_filterable', true)->pluck('name', 'id'),
|
|
|
|
'filterSubactivities' => Subactivity::where('is_filterable', true)->pluck('name', 'id'),
|
2021-08-22 05:15:56 +02:00
|
|
|
'toolbar' => [ ['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus'] ],
|
|
|
|
'paymentDefaults' => ['nr' => date('Y')],
|
2021-11-19 22:58:27 +01:00
|
|
|
'subscriptions' => Subscription::pluck('name', 'id'),
|
|
|
|
'statuses' => Status::pluck('name', 'id'),
|
2021-08-22 22:23:17 +02:00
|
|
|
'activities' => $activities->pluck('name', 'id'),
|
2021-11-19 22:58:27 +01:00
|
|
|
'courses' => Course::pluck('name', 'id'),
|
2021-08-22 22:23:17 +02:00
|
|
|
'subactivities' => $activities->map(function(Activity $activity) {
|
|
|
|
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
|
|
|
|
})->pluck('subactivities', 'id'),
|
2021-07-04 16:56:07 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function paymentEdit($member, $payment) {
|
|
|
|
return $this->additional($member, [
|
|
|
|
'model' => new PaymentResource($payment),
|
|
|
|
'links' => [ ['label' => 'Zurück', 'href' => route('member.payment.index', ['member' => $member]) ] ],
|
|
|
|
'mode' => 'edit',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function paymentIndex($member) {
|
|
|
|
return $this->additional($member, [
|
|
|
|
'model' => null,
|
2021-07-05 00:35:38 +02:00
|
|
|
'links' => [
|
|
|
|
['icon' => 'plus', 'href' => route('member.payment.create', ['member' => $member]) ],
|
|
|
|
],
|
2021-07-17 16:57:37 +02:00
|
|
|
'payment_links' => app(ActionFactory::class)->forMember($member),
|
2021-07-04 16:56:07 +02:00
|
|
|
'mode' => 'index',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function additional($member, $overwrites = []) {
|
|
|
|
return (new MemberResource($member->load('payments')))
|
|
|
|
->additional(array_merge([
|
2022-01-02 12:32:57 +01:00
|
|
|
'subscriptions' => Subscription::pluck('name', 'id'),
|
|
|
|
'statuses' => Status::pluck('name', 'id'),
|
2021-07-04 16:56:07 +02:00
|
|
|
], $overwrites));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|