service = $service; } public function show($inventoryYear = null) { $inventoryYear = $inventoryYear ?? date('Y'); $years = activityYearRange($inventoryYear, false); $gpcOutputs = ActivityGpcOutput::where('inventory_year', $inventoryYear) ->rowActive()->orderBy('activity_year', 'desc') ->whereBetween('activity_year', [$years[0], end($years)]) ->get(); $gpcOutputRList = []; foreach ($gpcOutputs as $gpcOutput) { $gpcOutputRList[] = $gpcOutput->getAllColumnsWithReference(); } return view($this->template.'.index', [ 'title' => $this->title, 'route' => $this->route, 'inventoryYear' => $inventoryYear, 'gpcOutputs' => $gpcOutputs, 'gpcOutputRList' => $gpcOutputRList, ]); } public function export(Request $request) { $validator = Validator::make($request->all(), [ 'inventoryYear' => 'required|integer', ]); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $inventoryYear = $request->input('inventoryYear'); // Fetch the necessary data $gpcOutputs = ActivityGpcOutput::where('inventory_year', $inventoryYear) ->rowActive()->orderBy('activity_year', 'desc')->get(); $gpcOutputRList = []; foreach ($gpcOutputs as $gpcOutput) { $gpcOutputRList[] = $gpcOutput->getAllColumnsWithReference(); } $titleExcel = 'GPC-OUTPUT_' . $inventoryYear; return Excel::download(new GpcOutputExport($inventoryYear, $gpcOutputs, $gpcOutputRList), $titleExcel . '.xlsx'); } }