This commit is contained in:
philipp lang 2022-02-12 16:16:56 +01:00
parent 09e8ab1bcc
commit d0b78d3120
20 changed files with 102 additions and 57 deletions

View File

@ -2,10 +2,11 @@
namespace App; namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Member\Member; use App\Member\Member;
use App\Payment\Subscription; use App\Payment\Subscription;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Fee extends Model class Fee extends Model
{ {
@ -14,8 +15,8 @@ class Fee extends Model
public $fillable = ['name', 'nami_id']; public $fillable = ['name', 'nami_id'];
public $timestamps = false; public $timestamps = false;
public function subscriptions(): HasMany
public function subscriptions() { {
return $this->hasMany(Subscription::class); return $this->hasMany(Subscription::class);
} }
} }

View File

@ -12,7 +12,8 @@ class Group extends Model
public $fillable = ['nami_id', 'name']; public $fillable = ['nami_id', 'name'];
public $timestamps = false; public $timestamps = false;
public static function nami($id) { public static function nami(int $id): self
{
return static::firstWhere('nami_id', $id); return static::firstWhere('nami_id', $id);
} }
} }

View File

@ -4,10 +4,11 @@ namespace App\Http\Controllers;
use App\Http\Views\HomeView; use App\Http\Views\HomeView;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Inertia\Response;
class HomeController extends Controller class HomeController extends Controller
{ {
public function __invoke(Request $request) public function __invoke(Request $request): Response
{ {
session()->put('menu', 'dashboard'); session()->put('menu', 'dashboard');
session()->put('title', 'Dashboard'); session()->put('title', 'Dashboard');

View File

@ -7,7 +7,7 @@ use Closure;
class RedirectIfNotInitializedMiddleware class RedirectIfNotInitializedMiddleware
{ {
public $dontRedirect = ['initialize.index', 'initialize.store']; public array $dontRedirect = ['initialize.index', 'initialize.store'];
/** /**
* Handle an incoming request. * Handle an incoming request.
@ -29,11 +29,13 @@ class RedirectIfNotInitializedMiddleware
return $next($request); return $next($request);
} }
public function shouldRedirect() { public function shouldRedirect(): bool
{
return !request()->routeIs($this->dontRedirect) && auth()->check(); return !request()->routeIs($this->dontRedirect) && auth()->check();
} }
public function initialized() { public function initialized(): bool
{
return \App\Fee::count() > 0; return \App\Fee::count() > 0;
} }
} }

View File

@ -11,7 +11,8 @@ use App\Payment\Subscription;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class HomeView { class HomeView {
public function index(Request $request) { public function index(Request $request): array
{
/** @var object{a: string} */ /** @var object{a: string} */
$amount = Payment::whereNeedsPayment()->selectRaw('sum(subscriptions.amount) AS a')->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')->first(); $amount = Payment::whereNeedsPayment()->selectRaw('sum(subscriptions.amount) AS a')->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')->first();
$members = Member::whereHasPendingPayment()->count(); $members = Member::whereHasPendingPayment()->count();

View File

@ -7,6 +7,7 @@ use App\Course\Models\Course;
use App\Member\Member; use App\Member\Member;
use App\Member\MemberResource; use App\Member\MemberResource;
use App\Payment\ActionFactory; use App\Payment\ActionFactory;
use App\Payment\Payment;
use App\Payment\PaymentResource; use App\Payment\PaymentResource;
use App\Payment\Status; use App\Payment\Status;
use App\Payment\Subscription; use App\Payment\Subscription;
@ -14,7 +15,8 @@ use App\Subactivity;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class MemberView { class MemberView {
public function index(Request $request, array $filter) { public function index(Request $request, array $filter): array
{
$activities = Activity::with('subactivities')->get(); $activities = Activity::with('subactivities')->get();
return [ return [
@ -39,7 +41,8 @@ class MemberView {
]; ];
} }
public function paymentEdit($member, $payment) { public function paymentEdit(Member $member, Payment $payment): MemberResource
{
return $this->additional($member, [ return $this->additional($member, [
'model' => new PaymentResource($payment), 'model' => new PaymentResource($payment),
'links' => [ ['label' => 'Zurück', 'href' => route('member.payment.index', ['member' => $member]) ] ], 'links' => [ ['label' => 'Zurück', 'href' => route('member.payment.index', ['member' => $member]) ] ],
@ -47,7 +50,8 @@ class MemberView {
]); ]);
} }
public function paymentIndex($member) { public function paymentIndex(Member $member): MemberResource
{
return $this->additional($member, [ return $this->additional($member, [
'model' => null, 'model' => null,
'links' => [ 'links' => [
@ -58,7 +62,8 @@ class MemberView {
]); ]);
} }
private function additional($member, $overwrites = []) { private function additional(Member $member, array $overwrites = []): MemberResource
{
return (new MemberResource($member->load('payments'))) return (new MemberResource($member->load('payments')))
->additional(array_merge([ ->additional(array_merge([
'subscriptions' => Subscription::pluck('name', 'id'), 'subscriptions' => Subscription::pluck('name', 'id'),

View File

@ -2,6 +2,8 @@
namespace App\Initialize; namespace App\Initialize;
use Zoomyboy\LaravelNami\Api;
class ActivityCreator { class ActivityCreator {
private array $tries = [ private array $tries = [
@ -13,8 +15,8 @@ class ActivityCreator {
'Schnuppermitgliedschaft', 'Schnuppermitgliedschaft',
]; ];
public function createFor(Api $api, int $groupId): void
public function createFor($api, int $groupId) { {
$api->activities($groupId)->each(function($activity) use ($api) { $api->activities($groupId)->each(function($activity) use ($api) {
$activity = \App\Activity::updateOrCreate(['nami_id' => $activity->id], [ $activity = \App\Activity::updateOrCreate(['nami_id' => $activity->id], [
'nami_id' => $activity->id, 'nami_id' => $activity->id,

View File

@ -2,17 +2,19 @@
namespace App\Initialize; namespace App\Initialize;
use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\NamiUser; use Zoomyboy\LaravelNami\NamiUser;
class InitializeActivities { class InitializeActivities {
private $api; private Api $api;
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function handle(NamiUser $user) { public function handle(NamiUser $user): void
{
app(ActivityCreator::class)->createFor($this->api, $user->getNamiGroupId()); app(ActivityCreator::class)->createFor($this->api, $user->getNamiGroupId());
} }
} }

View File

@ -3,17 +3,19 @@
namespace App\Initialize; namespace App\Initialize;
use App\Confession; use App\Confession;
use Zoomyboy\LaravelNami\Api;
class InitializeConfessions { class InitializeConfessions {
private $api; private Api $api;
public $nullName = 'ohne Konfession'; public string $nullName = 'ohne Konfession';
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function handle() { public function handle(): void
{
$this->api->confessions()->each(function($confession) { $this->api->confessions()->each(function($confession) {
Confession::create(['nami_id' => $confession->id, 'name' => $confession->name, 'is_null' => $this->nullName === $confession->name]); Confession::create(['nami_id' => $confession->id, 'name' => $confession->name, 'is_null' => $this->nullName === $confession->name]);
}); });

View File

@ -2,15 +2,18 @@
namespace App\Initialize; namespace App\Initialize;
use Zoomyboy\LaravelNami\Api;
class InitializeCountries { class InitializeCountries {
private $api; private Api $api;
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function handle() { public function handle(): void
{
$this->api->countries()->each(function($country) { $this->api->countries()->each(function($country) {
\App\Country::create(['nami_id' => $country->id, 'name' => $country->name]); \App\Country::create(['nami_id' => $country->id, 'name' => $country->name]);
}); });

View File

@ -2,17 +2,19 @@
namespace App\Initialize; namespace App\Initialize;
use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\NamiUser; use Zoomyboy\LaravelNami\NamiUser;
class InitializeFees { class InitializeFees {
private $api; private Api $api;
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function handle(NamiUser $user) { public function handle(NamiUser $user): void
{
$this->api->feesOf($user->getNamiGroupId())->each(function($fee) { $this->api->feesOf($user->getNamiGroupId())->each(function($fee) {
\App\Fee::create(['nami_id' => $fee->id, 'name' => $fee->name]) \App\Fee::create(['nami_id' => $fee->id, 'name' => $fee->name])
->subscriptions()->create([ ->subscriptions()->create([

View File

@ -2,17 +2,19 @@
namespace App\Initialize; namespace App\Initialize;
use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\NamiUser; use Zoomyboy\LaravelNami\NamiUser;
class InitializeGenders { class InitializeGenders {
private $api; private Api $api;
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function handle(NamiUser $user) { public function handle(NamiUser $user): void
{
$this->api->genders()->each(function($gender) { $this->api->genders()->each(function($gender) {
\App\Gender::create(['nami_id' => $gender->id, 'name' => $gender->name]); \App\Gender::create(['nami_id' => $gender->id, 'name' => $gender->name]);
}); });

View File

@ -15,7 +15,7 @@ class InitializeJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasProgress; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, HasProgress;
public $user; public NamiUser $user;
public function __construct(NamiUser $user) public function __construct(NamiUser $user)
{ {

View File

@ -15,19 +15,22 @@ use App\Region;
use App\Subactivity; use App\Subactivity;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Zoomyboy\LaravelNami\Api;
use Zoomyboy\LaravelNami\Exceptions\RightException; use Zoomyboy\LaravelNami\Exceptions\RightException;
use Zoomyboy\LaravelNami\Member as NamiMember; use Zoomyboy\LaravelNami\Member as NamiMember;
use Zoomyboy\LaravelNami\Membership as NamiMembership;
use Zoomyboy\LaravelNami\NamiException; use Zoomyboy\LaravelNami\NamiException;
class InitializeMembers { class InitializeMembers {
private $api; private Api $api;
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function getSubscriptionId($member) { public function getSubscriptionId(NamiMember $member): ?int
{
$fee = Fee::firstWhere('nami_id', $member->fee_id ?: -1); $fee = Fee::firstWhere('nami_id', $member->fee_id ?: -1);
if (is_null($fee)) { if (is_null($fee)) {
return null; return null;
@ -36,10 +39,11 @@ class InitializeMembers {
return optional($fee->subscriptions()->first())->id; return optional($fee->subscriptions()->first())->id;
} }
public function handle() { public function handle(): void
{
$allMembers = collect([]); $allMembers = collect([]);
$this->api->search([])->each(function($member) { $this->api->search([])->each(function(NamiMember $member): void {
$member = NamiMember::fromNami($this->api->member($member->group_id, $member->id)); $member = NamiMember::fromNami($this->api->member($member->group_id, $member->id));
if (!$member->joined_at) { if (!$member->joined_at) {
return; return;
@ -118,7 +122,8 @@ class InitializeMembers {
}); });
} }
private function fetchMembership($member, $membership) { private function fetchMembership(NamiMember $member, array $membership): array
{
if ($this->shouldSyncMembership($membership)) { if ($this->shouldSyncMembership($membership)) {
$singleMembership = $this->api->membership($member->id, $membership['id']); $singleMembership = $this->api->membership($member->id, $membership['id']);
app(ActivityCreator::class)->createFor($this->api, $singleMembership['gruppierungId']); app(ActivityCreator::class)->createFor($this->api, $singleMembership['gruppierungId']);
@ -149,7 +154,8 @@ class InitializeMembers {
return [$activityId, $subactivityId, $groupId]; return [$activityId, $subactivityId, $groupId];
} }
private function shouldSyncMembership($membership) { private function shouldSyncMembership(array $membership): bool
{
if (!Group::where('name', $membership['entries_gruppierung'])->exists()) { if (!Group::where('name', $membership['entries_gruppierung'])->exists()) {
return true; return true;
} }

View File

@ -2,15 +2,18 @@
namespace App\Initialize; namespace App\Initialize;
use Zoomyboy\LaravelNami\Api;
class InitializeNationalities { class InitializeNationalities {
private $api; private Api $api;
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function handle() { public function handle(): void
{
$this->api->nationalities()->each(function($nationality) { $this->api->nationalities()->each(function($nationality) {
\App\Nationality::create(['nami_id' => $nationality->id, 'name' => $nationality->name]); \App\Nationality::create(['nami_id' => $nationality->id, 'name' => $nationality->name]);
}); });

View File

@ -2,16 +2,19 @@
namespace App\Initialize; namespace App\Initialize;
use Zoomyboy\LaravelNami\Api;
class InitializeRegions { class InitializeRegions {
private $api; private Api $api;
private $nullName = 'Nicht-DE'; private string $nullName = 'Nicht-DE';
public function __construct($api) { public function __construct(Api $api) {
$this->api = $api; $this->api = $api;
} }
public function handle() { public function handle(): void
{
$this->api->regions()->each(function($region) { $this->api->regions()->each(function($region) {
\App\Region::create(['nami_id' => $region->id, 'name' => $region->name, 'is_null' => $region->name == $this->nullName]); \App\Region::create(['nami_id' => $region->id, 'name' => $region->name, 'is_null' => $region->name == $this->nullName]);
}); });

View File

@ -3,11 +3,13 @@
namespace App\Member; namespace App\Member;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class MemberConfirmController extends Controller class MemberConfirmController extends Controller
{ {
public function __invoke(Request $request, Member $member) { public function __invoke(Request $request, Member $member): RedirectResponse
{
$member->update(['confirmed_at' => now()]); $member->update(['confirmed_at' => now()]);
return redirect()->route('member.index'); return redirect()->route('member.index');

View File

@ -15,13 +15,14 @@ use App\Nationality;
use App\Payment\Subscription; use App\Payment\Subscription;
use App\Region; use App\Region;
use App\Setting\GeneralSettings; use App\Setting\GeneralSettings;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Inertia\Response; use Inertia\Response;
class MemberController extends Controller class MemberController extends Controller
{ {
public $filter = [ public array $filter = [
'ausstand' => false, 'ausstand' => false,
'bill_kind' => null, 'bill_kind' => null,
'activity_id' => null, 'activity_id' => null,
@ -51,7 +52,8 @@ class MemberController extends Controller
return \Inertia::render('member/VIndex', $payload); return \Inertia::render('member/VIndex', $payload);
} }
public function create(): Response { public function create(): Response
{
session()->put('menu', 'member'); session()->put('menu', 'member');
session()->put('title', 'Mitglied erstellen'); session()->put('title', 'Mitglied erstellen');
@ -76,13 +78,15 @@ class MemberController extends Controller
]); ]);
} }
public function store(MemberRequest $request) { public function store(MemberRequest $request): RedirectResponse
{
$request->persistCreate(); $request->persistCreate();
return redirect()->route('member.index'); return redirect()->route('member.index');
} }
public function edit(Member $member, Request $request) { public function edit(Member $member, Request $request): Response
{
session()->put('menu', 'member'); session()->put('menu', 'member');
session()->put('title', "Mitglied {$member->firstname} {$member->lastname} bearbeiten"); session()->put('title', "Mitglied {$member->firstname} {$member->lastname} bearbeiten");
@ -105,13 +109,15 @@ class MemberController extends Controller
]); ]);
} }
public function update(Member $member, MemberRequest $request) { public function update(Member $member, MemberRequest $request): RedirectResponse
{
$request->persistUpdate($member); $request->persistUpdate($member);
return redirect()->route('member.index'); return redirect()->route('member.index');
} }
public function destroy(Member $member) { public function destroy(Member $member): RedirectResponse
{
if ($member->has_nami) { if ($member->has_nami) {
DeleteJob::dispatch($member, auth()->user()); DeleteJob::dispatch($member, auth()->user());
} }

View File

@ -66,7 +66,8 @@ class MemberRequest extends FormRequest
} }
} }
public function persistUpdate(Member $member) { public function persistUpdate(Member $member): void
{
$member->update($this->input()); $member->update($this->input());
if($this->input('has_nami') && $member->nami_id === null) { if($this->input('has_nami') && $member->nami_id === null) {

@ -1 +1 @@
Subproject commit a53cf6abd9add58f0a1a54c9c9f4b6cb41b01712 Subproject commit 3c64ccb6ea27066983e9fcb3151f5e13782f2667