Implement modern Excel, CSV, and PDF export functionality for all 3 tables
This commit is contained in:
22
Exports/DailySalePaymentReportExport.php
Normal file
22
Exports/DailySalePaymentReportExport.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DailySalePaymentReportModule\Exports;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
|
||||
class DailySalePaymentReportExport implements FromView, ShouldAutoSize
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
return view('dailysalepaymentreportmodule::export', $this->data);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
272
Resources/views/export.blade.php
Normal file
272
Resources/views/export.blade.php
Normal file
@@ -0,0 +1,272 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<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>
|
||||
<td style="border: none; border-bottom: 3px solid #00489f; padding-bottom: 10px; font-size: 24px; color: #00489f; font-weight: bold; text-transform: uppercase;">
|
||||
Daily Sale Payment Report
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table style="width: 100%; border-collapse: collapse; margin-bottom: 30px;">
|
||||
<tr>
|
||||
<td style="border: none; border-left: 4px solid #078bce; background-color: #f0f4f8; padding: 10px; font-size: 12px; font-weight: bold; color: #444;">
|
||||
REPORT DATE: {{ $report_date }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table style="width: 100%; border-collapse: collapse; margin-bottom: 5px;">
|
||||
<tr>
|
||||
<td style="border: none; color: #00489f; font-weight: bold; font-size: 14px; text-transform: uppercase;">
|
||||
Daily Sales
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">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
|
||||
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Due Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@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>
|
||||
<td>{{ $sale->date }}</td>
|
||||
<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>
|
||||
<td style="border: none; color: #00489f; font-weight: bold; font-size: 14px; text-transform: uppercase;">
|
||||
Credit Sale Collections
|
||||
</td>
|
||||
</tr>
|
||||
</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
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="4" class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">COLLECTION TOTALS</td>
|
||||
<td class="text-right" style="background-color: #e0e5ea; font-weight: bold; color: #00489f;">{{ number_format($creditTotals['grand_total'], 2) }}</td>
|
||||
@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>
|
||||
@endforeach
|
||||
</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>
|
||||
<td style="border: none; color: #00489f; font-weight: bold; font-size: 14px; text-transform: uppercase;">
|
||||
Payment Method Summary
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="background-color: #00489f; color: #ffffff; font-weight: bold;">Payment Option</th>
|
||||
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Sale Amount</th>
|
||||
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Received Amount</th>
|
||||
<th class="text-right" style="background-color: #00489f; color: #ffffff; font-weight: bold;">Total Amount</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$grand_sale = 0;
|
||||
$grand_received = 0;
|
||||
$grand_total = 0;
|
||||
@endphp
|
||||
@foreach ($summaryData as $summary)
|
||||
<tr>
|
||||
<td><strong>{{ strtoupper($summary['name']) }}</strong></td>
|
||||
<td class="text-right">{{ number_format($summary['sale_amount'], 2) }}</td>
|
||||
<td class="text-right">{{ number_format($summary['received_amount'], 2) }}</td>
|
||||
<td class="text-right">{{ number_format($summary['total_amount'], 2) }}</td>
|
||||
</tr>
|
||||
@php
|
||||
$grand_sale += $summary['sale_amount'];
|
||||
$grand_received += $summary['received_amount'];
|
||||
$grand_total += $summary['total_amount'];
|
||||
@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>
|
||||
Reference in New Issue
Block a user