From 70ca6fe7891e23af176931ecb64fc2b74f466c0b Mon Sep 17 00:00:00 2001 From: Nethma-Yasith Date: Fri, 3 Jul 2026 17:21:45 +0530 Subject: [PATCH] Implement modern Excel, CSV, and PDF export functionality for all 3 tables --- Exports/DailySalePaymentReportExport.php | 22 ++ ...DailySalePaymentReportModuleController.php | 36 ++- Resources/views/export.blade.php | 272 ++++++++++++++++++ 3 files changed, 323 insertions(+), 7 deletions(-) create mode 100644 Exports/DailySalePaymentReportExport.php create mode 100644 Resources/views/export.blade.php diff --git a/Exports/DailySalePaymentReportExport.php b/Exports/DailySalePaymentReportExport.php new file mode 100644 index 0000000..441ae2a --- /dev/null +++ b/Exports/DailySalePaymentReportExport.php @@ -0,0 +1,22 @@ +data = $data; + } + + public function view(): View + { + return view('dailysalepaymentreportmodule::export', $this->data); + } +} diff --git a/Http/Controllers/DailySalePaymentReportModuleController.php b/Http/Controllers/DailySalePaymentReportModuleController.php index 9c6b46b..d4b277c 100644 --- a/Http/Controllers/DailySalePaymentReportModuleController.php +++ b/Http/Controllers/DailySalePaymentReportModuleController.php @@ -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); } } diff --git a/Resources/views/export.blade.php b/Resources/views/export.blade.php new file mode 100644 index 0000000..21964fd --- /dev/null +++ b/Resources/views/export.blade.php @@ -0,0 +1,272 @@ + + + + + Daily Sale Payment Report + + + + + + + + +
+ Daily Sale Payment Report +
+ + + + + +
+ REPORT DATE: {{ $report_date }} +
+ + + + + +
+ Daily Sales +
+ + + + + + + + + @foreach($paymentOptions as $option) + + @endforeach + + + + + @php + $tot_grand = 0; + $tot_due = 0; + $option_totals = []; + foreach ($paymentOptions as $opt) { + $option_totals[$opt->id] = 0; + } + @endphp + @foreach($sales_data as $sale) + + + + + + + @foreach($paymentOptions as $option) + + @endforeach + + + @php + $tot_grand += $sale->grand_total; + $tot_due += $sale->due_amount; + foreach ($paymentOptions as $opt) { + $option_totals[$opt->id] += ($sale->methods[$opt->id] ?? 0); + } + @endphp + @endforeach + + + + + + @foreach($paymentOptions as $option) + + @endforeach + + + +
DateReference NumberCashierCustomerGrand Total{{ $option->name }}Due Amount
{{ $sale->date }}{{ $sale->reference_no }}{{ $sale->cashier }}{{ $sale->customer }}{{ number_format($sale->grand_total, 2) }}{{ number_format($sale->methods[$option->id] ?? 0, 2) }}{{ number_format($sale->due_amount, 2) }}
DAILY TOTALS{{ number_format($tot_grand, 2) }}{{ number_format($option_totals[$option->id], 2) }}{{ number_format($tot_due, 2) }}
+ + +
+ + + + + +
+ Credit Sale Collections +
+ + + + + + + + + @foreach ($paymentOptions as $option) + + @endforeach + + + + @foreach ($creditCollections as $row) + + + + + + + @foreach ($paymentOptions as $option) + + @endforeach + + @endforeach + + + + + + @foreach ($paymentOptions as $option) + + @endforeach + + +
Original Bill DateReference NumberCashierCustomerGrand Total{{ $option->name }}
{{ \Carbon\Carbon::parse($row['date'])->format('Y-m-d') }}{{ $row['reference'] }}{{ $row['cashier'] }}{{ $row['customer'] }}{{ number_format($row['grand_total'], 2) }}{{ number_format($row['methods'][$option->id] ?? 0, 2) }}
COLLECTION TOTALS{{ number_format($creditTotals['grand_total'], 2) }}{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}
+ + +
+ + + + + +
+ Payment Method Summary +
+ + + + + + + + + + + @php + $grand_sale = 0; + $grand_received = 0; + $grand_total = 0; + @endphp + @foreach ($summaryData as $summary) + + + + + + + @php + $grand_sale += $summary['sale_amount']; + $grand_received += $summary['received_amount']; + $grand_total += $summary['total_amount']; + @endphp + @endforeach + + + + + + + + + +
Payment OptionSale AmountReceived AmountTotal Amount
{{ strtoupper($summary['name']) }}{{ number_format($summary['sale_amount'], 2) }}{{ number_format($summary['received_amount'], 2) }}{{ number_format($summary['total_amount'], 2) }}
GRAND TOTAL{{ number_format($grand_sale, 2) }}{{ number_format($grand_received, 2) }}{{ number_format($grand_total, 2) }}
+ + +