This commit is contained in:
philipp lang 2022-01-02 12:32:57 +01:00
parent 2920c57e69
commit ada4715a81
31 changed files with 107 additions and 73 deletions

View File

@ -5,6 +5,9 @@ namespace App\Course\Resources;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin \App\Course\Models\CourseMember
*/
class CourseResource extends JsonResource
{
/**

View File

@ -11,7 +11,7 @@ class Handler extends ExceptionHandler
/**
* A list of the exception types that are not reported.
*
* @var array
* @var string[]
*/
protected $dontReport = [
//
@ -20,7 +20,7 @@ class Handler extends ExceptionHandler
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
* @var string[]
*/
protected $dontFlash = [
'password',

View File

@ -15,7 +15,6 @@ class InertiaShareMiddleware
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param GeneralSettings $settings
* @return mixed
*/
public function handle($request, Closure $next)

View File

@ -30,10 +30,10 @@ class RedirectIfNotInitializedMiddleware
}
public function shouldRedirect() {
return !in_array(request()->route()->getName(), $this->dontRedirect) && auth()->check();
return !request()->routeIs($this->dontRedirect) && auth()->check();
}
public function initialized() {
return \App\Fee::get()->count() > 0;
return \App\Fee::count() > 0;
}
}

View File

@ -5,6 +5,9 @@ namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Storage;
/**
* @mixin \Zoomyboy\LaravelNami\NamiUser
*/
class UserResource extends JsonResource
{
/**

View File

@ -12,7 +12,8 @@ use Illuminate\Http\Request;
class HomeView {
public function index(Request $request) {
$amount = Payment::whereNeedsPayment()->selectRaw('sum(subscriptions.amount) AS a')->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')->first()->a;
/** @var object{a: string} */
$amount = Payment::whereNeedsPayment()->selectRaw('sum(subscriptions.amount) AS a')->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')->first();
$members = Member::whereHasPendingPayment()->count();
return [
@ -20,7 +21,7 @@ class HomeView {
'payments' => [
'users' => $members,
'all_users' => Member::count(),
'amount' => number_format($amount / 100, 2, ',', '.').' €'
'amount' => number_format($amount->a / 100, 2, ',', '.').' €'
],
'groups' => Member::select('subactivities.slug', 'subactivities.name')->selectRaw('COUNT(members.id) AS count')->join('memberships', 'memberships.member_id', 'members.id')
->join('activities', 'memberships.activity_id', 'activities.id')

View File

@ -5,6 +5,9 @@ namespace App\Http\Views;
use App\Member\MemberResource;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin \App\Member\Member
*/
class MemberTriesResource extends MemberResource
{
/**

View File

@ -61,8 +61,8 @@ class MemberView {
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'),
'subscriptions' => Subscription::pluck('name', 'id'),
'statuses' => Status::pluck('name', 'id'),
], $overwrites));
}

View File

@ -1,4 +1,4 @@
<?php
<?php
namespace App\Initialize;
@ -35,7 +35,7 @@ class InitializeActivities {
$groups = [];
$this->api->subactivitiesOf($activity->nami_id)->each(function($group) use ($activity, &$groups) {
$this->api->subactivitiesOf($activity->nami_id)->each(function($group) use (&$groups) {
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
'nami_id' => $group->id,
'name' => $group->name,

View File

@ -1,4 +1,4 @@
<?php
<?php
namespace App\Initialize;
@ -9,8 +9,8 @@ use Zoomyboy\LaravelNami\NamiUser;
class InitializeCourses {
private Progress $bar;
private Api $api;
private Progress $bar;
public function __construct(Progress $bar, Api $api) {
$this->bar = $bar;
@ -19,8 +19,10 @@ class InitializeCourses {
public function handle(NamiUser $user): void
{
$this->api->courses()->each(function($course) {
Course::create(['nami_id' => $course->id, 'name' => $course->name]);
$this->bar->task('Synchronisiere Kurse', function() {
$this->api->courses()->each(function($course) {
Course::create(['nami_id' => $course->id, 'name' => $course->name]);
});
});
}
}

View File

@ -47,7 +47,6 @@ class InitializeMembers {
$m = Member::create([
'firstname' => $member->firstname,
'lastname' => $member->lastname,
'nickname' => $member->nickname,
'joined_at' => $member->joined_at,
'birthday' => $member->birthday,
'send_newspaper' => $member->send_newspaper,

View File

@ -37,13 +37,12 @@ class CreateJob implements ShouldQueue
$this->member = Member::find($this->memberId);
if ($this->member->hasNami) {
return false;
return;
}
$response = $this->user->api()->putMember([
'firstname' => $this->member->firstname,
'lastname' => $this->member->lastname,
'nickname' => $this->member->nickname,
'joined_at' => $this->member->joined_at,
'birthday' => $this->member->birthday,
'send_newspaper' => $this->member->send_newspaper,
@ -77,10 +76,10 @@ class CreateJob implements ShouldQueue
$memberships = $this->member->getNamiMemberships($this->user->api());
foreach ($memberships as $membership) {
$this->member->memberships()->create([
'activity_id' => Activity::nami($membership['activity_id'])->id,
'activity_id' => Activity::nami($membership['activity_id'])->id,
'subactivity_id' => $membership['subactivity_id']
? Subactivity::nami($membership['subactivity_id'])->id
: null,
: null,
'group_id' => Group::nami($membership['group_id'])->id,
'nami_id' => $membership['id'],
'created_at' => $membership['starts_at'],

View File

@ -2,13 +2,13 @@
namespace App\Member;
use App\Confession;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Zoomyboy\LaravelNami\Nami;
use App\Confession;
class DeleteJob implements ShouldQueue
{
@ -34,7 +34,7 @@ class DeleteJob implements ShouldQueue
$this->member = Member::find($this->memberId);
if (!$this->member->hasNami) {
return false;
return;
}
Nami::login($this->user->mglnr)->deleteMember($this->member->nami_id);

View File

@ -22,6 +22,13 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Notifications\Notifiable;
use Zoomyboy\LaravelNami\Api;
/**
* @property string $subscription_name
* @property int $pending_payment
* @property bool $is_confirmed
* @property string $age_group_icon
* @property \Carbon\Carbon $try_created_at
*/
class Member extends Model
{
use Notifiable;

View File

@ -31,7 +31,7 @@ class MemberController extends Controller
public function index(Request $request, GeneralSettings $settings): Response {
session()->put('menu', 'member');
session()->put('title', 'Mitglieder');
$query = [
'filter' => array_merge(
$this->filter,
@ -46,7 +46,7 @@ class MemberController extends Controller
['href' => route('sendpayment.create'), 'label' => 'Rechnungen versenden', 'color' => 'info', 'icon' => 'envelope', 'show' => $settings->hasModule('bill')],
];
$payload['query'] = $query;
$payload['billKinds'] = BillKind::get()->pluck('name', 'id');
$payload['billKinds'] = BillKind::pluck('name', 'id');
return \Inertia::render('member/Index', $payload);
}
@ -60,15 +60,15 @@ class MemberController extends Controller
return \Inertia::render('member/Form', [
'activities' => $activities->pluck('name', 'id'),
'subactivities' => $activities->map(function(Activity $activity) {
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
return ['subactivities' => $activity->subactivities()->pluck('name', 'id'), 'id' => $activity->id];
})->pluck('subactivities', 'id'),
'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'),
'subscriptions' => Subscription::get()->pluck('name', 'id'),
'billKinds' => BillKind::pluck('name', 'id'),
'genders' => Gender::pluck('name', 'id'),
'countries' => Country::pluck('name', 'id'),
'regions' => Region::where('is_null', false)->pluck('name', 'id'),
'nationalities' => Nationality::pluck('name', 'id'),
'confessions' => Confession::where('is_null', false)->pluck('name', 'id'),
'subscriptions' => Subscription::pluck('name', 'id'),
'data' => [
'country_id' => Country::default()
],
@ -93,13 +93,13 @@ class MemberController extends Controller
'subactivities' => $activities->map(function($activity) {
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
})->pluck('subactivities', 'id'),
'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'),
'subscriptions' => Subscription::get()->pluck('name', 'id'),
'billKinds' => BillKind::pluck('name', 'id'),
'genders' => Gender::pluck('name', 'id'),
'countries' => Country::pluck('name', 'id'),
'regions' => Region::where('is_null', false)->pluck('name', 'id'),
'nationalities' => Nationality::pluck('name', 'id'),
'confessions' => Confession::where('is_null', false)->pluck('name', 'id'),
'subscriptions' => Subscription::pluck('name', 'id'),
'data' => new MemberResource($member),
'mode' => 'edit',
]);

View File

@ -2,13 +2,13 @@
namespace App\Member;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use App\Group;
use Illuminate\Support\Str;
use App\Activity;
use App\Group;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
class MemberRequest extends FormRequest
{
@ -30,15 +30,15 @@ class MemberRequest extends FormRequest
public function rules()
{
return [
'first_activity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'),
'first_subactivity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'),
'first_activity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'),
'first_subactivity_id' => Rule::requiredIf(fn() => $this->method() == 'POST'),
'subscription_id' => Rule::requiredIf(function() {
if ($this->method() != 'POST') {
return false;
}
if (!$this->input('first_activity_id')) { return true; }
return Str::contains(Activity::findOrFail($this->input('first_activity_id'))->name, '€');
}),
'firstname' => 'required',

View File

@ -7,6 +7,9 @@ use App\Membership\MembershipResource;
use App\Payment\PaymentResource;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin \App\Member\Member
*/
class MemberResource extends JsonResource
{
/**

View File

@ -2,13 +2,13 @@
namespace App\Member;
use App\Confession;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Zoomyboy\LaravelNami\Nami;
use App\Confession;
class UpdateJob implements ShouldQueue
{
@ -34,13 +34,12 @@ class UpdateJob implements ShouldQueue
$this->member = Member::find($this->memberId);
if (!$this->member->hasNami) {
return false;
return;
}
$response = Nami::login($this->user->mglnr)->putMember([
'firstname' => $this->member->firstname,
'lastname' => $this->member->lastname,
'nickname' => $this->member->nickname,
'joined_at' => $this->member->joined_at,
'birthday' => $this->member->birthday,
'send_newspaper' => $this->member->send_newspaper,

View File

@ -4,6 +4,9 @@ namespace App\Membership;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin \App\Member\Membership
*/
class MembershipResource extends JsonResource
{
/**

View File

@ -14,7 +14,7 @@ class PaymentController extends Controller
session()->put('menu', 'member');
session()->put('title', "Zahlungen für Mitglied {$member->fullname}");
$payload = app(MemberView::class)->index($request);
$payload = app(MemberView::class)->index($request, []);
$payload['single'] = app(MemberView::class)->paymentIndex($member);
return \Inertia::render('member/Index', $payload);
@ -34,7 +34,7 @@ class PaymentController extends Controller
session()->put('menu', 'member');
session()->put('title', "Zahlungen für Mitglied {$member->fullname}");
$payload = app(MemberView::class)->index($request);
$payload = app(MemberView::class)->index($request, []);
$payload['single'] = app(MemberView::class)->paymentEdit($member, $payment);
return \Inertia::render('member/Index', $payload);

View File

@ -4,6 +4,9 @@ namespace App\Payment;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Payment
*/
class PaymentResource extends JsonResource
{
/**

View File

@ -44,6 +44,8 @@ class PaymentSendCommand extends Command
{
$this->sendBills();
$this->sendRemembers();
return 0;
}
private function sendBills(): void

View File

@ -21,7 +21,8 @@ class Status extends Model
return static::where('is_bill', true)->where('is_remember', true)->first()->id;
}
public function isAccepted() {
public function isAccepted(): bool
{
return $this->is_bill === false && $this->is_remember === false;
}

View File

@ -2,9 +2,10 @@
namespace App\Payment;
use App\Fee;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Fee;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Subscription extends Model
{
@ -12,7 +13,7 @@ class Subscription extends Model
public $fillable = ['name', 'amount', 'fee_id'];
public function fee() {
public function fee(): BelongsTo {
return $this->belongsTo(Fee::class);
}
}

View File

@ -2,9 +2,9 @@
namespace App\Payment;
use App\Fee;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Fee;
class SubscriptionController extends Controller
{
@ -23,7 +23,7 @@ class SubscriptionController extends Controller
session()->put('title', 'Beitrag erstellen');
return \Inertia::render('subscription/Form', [
'fees' => Fee::get()->pluck('name', 'id'),
'fees' => Fee::pluck('name', 'id'),
'mode' => 'create',
'data' => (object) []
]);
@ -44,7 +44,7 @@ class SubscriptionController extends Controller
session()->put('title', "Beitrag {$subscription->name} bearbeiten");
return \Inertia::render('subscription/Form', [
'fees' => Fee::get()->pluck('name', 'id'),
'fees' => Fee::pluck('name', 'id'),
'mode' => 'edit',
'data' => new SubscriptionResource($subscription),
]);

View File

@ -4,6 +4,9 @@ namespace App\Payment;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Subscription
*/
class SubscriptionResource extends JsonResource
{
/**

View File

@ -10,12 +10,6 @@ class BillType extends Repository implements PdfRepository
{
public string $filename;
public Collection $pages;
public function __construct(Collection $pages)
{
$this->pages = $pages;
}
public function getPayments(Member $member): Collection
{
@ -97,7 +91,7 @@ class BillType extends Repository implements PdfRepository
return "Mitgliedsbeitrag für {$this->getFamilyName($page)}";
}
public function allLabel(): string
public function allLabel(): string
{
return 'Rechnungen versenden';
}
@ -107,7 +101,7 @@ class BillType extends Repository implements PdfRepository
*
* @return array<int, string>
*/
public function getDescription(): array
public function getDescription(): array
{
return [
'Diese Funktion erstellt ein PDF mit allen noch nicht versendenden Rechnungen bei den Mitgliedern die Post als Versandweg haben.',

View File

@ -5,6 +5,7 @@ namespace App\Pdf;
use App\Member\Member;
use App\Payment\Payment;
use Carbon\Carbon;
use Generator;
use Illuminate\Support\Collection;
interface PdfRepository
@ -50,4 +51,6 @@ interface PdfRepository
public function getMailSubject(): string;
public function allPayments(): Generator;
}

View File

@ -10,12 +10,6 @@ class RememberType extends Repository implements PdfRepository
{
public string $filename;
public Collection $pages;
public function __construct(Collection $pages)
{
$this->pages = $pages;
}
public function getPayments(Member $member): Collection
{

View File

@ -5,10 +5,20 @@ namespace App\Pdf;
use App\Member\Member;
use Carbon\Carbon;
use Generator;
use Illuminate\Support\Collection;
abstract class Repository
{
abstract public function getPayments(Member $member): Collection;
public Collection $pages;
public function __construct(Collection $pages)
{
$this->pages = $pages;
}
public function number(int $number): string
{
return number_format($number / 100, 2, '.', '');

View File

@ -10,6 +10,8 @@ parameters:
level: 5
ignoreErrors:
- '#Unsafe usage of new static#'
- '#Call to an undefined method Illuminate\\Contracts\\Auth\\Authenticatable::api\(\)#'
- '#Call to an undefined method Illuminate\\Contracts\\Auth\\Authenticatable::getNamiGroupId\(\)#'
- '#Illuminate\\Contracts\\Auth\\Authenticatable\|null given#'
checkMissingIterableValueType: false