Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TrialBalanceReportTransformer.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Transformers;
  3. use App\DTO\AccountDTO;
  4. use App\DTO\ReportCategoryDTO;
  5. class TrialBalanceReportTransformer extends BaseReportTransformer
  6. {
  7. public function getTitle(): string
  8. {
  9. return match ($this->report->reportType) {
  10. 'postClosing' => 'Post-Closing Trial Balance',
  11. default => 'Standard Trial Balance',
  12. };
  13. }
  14. /**
  15. * @return ReportCategoryDTO[]
  16. */
  17. public function getCategories(): array
  18. {
  19. $categories = [];
  20. foreach ($this->report->categories as $accountCategoryName => $accountCategory) {
  21. // Initialize header with empty strings
  22. $header = [];
  23. foreach ($this->getColumns() as $column) {
  24. $header[$column->getName()] = $column->getName() === 'account_name' ? $accountCategoryName : '';
  25. }
  26. $data = array_map(function (AccountDTO $account) {
  27. $row = [];
  28. foreach ($this->getColumns() as $column) {
  29. $row[$column->getName()] = match ($column->getName()) {
  30. 'account_code' => $account->accountCode,
  31. 'account_name' => [
  32. 'name' => $account->accountName,
  33. 'id' => $account->accountId ?? null,
  34. 'start_date' => $account->startDate,
  35. 'end_date' => $account->endDate,
  36. ],
  37. 'debit_balance' => $account->balance->debitBalance,
  38. 'credit_balance' => $account->balance->creditBalance,
  39. default => '',
  40. };
  41. }
  42. return $row;
  43. }, $accountCategory->accounts);
  44. $summary = [];
  45. foreach ($this->getColumns() as $column) {
  46. $summary[$column->getName()] = match ($column->getName()) {
  47. 'account_name' => 'Total ' . $accountCategoryName,
  48. 'debit_balance' => $accountCategory->summary->debitBalance,
  49. 'credit_balance' => $accountCategory->summary->creditBalance,
  50. default => '',
  51. };
  52. }
  53. $categories[] = new ReportCategoryDTO(
  54. header: $header,
  55. data: $data,
  56. summary: $summary,
  57. );
  58. }
  59. return $categories;
  60. }
  61. public function getOverallTotals(): array
  62. {
  63. $totals = [];
  64. foreach ($this->getColumns() as $column) {
  65. $totals[$column->getName()] = match ($column->getName()) {
  66. 'account_name' => 'Total for all accounts',
  67. 'debit_balance' => $this->report->overallTotal->debitBalance,
  68. 'credit_balance' => $this->report->overallTotal->creditBalance,
  69. default => '',
  70. };
  71. }
  72. return $totals;
  73. }
  74. }