adrema/app/Http/Views/MemberView.php

52 lines
1.9 KiB
PHP
Raw Normal View History

2021-07-04 16:56:07 +02:00
<?php
namespace App\Http\Views;
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-07-16 00:12:19 +02:00
use Illuminate\Http\Request;
2021-07-04 16:56:07 +02:00
class MemberView {
public function index(Request $request) {
return [
2021-08-22 05:15:56 +02:00
'data' => MemberResource::collection(Member::select('*')->search($request->query('search', null))->with('billKind')->with('payments')->withSubscriptionName()->withIsConfirmed()->withPendingPayment()->orderByRaw('lastname, firstname')->paginate(15)),
'toolbar' => [ ['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus'] ],
'paymentDefaults' => ['nr' => date('Y')],
'subscriptions' => Subscription::get()->pluck('name', 'id'),
'statuses' => Status::get()->pluck('name', '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([
'subscriptions' => Subscription::get()->pluck('name', 'id'),
'statuses' => Status::get()->pluck('name', 'id'),
], $overwrites));
}
}