Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

AccountTransactionReportTransformer.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Transformers;
  3. use App\DTO\AccountTransactionDTO;
  4. use App\DTO\ReportCategoryDTO;
  5. use App\Support\Column;
  6. class AccountTransactionReportTransformer extends BaseReportTransformer
  7. {
  8. public function getPdfView(): string
  9. {
  10. return 'components.company.reports.account-transactions-report-pdf';
  11. }
  12. public function getTitle(): string
  13. {
  14. return 'Account Transactions';
  15. }
  16. public function getHeaders(): array
  17. {
  18. return array_map(fn (Column $column) => $column->getLabel(), $this->getColumns());
  19. }
  20. /**
  21. * @return ReportCategoryDTO[]
  22. */
  23. public function getCategories(): array
  24. {
  25. $categories = [];
  26. foreach ($this->report->categories as $categoryData) {
  27. // Initialize header with account and category information
  28. $header = [
  29. array_fill(0, count($this->getColumns()), ''),
  30. array_fill(0, count($this->getColumns()), ''),
  31. ];
  32. foreach ($this->getColumns() as $index => $column) {
  33. if ($column->getName() === 'date') {
  34. $header[0][$index] = $categoryData['category'];
  35. $header[1][$index] = $categoryData['under'];
  36. }
  37. }
  38. // Map transaction data
  39. $data = array_map(function (AccountTransactionDTO $transaction) {
  40. $row = [];
  41. foreach ($this->getColumns() as $column) {
  42. $row[] = match ($column->getName()) {
  43. 'date' => $transaction->date,
  44. 'description' => [
  45. 'id' => $transaction->id,
  46. 'description' => $transaction->description,
  47. 'tableAction' => $transaction->tableAction,
  48. ],
  49. 'debit' => $transaction->debit,
  50. 'credit' => $transaction->credit,
  51. 'balance' => $transaction->balance,
  52. default => '',
  53. };
  54. }
  55. return $row;
  56. }, $categoryData['transactions']);
  57. $categories[] = new ReportCategoryDTO(
  58. header: $header,
  59. data: $data,
  60. );
  61. }
  62. return $categories;
  63. }
  64. public function getOverallTotals(): array
  65. {
  66. return [];
  67. }
  68. }