startDate || !$this->endDate) { session()->flash('error', 'Silahkan pilih tanggal mulai dan tanggal akhir.'); return; } // Query data $this->reportData = [ 'totalPatients' => Patient::whereBetween('created_at', [$this->startDate, $this->endDate])->count(), 'totalRegistrations' => Registration::whereBetween('registration_date', [$this->startDate, $this->endDate])->count(), 'totalIncome' => Payment::whereBetween('payment_date', [$this->startDate, $this->endDate])->sum('total_amount'), ]; $this->generatedAt = now()->format('d-m-Y H:i:s'); } public function exportExcel() { return Excel::download(new ReportExport($this->reportData), 'laporan.xlsx'); } public function exportPDF() { $pdf = Pdf::loadView('exports.report-pdf', ['reportData' => $this->reportData]); return response()->streamDownload(fn () => print($pdf->output()), 'laporan.pdf'); } public function render() { return view('livewire.dashboard.report-generator'); } }