tambah grafik
This commit is contained in:
parent
04462db32b
commit
0bb466573d
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use App\Models\Reservasii;
|
||||||
|
use Filament\Widgets\ChartWidget;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
|
class IncomeChart extends ChartWidget
|
||||||
|
{
|
||||||
|
protected static ?string $heading = 'Grafik Pendapatan per Bulan';
|
||||||
|
protected static ?int $sort = 2;
|
||||||
|
protected string|array|int $columnSpan = 'full';
|
||||||
|
protected static ?string $maxHeight = '200px';
|
||||||
|
|
||||||
|
protected function getData(): array
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
$labels = [];
|
||||||
|
$details = [];
|
||||||
|
|
||||||
|
// Ambil data 12 bulan terakhir
|
||||||
|
for ($i = 11; $i >= 0; $i--) {
|
||||||
|
$month = Carbon::now()->subMonths($i);
|
||||||
|
$startOfMonth = $month->copy()->startOfMonth();
|
||||||
|
$endOfMonth = $month->copy()->endOfMonth();
|
||||||
|
|
||||||
|
$total = Reservasii::whereBetween('tanggal', [$startOfMonth, $endOfMonth])
|
||||||
|
->sum('total');
|
||||||
|
|
||||||
|
$count = Reservasii::whereBetween('tanggal', [$startOfMonth, $endOfMonth])
|
||||||
|
->count();
|
||||||
|
|
||||||
|
$data[] = $total;
|
||||||
|
$labels[] = $month->format('M Y');
|
||||||
|
$details[] = [
|
||||||
|
'total' => $total,
|
||||||
|
'count' => $count,
|
||||||
|
'month' => $month->format('F Y')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'datasets' => [
|
||||||
|
[
|
||||||
|
'label' => 'Pendapatan',
|
||||||
|
'data' => $data,
|
||||||
|
'backgroundColor' => '#6B7280',
|
||||||
|
'borderColor' => '#4B5563',
|
||||||
|
'details' => $details,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'labels' => $labels,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getType(): string
|
||||||
|
{
|
||||||
|
return 'bar';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'scales' => [
|
||||||
|
'y' => [
|
||||||
|
'beginAtZero' => true,
|
||||||
|
'ticks' => [
|
||||||
|
'callback' => 'function(value) { return "Rp " + value.toLocaleString("id-ID"); }'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'plugins' => [
|
||||||
|
'tooltip' => [
|
||||||
|
'enabled' => true,
|
||||||
|
'mode' => 'index',
|
||||||
|
'intersect' => false,
|
||||||
|
'callbacks' => [
|
||||||
|
'title' => 'function(tooltipItems) {
|
||||||
|
const details = tooltipItems[0].dataset.details[tooltipItems[0].dataIndex];
|
||||||
|
return details.month;
|
||||||
|
}',
|
||||||
|
'label' => 'function(context) {
|
||||||
|
const details = context.dataset.details[context.dataIndex];
|
||||||
|
return [
|
||||||
|
"Total Pendapatan: Rp " + details.total.toLocaleString("id-ID"),
|
||||||
|
"Jumlah Reservasi: " + details.count
|
||||||
|
];
|
||||||
|
}'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,19 +22,15 @@ public function table(Table $table): Table
|
||||||
->defaultSort('created_at', 'desc')
|
->defaultSort('created_at', 'desc')
|
||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('id')
|
TextColumn::make('id')
|
||||||
->label('ID')
|
->label('ID'),
|
||||||
->searchable(),
|
|
||||||
TextColumn::make('nama')
|
TextColumn::make('nama')
|
||||||
->label('Nama')
|
->label('Nama'),
|
||||||
->searchable(),
|
|
||||||
TextColumn::make('detail.paketFoto.nama_paket_foto')
|
TextColumn::make('detail.paketFoto.nama_paket_foto')
|
||||||
->label('Paket Foto')
|
->label('Paket Foto'),
|
||||||
->searchable(),
|
|
||||||
TextColumn::make('tanggal')
|
TextColumn::make('tanggal')
|
||||||
->label('Tanggal')
|
->label('Tanggal')
|
||||||
->date('d F Y')
|
->date('d F Y')
|
||||||
->sortable()
|
->sortable(),
|
||||||
->searchable(),
|
|
||||||
TextColumn::make('waktu')
|
TextColumn::make('waktu')
|
||||||
->label('Jam')
|
->label('Jam')
|
||||||
->time('H:i'),
|
->time('H:i'),
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||||
use App\Filament\Widgets\CalendarReservationWidget;
|
use App\Filament\Widgets\CalendarReservationWidget;
|
||||||
use App\Filament\Widgets\CalendarWidget;
|
use App\Filament\Widgets\CalendarWidget;
|
||||||
|
use App\Filament\Widgets\IncomeChart;
|
||||||
|
|
||||||
class AdminPanelProvider extends PanelProvider
|
class AdminPanelProvider extends PanelProvider
|
||||||
{
|
{
|
||||||
|
@ -46,6 +47,7 @@ public function panel(Panel $panel): Panel
|
||||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
|
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
|
||||||
->widgets([
|
->widgets([
|
||||||
ReservasiiStats::class,
|
ReservasiiStats::class,
|
||||||
|
IncomeChart::class,
|
||||||
//CalendarWidget::class
|
//CalendarWidget::class
|
||||||
//Widgets\AccountWidget::class,
|
//Widgets\AccountWidget::class,
|
||||||
//Widgets\FilamentInfoWidget::class,
|
//Widgets\FilamentInfoWidget::class,
|
||||||
|
|
Loading…
Reference in New Issue