Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AccountTransactions.php 3.6KB

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