Add filter

This commit is contained in:
philipp lang 2021-08-22 05:51:25 +02:00
parent 45af77fb44
commit de0881a2c7
6 changed files with 71 additions and 22 deletions

View File

@ -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'),

View File

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

View File

@ -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');
$payload = app(MemberView::class)->index($request);
$query = [
'filter' => array_merge(
$this->filter,
json_decode($request->query('filter', '{}'), true)
),
];
$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);
}

View File

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

View File

@ -0,0 +1,28 @@
<template>
<div class="px-6 py-2 flex border-b border-gray-600 space-x-3">
<f-switch id="ausstand" @input="reload" v-model="value.ausstand" label="Nur Ausstände" size="sm"></f-switch>
<f-select id="billKinds" @input="reload" :options="billKinds" v-model="value.bill_kind" label="Rechnung" size="sm"></f-select>
</div>
</template>
<script>
import mergesQueryString from '../../mixins/mergesQueryString.js';
export default {
mixins: [mergesQueryString],
props: {
value: {},
billKinds: {},
},
methods: {
reload() {
this.$inertia.visit(this.qs({filter: JSON.stringify(this.value)}), {
preserveState: true
});
}
}
};
</script>

View File

@ -1,6 +1,8 @@
<template>
<div>
<filt v-model="query.filter" :bill-kinds="billKinds"></filt>
<div class="custom-table">
<header>
<div>Nachname</div>
@ -66,6 +68,7 @@
<script>
import App from '../../layouts/App';
import Payments from './Payments.vue';
import Filt from './Filt.vue';
import mergesQueryString from '../../mixins/mergesQueryString.js';
export default {
@ -81,7 +84,7 @@ export default {
mixins: [mergesQueryString],
components: { Payments },
components: { Payments, Filt },
methods: {
remove(member) {
@ -104,6 +107,8 @@ export default {
subscriptions: {},
statuses: {},
paymentDefaults: {},
query: {},
billKinds: {},
}
}
</script>