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

BaseEntityBalanceSummaryReportPage.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Filament\Company\Pages\Reports;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. use App\Enums\Accounting\DocumentEntityType;
  6. use App\Services\ExportService;
  7. use App\Services\ReportService;
  8. use App\Support\Column;
  9. use App\Transformers\EntityBalanceSummaryReportTransformer;
  10. use Filament\Forms\Form;
  11. use Filament\Support\Enums\Alignment;
  12. use Guava\FilamentClusters\Forms\Cluster;
  13. use Symfony\Component\HttpFoundation\StreamedResponse;
  14. abstract class BaseEntityBalanceSummaryReportPage extends BaseReportPage
  15. {
  16. protected static string $view = 'filament.company.pages.reports.detailed-report';
  17. protected ReportService $reportService;
  18. protected ExportService $exportService;
  19. abstract protected function getEntityType(): DocumentEntityType;
  20. public function boot(ReportService $reportService, ExportService $exportService): void
  21. {
  22. $this->reportService = $reportService;
  23. $this->exportService = $exportService;
  24. }
  25. public function getTable(): array
  26. {
  27. return [
  28. Column::make('entity_name')
  29. ->label($this->getEntityType()->getLabel())
  30. ->alignment(Alignment::Left),
  31. Column::make('total_balance')
  32. ->label('Total')
  33. ->toggleable()
  34. ->alignment(Alignment::Right),
  35. Column::make('paid_balance')
  36. ->label('Paid')
  37. ->toggleable()
  38. ->alignment(Alignment::Right),
  39. Column::make('unpaid_balance')
  40. ->label('Unpaid')
  41. ->toggleable()
  42. ->alignment(Alignment::Right),
  43. ];
  44. }
  45. public function filtersForm(Form $form): Form
  46. {
  47. return $form
  48. ->inlineLabel()
  49. ->columns()
  50. ->schema([
  51. $this->getDateRangeFormComponent(),
  52. Cluster::make([
  53. $this->getStartDateFormComponent(),
  54. $this->getEndDateFormComponent(),
  55. ])->hiddenLabel(),
  56. ]);
  57. }
  58. protected function buildReport(array $columns): ReportDTO
  59. {
  60. return $this->reportService->buildEntityBalanceSummaryReport(
  61. startDate: $this->getFormattedStartDate(),
  62. endDate: $this->getFormattedEndDate(),
  63. entityType: $this->getEntityType(),
  64. columns: $columns
  65. );
  66. }
  67. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  68. {
  69. return new EntityBalanceSummaryReportTransformer($reportDTO, $this->getEntityType());
  70. }
  71. public function exportCSV(): StreamedResponse
  72. {
  73. return $this->exportService->exportToCsv(
  74. $this->company,
  75. $this->report,
  76. $this->getFilterState('startDate'),
  77. $this->getFilterState('endDate')
  78. );
  79. }
  80. public function exportPDF(): StreamedResponse
  81. {
  82. return $this->exportService->exportToPdf(
  83. $this->company,
  84. $this->report,
  85. $this->getFilterState('startDate'),
  86. $this->getFilterState('endDate')
  87. );
  88. }
  89. }