diff --git a/app/Member/Member.php b/app/Member/Member.php index 863ad433..578eeb36 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -154,4 +154,14 @@ class Member extends Model ]); } + public function scopePayable($q) { + $q->where('bill_kind_id', '!=', null)->where('subscription_id', '!=', null); + } + + public function scopeWhereNoPayment($q, $year) { + return $q->whereDoesntHave('payments', function($q) use ($year) { + return $q->where('nr', '=', $year); + }); + } + } diff --git a/app/Member/MemberController.php b/app/Member/MemberController.php index 54bd37f2..9746881b 100644 --- a/app/Member/MemberController.php +++ b/app/Member/MemberController.php @@ -24,7 +24,10 @@ class MemberController extends Controller session()->put('title', 'Mitglieder'); $payload = app(MemberView::class)->index($request); - $payload['toolbar'] = [ ['href' => route('member.create'), 'label' => 'Mitglied anlegen', 'color' => 'primary', 'icon' => 'plus'] ]; + $payload['toolbar'] = [ + ['href' => route('member.create'), 'label' => 'Mitglied anlegen', 'color' => 'primary', 'icon' => 'plus'], + ['href' => route('allpayment.create'), 'label' => 'Rechnungen erstellen', 'color' => 'primary', 'icon' => 'plus'] + ]; return \Inertia::render('member/Index', $payload); } diff --git a/app/Payment/AllpaymentController.php b/app/Payment/AllpaymentController.php new file mode 100644 index 00000000..f4bfb3fe --- /dev/null +++ b/app/Payment/AllpaymentController.php @@ -0,0 +1,35 @@ +put('menu', 'member'); + session()->put('title', 'Rechnungen erstellen'); + + return \Inertia::render('allpayment/Form', [ + ]); + } + + public function store(Request $request) { + $request->validate([ + 'year' => 'required|numeric' + ]); + + foreach (Member::payable()->whereNoPayment($request->year)->get() as $member) { + $member->payments()->create([ + 'nr' => $request->year, + 'subscription_id' => $member->subscription_id, + 'status_id' => Status::default(), + ]); + } + + return redirect()->back(); + } +} diff --git a/resources/js/layouts/App.vue b/resources/js/layouts/App.vue index b324a2ce..2d35f7b0 100644 --- a/resources/js/layouts/App.vue +++ b/resources/js/layouts/App.vue @@ -17,7 +17,7 @@