You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AccountBalances.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Filament\Company\Pages\Reports;
  3. use App\Contracts\ExportableReport;
  4. use App\Services\ExportService;
  5. use App\Services\ReportService;
  6. use App\Transformers\AccountBalanceReportTransformer;
  7. use Filament\Forms\Components\Checkbox;
  8. use Filament\Forms\Components\CheckboxList;
  9. use Filament\Forms\Components\Grid;
  10. use Filament\Forms\Components\Split;
  11. use Filament\Forms\Form;
  12. use Guava\FilamentClusters\Forms\Cluster;
  13. use Symfony\Component\HttpFoundation\StreamedResponse;
  14. class AccountBalances extends BaseReportPage
  15. {
  16. protected static string $view = 'filament.company.pages.reports.account-balances';
  17. protected static ?string $slug = 'reports/account-balances';
  18. protected static bool $shouldRegisterNavigation = false;
  19. protected ReportService $reportService;
  20. public ExportableReport $accountBalanceReport;
  21. protected ExportService $exportService;
  22. public function boot(ReportService $reportService, ExportService $exportService): void
  23. {
  24. $this->reportService = $reportService;
  25. $this->exportService = $exportService;
  26. }
  27. public function loadReportData(): void
  28. {
  29. $reportDTO = $this->reportService->buildAccountBalanceReport($this->startDate, $this->endDate);
  30. $options = array_fill_keys($this->options, true);
  31. $this->accountBalanceReport = new AccountBalanceReportTransformer($reportDTO, $options);
  32. }
  33. public function form(Form $form): Form
  34. {
  35. return $form
  36. ->inlineLabel()
  37. ->schema([
  38. Split::make([
  39. $this->getDateRangeFormComponent(),
  40. Cluster::make([
  41. $this->getStartDateFormComponent(),
  42. $this->getEndDateFormComponent(),
  43. ])
  44. ->hiddenLabel(),
  45. ])->live(),
  46. CheckboxList::make('options')
  47. ->options([
  48. 'showAccountCode' => 'Show Account Code',
  49. 'showZeroBalances' => 'Show Zero Balances',
  50. ])
  51. ->columns(2),
  52. ]);
  53. }
  54. public function exportCSV(): StreamedResponse
  55. {
  56. return $this->exportService->exportToCsv($this->company, $this->accountBalanceReport, $this->startDate, $this->endDate);
  57. }
  58. public function exportPDF(): StreamedResponse
  59. {
  60. return $this->exportService->exportToPdf($this->company, $this->accountBalanceReport, $this->startDate, $this->endDate);
  61. }
  62. }