|null $filterJson */ public function enqueue(AdminUser $admin, Request $request, string $reportType, string $exportFormat, ?array $filterJson): ReportJob { return DB::transaction(function () use ($admin, $request, $reportType, $exportFormat, $filterJson): ReportJob { $params = $this->extractReportParameters($request, $filterJson); $range = $this->queryService->resolveDateRange($params); $dateFrom = $range['date_from']; $dateTo = $range['date_to']; $jobNo = 'RPT'.now()->format('YmdHis').strtoupper(Str::random(4)); $exportFormat = $exportFormat === 'xlsx' ? 'xlsx' : 'csv'; $pathSuffix = $this->queryService->resolveOutputPathSuffix($reportType, $params, $dateFrom, $dateTo); $job = ReportJob::query()->create([ 'job_no' => $jobNo, 'admin_user_id' => (int) $admin->getKey(), 'report_type' => $reportType, 'export_format' => $exportFormat, 'filter_json' => $params, 'status' => 'completed', 'output_path' => 'reports/'.$this->queryService->reportLabel($reportType).'_'.$pathSuffix.'.'.$exportFormat, 'error_message' => null, 'finished_at' => now(), ]); AuditLogger::recordForAdmin( $admin, $request, 'report_jobs', 'enqueue', 'report_job', (string) $job->getKey(), null, [ 'job_no' => $jobNo, 'report_type' => $reportType, 'export_format' => $exportFormat, ], ); return $job; }); } /** * @return list> */ public function reportRows(string $reportType, ?array $filterJson, ?AdminUser $scopedAdmin = null): array { return $this->queryService->reportRows($reportType, $filterJson, $scopedAdmin); } public function reportLabel(string $reportType): string { return $this->queryService->reportLabel($reportType); } /** * @return array */ private function extractReportParameters(Request $request, ?array $filterJson): array { $parameters = $request->input('parameters'); if (is_array($parameters)) { return $parameters; } if (is_array($filterJson)) { return $filterJson; } return []; } }