Add all payments

This commit is contained in:
philipp lang 2021-07-04 22:32:40 +02:00
parent fb1bdca780
commit 0db404ed69
6 changed files with 80 additions and 2 deletions

View File

@ -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);
});
}
}

View File

@ -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);
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Payment;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Member\Member;
use App\Payment\Status;
class AllpaymentController extends Controller
{
public function create() {
session()->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();
}
}

View File

@ -17,7 +17,7 @@
<div class="flex">
<span class="text-xl font-semibold text-white" v-html="$page.props.title"></span>
<div class="flex ml-4">
<inertia-link v-for="link, index in $page.props.toolbar" :key="index" :href="link.href" v-text="link.label" class="btn label" :class="link.color">
<inertia-link v-for="link, index in $page.props.toolbar" :key="index" :href="link.href" v-text="link.label" class="btn label mr-2" :class="link.color">
<sprite :src="link.icon"></sprite>
</inertia-link>
</div>

View File

@ -0,0 +1,28 @@
<template>
<form class="p-6 grid gap-4 justify-start" @submit.prevent="submit">
<f-text id="year" v-model="inner.year" label="Jahr" required></f-text>
<button type="submit" class="btn btn-primary">Absenden</button>
</form>
</template>
<script>
export default {
data: function() {
return {
inner: {},
};
},
props: {
},
methods: {
submit() {
this.$inertia.post(`/allpayment`, this.inner)
}
}
};
</script>

View File

@ -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);
});