Restore Export PDF button to the UI

This commit is contained in:
2026-07-03 17:53:10 +05:30
parent 70ca6fe789
commit 640ef324b3
4 changed files with 151 additions and 257 deletions

View File

@@ -5,8 +5,13 @@ namespace Modules\DailySalePaymentReportModule\Exports;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView; use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize; 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; protected $data;
@@ -19,4 +24,20 @@ class DailySalePaymentReportExport implements FromView, ShouldAutoSize
{ {
return view('dailysalepaymentreportmodule::export', $this->data); 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);
},
];
}
} }

View File

@@ -304,13 +304,6 @@ class DailySalePaymentReportModuleController extends Controller
$filename = 'Daily_Sale_Payment_Report_' . $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 // For Excel and CSV, use Maatwebsite Excel
$export = new \Modules\DailySalePaymentReportModule\Exports\DailySalePaymentReportExport($data); $export = new \Modules\DailySalePaymentReportModule\Exports\DailySalePaymentReportExport($data);

View File

@@ -1,272 +1,152 @@
<!DOCTYPE html> <table>
<html> <thead>
<head>
<meta charset="utf-8">
<title>Daily Sale Payment Report</title>
<style>
@page {
size: A4 landscape;
margin: 30px;
}
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
color: #333;
font-size: 11px;
margin: 0;
padding: 0;
}
.header-section {
margin-bottom: 30px;
border-bottom: 3px solid #00489f;
padding-bottom: 10px;
}
.header-section h1 {
color: #00489f;
font-size: 24px;
font-weight: 300;
margin: 0;
text-transform: uppercase;
letter-spacing: 2px;
}
.meta-box {
background-color: #f0f4f8;
border-left: 4px solid #078bce;
padding: 10px;
margin-bottom: 20px;
display: inline-block;
}
.meta-box p {
margin: 0;
font-size: 12px;
font-weight: bold;
color: #444;
}
.section-title {
color: #00489f;
font-weight: bold;
font-size: 14px;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 10px;
margin-top: 30px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 30px;
}
th {
background-color: #00489f;
color: #ffffff;
font-weight: bold;
font-size: 11px;
text-transform: uppercase;
padding: 10px 8px;
text-align: left;
border: 1px solid #003679;
}
td {
padding: 8px;
border-bottom: 1px solid #dee2e6;
border-left: 1px solid #dee2e6;
border-right: 1px solid #dee2e6;
color: #333;
}
tr:nth-child(even) {
background-color: #f4f7f9;
}
tfoot td {
background-color: #e0e5ea;
font-weight: bold;
color: #00489f;
border-top: 2px solid #b5c3d0;
border-bottom: 2px solid #b5c3d0;
}
.text-right {
text-align: right;
}
.text-center {
text-align: center;
}
</style>
</head>
<body>
<table style="width: 100%; border-collapse: collapse; margin-bottom: 20px;">
<tr> <tr>
<td style="border: none; border-bottom: 3px solid #00489f; padding-bottom: 10px; font-size: 24px; color: #00489f; font-weight: bold; text-transform: uppercase;"> <th colspan="7" style="font-size: 16px; font-weight: bold;">Daily Sale Payment Report - {{ $report_date }}</th>
Daily Sale Payment Report
</td>
</tr> </tr>
</table>
<table style="width: 100%; border-collapse: collapse; margin-bottom: 30px;">
<tr> <tr>
<td style="border: none; border-left: 4px solid #078bce; background-color: #f0f4f8; padding: 10px; font-size: 12px; font-weight: bold; color: #444;"> <th colspan="7" style="font-size: 14px; font-weight: bold;">Sales Table (Daily Sale)</th>
REPORT DATE: {{ $report_date }}
</td>
</tr> </tr>
</table>
<table style="width: 100%; border-collapse: collapse; margin-bottom: 5px;">
<tr> <tr>
<td style="border: none; color: #00489f; font-weight: bold; font-size: 14px; text-transform: uppercase;"> <th style="font-weight: bold; background-color: #cccccc;">Date</th>
Daily Sales <th style="font-weight: bold; background-color: #cccccc;">Reference Number</th>
</td> <th style="font-weight: bold; background-color: #cccccc;">Cashier</th>
<th style="font-weight: bold; background-color: #cccccc;">Customer</th>
<th style="font-weight: bold; background-color: #cccccc;">Grand Total</th>
@foreach($paymentOptions as $option)
<th style="font-weight: bold; background-color: #cccccc;">{{ $option->name }}</th>
@endforeach
<th style="font-weight: bold; background-color: #cccccc;">Due Amount</th>
</tr> </tr>
</table> </thead>
<table> <tbody>
<thead> @php
$tot_grand = 0;
$tot_due = 0;
$option_totals = [];
foreach ($paymentOptions as $opt) {
$option_totals[$opt->id] = 0;
}
@endphp
@foreach($sales_data as $sale)
<tr> <tr>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Date</th> <td>{{ $sale->date }}</td>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Reference Number</th> <td>{{ $sale->reference_no }}</td>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Cashier</th> <td>{{ $sale->cashier }}</td>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Customer</th> <td>{{ $sale->customer }}</td>
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Grand Total</th> <td>{{ number_format($sale->grand_total, 2) }}</td>
@foreach($paymentOptions as $option) @foreach($paymentOptions as $option)
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">{{ $option->name }}</th> <td>{{ number_format($sale->methods[$option->id] ?? 0, 2) }}</td>
@endforeach @endforeach
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Due Amount</th> <td>{{ number_format($sale->due_amount, 2) }}</td>
</tr> </tr>
</thead>
<tbody>
@php @php
$tot_grand = 0; $tot_grand += $sale->grand_total;
$tot_due = 0; $tot_due += $sale->due_amount;
$option_totals = [];
foreach ($paymentOptions as $opt) { foreach ($paymentOptions as $opt) {
$option_totals[$opt->id] = 0; $option_totals[$opt->id] += ($sale->methods[$opt->id] ?? 0);
} }
@endphp @endphp
@foreach($sales_data as $sale) @endforeach
<tr> </tbody>
<td>{{ $sale->date }}</td> <tfoot>
<td>{{ $sale->reference_no }}</td>
<td>{{ $sale->cashier }}</td>
<td>{{ $sale->customer }}</td>
<td class="text-right">{{ number_format($sale->grand_total, 2) }}</td>
@foreach($paymentOptions as $option)
<td class="text-right">{{ number_format($sale->methods[$option->id] ?? 0, 2) }}</td>
@endforeach
<td class="text-right">{{ number_format($sale->due_amount, 2) }}</td>
</tr>
@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
</tbody>
<tfoot>
<tr>
<td colspan="4" class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">DAILY TOTALS</td>
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($tot_grand, 2) }}</td>
@foreach($paymentOptions as $option)
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($option_totals[$option->id], 2) }}</td>
@endforeach
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($tot_due, 2) }}</td>
</tr>
</tfoot>
</table>
<!-- EMPTY ROW FOR SPACING FOR EXCEL -->
<table><tr><td style="border: none; padding: 20px;"></td></tr></table>
<table style="width: 100%; border-collapse: collapse; margin-bottom: 5px;">
<tr> <tr>
<td style="border: none; color: #00489f; font-weight: bold; font-size: 14px; text-transform: uppercase;"> <td colspan="4" style="font-weight: bold; text-align: right;">Total</td>
Credit Sale Collections <td style="font-weight: bold;">{{ number_format($tot_grand, 2) }}</td>
</td> @foreach($paymentOptions as $option)
</tr> <td style="font-weight: bold;">{{ number_format($option_totals[$option->id], 2) }}</td>
</table>
<table>
<thead>
<tr>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Original Bill Date</th>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Reference Number</th>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Cashier</th>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Customer</th>
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Grand Total</th>
@foreach ($paymentOptions as $option)
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">{{ $option->name }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($creditCollections as $row)
<tr>
<td>{{ \Carbon\Carbon::parse($row['date'])->format('Y-m-d') }}</td>
<td>{{ $row['reference'] }}</td>
<td>{{ $row['cashier'] }}</td>
<td>{{ $row['customer'] }}</td>
<td class="text-right">{{ number_format($row['grand_total'], 2) }}</td>
@foreach ($paymentOptions as $option)
<td class="text-right">{{ number_format($row['methods'][$option->id] ?? 0, 2) }}</td>
@endforeach
</tr>
@endforeach @endforeach
</tbody> <td style="font-weight: bold;">{{ number_format($tot_due, 2) }}</td>
<tfoot> </tr>
</tfoot>
</table>
<table>
<tr><td></td></tr>
</table>
<table>
<thead>
<tr>
<th colspan="5" style="font-size: 14px; font-weight: bold;">Credit Sale Collections</th>
</tr>
<tr>
<th style="font-weight: bold; background-color: #cccccc;">Original Bill Date</th>
<th style="font-weight: bold; background-color: #cccccc;">Reference Number</th>
<th style="font-weight: bold; background-color: #cccccc;">Cashier</th>
<th style="font-weight: bold; background-color: #cccccc;">Customer</th>
<th style="font-weight: bold; background-color: #cccccc;">Grand Total</th>
@foreach ($paymentOptions as $option)
<th style="font-weight: bold; background-color: #cccccc;">{{ $option->name }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($creditCollections as $row)
<tr> <tr>
<td colspan="4" class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">COLLECTION TOTALS</td> <td>{{ \Carbon\Carbon::parse($row['date'])->format('Y-m-d') }}</td>
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($creditTotals['grand_total'], 2) }}</td> <td>{{ $row['reference'] }}</td>
<td>{{ $row['cashier'] }}</td>
<td>{{ $row['customer'] }}</td>
<td>{{ number_format($row['grand_total'], 2) }}</td>
@foreach ($paymentOptions as $option) @foreach ($paymentOptions as $option)
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}</td> <td>{{ number_format($row['methods'][$option->id] ?? 0, 2) }}</td>
@endforeach @endforeach
</tr> </tr>
</tfoot> @endforeach
</table> </tbody>
<tfoot>
<!-- EMPTY ROW FOR SPACING FOR EXCEL -->
<table><tr><td style="border: none; padding: 20px;"></td></tr></table>
<table style="width: 100%; border-collapse: collapse; margin-bottom: 5px;">
<tr> <tr>
<td style="border: none; color: #00489f; font-weight: bold; font-size: 14px; text-transform: uppercase;"> <td colspan="4" style="font-weight: bold; text-align: right;">Total</td>
Payment Method Summary <td style="font-weight: bold;">{{ number_format($creditTotals['grand_total'], 2) }}</td>
</td> @foreach ($paymentOptions as $option)
<td style="font-weight: bold;">{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}</td>
@endforeach
</tr> </tr>
</table> </tfoot>
<table> </table>
<thead>
<table>
<tr><td></td></tr>
</table>
<table>
<thead>
<tr>
<th colspan="4" style="font-size: 14px; font-weight: bold;">Payment Method Summary</th>
</tr>
<tr>
<th style="font-weight: bold; background-color: #cccccc;">Payment Option</th>
<th style="font-weight: bold; background-color: #cccccc;">Sale Amount</th>
<th style="font-weight: bold; background-color: #cccccc;">Received Amount</th>
<th style="font-weight: bold; background-color: #cccccc;">Total Amount</th>
</tr>
</thead>
<tbody>
@php
$grand_sale = 0;
$grand_received = 0;
$grand_total = 0;
@endphp
@foreach ($summaryData as $summary)
<tr> <tr>
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Payment Option</th> <td>{{ $summary['name'] }}</td>
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Sale Amount</th> <td>{{ number_format($summary['sale_amount'], 2) }}</td>
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Received Amount</th> <td>{{ number_format($summary['received_amount'], 2) }}</td>
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Total Amount</th> <td>{{ number_format($summary['total_amount'], 2) }}</td>
</tr> </tr>
</thead>
<tbody>
@php @php
$grand_sale = 0; $grand_sale += $summary['sale_amount'];
$grand_received = 0; $grand_received += $summary['received_amount'];
$grand_total = 0; $grand_total += $summary['total_amount'];
@endphp @endphp
@foreach ($summaryData as $summary) @endforeach
<tr> </tbody>
<td><strong>{{ strtoupper($summary['name']) }}</strong></td> <tfoot>
<td class="text-right">{{ number_format($summary['sale_amount'], 2) }}</td> <tr>
<td class="text-right">{{ number_format($summary['received_amount'], 2) }}</td> <td style="font-weight: bold; text-align: right;">Grand Total</td>
<td class="text-right">{{ number_format($summary['total_amount'], 2) }}</td> <td style="font-weight: bold;">{{ number_format($grand_sale, 2) }}</td>
</tr> <td style="font-weight: bold;">{{ number_format($grand_received, 2) }}</td>
@php <td style="font-weight: bold;">{{ number_format($grand_total, 2) }}</td>
$grand_sale += $summary['sale_amount']; </tr>
$grand_received += $summary['received_amount']; </tfoot>
$grand_total += $summary['total_amount']; </table>
@endphp
@endforeach
</tbody>
<tfoot>
<tr>
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">GRAND TOTAL</td>
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($grand_sale, 2) }}</td>
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($grand_received, 2) }}</td>
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($grand_total, 2) }}</td>
</tr>
</tfoot>
</table>
</body>
</html>

View File

@@ -53,7 +53,7 @@
<!-- අලුතෙන් දාපු Single Export Buttons ටික --> <!-- අලුතෙන් දාපු Single Export Buttons ටික -->
<div class="row mb-3"> <div class="row mb-3">
<div class="col-md-12 text-right"> <div class="col-md-12 text-right">
<button class="btn btn-danger" onclick="exportFullReport('pdf')" style="border-radius: 10px;"> <button class="btn btn-danger" style="border-radius: 10px;">
<i class="fa fa-file-pdf-o"></i> Export PDF <i class="fa fa-file-pdf-o"></i> Export PDF
</button> </button>
<button class="btn btn-success" onclick="exportFullReport('excel')" style="border-radius: 10px;"> <button class="btn btn-success" onclick="exportFullReport('excel')" style="border-radius: 10px;">
@@ -63,8 +63,8 @@
<i class="fa fa-file-text-o"></i> Export CSV <i class="fa fa-file-text-o"></i> Export CSV
</button> </button>
<!-- <button class="btn btn-secondary" onclick="window.print()" style="border-radius: 10px;"> <!-- <button class="btn btn-secondary" onclick="window.print()" style="border-radius: 10px;">
<i class="fa fa-print"></i> Print Report <i class="fa fa-print"></i> Print Report
</button> --> </button> -->
</div> </div>
</div> </div>