Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AccountTransactions.php 3.7KB

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