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.

EntityBalanceSummaryReportTransformer.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Transformers;
  3. use App\DTO\EntityReportDTO;
  4. use App\DTO\ReportCategoryDTO;
  5. use App\DTO\ReportDTO;
  6. use App\Enums\Accounting\DocumentEntityType;
  7. class EntityBalanceSummaryReportTransformer extends BaseReportTransformer
  8. {
  9. public function __construct(
  10. ReportDTO $report,
  11. private readonly DocumentEntityType $entityType,
  12. ) {
  13. parent::__construct($report);
  14. }
  15. public function getTitle(): string
  16. {
  17. return $this->entityType->getBalanceSummaryReportTitle();
  18. }
  19. /**
  20. * @return ReportCategoryDTO[]
  21. */
  22. public function getCategories(): array
  23. {
  24. $categories = [];
  25. foreach ($this->report->categories as $categoryName => $category) {
  26. $data = array_map(function (EntityReportDTO $entity) {
  27. $row = [];
  28. foreach ($this->getColumns() as $column) {
  29. $row[$column->getName()] = match ($column->getName()) {
  30. 'entity_name' => [
  31. 'name' => $entity->name,
  32. 'id' => $entity->id,
  33. ],
  34. 'total_balance' => $entity->balance->totalBalance,
  35. 'paid_balance' => $entity->balance->paidBalance,
  36. 'unpaid_balance' => $entity->balance->unpaidBalance,
  37. default => '',
  38. };
  39. }
  40. return $row;
  41. }, $category);
  42. $categories[] = new ReportCategoryDTO(
  43. header: null,
  44. data: $data,
  45. summary: null,
  46. );
  47. }
  48. return $categories;
  49. }
  50. public function getOverallTotals(): array
  51. {
  52. $totals = [];
  53. foreach ($this->getColumns() as $column) {
  54. $totals[$column->getName()] = match ($column->getName()) {
  55. 'entity_name' => 'Total',
  56. 'total_balance' => $this->report->entityBalanceTotal->totalBalance,
  57. 'paid_balance' => $this->report->entityBalanceTotal->paidBalance,
  58. 'unpaid_balance' => $this->report->entityBalanceTotal->unpaidBalance,
  59. default => '',
  60. };
  61. }
  62. return $totals;
  63. }
  64. }