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;
|
2022-02-12 16:16:56 +01:00
|
|
|
use App\Payment\Payment;
|
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;
|
2022-03-20 12:20:01 +01:00
|
|
|
use App\Region;
|
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
|
|
|
|
2022-03-11 20:19:17 +01:00
|
|
|
class MemberView
|
|
|
|
{
|
2022-02-12 16:16:56 +01:00
|
|
|
public function index(Request $request, array $filter): array
|
|
|
|
{
|
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'),
|
2022-03-11 20:19:17 +01:00
|
|
|
'toolbar' => [['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus']],
|
2021-08-22 05:15:56 +02:00
|
|
|
'paymentDefaults' => ['nr' => date('Y')],
|
2021-11-19 22:58:27 +01:00
|
|
|
'subscriptions' => Subscription::pluck('name', 'id'),
|
|
|
|
'statuses' => Status::pluck('name', 'id'),
|
2022-03-20 12:20:01 +01:00
|
|
|
'regions' => Region::forSelect(),
|
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'),
|
2022-03-11 20:19:17 +01:00
|
|
|
'subactivities' => $activities->map(function (Activity $activity) {
|
2021-08-22 22:23:17 +02:00
|
|
|
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
|
|
|
|
})->pluck('subactivities', 'id'),
|
2021-07-04 16:56:07 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
public function paymentEdit(Member $member, Payment $payment): MemberResource
|
|
|
|
{
|
2021-07-04 16:56:07 +02:00
|
|
|
return $this->additional($member, [
|
|
|
|
'model' => new PaymentResource($payment),
|
2022-03-11 20:19:17 +01:00
|
|
|
'links' => [['label' => 'Zurück', 'href' => route('member.payment.index', ['member' => $member])]],
|
2021-07-04 16:56:07 +02:00
|
|
|
'mode' => 'edit',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
public function paymentIndex(Member $member): MemberResource
|
|
|
|
{
|
2021-07-04 16:56:07 +02:00
|
|
|
return $this->additional($member, [
|
|
|
|
'model' => null,
|
2021-07-05 00:35:38 +02:00
|
|
|
'links' => [
|
2022-03-11 20:19:17 +01:00
|
|
|
['icon' => 'plus', 'href' => route('member.payment.create', ['member' => $member])],
|
2021-07-05 00:35:38 +02:00
|
|
|
],
|
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',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
private function additional(Member $member, array $overwrites = []): MemberResource
|
|
|
|
{
|
2021-07-04 16:56:07 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|