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.

TrialBalance.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Filament\Company\Pages\Reports;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use App\Filament\Forms\Components\DateRangeSelect;
  6. use App\Services\ExportService;
  7. use App\Services\ReportService;
  8. use App\Support\Column;
  9. use App\Transformers\TrialBalanceReportTransformer;
  10. use Filament\Forms\Components\Select;
  11. use Filament\Forms\Form;
  12. use Filament\Support\Enums\Alignment;
  13. use Symfony\Component\HttpFoundation\StreamedResponse;
  14. class TrialBalance extends BaseReportPage
  15. {
  16. protected static string $view = 'filament.company.pages.reports.trial-balance';
  17. protected ReportService $reportService;
  18. protected ExportService $exportService;
  19. public function boot(ReportService $reportService, ExportService $exportService): void
  20. {
  21. $this->reportService = $reportService;
  22. $this->exportService = $exportService;
  23. }
  24. protected function initializeDefaultFilters(): void
  25. {
  26. if (empty($this->getFilterState('reportType'))) {
  27. $this->setFilterState('reportType', 'standard');
  28. }
  29. }
  30. public function getTable(): array
  31. {
  32. return [
  33. Column::make('account_code')
  34. ->label('ACCOUNT CODE')
  35. ->toggleable(isToggledHiddenByDefault: true)
  36. ->alignment(Alignment::Left),
  37. Column::make('account_name')
  38. ->label('ACCOUNTS')
  39. ->alignment(Alignment::Left),
  40. Column::make('debit_balance')
  41. ->label('DEBIT')
  42. ->alignment(Alignment::Right),
  43. Column::make('credit_balance')
  44. ->label('CREDIT')
  45. ->alignment(Alignment::Right),
  46. ];
  47. }
  48. public function filtersForm(Form $form): Form
  49. {
  50. return $form
  51. ->columns(4)
  52. ->schema([
  53. Select::make('reportType')
  54. ->label('Report type')
  55. ->options([
  56. 'standard' => 'Standard',
  57. 'postClosing' => 'Post-Closing',
  58. ])
  59. ->selectablePlaceholder(false),
  60. DateRangeSelect::make('dateRange')
  61. ->label('As of')
  62. ->selectablePlaceholder(false)
  63. ->endDateField('asOfDate'),
  64. $this->getAsOfDateFormComponent(),
  65. ]);
  66. }
  67. protected function buildReport(array $columns): ReportDTO
  68. {
  69. return $this->reportService->buildTrialBalanceReport($this->getFilterState('reportType'), $this->getFormattedAsOfDate(), $columns);
  70. }
  71. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  72. {
  73. return new TrialBalanceReportTransformer($reportDTO);
  74. }
  75. public function exportCSV(): StreamedResponse
  76. {
  77. return $this->exportService->exportToCsv($this->company, $this->report, endDate: $this->getFilterState('asOfDate'));
  78. }
  79. public function exportPDF(): StreamedResponse
  80. {
  81. return $this->exportService->exportToPdf($this->company, $this->report, endDate: $this->getFilterState('asOfDate'));
  82. }
  83. }