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.

AccountTransactions.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Filament\Company\Pages\Reports;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use App\Services\ExportService;
  6. use App\Services\ReportService;
  7. use App\Support\Column;
  8. use App\Transformers\AccountBalanceReportTransformer;
  9. use App\Transformers\AccountTransactionReportTransformer;
  10. use Filament\Forms\Form;
  11. use Filament\Support\Enums\Alignment;
  12. use Guava\FilamentClusters\Forms\Cluster;
  13. use Symfony\Component\HttpFoundation\StreamedResponse;
  14. class AccountTransactions extends BaseReportPage
  15. {
  16. protected static string $view = 'filament.company.pages.reports.account-transactions';
  17. protected static ?string $slug = 'reports/account-transactions';
  18. protected static bool $shouldRegisterNavigation = false;
  19. protected ReportService $reportService;
  20. protected ExportService $exportService;
  21. public function boot(ReportService $reportService, ExportService $exportService): void
  22. {
  23. $this->reportService = $reportService;
  24. $this->exportService = $exportService;
  25. }
  26. /**
  27. * @return array<Column>
  28. */
  29. public function getTable(): array
  30. {
  31. return [
  32. Column::make('date')
  33. ->label('Date')
  34. ->alignment(Alignment::Left),
  35. Column::make('description')
  36. ->label('Description')
  37. ->alignment(Alignment::Left),
  38. Column::make('debit')
  39. ->label('Debit')
  40. ->alignment(Alignment::Right),
  41. Column::make('credit')
  42. ->label('Credit')
  43. ->alignment(Alignment::Right),
  44. Column::make('balance')
  45. ->label('Balance')
  46. ->alignment(Alignment::Right),
  47. ];
  48. }
  49. public function form(Form $form): Form
  50. {
  51. return $form
  52. ->inlineLabel()
  53. ->columns([
  54. 'lg' => 1,
  55. '2xl' => 2,
  56. ])
  57. ->live()
  58. ->schema([
  59. $this->getDateRangeFormComponent(),
  60. Cluster::make([
  61. $this->getStartDateFormComponent(),
  62. $this->getEndDateFormComponent(),
  63. ])->hiddenLabel(),
  64. ]);
  65. }
  66. protected function buildReport(array $columns): ReportDTO
  67. {
  68. return $this->reportService->buildAccountTransactionsReport($this->startDate, $this->endDate, $columns);
  69. }
  70. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  71. {
  72. return new AccountTransactionReportTransformer($reportDTO);
  73. }
  74. public function exportCSV(): StreamedResponse
  75. {
  76. return $this->exportService->exportToCsv($this->company, $this->report, $this->startDate, $this->endDate);
  77. }
  78. public function exportPDF(): StreamedResponse
  79. {
  80. return $this->exportService->exportToPdf($this->company, $this->report, $this->startDate, $this->endDate);
  81. }
  82. }