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.

IncomeStatement.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Filament\Company\Pages\Reports;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use App\Services\ExportService;
  6. use App\Services\ReportService;
  7. use App\Support\Column;
  8. use App\Transformers\IncomeStatementReportTransformer;
  9. use Filament\Forms\Form;
  10. use Filament\Support\Enums\Alignment;
  11. use Guava\FilamentClusters\Forms\Cluster;
  12. use Livewire\Attributes\Url;
  13. use Symfony\Component\HttpFoundation\StreamedResponse;
  14. class IncomeStatement extends BaseReportPage
  15. {
  16. protected static string $view = 'filament.company.pages.reports.income-statement';
  17. protected static ?string $slug = 'reports/income-statement';
  18. protected static bool $shouldRegisterNavigation = false;
  19. protected ReportService $reportService;
  20. protected ExportService $exportService;
  21. #[Url]
  22. public ?string $activeTab = 'summary';
  23. public function boot(ReportService $reportService, ExportService $exportService): void
  24. {
  25. $this->reportService = $reportService;
  26. $this->exportService = $exportService;
  27. }
  28. public function getTable(): array
  29. {
  30. return [
  31. Column::make('account_code')
  32. ->label('Account Code')
  33. ->toggleable()
  34. ->alignment(Alignment::Center),
  35. Column::make('account_name')
  36. ->label('Account')
  37. ->alignment(Alignment::Left),
  38. Column::make('net_movement')
  39. ->label('Amount')
  40. ->alignment(Alignment::Right),
  41. ];
  42. }
  43. public function filtersForm(Form $form): Form
  44. {
  45. return $form
  46. ->inlineLabel()
  47. ->columns()
  48. ->schema([
  49. $this->getDateRangeFormComponent(),
  50. Cluster::make([
  51. $this->getStartDateFormComponent(),
  52. $this->getEndDateFormComponent(),
  53. ])->hiddenLabel(),
  54. ]);
  55. }
  56. protected function buildReport(array $columns): ReportDTO
  57. {
  58. return $this->reportService->buildIncomeStatementReport($this->getFormattedStartDate(), $this->getFormattedEndDate(), $columns);
  59. }
  60. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  61. {
  62. return new IncomeStatementReportTransformer($reportDTO);
  63. }
  64. public function exportCSV(): StreamedResponse
  65. {
  66. return $this->exportService->exportToCsv($this->company, $this->report, $this->getFilterState('startDate'), $this->getFilterState('endDate'));
  67. }
  68. public function exportPDF(): StreamedResponse
  69. {
  70. return $this->exportService->exportToPdf($this->company, $this->report, $this->getFilterState('startDate'), $this->getFilterState('endDate'));
  71. }
  72. }