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.
topnotch_website/app/Filament/Widgets/OrderStats.php

87 lines
2.5 KiB
PHTML

2 months ago
<?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'),
2 months ago
Stat::make('Active Orders', $this->getActiveOrders())
->icon('heroicon-o-arrow-path')
->description('Orders that have yet to be completed'),
2 months ago
Stat::make('Due Today', $this->getDueOrders())
->icon('heroicon-o-clock')
->chartColor('info')
->chart($this->getDueOrdersChart())
2 months ago
->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
2 months ago
{
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;
}
2 months ago
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;
}
2 months ago
}