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.

BalanceSheet.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\BalanceSheetReportTransformer;
  10. use Filament\Forms\Form;
  11. use Filament\Support\Enums\Alignment;
  12. use Symfony\Component\HttpFoundation\StreamedResponse;
  13. class BalanceSheet extends BaseReportPage
  14. {
  15. protected static string $view = 'filament.company.pages.reports.balance-sheet';
  16. protected static bool $shouldRegisterNavigation = false;
  17. protected ReportService $reportService;
  18. protected ExportService $exportService;
  19. public function boot(ReportService $reportService, ExportService $exportService): void
  20. {
  21. $this->reportService = $reportService;
  22. $this->exportService = $exportService;
  23. }
  24. public function getTable(): array
  25. {
  26. return [
  27. Column::make('account_code')
  28. ->label('Account Code')
  29. ->toggleable()
  30. ->alignment(Alignment::Center),
  31. Column::make('account_name')
  32. ->label('Account')
  33. ->alignment(Alignment::Left),
  34. Column::make('ending_balance')
  35. ->label('Amount')
  36. ->alignment(Alignment::Right),
  37. ];
  38. }
  39. public function filtersForm(Form $form): Form
  40. {
  41. return $form
  42. ->inlineLabel()
  43. ->columns(3)
  44. ->schema([
  45. DateRangeSelect::make('dateRange')
  46. ->label('As of')
  47. ->selectablePlaceholder(false)
  48. ->endDateField('asOfDate'),
  49. $this->getAsOfDateFormComponent()
  50. ->hiddenLabel()
  51. ->extraFieldWrapperAttributes([]),
  52. ]);
  53. }
  54. protected function buildReport(array $columns): ReportDTO
  55. {
  56. return $this->reportService->buildBalanceSheetReport($this->getFormattedAsOfDate(), $columns);
  57. }
  58. protected function getTransformer(ReportDTO $reportDTO): ExportableReport
  59. {
  60. return new BalanceSheetReportTransformer($reportDTO);
  61. }
  62. public function exportCSV(): StreamedResponse
  63. {
  64. return $this->exportService->exportToCsv($this->company, $this->report, $this->getFilterState('asOfDate'));
  65. }
  66. public function exportPDF(): StreamedResponse
  67. {
  68. return $this->exportService->exportToPdf($this->company, $this->report, $this->getFilterState('asOfDate'));
  69. }
  70. }