$exception, ]); } return view('m3::liberty-theme.pages.WhsPerfMetrics', $context); } public static function downloadFiles(Request $request) { $validated = $request->validate([ 'filename' => ['required', 'string'], ]); $fileName = ltrim($validated['filename'], '/'); $disk = Storage::disk('publicLabels'); if (! $disk->exists($fileName)) { abort(404, 'Warehouse performance file not found.'); } return $disk->download($fileName, basename($fileName)); } private static function defaultContext(): array { return [ 'IC670M' => collect(), 'WHDDA' => '', 'COMPANY' => '', 'PLANT' => '', 'WHS' => '', 'allReportsUrls' => [], ]; } private static function loadUserContext(): array { $connection = config('m3.connection', 'pgsql'); $user = Str::upper(trim((string) m3User())); if ($user === '' || ! Schema::connection($connection)->hasTable('icm428m')) { return ['COMPANY' => '', 'PLANT' => '', 'WHS' => '']; } $profile = DB::connection($connection)->table('icm428m') ->select('R428CO', 'R428PL', 'R428WH') ->where('R428US', $user) ->first(); return [ 'COMPANY' => trim((string) ($profile->R428CO ?? '')), 'PLANT' => trim((string) ($profile->R428PL ?? '')), 'WHS' => trim((string) ($profile->R428WH ?? '')), ]; } private static function loadWarehouses() { $connection = config('m3.connection', 'pgsql'); if (! Schema::connection($connection)->hasTable('ic670m')) { return collect(); } return DB::connection($connection)->table('ic670m')->get(); } private static function loadReportUrls(string $warehouse): array { if ($warehouse === '') { return []; } $disk = Storage::disk('publicLabels'); $urls = []; foreach ($disk->allFiles('WhsPerf/' . $warehouse) as $file) { $urls[$file] = $disk->url($file); } return $urls; } }