diff --git a/app/Http/Views/MemberView.php b/app/Http/Views/MemberView.php index 0f8fcab6..ac4817e0 100644 --- a/app/Http/Views/MemberView.php +++ b/app/Http/Views/MemberView.php @@ -11,9 +11,9 @@ use App\Payment\Subscription; use Illuminate\Http\Request; class MemberView { - public function index(Request $request) { + public function index(Request $request, array $filter) { return [ - 'data' => MemberResource::collection(Member::select('*')->search($request->query('search', null))->with('billKind')->with('payments')->withSubscriptionName()->withIsConfirmed()->withPendingPayment()->orderByRaw('lastname, firstname')->paginate(15)), + 'data' => MemberResource::collection(Member::select('*')->filter($filter)->search($request->query('search', null))->with('billKind')->with('payments')->withSubscriptionName()->withIsConfirmed()->withPendingPayment()->orderByRaw('lastname, firstname')->paginate(15)), 'toolbar' => [ ['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus'] ], 'paymentDefaults' => ['nr' => date('Y')], 'subscriptions' => Subscription::get()->pluck('name', 'id'), diff --git a/app/Member/Member.php b/app/Member/Member.php index 9419a2e3..16d48da0 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -166,6 +166,12 @@ class Member extends Model }); } + public function scopeWhereAusstand(Builder $q): Builder { + return $q->whereHas('payments', function($q) { + return $q->whereHas('status', fn ($q) => $q->where('is_remember', true)); + }); + } + public function scopePayable(Builder $q): Builder { return $q->where('bill_kind_id', '!=', null)->where('subscription_id', '!=', null); } @@ -180,4 +186,16 @@ class Member extends Model return $q->selectRaw('SUM(id)'); } + public function scopeFilter(Builder $q, array $filter): Builder + { + if (data_get($filter, 'ausstand', false) === true) { + $q->whereAusstand(); + } + if (data_get($filter, 'bill_kind', false)) { + $q->where('bill_kind_id', $filter['bill_kind']); + } + + return $q; + } + } diff --git a/app/Member/MemberController.php b/app/Member/MemberController.php index 2894d7e8..3077cacf 100644 --- a/app/Member/MemberController.php +++ b/app/Member/MemberController.php @@ -20,16 +20,30 @@ use Inertia\Response; class MemberController extends Controller { + public $filter = [ + 'ausstand' => false, + 'bill_kind' => false, + ]; + public function index(Request $request): Response { session()->put('menu', 'member'); session()->put('title', 'Mitglieder'); + + $query = [ + 'filter' => array_merge( + $this->filter, + json_decode($request->query('filter', '{}'), true) + ), + ]; - $payload = app(MemberView::class)->index($request); + $payload = app(MemberView::class)->index($request, $query['filter']); $payload['toolbar'] = [ ['href' => route('member.create'), 'label' => 'Mitglied anlegen', 'color' => 'primary', 'icon' => 'plus'], ['href' => route('allpayment.create'), 'label' => 'Rechnungen erstellen', 'color' => 'primary', 'icon' => 'plus'], ['href' => route('sendpayment.create'), 'label' => 'Rechnungen versenden', 'color' => 'info', 'icon' => 'envelope'], ]; + $payload['query'] = $query; + $payload['billKinds'] = BillKind::get()->pluck('name', 'id'); return \Inertia::render('member/Index', $payload); } diff --git a/resources/js/mixins/mergesQueryString.js b/resources/js/mixins/mergesQueryString.js index 97f64a72..f110a103 100644 --- a/resources/js/mixins/mergesQueryString.js +++ b/resources/js/mixins/mergesQueryString.js @@ -18,24 +18,8 @@ export default { var merged = queryString.stringify(mn); return window.location.pathname + (merged ? '?'+merged : ''); - }, - - query(options) { - options = merge({ - only: null, - }, options); - var c = queryString.parse(window.location.search); - - if (options.only !== null) { - for (var k in c) { - if (options.only.indexOf(k) < 0) { - delete c[k]; - } - } - } - - return Object.keys(c).length === 0 ? '' : `?${queryString.stringify(c)}`; } + } }; diff --git a/resources/js/views/member/Filt.vue b/resources/js/views/member/Filt.vue new file mode 100644 index 00000000..da531b90 --- /dev/null +++ b/resources/js/views/member/Filt.vue @@ -0,0 +1,28 @@ + + + diff --git a/resources/js/views/member/Index.vue b/resources/js/views/member/Index.vue index 519a2068..b82ae200 100644 --- a/resources/js/views/member/Index.vue +++ b/resources/js/views/member/Index.vue @@ -1,6 +1,8 @@