feat(overview, analysa): memberikan pengecekan untuk stats

- type label untuk chart
- membuat permission baru
This commit is contained in:
Yoga Pangestu 2025-11-13 19:09:54 +07:00
parent c63ec1b30e
commit 4988fe4420
5 changed files with 37 additions and 18 deletions

View File

@ -24,7 +24,7 @@ public function mount(array $outlets)
foreach ($outlets as $id => $name) { foreach ($outlets as $id => $name) {
$expenseTotal = Expense::where('outlet_id', $id)->sum('amount'); $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'); $payrollTotal = Payroll::whereHas('user.outlets', fn ($q) => $q->where('outlet_id', $id))->sum('total_salary');

View File

@ -163,7 +163,7 @@ protected function loadData()
], ],
]; ];
$this->orders = [ $this->orders = array_filter([
[ [
'title' => 'Total Order', 'title' => 'Total Order',
'value' => currency( 'value' => currency(
@ -181,7 +181,8 @@ protected function loadData()
'Rp' 'Rp'
), ),
], ],
[
auth()->user()?->hasPermissionTo('view cogs') ? [
'title' => 'HPP', 'title' => 'HPP',
'value' => currency( 'value' => currency(
Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) Order::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
@ -189,7 +190,8 @@ protected function loadData()
->sum('cogs'), ->sum('cogs'),
'Rp' 'Rp'
), ),
], ] : null,
[ [
'title' => 'Diskon', 'title' => 'Diskon',
'value' => currency( 'value' => currency(
@ -231,9 +233,9 @@ protected function loadData()
->sum('quantity') ->sum('quantity')
).' pcs', ).' pcs',
], ],
]; ]);
$this->expenses = [ $this->expenses = array_filter([
[ [
'title' => 'Beban Toko', 'title' => 'Beban Toko',
'value' => currency( 'value' => currency(
@ -243,7 +245,8 @@ protected function loadData()
'Rp' 'Rp'
), ),
], ],
[
auth()->user()?->hasPermissionTo('view cogs') ? [
'title' => 'Belanja Barang', 'title' => 'Belanja Barang',
'value' => currency( 'value' => currency(
Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds))
@ -251,7 +254,8 @@ protected function loadData()
->sum('total'), ->sum('total'),
'Rp' 'Rp'
), ),
], ] : null,
[ [
'title' => 'Penggajian', 'title' => 'Penggajian',
'value' => currency( 'value' => currency(
@ -261,7 +265,7 @@ protected function loadData()
'Rp' 'Rp'
), ),
], ],
]; ]);
$this->topPerfumes = Perfume::with(['items' => function ($query) use ($outletIds, $dateQuery, $startDate, $endDate, $filterDate) { $this->topPerfumes = Perfume::with(['items' => function ($query) use ($outletIds, $dateQuery, $startDate, $endDate, $filterDate) {
$query->whereNotNull('order_id') $query->whereNotNull('order_id')

View File

@ -127,7 +127,7 @@ protected function loadStats()
->with('orderable') ->with('orderable')
->first(); ->first();
$this->stats = [ $this->stats = array_filter([
[ [
'title' => 'Total Order', 'title' => 'Total Order',
'value' => $todayOrder, 'value' => $todayOrder,
@ -147,7 +147,8 @@ protected function loadStats()
'trendUp' => $todayIncome > $yesterdayIncome, 'trendUp' => $todayIncome > $yesterdayIncome,
'formatted' => currency($todayIncome, 'Rp'), 'formatted' => currency($todayIncome, 'Rp'),
], ],
[
auth()->user()?->hasPermissionTo('view cogs') ? [
'title' => 'HPP', 'title' => 'HPP',
'value' => currency($todayCogs, 'Rp'), 'value' => currency($todayCogs, 'Rp'),
'previous' => currency($yesterdayCogs, 'Rp'), 'previous' => currency($yesterdayCogs, 'Rp'),
@ -156,7 +157,8 @@ protected function loadStats()
: '∞%', : '∞%',
'trendUp' => $todayCogs > $yesterdayCogs, 'trendUp' => $todayCogs > $yesterdayCogs,
'formatted' => currency($todayCogs, 'Rp'), 'formatted' => currency($todayCogs, 'Rp'),
], ] : null,
[ [
'title' => 'Diskon', 'title' => 'Diskon',
'value' => currency($todayDiscount, 'Rp'), 'value' => currency($todayDiscount, 'Rp'),
@ -185,7 +187,9 @@ protected function loadStats()
: '∞%', : '∞%',
'trendUp' => $todayExpense > $yesterdayExpense, 'trendUp' => $todayExpense > $yesterdayExpense,
], ],
[
auth()->user()?->hasPermissionTo('view cogs') ? [
'title' => 'Laba Kotor', 'title' => 'Laba Kotor',
'value' => currency($todayGrossProfit, 'Rp'), 'value' => currency($todayGrossProfit, 'Rp'),
'previous' => currency($yesterdayGrossProfit, 'Rp'), 'previous' => currency($yesterdayGrossProfit, 'Rp'),
@ -193,8 +197,9 @@ protected function loadStats()
? round((($todayGrossProfit - $yesterdayGrossProfit) / $yesterdayGrossProfit) * 100, 1).'%' ? round((($todayGrossProfit - $yesterdayGrossProfit) / $yesterdayGrossProfit) * 100, 1).'%'
: '∞%', : '∞%',
'trendUp' => $todayGrossProfit > $yesterdayGrossProfit, 'trendUp' => $todayGrossProfit > $yesterdayGrossProfit,
], ] : null,
[
auth()->user()?->hasPermissionTo('view cogs') ? [
'title' => 'Laba Bersih', 'title' => 'Laba Bersih',
'value' => currency($todayNetProfit, 'Rp'), 'value' => currency($todayNetProfit, 'Rp'),
'previous' => currency($yesterdayNetProfit, 'Rp'), 'previous' => currency($yesterdayNetProfit, 'Rp'),
@ -202,7 +207,8 @@ protected function loadStats()
? round((($todayNetProfit - $yesterdayNetProfit) / $yesterdayNetProfit) * 100, 1).'%' ? round((($todayNetProfit - $yesterdayNetProfit) / $yesterdayNetProfit) * 100, 1).'%'
: '∞%', : '∞%',
'trendUp' => $todayNetProfit > $yesterdayNetProfit, 'trendUp' => $todayNetProfit > $yesterdayNetProfit,
], ] : null,
[ [
'title' => 'Parfum Terjual', 'title' => 'Parfum Terjual',
'value' => $todaySoldPerfume.' ml', 'value' => $todaySoldPerfume.' ml',
@ -221,7 +227,7 @@ protected function loadStats()
: '∞%', : '∞%',
'trendUp' => ($todayTopPerfume?->total_sold ?? 0) > ($yesterdayTopPerfume?->total_sold ?? 0), 'trendUp' => ($todayTopPerfume?->total_sold ?? 0) > ($yesterdayTopPerfume?->total_sold ?? 0),
], ],
]; ]);
} }
public function render() public function render()

View File

@ -158,6 +158,9 @@ public function run(): void
// partner // partner
'view partner overview', 'view partner overview',
// other
'view cogs',
]; ];
foreach ($permissions as $permission) { foreach ($permissions as $permission) {
@ -260,12 +263,16 @@ public function run(): void
'view social settings', 'view social settings',
'update social settings', 'update social settings',
'view cogs',
])); ]));
$admin->syncPermissions(array_diff($permissions, [ $admin->syncPermissions(array_diff($permissions, [
'view member overview', 'view member overview',
'view partner overview', 'view partner overview',
'view analysis',
'view member voucher', 'view member voucher',
'view member membership', 'view member membership',
@ -356,6 +363,8 @@ public function run(): void
'view social settings', 'view social settings',
'update social settings', 'update social settings',
'view cogs',
])); ]));
$partner->syncPermissions([ $partner->syncPermissions([

View File

@ -1,5 +1,5 @@
<div> <div>
<h3>Pengeluaran per Outlet</h3> <h3>Pendapatan Vs Pengeluaran</h3>
<flux:card class="mb-6 mt-2 bg-zinc-200 dark:bg-zinc-700"> <flux:card class="mb-6 mt-2 bg-zinc-200 dark:bg-zinc-700">
<canvas id="outletRevenueExpenseChart" width="400" height="200"></canvas> <canvas id="outletRevenueExpenseChart" width="400" height="200"></canvas>
</flux:card> </flux:card>