From eb5eeaf73b55f0ff49e94192cd717f686dc43771 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Sat, 27 Jun 2026 17:19:32 +0700 Subject: [PATCH] feat: enhance expense chart visibility based on user roles in Analysis and Dashboard components --- app/Services/System/AnalysisService.php | 10 ++++++++++ app/Services/System/DashboardService.php | 3 +++ resources/js/pages/admin/Analysis.vue | 12 ++++++++++-- resources/js/pages/admin/Dashboard.vue | 6 +++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/Services/System/AnalysisService.php b/app/Services/System/AnalysisService.php index 8f2db93..952252a 100644 --- a/app/Services/System/AnalysisService.php +++ b/app/Services/System/AnalysisService.php @@ -272,6 +272,9 @@ public function getExpenseSummary(?Carbon $startDate = null, ?Carbon $endDate = ->first(); $purchaseTotal = (int) ($purchase->total ?? 0); + if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) { + $purchaseTotal = 0; + } $expenseTotal = (int) ($expenses->total ?? 0); $advanceTotal = (int) ($employeeAdvance->total ?? 0); @@ -328,6 +331,9 @@ public function getMonthlyExpense(?Carbon $startDate = null, ?Carbon $endDate = $monthLabel = $current->locale('id')->translatedFormat('M Y'); $purchaseAmount = (int) ($purchases->firstWhere('month_key', $key)->total ?? 0); + if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) { + $purchaseAmount = 0; + } $expenseAmount = (int) ($expenses->firstWhere('month_key', $key)->total ?? 0); $advanceAmount = (int) ($advances->firstWhere('month_key', $key)->total ?? 0); @@ -400,6 +406,10 @@ public function getProfitMetrics(?Carbon $startDate = null, ?Carbon $endDate = n ->when($startDate && $endDate, fn ($q) => $q->whereBetween('purchases.created_at', [$startDate, $endDate])) ->sum('total'); + if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) { + $purchaseTotal = 0; + } + $expenseTotal = Expense::query() ->when($startDate && $endDate, fn ($q) => $q->whereBetween('expenses.created_at', [$startDate, $endDate])) ->sum('amount'); diff --git a/app/Services/System/DashboardService.php b/app/Services/System/DashboardService.php index 419600a..21fa3f3 100644 --- a/app/Services/System/DashboardService.php +++ b/app/Services/System/DashboardService.php @@ -155,6 +155,9 @@ public function getExpenseSummary(): array ->first(); $purchaseTotal = (int) ($purchase->total ?? 0); + if (auth()->user()?->hasRole(\App\Enums\Role::ADMIN_TOKO->value)) { + $purchaseTotal = 0; + } $expenseTotal = (int) ($expenses->total ?? 0); $advanceTotal = (int) ($employeeAdvance->total ?? 0); diff --git a/resources/js/pages/admin/Analysis.vue b/resources/js/pages/admin/Analysis.vue index 1664330..d60b954 100644 --- a/resources/js/pages/admin/Analysis.vue +++ b/resources/js/pages/admin/Analysis.vue @@ -21,7 +21,7 @@ import AdminLayout from '@/layouts/AdminLayout.vue'; import { formatRupiah } from '@/lib/rupiah'; import admin from '@/routes/admin'; -const { can } = useCan(); +const { can, hasRole } = useCan(); const props = defineProps<{ filters: { @@ -229,6 +229,14 @@ const expenseTotals = computed(() => ({ kasbon: props.expenseSummary.advance_total, })); +const visibleExpenseCharts = computed(() => { + const charts = ['total', 'belanja', 'pengeluaran', 'kasbon'] as const; + if (hasRole('admin-toko')) { + return charts.filter((c) => c !== 'belanja'); + } + return charts; +}); + // Busy Hours Chart type BusyHourData = { hour: string; orders: number }; @@ -492,7 +500,7 @@ watch([startDate, endDate], () => { Pengeluaran
-