You've already forked Atomcms-edit
53f88b840a
- Replace flowframe/laravel-trend with direct Eloquent DB queries
- Replace srmklive/paypal (abandoned) with new PayPalService using PayPal REST API v2 via Guzzle
- Remove old config/paypal.php, migrate to config('habbo.paypal.*')
- Update blade templates to use habbo.paypal config
- Bump npm packages to latest: @inertiajs/react, axios, esbuild, eslint, sass, tailwindcss, etc.
- Run composer update and yarn upgrade
79 lines
2.4 KiB
PHP
Executable File
79 lines
2.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Filament\Resources\DashboardResource\Widgets;
|
|
|
|
use App\Models\User\UserOrder;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class OrdersAggregateChart extends ChartWidget
|
|
{
|
|
#[\Override]
|
|
protected ?string $maxHeight = '300px';
|
|
|
|
#[\Override]
|
|
protected string $color = 'secondary';
|
|
|
|
#[\Override]
|
|
public function getHeading(): string|Htmlable|null
|
|
{
|
|
return __('filament::resources.stats.orders_chart.title');
|
|
}
|
|
|
|
#[\Override]
|
|
public function getDescription(): string|Htmlable|null
|
|
{
|
|
return __('filament::resources.stats.orders_chart.description');
|
|
}
|
|
|
|
private function getTrendData($query): array
|
|
{
|
|
return $query->whereBetween('created_at', [now()->startOfMonth(), now()->endOfMonth()])
|
|
->selectRaw('DATE(created_at) as date, COUNT(*) as aggregate')
|
|
->groupBy(DB::raw('DATE(created_at)'))
|
|
->orderBy('date')
|
|
->pluck('aggregate', 'date')
|
|
->toArray();
|
|
}
|
|
|
|
#[\Override]
|
|
protected function getData(): array
|
|
{
|
|
$pendingData = $this->getTrendData(UserOrder::pending());
|
|
$cancelledData = $this->getTrendData(UserOrder::cancelled());
|
|
$completedData = $this->getTrendData(UserOrder::completed());
|
|
|
|
$allDates = collect(array_keys(array_merge($pendingData, $cancelledData, $completedData)))
|
|
->unique()
|
|
->sort()
|
|
->values();
|
|
|
|
$datasets = [
|
|
$this->getDataset($pendingData, $allDates, __('filament::resources.stats.orders_chart.pending'), '#fbbf24', '#f59e0b'),
|
|
$this->getDataset($cancelledData, $allDates, __('filament::resources.stats.orders_chart.cancelled'), '#dc2626', '#b91c1c'),
|
|
$this->getDataset($completedData, $allDates, __('filament::resources.stats.orders_chart.completed'), '#10b981', '#059669'),
|
|
];
|
|
|
|
return [
|
|
'datasets' => $datasets,
|
|
'labels' => $allDates,
|
|
];
|
|
}
|
|
|
|
private function getDataset(array $data, $allDates, string $label, string $backgroundColor, string $borderColor): array
|
|
{
|
|
return [
|
|
'label' => $label,
|
|
'data' => $allDates->map(fn ($date) => $data[$date] ?? 0),
|
|
'backgroundColor' => $backgroundColor,
|
|
'borderColor' => $borderColor,
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'bar';
|
|
}
|
|
}
|