From 640ef324b3fa8e420ab881c62dde601e164656f9 Mon Sep 17 00:00:00 2001 From: Nethma-Yasith Date: Fri, 3 Jul 2026 17:53:10 +0530 Subject: [PATCH] Restore Export PDF button to the UI --- Exports/DailySalePaymentReportExport.php | 23 +- ...DailySalePaymentReportModuleController.php | 7 - Resources/views/export.blade.php | 372 ++++++------------ Resources/views/index.blade.php | 6 +- 4 files changed, 151 insertions(+), 257 deletions(-) diff --git a/Exports/DailySalePaymentReportExport.php b/Exports/DailySalePaymentReportExport.php index 441ae2a..0df0a11 100644 --- a/Exports/DailySalePaymentReportExport.php +++ b/Exports/DailySalePaymentReportExport.php @@ -5,8 +5,13 @@ namespace Modules\DailySalePaymentReportModule\Exports; use Illuminate\Contracts\View\View; use Maatwebsite\Excel\Concerns\FromView; use Maatwebsite\Excel\Concerns\ShouldAutoSize; +use Maatwebsite\Excel\Concerns\WithEvents; +use Maatwebsite\Excel\Events\AfterSheet; +use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Style\Border; +use PhpOffice\PhpSpreadsheet\Style\Fill; -class DailySalePaymentReportExport implements FromView, ShouldAutoSize +class DailySalePaymentReportExport implements FromView, ShouldAutoSize, WithEvents { protected $data; @@ -19,4 +24,20 @@ class DailySalePaymentReportExport implements FromView, ShouldAutoSize { return view('dailysalepaymentreportmodule::export', $this->data); } + + public function registerEvents(): array + { + return [ + AfterSheet::class => function (AfterSheet $event) { + $sheet = $event->sheet->getDelegate(); + $highestColumn = $sheet->getHighestColumn(); + $highestRow = $sheet->getHighestRow(); + $dataRange = 'A1:' . $highestColumn . $highestRow; + + // Set borders for everything + $sheet->getStyle($dataRange)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN); + $sheet->getStyle($dataRange)->getAlignment()->setVertical(Alignment::VERTICAL_TOP); + }, + ]; + } } diff --git a/Http/Controllers/DailySalePaymentReportModuleController.php b/Http/Controllers/DailySalePaymentReportModuleController.php index d4b277c..99af0c4 100644 --- a/Http/Controllers/DailySalePaymentReportModuleController.php +++ b/Http/Controllers/DailySalePaymentReportModuleController.php @@ -303,13 +303,6 @@ class DailySalePaymentReportModuleController extends Controller $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); diff --git a/Resources/views/export.blade.php b/Resources/views/export.blade.php index 21964fd..0a89e41 100644 --- a/Resources/views/export.blade.php +++ b/Resources/views/export.blade.php @@ -1,272 +1,152 @@ - - - - - Daily Sale Payment Report - - - - - +
+ - + -
- Daily Sale Payment Report - Daily Sale Payment Report - {{ $report_date }}
- - - + -
- REPORT DATE: {{ $report_date }} - Sales Table (Daily Sale)
- - - + + + + + + @foreach($paymentOptions as $option) + + @endforeach + -
- Daily Sales - DateReference NumberCashierCustomerGrand Total{{ $option->name }}Due Amount
- - + + + @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 = 0; - $tot_due = 0; - $option_totals = []; + $tot_grand += $sale->grand_total; + $tot_due += $sale->due_amount; foreach ($paymentOptions as $opt) { - $option_totals[$opt->id] = 0; + $option_totals[$opt->id] += ($sale->methods[$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{{ $sale->date }}{{ $sale->reference_no }}{{ $sale->cashier }}{{ $sale->customer }}{{ number_format($sale->grand_total, 2) }}{{ $option->name }}{{ number_format($sale->methods[$option->id] ?? 0, 2) }}Due Amount{{ number_format($sale->due_amount, 2) }}
{{ $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) }}
- - -
- - + @endforeach + + - - -
- Credit Sale Collections -
- - - - - - - - - @foreach ($paymentOptions as $option) - - @endforeach - - - - @foreach ($creditCollections as $row) - - - - - - - @foreach ($paymentOptions as $option) - - @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) }}
Total{{ number_format($tot_grand, 2) }}{{ number_format($option_totals[$option->id], 2) }}
{{ number_format($tot_due, 2) }}
+ + + +
+ + + + + + + + + + + + + @foreach ($paymentOptions as $option) + + @endforeach + + + + @foreach ($creditCollections as $row) - - + + + + + @foreach ($paymentOptions as $option) - + @endforeach - -
Credit Sale Collections
Original Bill DateReference NumberCashierCustomerGrand Total{{ $option->name }}
COLLECTION TOTALS{{ number_format($creditTotals['grand_total'], 2) }}{{ \Carbon\Carbon::parse($row['date'])->format('Y-m-d') }}{{ $row['reference'] }}{{ $row['cashier'] }}{{ $row['customer'] }}{{ number_format($row['grand_total'], 2) }}{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}{{ number_format($row['methods'][$option->id] ?? 0, 2) }}
- - -
- - + @endforeach + + - + + + @foreach ($paymentOptions as $option) + + @endforeach -
- Payment Method Summary - Total{{ number_format($creditTotals['grand_total'], 2) }}{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}
- - + +
+ + + +
+ + + + + + + + + + + + + + + @php + $grand_sale = 0; + $grand_received = 0; + $grand_total = 0; + @endphp + @foreach ($summaryData as $summary) - - - - + + + + - - @php - $grand_sale = 0; - $grand_received = 0; - $grand_total = 0; + $grand_sale += $summary['sale_amount']; + $grand_received += $summary['received_amount']; + $grand_total += $summary['total_amount']; @endphp - @foreach ($summaryData as $summary) - - - - - - - @php - $grand_sale += $summary['sale_amount']; - $grand_received += $summary['received_amount']; - $grand_total += $summary['total_amount']; - @endphp - @endforeach - - - - - - - - - -
Payment Method Summary
Payment OptionSale AmountReceived AmountTotal Amount
Payment OptionSale AmountReceived AmountTotal Amount{{ $summary['name'] }}{{ number_format($summary['sale_amount'], 2) }}{{ number_format($summary['received_amount'], 2) }}{{ number_format($summary['total_amount'], 2) }}
{{ 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) }}
- - - + @endforeach + + + + Grand Total + {{ number_format($grand_sale, 2) }} + {{ number_format($grand_received, 2) }} + {{ number_format($grand_total, 2) }} + + + diff --git a/Resources/views/index.blade.php b/Resources/views/index.blade.php index 35b1a7d..1db3a2e 100644 --- a/Resources/views/index.blade.php +++ b/Resources/views/index.blade.php @@ -53,7 +53,7 @@
- + Print Report + -->