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 }}
+ |
+
+
+
+
+
+
+
+ | Date |
+ Reference Number |
+ Cashier |
+ Customer |
+ Grand Total |
+ @foreach($paymentOptions as $option)
+ {{ $option->name }} |
+ @endforeach
+ 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)
+
+ | {{ $sale->date }} |
+ {{ $sale->reference_no }} |
+ {{ $sale->cashier }} |
+ {{ $sale->customer }} |
+ {{ number_format($sale->grand_total, 2) }} |
+ @foreach($paymentOptions as $option)
+ {{ number_format($sale->methods[$option->id] ?? 0, 2) }} |
+ @endforeach
+ {{ number_format($sale->due_amount, 2) }} |
+
+ @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
+
+
+
+ | DAILY TOTALS |
+ {{ number_format($tot_grand, 2) }} |
+ @foreach($paymentOptions as $option)
+ {{ number_format($option_totals[$option->id], 2) }} |
+ @endforeach
+ {{ number_format($tot_due, 2) }} |
+
+
+
+
+
+
+
+
+
+ |
+ Credit Sale Collections
+ |
+
+
+
+
+
+ | Original Bill Date |
+ Reference Number |
+ Cashier |
+ Customer |
+ Grand Total |
+ @foreach ($paymentOptions as $option)
+ {{ $option->name }} |
+ @endforeach
+
+
+
+ @foreach ($creditCollections as $row)
+
+ | {{ \Carbon\Carbon::parse($row['date'])->format('Y-m-d') }} |
+ {{ $row['reference'] }} |
+ {{ $row['cashier'] }} |
+ {{ $row['customer'] }} |
+ {{ number_format($row['grand_total'], 2) }} |
+ @foreach ($paymentOptions as $option)
+ {{ number_format($row['methods'][$option->id] ?? 0, 2) }} |
+ @endforeach
+
+ @endforeach
+
+
+
+ | COLLECTION TOTALS |
+ {{ number_format($creditTotals['grand_total'], 2) }} |
+ @foreach ($paymentOptions as $option)
+ {{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }} |
+ @endforeach
+
+
+
+
+
+
+
+
+
+ |
+ Payment Method Summary
+ |
+
+
+
+
+
+ | Payment Option |
+ Sale Amount |
+ Received Amount |
+ Total Amount |
+
+
+
+ @php
+ $grand_sale = 0;
+ $grand_received = 0;
+ $grand_total = 0;
+ @endphp
+ @foreach ($summaryData as $summary)
+
+ | {{ strtoupper($summary['name']) }} |
+ {{ number_format($summary['sale_amount'], 2) }} |
+ {{ number_format($summary['received_amount'], 2) }} |
+ {{ number_format($summary['total_amount'], 2) }} |
+
+ @php
+ $grand_sale += $summary['sale_amount'];
+ $grand_received += $summary['received_amount'];
+ $grand_total += $summary['total_amount'];
+ @endphp
+ @endforeach
+
+
+
+ | GRAND TOTAL |
+ {{ number_format($grand_sale, 2) }} |
+ {{ number_format($grand_received, 2) }} |
+ {{ number_format($grand_total, 2) }} |
+
+
+
+
+
+