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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 static ?string $slug = 'reports/trial-balance';
  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. protected function initializeDefaultFilters(): void
  27. {
  28. if (empty($this->getFilterState('reportType'))) {
  29. $this->setFilterState('reportType', 'standard');
  30. }
  31. }
  32. public function getTable(): array
  33. {
  34. return [
  35. Column::make('account_code')
  36. ->label('Account Code')
  37. ->toggleable()
  38. ->alignment(Alignment::Center),
  39. Column::make('account_name')
  40. ->label('Account')
  41. ->alignment(Alignment::Left),
  42. Column::make('debit_balance')
  43. ->label('Debit')
  44. ->alignment(Alignment::Right),
  45. Column::make('credit_balance')
  46. ->label('Credit')
  47. ->alignment(Alignment::Right),
  48. ];
  49. }
  50. public function filtersForm(Form $form): Form
  51. {
  52. return $form
  53. ->columns(4)
  54. ->schema([
  55. Select::make('reportType')
  56. ->label('Report Type')
  57. ->options([
  58. 'standard' => 'Standard',
  59. 'postClosing' => 'Post-Closing',
  60. ])
  61. ->selectablePlaceholder(false),
  62. DateRangeSelect::make('dateRange')
  63. ->label('As of')
  64. ->selectablePlaceholder(false)
  65. ->endDateField('asOfDate'),
  66. $this->getAsOfDateFormComponent(),
  67. ]);
  68. }
  69. protected function buildReport(array $columns): ReportDTO
  70. {
  71. return $this->reportService->buildTrialBalanceReport($this->getFilterState('reportType'), $this->getFormattedAsOfDate(), $columns);
  72. }
  73. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  74. {
  75. return new TrialBalanceReportTransformer($reportDTO);
  76. }
  77. public function exportCSV(): StreamedResponse
  78. {
  79. return $this->exportService->exportToCsv($this->company, $this->report, $this->getFilterState('startDate'), $this->getFilterState('endDate'));
  80. }
  81. public function exportPDF(): StreamedResponse
  82. {
  83. return $this->exportService->exportToPdf($this->company, $this->report, $this->getFilterState('startDate'), $this->getFilterState('endDate'));
  84. }
  85. }