header('X-Api-Key'); if (! is_string($shareSecret)) { throw new ModelNotFoundException; } $report = Report::query() ->with([ 'organization', ]) ->where('share_secret', '=', $shareSecret) ->where('is_public', '=', true) ->where(function (Builder $builder): void { /** @var Builder $builder */ $builder->whereNull('public_until') ->orWhere('public_until', '>', now()); }) ->firstOrFail(); /** @var ReportPropertiesDto $properties */ $properties = $report->properties; $timeEntriesQuery = TimeEntry::query() ->whereBelongsTo($report->organization, 'organization'); $filter = new TimeEntryFilter($timeEntriesQuery); $filter->addStart($properties->start); $filter->addEnd($properties->end); $filter->addActive($properties->active); $filter->addBillable($properties->billable); $filter->addMemberIdsFilter($properties->memberIds?->toArray()); $filter->addProjectIdsFilter($properties->projectIds?->toArray()); $filter->addTagIdsFilter($properties->tagIds?->toArray()); $filter->addTaskIdsFilter($properties->taskIds?->toArray()); $filter->addClientIdsFilter($properties->clientIds?->toArray()); $timeEntriesQuery = $filter->get(); $data = $timeEntryAggregationService->getAggregatedTimeEntriesWithDescriptions( $timeEntriesQuery->clone(), $report->properties->group, $report->properties->subGroup, $report->properties->timezone, $report->properties->weekStart, false, $report->properties->start, $report->properties->end, true ); $historyData = $timeEntryAggregationService->getAggregatedTimeEntriesWithDescriptions( $timeEntriesQuery->clone(), TimeEntryAggregationType::fromInterval($report->properties->historyGroup), null, $report->properties->timezone, $report->properties->weekStart, true, $report->properties->start, $report->properties->end, true ); return new DetailedWithDataReportResource($report, $data, $historyData); } }