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.

TrialBalanceReportTransformer.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Transformers;
  3. use App\Contracts\ExportableReport;
  4. use App\DTO\ReportDTO;
  5. class TrialBalanceReportTransformer 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 'Trial Balance';
  15. }
  16. public function getHeaders(): array
  17. {
  18. return ['ACCOUNT CODE', 'ACCOUNT', 'DEBIT', 'CREDIT'];
  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->debitBalance,
  32. $account->balance->creditBalance,
  33. ];
  34. }
  35. // Category Summary row
  36. $data[] = [
  37. '',
  38. 'Total ' . $accountCategoryName,
  39. $accountCategory->summary->debitBalance,
  40. $accountCategory->summary->creditBalance,
  41. ];
  42. // Add an empty row after each category
  43. $data[] = [''];
  44. }
  45. return $data;
  46. }
  47. public function getOverallTotals(): array
  48. {
  49. return [
  50. '',
  51. 'Total for all accounts',
  52. $this->report->overallTotal->debitBalance,
  53. $this->report->overallTotal->creditBalance,
  54. ];
  55. }
  56. }