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.

AccountTransactions.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Filament\Company\Pages\Reports;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use App\Models\Accounting\Account;
  6. use App\Services\ExportService;
  7. use App\Services\ReportService;
  8. use App\Support\Column;
  9. use App\Transformers\AccountTransactionReportTransformer;
  10. use Filament\Forms\Components\Actions;
  11. use Filament\Forms\Components\Select;
  12. use Filament\Forms\Form;
  13. use Filament\Support\Enums\Alignment;
  14. use Guava\FilamentClusters\Forms\Cluster;
  15. use Illuminate\Support\Collection;
  16. use Livewire\Attributes\Session;
  17. use Symfony\Component\HttpFoundation\StreamedResponse;
  18. class AccountTransactions extends BaseReportPage
  19. {
  20. protected static string $view = 'filament.company.pages.reports.account-transactions';
  21. protected static ?string $slug = 'reports/account-transactions';
  22. protected static bool $shouldRegisterNavigation = false;
  23. protected ReportService $reportService;
  24. protected ExportService $exportService;
  25. #[Session]
  26. public ?string $account_id = 'all';
  27. public function boot(ReportService $reportService, ExportService $exportService): void
  28. {
  29. $this->reportService = $reportService;
  30. $this->exportService = $exportService;
  31. }
  32. /**
  33. * @return array<Column>
  34. */
  35. public function getTable(): array
  36. {
  37. return [
  38. Column::make('date')
  39. ->label('Date')
  40. ->alignment(Alignment::Left),
  41. Column::make('description')
  42. ->label('Description')
  43. ->alignment(Alignment::Left),
  44. Column::make('debit')
  45. ->label('Debit')
  46. ->alignment(Alignment::Right),
  47. Column::make('credit')
  48. ->label('Credit')
  49. ->alignment(Alignment::Right),
  50. Column::make('balance')
  51. ->label('Balance')
  52. ->alignment(Alignment::Right),
  53. ];
  54. }
  55. public function form(Form $form): Form
  56. {
  57. return $form
  58. ->columns(4)
  59. ->live()
  60. ->schema([
  61. Select::make('account_id')
  62. ->label('Account')
  63. ->options($this->getAccountOptions())
  64. ->selectablePlaceholder(false)
  65. ->searchable(),
  66. $this->getDateRangeFormComponent(),
  67. Cluster::make([
  68. $this->getStartDateFormComponent(),
  69. $this->getEndDateFormComponent(),
  70. ])->label("\u{200B}"), // its too bad hiddenLabel removes spacing of the label
  71. Actions::make([
  72. Actions\Action::make('loadReportData')
  73. ->label('Update Report')
  74. ->submit('loadReportData')
  75. ->keyBindings(['mod+s']),
  76. ])->alignEnd()->verticallyAlignEnd(),
  77. ]);
  78. }
  79. protected function getAccountOptions(): array
  80. {
  81. $accounts = Account::query()
  82. ->get()
  83. ->groupBy(fn (Account $account) => $account->category->getPluralLabel())
  84. ->map(fn (Collection $accounts, string $category) => $accounts->pluck('name', 'id'))
  85. ->toArray();
  86. $allAccountsOption = [
  87. 'All Accounts' => ['all' => 'All Accounts'],
  88. ];
  89. return $allAccountsOption + $accounts;
  90. }
  91. protected function buildReport(array $columns): ReportDTO
  92. {
  93. return $this->reportService->buildAccountTransactionsReport($this->startDate, $this->endDate, $columns, $this->account_id);
  94. }
  95. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  96. {
  97. return new AccountTransactionReportTransformer($reportDTO);
  98. }
  99. public function exportCSV(): StreamedResponse
  100. {
  101. return $this->exportService->exportToCsv($this->company, $this->report, $this->startDate, $this->endDate);
  102. }
  103. public function exportPDF(): StreamedResponse
  104. {
  105. return $this->exportService->exportToPdf($this->company, $this->report, $this->startDate, $this->endDate);
  106. }
  107. }