*/ final readonly class GetBoDashboardQuery implements Query { public function __construct( private StatsService $statsService, ) { } #[\Override] public function __invoke(QueryInput $input): GetBoDashboardQueryOutput { Assert::isInstanceOf($input, GetBoDashboardQueryInput::class); $statsShop = []; $adhesion = $this->statsService->getMembershipPercentage(); $statsCustomer = []; $prevDates = null; if ($input->start !== null && $input->end !== null) { $prevDates = $this->statsService->getPreviousPeriod($input->start, $input->end); $statsShop = $this->statsService->getStats(StatsShopType::cases(), $input->start, $input->end); $statsCustomer = $this->statsService->getStats(StatsCustomerType::cases(), $input->start, $input->end); } $employeeCount = Employee::query()->active()->count(); $customersLinkedToEmployeeCount = Employee::query()->active()->whereHas('customer')->count(); return new GetBoDashboardQueryOutput( employeeCount: $employeeCount, customersLinkedToEmployeeCount: $customersLinkedToEmployeeCount, adhesion: $adhesion, prevDates: $prevDates, statsShop: $statsShop, statsCustomer: $statsCustomer, ); } }