您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AccountBalanceReportTransformer.php 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Transformers;
  3. use App\DTO\AccountDTO;
  4. use App\DTO\ReportCategoryDTO;
  5. class AccountBalanceReportTransformer extends BaseReportTransformer
  6. {
  7. public function getTitle(): string
  8. {
  9. return 'Account Balances';
  10. }
  11. public function getHeaders(): array
  12. {
  13. $headers = ['Account', 'Starting Balance', 'Debit', 'Credit', 'Net Movement', 'Ending Balance'];
  14. if ($this->options['showAccountCode'] ?? false) {
  15. array_unshift($headers, 'Account Code');
  16. }
  17. return $headers;
  18. }
  19. public function getRightAlignedColumns(): array
  20. {
  21. $columns = [1, 2, 3, 4, 5];
  22. if ($this->options['showAccountCode'] ?? false) {
  23. $columns = [2, 3, 4, 5, 6];
  24. }
  25. return $columns;
  26. }
  27. public function getLeftAlignedColumns(): array
  28. {
  29. $columns = [0];
  30. if ($this->options['showAccountCode'] ?? false) {
  31. $columns = [1];
  32. }
  33. return $columns;
  34. }
  35. public function getCenterAlignedColumns(): array
  36. {
  37. if ($this->options['showAccountCode'] ?? false) {
  38. return [0];
  39. }
  40. return [];
  41. }
  42. /**
  43. * @return ReportCategoryDTO[]
  44. */
  45. public function getCategories(): array
  46. {
  47. $categories = [];
  48. foreach ($this->report->categories as $accountCategoryName => $accountCategory) {
  49. $header = [$accountCategoryName, '', '', '', '', ''];
  50. if ($this->options['showAccountCode'] ?? false) {
  51. array_unshift($header, '');
  52. }
  53. $data = array_map(function (AccountDTO $account) {
  54. $row = [
  55. $account->accountName,
  56. $account->balance->startingBalance ?? '',
  57. $account->balance->debitBalance,
  58. $account->balance->creditBalance,
  59. $account->balance->netMovement ?? '',
  60. $account->balance->endingBalance ?? '',
  61. ];
  62. if ($this->options['showAccountCode'] ?? false) {
  63. array_unshift($row, $account->accountCode);
  64. }
  65. return $row;
  66. }, $accountCategory->accounts);
  67. $summary = [
  68. 'Total ' . $accountCategoryName,
  69. $accountCategory->summary->startingBalance ?? '',
  70. $accountCategory->summary->debitBalance,
  71. $accountCategory->summary->creditBalance,
  72. $accountCategory->summary->netMovement ?? '',
  73. $accountCategory->summary->endingBalance ?? '',
  74. ];
  75. if ($this->options['showAccountCode'] ?? false) {
  76. array_unshift($summary, '');
  77. }
  78. $categories[] = new ReportCategoryDTO(
  79. header: $header,
  80. data: $data,
  81. summary: $summary,
  82. );
  83. }
  84. return $categories;
  85. }
  86. public function getOverallTotals(): array
  87. {
  88. $totals = [
  89. 'Total for all accounts',
  90. '',
  91. $this->report->overallTotal->debitBalance,
  92. $this->report->overallTotal->creditBalance,
  93. '',
  94. '',
  95. ];
  96. if ($this->options['showAccountCode'] ?? false) {
  97. array_unshift($totals, '');
  98. }
  99. return $totals;
  100. }
  101. }