You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.5 KiB
PHP
87 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Enums\OrderStatus;
|
|
use App\Models\Order;
|
|
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
class OrderStats extends BaseWidget
|
|
{
|
|
// protected int|string|array $columnSpan = '2';
|
|
|
|
protected function getStats(): array
|
|
{
|
|
return [
|
|
Stat::make('This Month', $this->getOrdersPast30Days())
|
|
->icon('heroicon-s-calendar')
|
|
->chartColor('success')
|
|
->chart($this->getOrdersInPast30DaysChart())
|
|
->description('New orders in the past 30 days'),
|
|
|
|
Stat::make('Active Orders', $this->getActiveOrders())
|
|
->icon('heroicon-o-arrow-path')
|
|
->description('Orders that have yet to be completed'),
|
|
|
|
Stat::make('Due Today', $this->getDueOrders())
|
|
->icon('heroicon-o-clock')
|
|
->chartColor('info')
|
|
->chart($this->getDueOrdersChart())
|
|
->description('Orders that are scheduled to be due today'),
|
|
];
|
|
}
|
|
|
|
private function getActiveOrders(): string
|
|
{
|
|
return Order::all()
|
|
->where('order_status', '!=', OrderStatus::SHIPPED)
|
|
->where('order_status', '!=', OrderStatus::INVOICED)
|
|
->count();
|
|
}
|
|
|
|
private function getOrdersPast30Days(): string
|
|
{
|
|
return Order::all()
|
|
->where('order_status', '!=', OrderStatus::SHIPPED)
|
|
->where('order_status', '!=', OrderStatus::INVOICED)
|
|
->whereBetween('created_at', [now()->startOfMonth(), now()->endOfMonth()])
|
|
->count();
|
|
}
|
|
|
|
private function getOrdersInPast30DaysChart(): array
|
|
{
|
|
$chart = [];
|
|
$points = 30;
|
|
$startDate = today()->subDays(31);
|
|
|
|
for ($i = 0; $i < $points; $i++) {
|
|
$chart[$i] = Order::where('order_date', $startDate->addDay())->count();
|
|
}
|
|
|
|
return $chart;
|
|
}
|
|
|
|
private function getDueOrders(): string
|
|
{
|
|
return Order::all()
|
|
->where('order_status', '!=', OrderStatus::SHIPPED)
|
|
->where('order_status', '!=', OrderStatus::INVOICED)
|
|
->where('due_date', '<=', now())
|
|
->count();
|
|
}
|
|
|
|
private function getDueOrdersChart(): array
|
|
{
|
|
$chart = [];
|
|
$points = 30;
|
|
$startDate = today()->subDays(31);
|
|
|
|
for ($i = 0; $i < $points; $i++) {
|
|
$chart[$i] = Order::where('due_date', $startDate->addDay())->count();
|
|
}
|
|
|
|
return $chart;
|
|
}
|
|
}
|