Files
cheerstothe_season_2.0/app/Http/Controllers/Admin/ManageReportsController.php

94 lines
2.9 KiB
PHP
Raw Normal View History

2024-05-23 15:20:21 +05:30
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
2024-07-03 16:24:22 +05:30
use App\Models\ManageState;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel;
2024-07-15 19:11:04 +05:30
use App\Exports\ReportExports;
2024-07-03 19:30:35 +05:30
use App\Models\ManageRestaurant;
2024-07-11 19:56:53 +05:30
use App\Models\ReferralUsers;
2024-07-15 19:11:04 +05:30
use App\Exports\ExportReports;
2024-05-23 15:20:21 +05:30
class ManageReportsController extends Controller
{
2024-07-04 13:02:23 +05:30
/**
* Created By : sayali parab
* Created at : 03 July 2024
* Use : To get manage report page.
*/
2024-07-03 16:24:22 +05:30
public function index()
{
try {
$states = ManageState::all();
2024-07-03 19:30:35 +05:30
$restaurants = ManageRestaurant::all();
return view('Admin.pages.manage_reports.manage_reports', compact('states','restaurants'));
2024-07-03 16:24:22 +05:30
} catch (\Exception $e) {
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
2024-05-23 15:20:21 +05:30
}
}
2024-07-03 16:24:22 +05:30
2024-07-04 13:02:23 +05:30
/**
* Created By : sayali parab
* Created at : 03 July 2024
* Use : To download the excel.
*/
2024-07-15 19:11:04 +05:30
// 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)
2024-07-03 16:24:22 +05:30
{
2024-07-15 19:11:04 +05:30
// dd($request->all());
2024-07-03 16:24:22 +05:30
$reportType = $request->input('reportType');
$states = $request->input('states');
2024-07-03 19:30:35 +05:30
$restaurants = $request->input('restaurants', []);
2024-07-03 16:24:22 +05:30
$startDate = $request->input('startDate');
$endDate = $request->input('endDate');
2024-07-15 19:11:04 +05:30
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);
}
2024-07-03 16:24:22 +05:30
}
2024-07-11 19:56:53 +05:30
}