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.

AccountTransactionReportTransformer.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 ?? null,
  46. 'description' => $transaction->description,
  47. ],
  48. 'debit' => $transaction->debit,
  49. 'credit' => $transaction->credit,
  50. 'balance' => $transaction->balance,
  51. default => '',
  52. };
  53. }
  54. return $row;
  55. }, $categoryData['transactions']);
  56. $categories[] = new ReportCategoryDTO(
  57. header: $header,
  58. data: $data,
  59. );
  60. }
  61. return $categories;
  62. }
  63. public function getOverallTotals(): array
  64. {
  65. return [];
  66. }
  67. }