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.

AccountBalanceReportTransformer.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Transformers;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. class AccountBalanceReportTransformer implements ExportableReport
  6. {
  7. protected ReportDTO $report;
  8. public function __construct(ReportDTO $report)
  9. {
  10. $this->report = $report;
  11. }
  12. public function getTitle(): string
  13. {
  14. return 'Account Balances';
  15. }
  16. public function getHeaders(): array
  17. {
  18. return ['ACCOUNT CODE', 'ACCOUNT', 'STARTING BALANCE', 'DEBIT', 'CREDIT', 'NET MOVEMENT', 'ENDING BALANCE'];
  19. }
  20. public function getData(): array
  21. {
  22. $data = [];
  23. foreach ($this->report->categories as $accountCategoryName => $accountCategory) {
  24. // Category Header row
  25. $data[] = ['', $accountCategoryName];
  26. // Account rows
  27. foreach ($accountCategory->accounts as $account) {
  28. $data[] = [
  29. $account->accountCode,
  30. $account->accountName,
  31. $account->balance->startingBalance ?? '',
  32. $account->balance->debitBalance,
  33. $account->balance->creditBalance,
  34. $account->balance->netMovement,
  35. $account->balance->endingBalance ?? '',
  36. ];
  37. }
  38. // Category Summary row
  39. $data[] = [
  40. '',
  41. 'Total ' . $accountCategoryName,
  42. $accountCategory->summary->startingBalance ?? '',
  43. $accountCategory->summary->debitBalance,
  44. $accountCategory->summary->creditBalance,
  45. $accountCategory->summary->netMovement,
  46. $accountCategory->summary->endingBalance ?? '',
  47. ];
  48. // Add an empty row after each category
  49. $data[] = [''];
  50. }
  51. return $data;
  52. }
  53. public function getOverallTotals(): array
  54. {
  55. return [
  56. '',
  57. 'Total for all accounts',
  58. '',
  59. $this->report->overallTotal->debitBalance,
  60. $this->report->overallTotal->creditBalance,
  61. '',
  62. '',
  63. ];
  64. }
  65. }