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.

AccountBalances.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\AccountBalanceReportTransformer;
  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 AccountBalances extends BaseReportPage
  14. {
  15. protected static string $view = 'filament.company.pages.reports.detailed-report';
  16. protected static ?string $slug = 'reports/account-balances';
  17. protected static bool $shouldRegisterNavigation = false;
  18. protected ReportService $reportService;
  19. protected ExportService $exportService;
  20. public function boot(ReportService $reportService, ExportService $exportService): void
  21. {
  22. $this->reportService = $reportService;
  23. $this->exportService = $exportService;
  24. }
  25. /**
  26. * @return array<Column>
  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('starting_balance')
  39. ->label('Starting Balance')
  40. ->toggleable()
  41. ->alignment(Alignment::Right),
  42. Column::make('debit_balance')
  43. ->label('Debit')
  44. ->toggleable()
  45. ->alignment(Alignment::Right),
  46. Column::make('credit_balance')
  47. ->label('Credit')
  48. ->toggleable()
  49. ->alignment(Alignment::Right),
  50. Column::make('net_movement')
  51. ->label('Net Movement')
  52. ->toggleable()
  53. ->alignment(Alignment::Right),
  54. Column::make('ending_balance')
  55. ->label('Ending Balance')
  56. ->toggleable()
  57. ->alignment(Alignment::Right),
  58. ];
  59. }
  60. public function form(Form $form): Form
  61. {
  62. return $form
  63. ->inlineLabel()
  64. ->columns([
  65. 'lg' => 1,
  66. '2xl' => 2,
  67. ])
  68. ->live()
  69. ->schema([
  70. $this->getDateRangeFormComponent(),
  71. Cluster::make([
  72. $this->getStartDateFormComponent(),
  73. $this->getEndDateFormComponent(),
  74. ])->hiddenLabel(),
  75. ]);
  76. }
  77. protected function buildReport(array $columns): ReportDTO
  78. {
  79. return $this->reportService->buildAccountBalanceReport($this->startDate, $this->endDate, $columns);
  80. }
  81. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  82. {
  83. return new AccountBalanceReportTransformer($reportDTO);
  84. }
  85. public function exportCSV(): StreamedResponse
  86. {
  87. return $this->exportService->exportToCsv($this->company, $this->report, $this->startDate, $this->endDate);
  88. }
  89. public function exportPDF(): StreamedResponse
  90. {
  91. return $this->exportService->exportToPdf($this->company, $this->report, $this->startDate, $this->endDate);
  92. }
  93. }