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