From 50cf6ace259741f0aadb4d80ebaac6bbedebbbc1 Mon Sep 17 00:00:00 2001 From: LailaWulandarii Date: Thu, 22 Jan 2026 17:17:16 +0700 Subject: [PATCH 01/11] add DashboardService for statistics calculation and update beranda view with stat cards --- app/Services/DashboardService.php | 53 +++++++ resources/views/admin/beranda/index.blade.php | 148 +++++------------- 2 files changed, 88 insertions(+), 113 deletions(-) create mode 100644 app/Services/DashboardService.php diff --git a/app/Services/DashboardService.php b/app/Services/DashboardService.php new file mode 100644 index 0000000..919efc6 --- /dev/null +++ b/app/Services/DashboardService.php @@ -0,0 +1,53 @@ +subMonth(); + + $curr = self::calculate($now); + $past = self::calculate($prev); + + return [ + 'pendapatan' => $curr['income'], + 'pendapatan_grow' => self::growth($curr['income'], $past['income']), + 'masuk_count' => $curr['total'], + 'masuk_grow' => self::growth($curr['total'], $past['total']), + 'selesai_count' => $curr['done'], + 'selesai_grow' => self::growth($curr['done'], $past['done']), + 'batal_count' => $curr['cancel'], + 'batal_grow' => self::growth($curr['cancel'], $past['cancel']), + ]; + } + + private static function calculate($date) + { + $m = $date->month; + $y = $date->year; + + // Gabungan query Buket & Foto + return [ + 'income' => TransaksiBuket::whereMonth('created_at', $m)->whereYear('created_at', $y)->where('status_transaksi', 'diterima')->sum('total_bayar') + + BookingFoto::whereMonth('created_at', $m)->whereYear('created_at', $y)->where('status_booking', 'diterima')->sum('total_bayar'), + 'total' => TransaksiBuket::whereMonth('created_at', $m)->whereYear('created_at', $y)->count() + + BookingFoto::whereMonth('created_at', $m)->whereYear('created_at', $y)->count(), + 'done' => TransaksiBuket::whereMonth('created_at', $m)->whereYear('created_at', $y)->where('status_transaksi', 'selesai')->count() + + BookingFoto::whereMonth('created_at', $m)->whereYear('created_at', $y)->where('status_booking', 'selesai')->count(), + 'cancel' => TransaksiBuket::whereMonth('created_at', $m)->whereYear('created_at', $y)->where('status_transaksi', 'ditolak')->count() + + BookingFoto::whereMonth('created_at', $m)->whereYear('created_at', $y)->where('status_booking', 'ditolak')->count(), + ]; + } + + private static function growth($current, $previous) + { + if ($previous <= 0) return $current > 0 ? 100 : 0; + return round((($current - $previous) / $previous) * 100, 1); + } +} diff --git a/resources/views/admin/beranda/index.blade.php b/resources/views/admin/beranda/index.blade.php index 8f1ccdd..a394769 100755 --- a/resources/views/admin/beranda/index.blade.php +++ b/resources/views/admin/beranda/index.blade.php @@ -20,115 +20,39 @@ @endif
-
- @if (Auth::user()->role === 'pemilik') -
-
-
-
-
Pendapatan Bulan Ini
- -
-
-
- -
-
-
Rp {{ number_format($stat['pendapatan'], 0, ',', '.') }}
- - - {{ abs($stat['pendapatan_grow']) }}% - - dari bulan lalu -
-
-
-
-
- -
-
-
-
-
Total Pesanan Masuk
- -
-
-
- -
-
-
{{ $stat['masuk_count'] }} Pesanan
- - - {{ abs($stat['masuk_grow']) }}% - - dari bulan lalu -
-
-
-
-
-
-
-
-
-
Pesanan Selesai
- -
-
-
- -
-
-
{{ $stat['selesai_count'] }} Pesanan
- - {{ abs($stat['selesai_grow']) }}% - - dari bulan lalu -
-
-
-
-
-
-
-
-
-
Pesanan Ditolak
- -
-
-
- -
-
-
{{ $stat['batal_count'] }} Pesanan
- - - {{ abs($stat['batal_grow']) }}% - - dari bulan lalu -
-
-
-
-
- @endif -
- + @if (Auth::user()->role === 'pemilik') +
+ @include('admin.components._stat_card', [ + 'label' => 'Pendapatan', + 'icon' => 'bi-bank', + 'value' => 'Rp ' . number_format($stat['pendapatan'], 0, ',', '.'), + 'grow' => $stat['pendapatan_grow'], + 'tooltip' => 'Total pendapatan dari pesanan buket dan foto bulan ini', + ]) + @include('admin.components._stat_card', [ + 'label' => 'Pesanan Masuk', + 'icon' => 'bi-cart-fill', + 'value' => $stat['masuk_count'] . ' Pesanan', + 'grow' => $stat['masuk_grow'], + 'tooltip' => 'Total pesanan buket dan foto yang masuk bulan ini', + ]) + @include('admin.components._stat_card', [ + 'label' => 'Pesanan Selesai', + 'icon' => 'bi-cart-check-fill', + 'value' => $stat['selesai_count'] . ' Pesanan', + 'grow' => $stat['selesai_grow'], + 'tooltip' => 'Total pesanan buket dan foto yang selesai bulan ini', + ]) + @include('admin.components._stat_card', [ + 'label' => 'Pesanan Ditolak', + 'icon' => 'bi-cart-x-fill', + 'value' => $stat['batal_count'] . ' Pesanan', + 'grow' => $stat['batal_grow'], + 'tooltip' => 'Total pesanan buket dan foto yang ditolak bulan ini', + 'is_negative_metric' => true, + ]) +
+ @endif
@@ -201,8 +125,7 @@ class="bi {{ $stat['batal_grow'] >= 0 ? 'bi-arrow-up' : 'bi-arrow-down' }}"> {{ $p->paketFoto->nama }} + data-bs-toggle="modal" data-bs-target="#foto{{ $p->id_booking }}"> @@ -229,8 +152,7 @@ class="bi {{ $stat['batal_grow'] >= 0 ? 'bi-arrow-up' : 'bi-arrow-down' }}">
-