2020-06-02 23:45:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Member;
|
|
|
|
|
2021-06-23 01:05:17 +02:00
|
|
|
use App\Activity;
|
2021-07-17 18:46:02 +02:00
|
|
|
use App\Bill\BillKind;
|
|
|
|
use App\Confession;
|
|
|
|
use App\Country;
|
|
|
|
use App\Gender;
|
2021-06-23 01:05:17 +02:00
|
|
|
use App\Group;
|
2021-07-17 18:46:02 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
2021-07-04 16:56:07 +02:00
|
|
|
use App\Http\Views\MemberView;
|
2021-07-04 19:09:59 +02:00
|
|
|
use App\Member\DeleteJob;
|
2021-07-17 18:46:02 +02:00
|
|
|
use App\Nationality;
|
|
|
|
use App\Payment\Subscription;
|
|
|
|
use App\Region;
|
|
|
|
use Illuminate\Http\Request;
|
2021-07-15 20:56:53 +02:00
|
|
|
use Inertia\Response;
|
2020-06-02 23:45:25 +02:00
|
|
|
|
|
|
|
class MemberController extends Controller
|
|
|
|
{
|
2021-04-11 20:01:37 +02:00
|
|
|
|
2021-08-22 05:51:25 +02:00
|
|
|
public $filter = [
|
|
|
|
'ausstand' => false,
|
2021-08-22 16:15:16 +02:00
|
|
|
'bill_kind' => null,
|
2021-08-22 05:51:25 +02:00
|
|
|
];
|
|
|
|
|
2021-07-15 20:56:53 +02:00
|
|
|
public function index(Request $request): Response {
|
2021-04-11 01:25:40 +02:00
|
|
|
session()->put('menu', 'member');
|
|
|
|
session()->put('title', 'Mitglieder');
|
2021-08-22 05:51:25 +02:00
|
|
|
|
|
|
|
$query = [
|
|
|
|
'filter' => array_merge(
|
|
|
|
$this->filter,
|
|
|
|
json_decode($request->query('filter', '{}'), true)
|
|
|
|
),
|
|
|
|
];
|
2021-04-11 01:25:40 +02:00
|
|
|
|
2021-08-22 05:51:25 +02:00
|
|
|
$payload = app(MemberView::class)->index($request, $query['filter']);
|
2021-07-04 22:32:40 +02:00
|
|
|
$payload['toolbar'] = [
|
|
|
|
['href' => route('member.create'), 'label' => 'Mitglied anlegen', 'color' => 'primary', 'icon' => 'plus'],
|
2021-07-17 18:46:02 +02:00
|
|
|
['href' => route('allpayment.create'), 'label' => 'Rechnungen erstellen', 'color' => 'primary', 'icon' => 'plus'],
|
|
|
|
['href' => route('sendpayment.create'), 'label' => 'Rechnungen versenden', 'color' => 'info', 'icon' => 'envelope'],
|
2021-07-04 22:32:40 +02:00
|
|
|
];
|
2021-08-22 05:51:25 +02:00
|
|
|
$payload['query'] = $query;
|
|
|
|
$payload['billKinds'] = BillKind::get()->pluck('name', 'id');
|
2021-07-04 16:56:07 +02:00
|
|
|
|
|
|
|
return \Inertia::render('member/Index', $payload);
|
2020-06-02 23:45:25 +02:00
|
|
|
}
|
2021-04-11 11:19:55 +02:00
|
|
|
|
2021-07-15 20:56:53 +02:00
|
|
|
public function create(): Response {
|
2021-06-22 00:22:30 +02:00
|
|
|
session()->put('menu', 'member');
|
|
|
|
session()->put('title', 'Mitglied erstellen');
|
|
|
|
|
2021-06-23 01:05:17 +02:00
|
|
|
$activities = Activity::with('subactivities')->get();
|
|
|
|
|
2021-06-22 00:22:30 +02:00
|
|
|
return \Inertia::render('member/Form', [
|
2021-06-23 01:05:17 +02:00
|
|
|
'activities' => $activities->pluck('name', 'id'),
|
2021-07-15 20:56:53 +02:00
|
|
|
'subactivities' => $activities->map(function(Activity $activity) {
|
2021-06-23 01:05:17 +02:00
|
|
|
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
|
|
|
|
})->pluck('subactivities', 'id'),
|
2021-06-22 00:22:30 +02:00
|
|
|
'billKinds' => BillKind::get()->pluck('name', 'id'),
|
|
|
|
'genders' => Gender::get()->pluck('name', 'id'),
|
|
|
|
'countries' => Country::get()->pluck('name', 'id'),
|
|
|
|
'regions' => Region::where('is_null', false)->get()->pluck('name', 'id'),
|
|
|
|
'nationalities' => Nationality::get()->pluck('name', 'id'),
|
|
|
|
'confessions' => Confession::where('is_null', false)->get()->pluck('name', 'id'),
|
2021-07-04 12:09:30 +02:00
|
|
|
'subscriptions' => Subscription::get()->pluck('name', 'id'),
|
2021-06-22 23:00:27 +02:00
|
|
|
'data' => [
|
|
|
|
'country_id' => Country::default()
|
|
|
|
],
|
2021-06-22 00:22:30 +02:00
|
|
|
'mode' => 'create',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(MemberRequest $request) {
|
|
|
|
$request->persistCreate();
|
|
|
|
|
|
|
|
return redirect()->route('member.index');
|
|
|
|
}
|
|
|
|
|
2021-04-11 11:19:55 +02:00
|
|
|
public function edit(Member $member, Request $request) {
|
|
|
|
session()->put('menu', 'member');
|
2021-06-28 23:15:16 +02:00
|
|
|
session()->put('title', "Mitglied {$member->firstname} {$member->lastname} bearbeiten");
|
2021-04-11 11:19:55 +02:00
|
|
|
|
2021-07-05 13:31:20 +02:00
|
|
|
$activities = Activity::with('subactivities')->get();
|
|
|
|
|
2021-06-22 00:22:30 +02:00
|
|
|
return \Inertia::render('member/Form', [
|
2021-07-05 13:31:20 +02:00
|
|
|
'activities' => $activities->pluck('name', 'id'),
|
|
|
|
'subactivities' => $activities->map(function($activity) {
|
|
|
|
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
|
|
|
|
})->pluck('subactivities', 'id'),
|
2021-04-11 18:17:40 +02:00
|
|
|
'billKinds' => BillKind::get()->pluck('name', 'id'),
|
2021-04-11 17:02:49 +02:00
|
|
|
'genders' => Gender::get()->pluck('name', 'id'),
|
2021-04-11 11:44:51 +02:00
|
|
|
'countries' => Country::get()->pluck('name', 'id'),
|
|
|
|
'regions' => Region::where('is_null', false)->get()->pluck('name', 'id'),
|
|
|
|
'nationalities' => Nationality::get()->pluck('name', 'id'),
|
|
|
|
'confessions' => Confession::where('is_null', false)->get()->pluck('name', 'id'),
|
2021-07-04 12:09:30 +02:00
|
|
|
'subscriptions' => Subscription::get()->pluck('name', 'id'),
|
2021-06-22 00:22:30 +02:00
|
|
|
'data' => new MemberResource($member),
|
|
|
|
'mode' => 'edit',
|
2021-04-11 11:19:55 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2021-04-11 20:01:37 +02:00
|
|
|
public function update(Member $member, MemberRequest $request) {
|
|
|
|
$request->persistUpdate($member);
|
2021-04-11 11:19:55 +02:00
|
|
|
|
|
|
|
return redirect()->route('member.index');
|
|
|
|
}
|
2021-07-04 19:09:59 +02:00
|
|
|
|
|
|
|
public function destroy(Member $member) {
|
|
|
|
if ($member->has_nami) {
|
|
|
|
DeleteJob::dispatch($member, auth()->user());
|
|
|
|
}
|
|
|
|
|
|
|
|
$member->delete();
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
2020-06-02 23:45:25 +02:00
|
|
|
}
|