feat: Implement role-based dashboard content visibility and consolidate view permissions under 'Analisys'.
This commit is contained in:
parent
1eba57cb6b
commit
9619912f2f
@ -12,6 +12,7 @@
|
||||
use App\Models\Order;
|
||||
use App\Models\Payroll;
|
||||
use BackedEnum;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
@ -25,7 +26,7 @@
|
||||
|
||||
class Analisys extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
use HasPageShield, InteractsWithForms;
|
||||
|
||||
public ?array $data = [];
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Models\Customer;
|
||||
use App\Models\DelayedGood;
|
||||
use App\Models\EggCollectionItem;
|
||||
@ -10,6 +11,7 @@
|
||||
use App\Models\Order;
|
||||
use App\Models\Payroll;
|
||||
use Filament\Pages\Dashboard as BaseDashboard;
|
||||
use Filament\Widgets\AccountWidget;
|
||||
|
||||
class Dashboard extends BaseDashboard
|
||||
{
|
||||
@ -17,6 +19,13 @@ class Dashboard extends BaseDashboard
|
||||
|
||||
protected string $view = 'filament.pages.dashboard';
|
||||
|
||||
public function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
AccountWidget::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getViewData(): array
|
||||
{
|
||||
$formatNumber = fn ($val) => number_format((float) $val, $val == floor($val) ? 0 : 2, ',', '.');
|
||||
@ -118,6 +127,7 @@ public function getViewData(): array
|
||||
->get();
|
||||
|
||||
return [
|
||||
'isAdministrator' => auth()->user()->hasRole(RoleEnum::ADMINISTRATOR->value),
|
||||
'mainStats' => $mainStats,
|
||||
'totalEggsByUnit' => $totalEggsByUnit,
|
||||
'totalDelayedByUnit' => $delayedStatsByUnit,
|
||||
|
||||
@ -22,11 +22,7 @@ public function run(): void
|
||||
"name": "Developer",
|
||||
"guard_name": "web",
|
||||
"permissions" : [
|
||||
"View:StatsOverview",
|
||||
"View:EggProductionChart",
|
||||
"View:OrderTrendChart",
|
||||
"View:RevenueExpenseChart",
|
||||
"View:TopCustomersChart",
|
||||
"View:Analisys",
|
||||
|
||||
"ViewAny:Customer",
|
||||
"View:Customer",
|
||||
@ -189,11 +185,7 @@ public function run(): void
|
||||
"name": "Pemilik",
|
||||
"guard_name": "web",
|
||||
"permissions" : [
|
||||
"View:StatsOverview",
|
||||
"View:EggProductionChart",
|
||||
"View:OrderTrendChart",
|
||||
"View:RevenueExpenseChart",
|
||||
"View:TopCustomersChart",
|
||||
"View:Analisys",
|
||||
|
||||
"ViewAny:Customer",
|
||||
"View:Customer",
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
<x-filament-panels::page>
|
||||
@if (!$isAdministrator)
|
||||
|
||||
<div class="space-y-6 pb-12">
|
||||
{{-- Main Stats Grid --}}
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-4">
|
||||
@ -15,7 +17,8 @@ class="text-xs font-semibold text-gray-400 dark:text-gray-500">{{ $stat['prefix'
|
||||
@endif
|
||||
<span class="text-xl font-bold text-gray-900 dark:text-white">{{ $stat['value'] }}</span>
|
||||
</div>
|
||||
<span class="text-[9px] text-gray-900 dark:text-gray-600 uppercase">{{ $stat['desc'] }}</span>
|
||||
<span
|
||||
class="text-[9px] text-gray-900 dark:text-gray-600 uppercase">{{ $stat['desc'] }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
@ -23,7 +26,8 @@ class="text-xs font-semibold text-gray-400 dark:text-gray-500">{{ $stat['prefix'
|
||||
|
||||
{{-- Distribution Row --}}
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
<div class="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm p-6">
|
||||
<div
|
||||
class="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm p-6">
|
||||
<h3 class="text-sm font-bold text-gray-700 dark:text-gray-300 mb-6 flex items-center gap-2">
|
||||
<x-heroicon-o-arrows-right-left class="w-4 h-4 text-primary-500" />
|
||||
Sumber Pemasukan
|
||||
@ -32,7 +36,8 @@ class="text-xs font-semibold text-gray-400 dark:text-gray-500">{{ $stat['prefix'
|
||||
<canvas id="revenueSplitChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm p-6">
|
||||
<div
|
||||
class="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm p-6">
|
||||
<h3 class="text-sm font-bold text-gray-700 dark:text-gray-300 mb-6 flex items-center gap-2">
|
||||
<x-heroicon-o-chart-pie class="w-4 h-4 text-primary-500" />
|
||||
Alokasi Pengeluaran
|
||||
@ -41,7 +46,8 @@ class="text-xs font-semibold text-gray-400 dark:text-gray-500">{{ $stat['prefix'
|
||||
<canvas id="expenseChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm p-6">
|
||||
<div
|
||||
class="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm p-6">
|
||||
<h3 class="text-sm font-bold text-gray-700 dark:text-gray-300 mb-6 flex items-center gap-2">
|
||||
<x-heroicon-o-shopping-bag class="w-4 h-4 text-primary-500" />
|
||||
Penjualan per Satuan
|
||||
@ -82,7 +88,8 @@ class="text-sm font-bold text-rose-600 dark:text-rose-400">{{ $item['total_broke
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<div class="px-5 py-10 text-center text-gray-400 text-sm italic">Belum ada data produksi</div>
|
||||
<div class="px-5 py-10 text-center text-gray-400 text-sm italic">Belum ada data produksi
|
||||
</div>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
@ -101,10 +108,12 @@ class="px-5 py-3 border-b border-gray-100 dark:border-gray-800 bg-gray-50/50 dar
|
||||
class="px-5 py-3 flex justify-between items-center transition hover:bg-gray-50 dark:hover:bg-gray-800/40">
|
||||
<span
|
||||
class="text-sm text-gray-600 dark:text-gray-400 font-medium">{{ $item['unit_name'] }}</span>
|
||||
<span class="text-sm font-bold text-gray-900 dark:text-white">{{ $item['total'] }}</span>
|
||||
<span
|
||||
class="text-sm font-bold text-gray-900 dark:text-white">{{ $item['total'] }}</span>
|
||||
</div>
|
||||
@empty
|
||||
<div class="px-5 py-10 text-center text-gray-400 text-sm italic">Tidak ada barang tertunda hari
|
||||
<div class="px-5 py-10 text-center text-gray-400 text-sm italic">Tidak ada barang tertunda
|
||||
hari
|
||||
ini</div>
|
||||
@endforelse
|
||||
</div>
|
||||
@ -140,14 +149,17 @@ class="text-[10px] font-semibold text-gray-400 uppercase block leading-none mb-1
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<div class="px-5 py-10 text-center text-gray-400 text-sm italic">Belum ada transaksi hari ini
|
||||
<div class="px-5 py-10 text-center text-gray-400 text-sm italic">Belum ada transaksi hari
|
||||
ini
|
||||
</div>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (!$isAdministrator)
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
@ -168,7 +180,9 @@ class="text-[10px] font-semibold text-gray-400 uppercase block leading-none mb-1
|
||||
};
|
||||
|
||||
// Revenue Split Chart
|
||||
new Chart(document.getElementById('revenueSplitChart'), {
|
||||
const revenueSplitCtx = document.getElementById('revenueSplitChart');
|
||||
if (revenueSplitCtx) {
|
||||
new Chart(revenueSplitCtx, {
|
||||
type: 'doughnut',
|
||||
data: {
|
||||
labels: {!! json_encode($revenueSplit['labels']) !!},
|
||||
@ -182,9 +196,12 @@ class="text-[10px] font-semibold text-gray-400 uppercase block leading-none mb-1
|
||||
cutout: '70%'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Expense Category Chart
|
||||
new Chart(document.getElementById('expenseChart'), {
|
||||
const expenseCtx = document.getElementById('expenseChart');
|
||||
if (expenseCtx) {
|
||||
new Chart(expenseCtx, {
|
||||
type: 'doughnut',
|
||||
data: {
|
||||
labels: {!! json_encode($expenseDistribution['labels']) !!},
|
||||
@ -199,9 +216,12 @@ class="text-[10px] font-semibold text-gray-400 uppercase block leading-none mb-1
|
||||
cutout: '70%'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sales by Unit Chart
|
||||
new Chart(document.getElementById('salesUnitChart'), {
|
||||
const salesUnitCtx = document.getElementById('salesUnitChart');
|
||||
if (salesUnitCtx) {
|
||||
new Chart(salesUnitCtx, {
|
||||
type: 'pie',
|
||||
data: {
|
||||
labels: {!! json_encode($salesByUnit['labels']) !!},
|
||||
@ -212,9 +232,11 @@ class="text-[10px] font-semibold text-gray-400 uppercase block leading-none mb-1
|
||||
},
|
||||
options: chartOptions
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
@endif
|
||||
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@200;300;400;500;600;700;800&display=swap');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user