get('timezone', 'UTC'); return responder()->success( DashboardExport::init( $request->input('users') ?? User::all()->pluck('id')->toArray(), $request->input('projects') ?? Project::all()->pluck('id')->toArray(), Carbon::parse($request->input('start_at'))->setTimezone($companyTimezone), Carbon::parse($request->input('end_at'))->setTimezone($companyTimezone), $companyTimezone, $request->input('user_timezone'), )->collection()->all(), )->respond(); } /** * @throws Throwable * @api {post} /report/dashboard/download Download Dashboard Report * @apiDescription Generate and download a dashboard report * * @apiVersion 4.0.0 * @apiName DownloadDashboardReport * @apiGroup Report * * @apiUse AuthHeader * * @apiHeader {String} Accept Specifies the content type of the response. (Example: `text/csv`) * @apiHeader {String} Authorization Bearer token for API access. (Example: `82|LosbyrFljFDJqUcqMNG6UveCgrclt6OzTrCWdnJBEZ1fee08e6`) * @apiPermission report_generate * @apiPermission report_full_access * * @apiParam {String} start_at Start date and time (ISO 8601 format) * @apiParam {String} end_at End date and time (ISO 8601 format) * @apiParam {String} user_timezone User's timezone * @apiParam {String} sort_column Column to sort by * @apiParam {String} sort_direction Direction to sort (asc/desc) * * @apiParamExample {json} Request Example * { * "start_at": "2024-08-06T18:00:00.000Z", * "end_at": "2024-08-07T17:59:59.999Z", * "user_timezone": "Asia/Omsk", * "sort_column": "user", * "sort_direction": "asc", * } * * @apiSuccess {String} url URL to download the generated report * * @apiSuccessExample {json} Response Example * HTTP/1.1 200 OK * { * "status": 200, * "success": true, * "data": { * "url": "/storage/reports/f7ac500e-a741-47ee-9e61-1b62a341fb8d/Dashboard_Report.csv" * } * } * * @apiUse 400Error * @apiUse ValidationError * @apiUse UnauthorizedError * @apiUse ForbiddenError * @apiUse ItemNotFoundError */ public function download(DashboardRequest $request): JsonResponse { $companyTimezone = Settings::scope('core')->get('timezone', 'UTC'); $job = new GenerateAndSendReport( DashboardExport::init( $request->input('users') ?? User::all()->pluck('id')->toArray(), $request->input('projects') ?? Project::all()->pluck('id')->toArray(), Carbon::parse($request->input('start_at'))->setTimezone($companyTimezone), Carbon::parse($request->input('end_at'))->setTimezone($companyTimezone), $companyTimezone, $request->input('user_timezone'), DashboardSortBy::tryFrom($request->input('sort_column')), SortDirection::tryFrom($request->input('sort_direction')), ), $request->user(), ReportHelper::getReportFormat($request), ); app(Dispatcher::class)->dispatchSync($job); return responder()->success(['url' => $job->getPublicPath()])->respond(); } }