From fbd46403968718fd4dc19ede02853c79bf28189e Mon Sep 17 00:00:00 2001
From: philipp lang <philipp@aweos.de>
Date: Fri, 19 Nov 2021 00:53:19 +0100
Subject: [PATCH] Hide bill stuff when bill is disabled

---
 app/Member/MemberController.php     |  7 ++++---
 app/Setting/GeneralSettings.php     |  5 +++++
 resources/js/layouts/App.vue        |  7 ++++++-
 resources/js/views/member/Filt.vue  |  4 ++--
 resources/js/views/member/Index.vue | 10 +++++-----
 5 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/app/Member/MemberController.php b/app/Member/MemberController.php
index 6f34bb80..6889f5f2 100644
--- a/app/Member/MemberController.php
+++ b/app/Member/MemberController.php
@@ -14,6 +14,7 @@ use App\Member\DeleteJob;
 use App\Nationality;
 use App\Payment\Subscription;
 use App\Region;
+use App\Setting\GeneralSettings;
 use Illuminate\Http\Request;
 use Inertia\Response;
 
@@ -27,7 +28,7 @@ class MemberController extends Controller
         'subactivity_id' => null,
     ];
 
-    public function index(Request $request): Response {
+    public function index(Request $request, GeneralSettings $settings): Response {
         session()->put('menu', 'member');
         session()->put('title', 'Mitglieder');
         
@@ -41,8 +42,8 @@ class MemberController extends Controller
         $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'],
+            ['href' => route('allpayment.create'), 'label' => 'Rechnungen erstellen', 'color' => 'primary', 'icon' => 'plus', 'show' => $settings->hasModule('bill')],
+            ['href' => route('sendpayment.create'), 'label' => 'Rechnungen versenden', 'color' => 'info', 'icon' => 'envelope', 'show' => $settings->hasModule('bill')],
         ];
         $payload['query'] = $query;
         $payload['billKinds'] = BillKind::get()->pluck('name', 'id');
diff --git a/app/Setting/GeneralSettings.php b/app/Setting/GeneralSettings.php
index a53c68c2..a4cbc89c 100644
--- a/app/Setting/GeneralSettings.php
+++ b/app/Setting/GeneralSettings.php
@@ -27,4 +27,9 @@ class GeneralSettings extends Settings
         return 'general';
     }
 
+    public function hasModule(string $module): bool
+    {
+        return in_array($module, $this->modules);
+    }
+
 }
diff --git a/resources/js/layouts/App.vue b/resources/js/layouts/App.vue
index 560f7ed9..0de3f6be 100644
--- a/resources/js/layouts/App.vue
+++ b/resources/js/layouts/App.vue
@@ -17,7 +17,7 @@
                 <div class="flex">
                     <span class="text-xl font-semibold text-white leading-none" 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 mr-2" :class="`btn-${link.color}`">
+                        <inertia-link v-for="link, index in filterMenu" :key="index" :href="link.href" v-text="link.label" class="btn label mr-2" :class="`btn-${link.color}`">
                             <sprite :src="link.icon"></sprite>
                         </inertia-link>
                     </div>
@@ -57,6 +57,11 @@ export default {
             get() {
                 return this.$page.props.search;
             }
+        },
+        filterMenu() {
+            return this.$page.props.toolbar
+                ? this.$page.props.toolbar.filter(menu => menu.show !== false):
+                [];
         }
     }
 
diff --git a/resources/js/views/member/Filt.vue b/resources/js/views/member/Filt.vue
index f9e8a359..82251e5e 100644
--- a/resources/js/views/member/Filt.vue
+++ b/resources/js/views/member/Filt.vue
@@ -1,7 +1,7 @@
 <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>
+        <f-switch v-show="hasModule('bill')" id="ausstand" @input="reload" v-model="value.ausstand" label="Nur Ausstände" size="sm"></f-switch>
+        <f-select v-show="hasModule('bill')" id="billKinds" @input="reload" :options="billKinds" v-model="value.bill_kind" label="Rechnung" size="sm"></f-select>
         <f-select id="activity_id" @input="reload" :options="activities" v-model="value.activity_id" label="Tätigkeit" size="sm"></f-select>
         <f-select id="subactivity_id" @input="reload" :options="subactivities" v-model="value.subactivity_id" label="Untertätigkeit" size="sm"></f-select>
     </div>
diff --git a/resources/js/views/member/Index.vue b/resources/js/views/member/Index.vue
index debe9742..57b68bfc 100644
--- a/resources/js/views/member/Index.vue
+++ b/resources/js/views/member/Index.vue
@@ -14,8 +14,8 @@
                 <th>Tags</th>
                 <th>Beitrag</th>
                 <th>Geburtstag</th>
-                <th>Rechnung</th>
-                <th>Ausstand</th>
+                <th v-show="hasModule('bill')">Rechnung</th>
+                <th v-show="hasModule('bill')">Ausstand</th>
                 <th>Eintritt</th>
                 <th></th>
             </thead>
@@ -38,13 +38,13 @@
                 </td>
                 <td v-text="member.subscription_name"></td>
                 <td v-text="`${member.birthday_human}`"></td>
-                <td>
+                <td v-show="hasModule('bill')">
                     <div class="flex justify-center">
                         <div class="btn btn-sm label primary" v-text="member.bill_kind_name" v-if="member.bill_kind_name"></div>
                         <div class="text-xs" v-else>Kein</div>
                     </div>
                 </td>
-                <td>
+                <td v-show="hasModule('bill')">
                     <div class="flex justify-center">
                         <div class="btn btn-sm label primary" v-show="member.pending_payment" v-text="member.pending_payment"></div>
                     </div>
@@ -52,7 +52,7 @@
                 <td v-text="`${member.joined_at_human}`"></td>
                 <td class="flex">
                     <inertia-link :href="`/member/${member.id}/edit`" class="inline-flex btn btn-warning btn-sm"><sprite src="pencil"></sprite></inertia-link>
-                    <a href="#" @click.prevent="openSidebar(index, 'payment.index')" class="inline-flex btn btn-info btn-sm"><sprite src="money"></sprite></a>
+                    <a href="#" v-show="hasModule('bill')" @click.prevent="openSidebar(index, 'payment.index')" class="inline-flex btn btn-info btn-sm"><sprite src="money"></sprite></a>
                     <a href="#" @click.prevent="openSidebar(index, 'membership.index')" class="inline-flex btn btn-info btn-sm"><sprite src="user"></sprite></a>
                     <inertia-link href="#" @click.prevent="remove(member)" class="inline-flex btn btn-danger btn-sm"><sprite src="trash"></sprite></inertia-link>
                 </td>