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 @@
- +
diff --git a/resources/js/views/allpayment/Form.vue b/resources/js/views/allpayment/Form.vue new file mode 100644 index 00000000..8cb705bf --- /dev/null +++ b/resources/js/views/allpayment/Form.vue @@ -0,0 +1,28 @@ + + + diff --git a/routes/web.php b/routes/web.php index d39ece45..def18c7b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Member\MemberController; use App\Payment\PaymentController; +use App\Payment\AllpaymentController; use App\Payment\SubscriptionController; use App\Member\MemberConfirmController; use App\Http\Controllers\HomeController; @@ -16,6 +17,7 @@ Route::group(['middleware' => 'auth:web'], function () { Route::resource('initialize', InitializeController::class); Route::resource('member', MemberController::class); Route::resource('member.payment', PaymentController::class); + Route::resource('allpayment', AllpaymentController::class); Route::resource('subscription', SubscriptionController::class); Route::post('/member/{member}/confirm', MemberConfirmController::class); });