ReportExcel

This commit is contained in:
sayaliparab
2024-07-15 19:11:04 +05:30
parent 63b0a6a990
commit 57c4820219
10 changed files with 1034 additions and 486 deletions

View File

@@ -7,10 +7,10 @@ use Illuminate\Http\Request;
use App\Models\ManageState;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\ReportExport;
use App\Exports\ReportExports;
use App\Models\ManageRestaurant;
use App\Models\ReferralUsers;
use App\Exports\ExportReports;
class ManageReportsController extends Controller
{
@@ -41,8 +41,39 @@ class ManageReportsController extends Controller
* Use : To download the excel.
*/
public function exportReports(Request $request)
// 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', []);
@@ -50,9 +81,14 @@ public function exportReports(Request $request)
$startDate = $request->input('startDate');
$endDate = $request->input('endDate');
return Excel::download(new ReportExport($reportType, $states, $startDate, $endDate, $restaurants), 'report.xlsx');
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);
}
}
}