adrema/app/Http/Views/MemberView.php

59 lines
2.0 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;
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-07-04 21:47:20 +02:00
'data' => MemberResource::collection(Member::select('*')->search($request->query('search', null))->with('billKind')->withSubscriptionName()->withIsConfirmed()->withPendingPayment()->orderByRaw('lastname, firstname')->paginate(15)),
2021-07-04 16:56:07 +02:00
'toolbar' => [ ['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus'] ]
];
}
public function paymentCreate($member) {
return $this->additional($member, [
'model' => [
'subscription_id' => $member->subscription_id,
'status_id' => Status::default(),
'nr' => date('Y'),
],
'links' => [ ['label' => 'Zurück', 'href' => route('member.payment.index', ['member' => $member]) ] ],
'mode' => 'create',
]);
}
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-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));
}
}