選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AccountTransactionReportTransformer.php 2.2KB

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