Implement modern Excel, CSV, and PDF export functionality for all 3 tables

This commit is contained in:
2026-07-03 17:21:45 +05:30
parent 26273d92c2
commit 70ca6fe789
3 changed files with 323 additions and 7 deletions

View File

@@ -17,7 +17,14 @@ class DailySalePaymentReportModuleController extends Controller
public function index(Request $request)
{
$report_date = $request->input('report_date', Carbon::today()->toDateString());
$data = $this->getReportData($report_date);
return view('dailysalepaymentreportmodule::index', $data);
}
private function getReportData($report_date)
{
// Fetch dynamic payment options using DB facade since the model is missing in this branch
$paymentOptions = DB::table('payment_options')->where('is_active', 1)
->orderBy('id')
@@ -140,16 +147,14 @@ class DailySalePaymentReportModuleController extends Controller
}
}
return view('dailysalepaymentreportmodule::index', compact(
return compact(
'sales_data',
'report_date',
'paymentOptions',
'creditCollections',
'creditTotals',
'summaryData'
));
);
}
private function getCreditSaleCollections($date)
@@ -292,11 +297,28 @@ class DailySalePaymentReportModuleController extends Controller
public function exportReport(Request $request)
{
$date = $request->query('date', Carbon::today()->toDateString());
$type = $request->query('type', 'excel');
$date = $request->query('date');
$type = $request->query('type');
$data = $this->getReportData($date);
$filename = 'Daily_Sale_Payment_Report_' . $date;
if ($type === 'pdf') {
// Use DOMPDF directly for PDF to preserve advanced CSS and layout
$pdf = app('dompdf.wrapper')->loadView('dailysalepaymentreportmodule::export', $data);
$pdf->setPaper('a4', 'landscape');
return $pdf->download($filename . '.pdf');
}
// For Excel and CSV, use Maatwebsite Excel
$export = new \Modules\DailySalePaymentReportModule\Exports\DailySalePaymentReportExport($data);
if ($type === 'csv') {
return \Maatwebsite\Excel\Facades\Excel::download($export, $filename . '.csv', \Maatwebsite\Excel\Excel::CSV);
}
return "Export function is working. Selected Date: " . $date . " | Export Type: " . $type;
// Default to Excel
return \Maatwebsite\Excel\Facades\Excel::download($export, $filename . '.xlsx', \Maatwebsite\Excel\Excel::XLSX);
}
}