service = $service; } public function show($inventoryYear = null, $activityYear = null, $sectorCode = null) { $gpcOutput = ActivityGpcOutput::where('inventory_year', $inventoryYear) ->where('activity_year', $activityYear)->rowActive() ->first(); $gpc = []; if ($gpcOutput) { $gpc = $gpcOutput->getAllColumnsWithReference(); } $gpcData = GcomCrfData::getAllData(); return view($this->template.'.index', [ 'title' => $this->title, 'route' => $this->route, 'inventoryYear' => $inventoryYear ?? date('Y'), 'activityYear' => $activityYear ?? date('Y') - 1, 'gpcData' => $gpcData, 'gpcOutput' => $gpcOutput, 'gpc' => $gpc, ]); } public function export(Request $request) { // Validate and sanitize inputs $validator = Validator::make($request->all(), [ 'inventoryYear' => 'required|integer', 'activityYear' => 'required|integer', ]); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $inventoryYear = $request->input('inventoryYear'); $activityYear = $request->input('activityYear'); // Fetch the necessary data $gpcOutput = ActivityGpcOutput::where('inventory_year', $inventoryYear) ->where('activity_year', $activityYear)->rowActive() ->first(); $gpc = []; if ($gpcOutput) { $gpc = $gpcOutput->getAllColumnsWithReference(); } $gpcData = GcomCrfData::getAllData(); $titleExcel = 'GCOM-CRF_' . $inventoryYear . '_' . $activityYear; return Excel::download(new GcomCrfExport($inventoryYear, $activityYear, $gpcData, $gpc), $titleExcel . '.xlsx'); } }