From f2daffaee5b2cb899101f3747f09481b6971900f Mon Sep 17 00:00:00 2001 From: sayaliparab Date: Fri, 19 Jul 2024 13:33:10 +0530 Subject: [PATCH] rportChanges --- .../Admin/ManageReportsController.php | 157 ++++++------------ 1 file changed, 54 insertions(+), 103 deletions(-) diff --git a/app/Http/Controllers/Admin/ManageReportsController.php b/app/Http/Controllers/Admin/ManageReportsController.php index 644216c..4768f2e 100644 --- a/app/Http/Controllers/Admin/ManageReportsController.php +++ b/app/Http/Controllers/Admin/ManageReportsController.php @@ -14,122 +14,73 @@ use App\Exports\ExportReports; class ManageReportsController extends Controller { - + /** - * Created By : sayali parab - * Created at : 03 July 2024 - * Use : To get manage report page. - */ + * Created By : sayali parab + * Created at : 03 July 2024 + * Use : To get manage report page. + */ public function index() -{ - try { - $states = ManageState::all(); - $restaurants = ManageRestaurant::all(); - return view('Admin.pages.manage_reports.manage_reports', compact('states','restaurants')); - } catch (\Exception $e) { - Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); - return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + { + try { + $states = ManageState::all(); + $restaurants = ManageRestaurant::all(); + return view('Admin.pages.manage_reports.manage_reports', compact('states', 'restaurants')); + } catch (\Exception $e) { + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + } } -} /** - * Created By : sayali parab - * Created at : 03 July 2024 - * Use : To download the excel. - */ - -// public function exportReports(Request $request) -// { -// $reportType = $request->input('reportType'); -// $states = $request->input('states'); -// $restaurants = $request->input('restaurants', []); - -// $startDate = $request->input('startDate'); -// $endDate = $request->input('endDate'); - -// return Excel::download(new ReportExport($reportType, $states, $startDate, $endDate, $restaurants), 'report.xlsx'); -// } -// public function exportReports(Request $request) -// { -// // dd($request->all()); -// $reportType = $request->input('reportType'); -// $states = $request->input('states'); -// $restaurants = $request->input('restaurants', []); - -// $startDate = $request->input('startDate'); -// $endDate = $request->input('endDate'); - -// try { -// return Excel::download(new ReportExports($reportType, $states, $startDate, $endDate, $restaurants), 'report.xlsx'); -// } catch (\Exception $e) { -// // Log the error for debugging -// \Log::error('Export failed: ' . $e->getMessage()); - -// return response()->json(['error' => 'Export failed. Something went wrong.'], 500); -// } -// } -// public function exportReport(Request $request) -// { -// // dd($request->all()); -// $reportType = $request->input('reportType'); -// $states = $request->input('states'); -// $restaurants = $request->input('restaurants', []); - -// $startDate = $request->input('startDate'); -// $endDate = $request->input('endDate'); + * Created By : sayali parab + * Created at : 03 July 2024 + * Use : To download the excel. + */ -// try { -// return Excel::download(new ExportReports($reportType, $states, $startDate, $endDate, $restaurants), 'reports.Xlsx'); -// } catch (\Exception $e) { -// \Log::error('Export failed: ' . $e->getMessage()); -// \Log::error('Stack trace: ' . $e->getTraceAsString()); -// return response()->json(['error' => 'Export failed. Something went wrong.'], 500); -// } -// } -public function exportReport(Request $request) -{ - // dd($request->all()); - $reportType = $request->input('reportType'); - $states = $request->input('states'); - $restaurants = $request->input('restaurants', []); - $startDate = $request->input('startDate'); - $endDate = $request->input('endDate'); - // Set the file name based on the report type - $fileName = 'reports.xlsx'; // default file name + public function exportReport(Request $request) + { + // dd($request->all()); + $reportType = $request->input('reportType'); + $states = $request->input('states'); + $restaurants = $request->input('restaurants', []); + $startDate = $request->input('startDate'); + $endDate = $request->input('endDate'); - if ($reportType == 'Total Subscribed') { - $fileName = 'total_subscribed_report.xlsx'; - } elseif ($reportType == 'Total Users') { - $fileName = 'total_users_report.xlsx'; - } elseif ($reportType == 'Redemptions') { - $fileName = 'redemptions_report.xlsx'; - } elseif ($reportType == 'Redemptions for Specific Restaurants') { - $fileName = 'redemptions_specific_restaurants_report.xlsx'; - } elseif ($reportType == 'Subscriptions Cancelled') { - $fileName = 'subscriptions_cancelled_report.xlsx'; - } elseif ($reportType == 'Referrals Made') { - $fileName = 'referrals_made_report.xlsx'; - } elseif ($reportType == 'Referees Joined') { - $fileName = 'referees_joined_report.xlsx'; - } + // Set the file name based on the report type + $fileName = 'reports.xlsx'; // default file name - // Log the report type and file name for debugging purposes - \Log::info('Report type: ' . $reportType); - \Log::info('File name: ' . $fileName); + if ($reportType == 'Total Subscribed') { + $fileName = 'total_subscribed_report.xlsx'; + } elseif ($reportType == 'Total Users') { + $fileName = 'total_users_report.xlsx'; + } elseif ($reportType == 'Redemptions') { + $fileName = 'redemptions_report.xlsx'; + } elseif ($reportType == 'Redemptions for Specific Restaurants') { + $fileName = 'redemptions_specific_restaurants_report.xlsx'; + } elseif ($reportType == 'Subscriptions Cancelled') { + $fileName = 'subscriptions_cancelled_report.xlsx'; + } elseif ($reportType == 'Referrals Made') { + $fileName = 'referrals_made_report.xlsx'; + } elseif ($reportType == 'Referees Joined') { + $fileName = 'referees_joined_report.xlsx'; + } - try { - return Excel::download(new ExportReports($reportType, $states, $startDate, $endDate, $restaurants), $fileName); - } catch (\Exception $e) { - \Log::error('Export failed: ' . $e->getMessage()); - \Log::error('Stack trace: ' . $e->getTraceAsString()); - return response()->json(['error' => 'Export failed. Something went wrong.'], 500); + // Log the report type and file name for debugging purposes + \Log::info('Report type: ' . $reportType); + \Log::info('File name: ' . $fileName); + + try { + return Excel::download(new ExportReports($reportType, $states, $startDate, $endDate, $restaurants), $fileName); + } catch (\Exception $e) { + \Log::error('Export failed: ' . $e->getMessage()); + \Log::error('Stack trace: ' . $e->getTraceAsString()); + return response()->json(['error' => 'Export failed. Something went wrong.'], 500); + } } } - - -} \ No newline at end of file