Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

AccountBalances.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Filament\Company\Pages\Reports;
  3. use App\DTO\ReportDTO;
  4. use App\Services\AccountBalancesExportService;
  5. use App\Services\ReportService;
  6. use Barryvdh\DomPDF\Facade\Pdf;
  7. use Filament\Actions\Action;
  8. use Filament\Actions\ActionGroup;
  9. use Filament\Support\Enums\IconPosition;
  10. use Filament\Support\Enums\IconSize;
  11. use Illuminate\Support\Carbon;
  12. use Symfony\Component\HttpFoundation\StreamedResponse;
  13. class AccountBalances extends BaseReportPage
  14. {
  15. protected static string $view = 'filament.company.pages.reports.account-balances';
  16. protected static ?string $slug = 'reports/account-balances';
  17. protected static bool $shouldRegisterNavigation = false;
  18. protected ReportService $reportService;
  19. public ReportDTO $accountBalanceReport;
  20. protected AccountBalancesExportService $accountBalancesExportService;
  21. public function boot(ReportService $reportService, AccountBalancesExportService $accountBalancesExportService): void
  22. {
  23. $this->reportService = $reportService;
  24. $this->accountBalancesExportService = $accountBalancesExportService;
  25. }
  26. public function loadReportData(): void
  27. {
  28. $this->accountBalanceReport = $this->reportService->buildAccountBalanceReport($this->startDate, $this->endDate);
  29. }
  30. protected function getHeaderActions(): array
  31. {
  32. return [
  33. ActionGroup::make([
  34. Action::make('exportCSV')
  35. ->label('CSV')
  36. ->action(fn () => $this->exportCSV()),
  37. Action::make('exportPDF')
  38. ->label('PDF')
  39. ->action(fn () => $this->exportPDF()),
  40. ])
  41. ->label('Export')
  42. ->button()
  43. ->outlined()
  44. ->dropdownWidth('max-w-[7rem]')
  45. ->dropdownPlacement('bottom-end')
  46. ->icon('heroicon-c-chevron-down')
  47. ->iconSize(IconSize::Small)
  48. ->iconPosition(IconPosition::After),
  49. ];
  50. }
  51. public function exportCSV(): StreamedResponse
  52. {
  53. return $this->accountBalancesExportService->exportToCsv($this->company, $this->accountBalanceReport, $this->startDate, $this->endDate);
  54. }
  55. public function exportPDF(): StreamedResponse
  56. {
  57. $pdf = Pdf::loadView('components.company.reports.account-balances', [
  58. 'accountBalanceReport' => $this->accountBalanceReport,
  59. 'startDate' => Carbon::parse($this->startDate)->format('M d, Y'),
  60. 'endDate' => Carbon::parse($this->endDate)->format('M d, Y'),
  61. ])->setPaper('a4');
  62. return response()->streamDownload(function () use ($pdf) {
  63. echo $pdf->stream();
  64. }, 'account-balances.pdf');
  65. }
  66. }