feat: Remove all Filament dashboard widgets including stats overview and various charts.
This commit is contained in:
parent
e11accb8cc
commit
1eba57cb6b
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\EggCollection;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class EggProductionChart extends ChartWidget
|
||||
{
|
||||
use HasWidgetShield;
|
||||
|
||||
protected ?string $heading = 'Trend Produksi Telur (30 Hari Terakhir)';
|
||||
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = EggCollection::where('production_date', '>=', now()->subDays(30))
|
||||
->orderBy('production_date')
|
||||
->get()
|
||||
->groupBy(fn ($item) => Carbon::parse($item->production_date)->translatedFormat('Y-m-d'))
|
||||
->map(fn ($items) => $items->sum('total_eggs'));
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Total Telur',
|
||||
'data' => $data->values()->toArray(),
|
||||
'fill' => 'start',
|
||||
'tension' => 0.4,
|
||||
],
|
||||
],
|
||||
'labels' => $data->keys()->map(fn ($date) => Carbon::parse($date)->translatedFormat('d M'))->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Order;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class OrderTrendChart extends ChartWidget
|
||||
{
|
||||
use HasWidgetShield;
|
||||
|
||||
protected ?string $heading = 'Trend Jumlah Pesanan (30 Hari Terakhir)';
|
||||
|
||||
protected static ?int $sort = 4;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Order::where('order_date', '>=', now()->subDays(30))
|
||||
->orderBy('order_date')
|
||||
->get()
|
||||
->groupBy(fn ($item) => Carbon::parse($item->order_date)->translatedFormat('Y-m-d'))
|
||||
->map(fn ($items) => $items->count());
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Jumlah Pesanan',
|
||||
'data' => $data->values()->toArray(),
|
||||
'fill' => 'start',
|
||||
'tension' => 0.4,
|
||||
],
|
||||
],
|
||||
'labels' => $data->keys()->map(fn ($date) => Carbon::parse($date)->translatedFormat('d M'))->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Expense;
|
||||
use App\Models\FeedPurchase;
|
||||
use App\Models\Order;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RevenueExpenseChart extends ChartWidget
|
||||
{
|
||||
use HasWidgetShield;
|
||||
|
||||
protected ?string $heading = 'Pendapatan vs Pengeluaran (6 Bulan Terakhir)';
|
||||
|
||||
protected static ?int $sort = 3;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$months = collect(range(5, 0))->reverse()->map(function ($i) {
|
||||
return now()->subMonths($i)->format('Y-m');
|
||||
});
|
||||
|
||||
$revenues = Order::select(
|
||||
DB::raw("DATE_FORMAT(order_date, '%Y-%m') as month"),
|
||||
DB::raw('SUM(total_amount) as total')
|
||||
)
|
||||
->where('order_date', '>=', now()->subMonths(5)->startOfMonth())
|
||||
->groupBy('month')
|
||||
->get()
|
||||
->pluck('total', 'month');
|
||||
|
||||
$expenses = Expense::select(
|
||||
DB::raw("DATE_FORMAT(expense_date, '%Y-%m') as month"),
|
||||
DB::raw('SUM(amount) as total')
|
||||
)
|
||||
->where('expense_date', '>=', now()->subMonths(5)->startOfMonth())
|
||||
->groupBy('month')
|
||||
->get()
|
||||
->pluck('total', 'month');
|
||||
|
||||
$feedPurchases = FeedPurchase::select(
|
||||
DB::raw("DATE_FORMAT(purchase_date, '%Y-%m') as month"),
|
||||
DB::raw('SUM(total_price) as total')
|
||||
)
|
||||
->where('purchase_date', '>=', now()->subMonths(5)->startOfMonth())
|
||||
->groupBy('month')
|
||||
->get()
|
||||
->pluck('total', 'month');
|
||||
|
||||
$revenueData = $months->map(fn ($month) => (int) $revenues->get($month, 0));
|
||||
$expenseData = $months->map(fn ($month) => (int) ($expenses->get($month, 0) + $feedPurchases->get($month, 0)));
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Pendapatan (Order)',
|
||||
'data' => $revenueData->values()->toArray(),
|
||||
'backgroundColor' => '#10b981',
|
||||
'borderColor' => '#10b981',
|
||||
],
|
||||
[
|
||||
'label' => 'Pengeluaran (Operasional + Pakan)',
|
||||
'data' => $expenseData->values()->toArray(),
|
||||
'backgroundColor' => '#ef4444',
|
||||
'borderColor' => '#ef4444',
|
||||
],
|
||||
],
|
||||
'labels' => $months->values()->map(fn ($month) => Carbon::parse($month)->translatedFormat('M Y'))->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Models\DelayedGood;
|
||||
use App\Models\EggCollection;
|
||||
use App\Models\Expense;
|
||||
use App\Models\FeedPurchase;
|
||||
use App\Models\Order;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class StatsOverview extends BaseWidget
|
||||
{
|
||||
use HasWidgetShield;
|
||||
|
||||
protected static ?int $sort = 1;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make('Produksi Telur', number_format(EggCollection::sum('total_eggs'), 0, ',', '.'))
|
||||
->description('Total akumulasi produksi telur (berbagai satuan).')
|
||||
->descriptionIcon('heroicon-m-circle-stack')
|
||||
->color('warning'),
|
||||
|
||||
Stat::make('Order', number_format(Order::count(), 0, ',', '.').' Pesanan')
|
||||
->description('Jumlah pesanan yang dibuat.')
|
||||
->descriptionIcon('heroicon-m-shopping-cart')
|
||||
->color('info'),
|
||||
|
||||
Stat::make('Pendapatan', 'Rp '.number_format(Order::sum('total_amount'), 0, ',', '.'))
|
||||
->description('Total pendapatan dari pesanan.')
|
||||
->descriptionIcon('heroicon-m-banknotes')
|
||||
->color('success'),
|
||||
|
||||
Stat::make('Total Pelanggan', number_format(Customer::count(), 0, ',', '.').' Orang')
|
||||
->description('Total pelanggan terdaftar.')
|
||||
->descriptionIcon('heroicon-m-users')
|
||||
->color('primary'),
|
||||
|
||||
Stat::make('Total Pengeluaran', 'Rp '.number_format(Expense::sum('amount'), 0, ',', '.'))
|
||||
->description('Total akumulasi biaya pengeluaran.')
|
||||
->descriptionIcon('heroicon-m-credit-card')
|
||||
->color('danger'),
|
||||
|
||||
Stat::make('Barang Tertunda', number_format(DelayedGood::count(), 0, ',', '.').' Item')
|
||||
->description('Jumlah barang yang masih tertunda.')
|
||||
->descriptionIcon('heroicon-m-clock')
|
||||
->color('warning'),
|
||||
|
||||
Stat::make('Total Belanja Pakan', 'Rp '.number_format(FeedPurchase::sum('total_price'), 0, ',', '.'))
|
||||
->description('Total pengeluaran untuk pakan.')
|
||||
->descriptionIcon('heroicon-m-shopping-bag')
|
||||
->color('info'),
|
||||
|
||||
Stat::make('Laba Kotor', 'Rp '.number_format(Order::sum('total_amount') - (Expense::sum('amount') + FeedPurchase::sum('total_price')), 0, ',', '.'))
|
||||
->description('Pendapatan - (Pengeluaran + Pakan).')
|
||||
->descriptionIcon('heroicon-m-presentation-chart-line')
|
||||
->color('success'),
|
||||
|
||||
Stat::make('Piutang Belum Terbayar', 'Rp '.number_format(DelayedGood::where('is_paid', false)->sum('total_amount') - DelayedGood::where('is_paid', false)->sum('paid_amount'), 0, ',', '.'))
|
||||
->description('Total piutang dari barang tertunda.')
|
||||
->descriptionIcon('heroicon-m-receipt-percent')
|
||||
->color('danger'),
|
||||
|
||||
Stat::make('Total Biaya Operasional', 'Rp '.number_format(Expense::sum('amount') + FeedPurchase::sum('total_price'), 0, ',', '.'))
|
||||
->description('Total beban biaya saat ini.')
|
||||
->descriptionIcon('heroicon-m-calculator')
|
||||
->color('warning'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Order;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TopCustomersChart extends ChartWidget
|
||||
{
|
||||
use HasWidgetShield;
|
||||
|
||||
protected ?string $heading = 'Top 5 Pelanggan (Berdasarkan Total Order)';
|
||||
|
||||
protected static ?int $sort = 6;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$data = Order::with('customer')
|
||||
->select('customer_id', DB::raw('SUM(total_amount) as total_spent'))
|
||||
->groupBy('customer_id')
|
||||
->orderByDesc('total_spent')
|
||||
->limit(5)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Total Pembelian (Rp)',
|
||||
'data' => $data->pluck('total_spent')->toArray(),
|
||||
'backgroundColor' => [
|
||||
'#fbbf24',
|
||||
'#f59e0b',
|
||||
'#d97706',
|
||||
'#b45309',
|
||||
'#92400e',
|
||||
],
|
||||
],
|
||||
],
|
||||
'labels' => $data->map(fn ($item) => $item->customer?->name ?? 'Umum')->toArray(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'indexAxis' => 'y',
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user