Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

AccountBalanceReportTransformer.php 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /**
  12. * @return ReportCategoryDTO[]
  13. */
  14. public function getCategories(): array
  15. {
  16. $categories = [];
  17. foreach ($this->report->categories as $accountCategoryName => $accountCategory) {
  18. $header = [];
  19. foreach ($this->getColumns() as $column) {
  20. $header[$column->getName()] = $column->getName() === 'account_name' ? $accountCategoryName : '';
  21. }
  22. $data = array_map(function (AccountDTO $account) {
  23. $row = [];
  24. foreach ($this->getColumns() as $column) {
  25. $row[$column->getName()] = match ($column->getName()) {
  26. 'account_code' => $account->accountCode,
  27. 'account_name' => [
  28. 'name' => $account->accountName,
  29. 'id' => $account->accountId ?? null,
  30. 'start_date' => $account->startDate,
  31. 'end_date' => $account->endDate,
  32. ],
  33. 'starting_balance' => $account->balance->startingBalance ?? '',
  34. 'debit_balance' => $account->balance->debitBalance,
  35. 'credit_balance' => $account->balance->creditBalance,
  36. 'net_movement' => $account->balance->netMovement ?? '',
  37. 'ending_balance' => $account->balance->endingBalance ?? '',
  38. default => '',
  39. };
  40. }
  41. return $row;
  42. }, $accountCategory->accounts);
  43. $summary = [];
  44. foreach ($this->getColumns() as $column) {
  45. $summary[$column->getName()] = match ($column->getName()) {
  46. 'account_name' => 'Total ' . $accountCategoryName,
  47. 'starting_balance' => $accountCategory->summary->startingBalance ?? '',
  48. 'debit_balance' => $accountCategory->summary->debitBalance,
  49. 'credit_balance' => $accountCategory->summary->creditBalance,
  50. 'net_movement' => $accountCategory->summary->netMovement ?? '',
  51. 'ending_balance' => $accountCategory->summary->endingBalance ?? '',
  52. default => '',
  53. };
  54. }
  55. $categories[] = new ReportCategoryDTO(
  56. header: $header,
  57. data: $data,
  58. summary: $summary,
  59. );
  60. }
  61. return $categories;
  62. }
  63. public function getOverallTotals(): array
  64. {
  65. $totals = [];
  66. foreach ($this->getColumns() as $column) {
  67. $totals[$column->getName()] = match ($column->getName()) {
  68. 'account_name' => 'Total for all accounts',
  69. 'debit_balance' => $this->report->overallTotal->debitBalance,
  70. 'credit_balance' => $this->report->overallTotal->creditBalance,
  71. default => '',
  72. };
  73. }
  74. return $totals;
  75. }
  76. }