accountService = $accountService; $this->accountBalancesExportService = $accountBalancesExportService; } public function mount(): void { $this->company = auth()->user()->currentCompany; $this->fiscalYearStartDate = $this->company->locale->fiscalYearStartDate(); $this->fiscalYearEndDate = $this->company->locale->fiscalYearEndDate(); $this->dateRange = $this->getDefaultDateRange(); $this->setDateRange(Carbon::parse($this->fiscalYearStartDate), Carbon::parse($this->fiscalYearEndDate)); $this->loadAccountBalances(); } public function getDefaultDateRange(): string { return 'FY-' . now()->year; } public function loadAccountBalances(): void { $this->accountBalanceReport = $this->accountService->buildAccountBalanceReport($this->startDate, $this->endDate); } protected function getHeaderActions(): array { return [ ActionGroup::make([ Action::make('exportCSV') ->label('CSV') ->action(fn () => $this->exportCSV()), Action::make('exportPDF') ->label('PDF') ->action(fn () => $this->exportPDF()), ]) ->label('Export') ->button() ->outlined() ->dropdownWidth('max-w-[7rem]') ->dropdownPlacement('bottom-end') ->icon('heroicon-c-chevron-down') ->iconSize(IconSize::Small) ->iconPosition(IconPosition::After), ]; } public function exportCSV(): StreamedResponse { return $this->accountBalancesExportService->exportToCsv($this->company, $this->accountBalanceReport, $this->startDate, $this->endDate); } public function exportPDF(): StreamedResponse { $pdf = Pdf::loadView('components.company.reports.account-balances', [ 'accountBalanceReport' => $this->accountBalanceReport, 'startDate' => Carbon::parse($this->startDate)->format('M d, Y'), 'endDate' => Carbon::parse($this->endDate)->format('M d, Y'), ])->setPaper('a4'); return response()->streamDownload(function () use ($pdf) { echo $pdf->stream(); }, 'account-balances.pdf'); } public function form(Form $form): Form { return $form ->schema([ Split::make([ DateRangeSelect::make('dateRange') ->label('Date Range') ->selectablePlaceholder(false) ->startDateField('startDate') ->endDateField('endDate'), DatePicker::make('startDate') ->label('Start Date') ->displayFormat('Y-m-d') ->afterStateUpdated(static function (Set $set) { $set('dateRange', 'Custom'); }), DatePicker::make('endDate') ->label('End Date') ->displayFormat('Y-m-d') ->afterStateUpdated(static function (Set $set) { $set('dateRange', 'Custom'); }), ])->live(), ]); } public function setDateRange(Carbon $start, Carbon $end): void { $this->startDate = $start->format('Y-m-d'); $this->endDate = $end->isFuture() ? now()->format('Y-m-d') : $end->format('Y-m-d'); } public static function shouldRegisterNavigation(): bool { return false; } }