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 exportReport(Request $request) { // dd($request->all()); $reportType = $request->input('reportType'); $states = $request->input('states'); $restaurants = $request->input('restaurants', []); $startDate = \Carbon\Carbon::parse( $request->startDate)->format('Y-m-d'); $endDate = \Carbon\Carbon::parse( $request->endDate)->format('Y-m-d'); // Set the file name based on the report type $fileName = 'reports.xlsx'; // default file name 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); } } }