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; } }