From 4988fe442034a65d2f6c19cf7074b430bd6790d6 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 13 Nov 2025 19:09:54 +0700 Subject: [PATCH] feat(overview, analysa): memberikan pengecekan untuk stats - type label untuk chart - membuat permission baru --- app/Livewire/Chart/OutletExpense.php | 2 +- app/Livewire/Studio/Dashboard/Analysis.php | 20 ++++++++++------- app/Livewire/Studio/Dashboard/Overview.php | 22 ++++++++++++------- database/seeders/RolePermissionSeeder.php | 9 ++++++++ .../chart/outlet-revenue-expense.blade.php | 2 +- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/Livewire/Chart/OutletExpense.php b/app/Livewire/Chart/OutletExpense.php index be269a1..84bd530 100644 --- a/app/Livewire/Chart/OutletExpense.php +++ b/app/Livewire/Chart/OutletExpense.php @@ -24,7 +24,7 @@ public function mount(array $outlets) foreach ($outlets as $id => $name) { $expenseTotal = Expense::where('outlet_id', $id)->sum('amount'); - $purchaseTotal = Purchase::where('outlet_id', $id)->sum('total'); + $purchaseTotal = auth()->user()?->hasPermissionTo('view cogs') ? Purchase::where('outlet_id', $id)->sum('total') : 0; $payrollTotal = Payroll::whereHas('user.outlets', fn ($q) => $q->where('outlet_id', $id))->sum('total_salary'); diff --git a/app/Livewire/Studio/Dashboard/Analysis.php b/app/Livewire/Studio/Dashboard/Analysis.php index c46b9b2..f822793 100644 --- a/app/Livewire/Studio/Dashboard/Analysis.php +++ b/app/Livewire/Studio/Dashboard/Analysis.php @@ -163,7 +163,7 @@ protected function loadData() ], ]; - $this->orders = [ + $this->orders = array_filter([ [ 'title' => 'Total Order', 'value' => currency( @@ -181,7 +181,8 @@ protected function loadData() 'Rp' ), ], - [ + + auth()->user()?->hasPermissionTo('view cogs') ? [ 'title' => 'HPP', 'value' => currency( Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) @@ -189,7 +190,8 @@ protected function loadData() ->sum('cogs'), 'Rp' ), - ], + ] : null, + [ 'title' => 'Diskon', 'value' => currency( @@ -231,9 +233,9 @@ protected function loadData() ->sum('quantity') ).' pcs', ], - ]; + ]); - $this->expenses = [ + $this->expenses = array_filter([ [ 'title' => 'Beban Toko', 'value' => currency( @@ -243,7 +245,8 @@ protected function loadData() 'Rp' ), ], - [ + + auth()->user()?->hasPermissionTo('view cogs') ? [ 'title' => 'Belanja Barang', 'value' => currency( Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) @@ -251,7 +254,8 @@ protected function loadData() ->sum('total'), 'Rp' ), - ], + ] : null, + [ 'title' => 'Penggajian', 'value' => currency( @@ -261,7 +265,7 @@ protected function loadData() 'Rp' ), ], - ]; + ]); $this->topPerfumes = Perfume::with(['items' => function ($query) use ($outletIds, $dateQuery, $startDate, $endDate, $filterDate) { $query->whereNotNull('order_id') diff --git a/app/Livewire/Studio/Dashboard/Overview.php b/app/Livewire/Studio/Dashboard/Overview.php index 5846dcb..9ba4fa0 100644 --- a/app/Livewire/Studio/Dashboard/Overview.php +++ b/app/Livewire/Studio/Dashboard/Overview.php @@ -127,7 +127,7 @@ protected function loadStats() ->with('orderable') ->first(); - $this->stats = [ + $this->stats = array_filter([ [ 'title' => 'Total Order', 'value' => $todayOrder, @@ -147,7 +147,8 @@ protected function loadStats() 'trendUp' => $todayIncome > $yesterdayIncome, 'formatted' => currency($todayIncome, 'Rp'), ], - [ + + auth()->user()?->hasPermissionTo('view cogs') ? [ 'title' => 'HPP', 'value' => currency($todayCogs, 'Rp'), 'previous' => currency($yesterdayCogs, 'Rp'), @@ -156,7 +157,8 @@ protected function loadStats() : '∞%', 'trendUp' => $todayCogs > $yesterdayCogs, 'formatted' => currency($todayCogs, 'Rp'), - ], + ] : null, + [ 'title' => 'Diskon', 'value' => currency($todayDiscount, 'Rp'), @@ -185,7 +187,9 @@ protected function loadStats() : '∞%', 'trendUp' => $todayExpense > $yesterdayExpense, ], - [ + + auth()->user()?->hasPermissionTo('view cogs') ? [ + 'title' => 'Laba Kotor', 'value' => currency($todayGrossProfit, 'Rp'), 'previous' => currency($yesterdayGrossProfit, 'Rp'), @@ -193,8 +197,9 @@ protected function loadStats() ? round((($todayGrossProfit - $yesterdayGrossProfit) / $yesterdayGrossProfit) * 100, 1).'%' : '∞%', 'trendUp' => $todayGrossProfit > $yesterdayGrossProfit, - ], - [ + ] : null, + + auth()->user()?->hasPermissionTo('view cogs') ? [ 'title' => 'Laba Bersih', 'value' => currency($todayNetProfit, 'Rp'), 'previous' => currency($yesterdayNetProfit, 'Rp'), @@ -202,7 +207,8 @@ protected function loadStats() ? round((($todayNetProfit - $yesterdayNetProfit) / $yesterdayNetProfit) * 100, 1).'%' : '∞%', 'trendUp' => $todayNetProfit > $yesterdayNetProfit, - ], + ] : null, + [ 'title' => 'Parfum Terjual', 'value' => $todaySoldPerfume.' ml', @@ -221,7 +227,7 @@ protected function loadStats() : '∞%', 'trendUp' => ($todayTopPerfume?->total_sold ?? 0) > ($yesterdayTopPerfume?->total_sold ?? 0), ], - ]; + ]); } public function render() diff --git a/database/seeders/RolePermissionSeeder.php b/database/seeders/RolePermissionSeeder.php index 8dff5a8..0cd8605 100644 --- a/database/seeders/RolePermissionSeeder.php +++ b/database/seeders/RolePermissionSeeder.php @@ -158,6 +158,9 @@ public function run(): void // partner 'view partner overview', + + // other + 'view cogs', ]; foreach ($permissions as $permission) { @@ -260,12 +263,16 @@ public function run(): void 'view social settings', 'update social settings', + + 'view cogs', ])); $admin->syncPermissions(array_diff($permissions, [ 'view member overview', 'view partner overview', + 'view analysis', + 'view member voucher', 'view member membership', @@ -356,6 +363,8 @@ public function run(): void 'view social settings', 'update social settings', + + 'view cogs', ])); $partner->syncPermissions([ diff --git a/resources/views/livewire/chart/outlet-revenue-expense.blade.php b/resources/views/livewire/chart/outlet-revenue-expense.blade.php index 46c4580..7b66f7c 100644 --- a/resources/views/livewire/chart/outlet-revenue-expense.blade.php +++ b/resources/views/livewire/chart/outlet-revenue-expense.blade.php @@ -1,5 +1,5 @@
-

Pengeluaran per Outlet

+

Pendapatan Vs Pengeluaran