From da7fd88b5a6b9b967d1d5374f2e47d1f32fd3da1 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sun, 4 Jul 2021 23:27:00 +0200 Subject: [PATCH] Add dashboard --- app/Http/Controllers/HomeController.php | 7 +++--- app/Http/Views/HomeView.php | 29 +++++++++++++++++++++++++ app/Member/Member.php | 10 +++++++++ resources/js/views/Home.vue | 26 ---------------------- resources/js/views/home/Block.vue | 16 ++++++++++++++ resources/js/views/home/Index.vue | 27 +++++++++++++++++++++++ 6 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 app/Http/Views/HomeView.php delete mode 100644 resources/js/views/Home.vue create mode 100644 resources/js/views/home/Block.vue create mode 100644 resources/js/views/home/Index.vue diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 26cccd04..e38b6dee 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -3,14 +3,15 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use App\Http\Views\HomeView; class HomeController extends Controller { - public function __invoke() + public function __invoke(Request $request) { session()->put('menu', 'dashboard'); session()->put('title', 'Dashboard'); - - return \Inertia::render('Home', []); + + return \Inertia::render('home/Index', app(HomeView::class)->index($request)); } } diff --git a/app/Http/Views/HomeView.php b/app/Http/Views/HomeView.php new file mode 100644 index 00000000..1c27f607 --- /dev/null +++ b/app/Http/Views/HomeView.php @@ -0,0 +1,29 @@ +selectRaw('sum(subscriptions.amount) AS a')->join('subscriptions', 'subscriptions.id', 'payments.subscription_id')->first()->a; + $members = Member::whereHasPendingPayment()->count(); + + return [ + 'data' => [ + 'payments' => [ + 'users' => $members, + 'all_users' => Member::count(), + 'amount' => number_format($amount / 100, 2, ',', '.').' €' + ] + ] + ]; + } + +} diff --git a/app/Member/Member.php b/app/Member/Member.php index 578eeb36..cb78baf2 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -154,6 +154,12 @@ class Member extends Model ]); } + public function scopeWhereHasPendingPayment($q) { + return $q->whereHas('payments', function($q) { + return $q->whereNeedsPayment(); + }); + } + public function scopePayable($q) { $q->where('bill_kind_id', '!=', null)->where('subscription_id', '!=', null); } @@ -164,4 +170,8 @@ class Member extends Model }); } + public function scopeForDashboard($q) { + return $q->selectRaw('SUM(id)'); + } + } diff --git a/resources/js/views/Home.vue b/resources/js/views/Home.vue deleted file mode 100644 index b384f399..00000000 --- a/resources/js/views/Home.vue +++ /dev/null @@ -1,26 +0,0 @@ - - - diff --git a/resources/js/views/home/Block.vue b/resources/js/views/home/Block.vue new file mode 100644 index 00000000..bcacf8ad --- /dev/null +++ b/resources/js/views/home/Block.vue @@ -0,0 +1,16 @@ + + + diff --git a/resources/js/views/home/Index.vue b/resources/js/views/home/Index.vue new file mode 100644 index 00000000..f99fc2fb --- /dev/null +++ b/resources/js/views/home/Index.vue @@ -0,0 +1,27 @@ + + +