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.

ClientBalanceSummary.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\ClientBalanceSummaryReportTransformer;
  9. use Filament\Forms\Form;
  10. use Filament\Support\Enums\Alignment;
  11. use Guava\FilamentClusters\Forms\Cluster;
  12. use Symfony\Component\HttpFoundation\StreamedResponse;
  13. class ClientBalanceSummary extends BaseReportPage
  14. {
  15. protected static string $view = 'filament.company.pages.reports.detailed-report';
  16. protected ReportService $reportService;
  17. protected ExportService $exportService;
  18. public function boot(ReportService $reportService, ExportService $exportService): void
  19. {
  20. $this->reportService = $reportService;
  21. $this->exportService = $exportService;
  22. }
  23. public function getTable(): array
  24. {
  25. return [
  26. Column::make('client_name')
  27. ->label('Client')
  28. ->alignment(Alignment::Left),
  29. Column::make('total_balance')
  30. ->label('Total')
  31. ->toggleable()
  32. ->alignment(Alignment::Right),
  33. Column::make('paid_balance')
  34. ->label('Paid')
  35. ->toggleable()
  36. ->alignment(Alignment::Right),
  37. Column::make('unpaid_balance')
  38. ->label('Unpaid')
  39. ->toggleable()
  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->buildClientBalanceSummaryReport(
  59. $this->getFormattedStartDate(),
  60. $this->getFormattedEndDate(),
  61. $columns
  62. );
  63. }
  64. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  65. {
  66. return new ClientBalanceSummaryReportTransformer($reportDTO);
  67. }
  68. public function exportCSV(): StreamedResponse
  69. {
  70. return $this->exportService->exportToCsv(
  71. $this->company,
  72. $this->report,
  73. $this->getFilterState('startDate'),
  74. $this->getFilterState('endDate')
  75. );
  76. }
  77. public function exportPDF(): StreamedResponse
  78. {
  79. return $this->exportService->exportToPdf(
  80. $this->company,
  81. $this->report,
  82. $this->getFilterState('startDate'),
  83. $this->getFilterState('endDate')
  84. );
  85. }
  86. }