Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

AgingReportTransformer.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 AgingReportTransformer 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->getAgingReportTitle();
  18. }
  19. /**
  20. * @return ReportCategoryDTO[]
  21. */
  22. public function getCategories(): array
  23. {
  24. $categories = [];
  25. foreach ($this->report->categories as $category) {
  26. $data = array_map(function (EntityReportDTO $entity) {
  27. $row = [];
  28. foreach ($this->getColumns() as $column) {
  29. $columnName = $column->getName();
  30. $row[$columnName] = match ($columnName) {
  31. 'entity_name' => [
  32. 'name' => $entity->name,
  33. 'id' => $entity->id,
  34. ],
  35. 'current' => $entity->aging->current,
  36. 'over_periods' => $entity->aging->overPeriods,
  37. 'total' => $entity->aging->total,
  38. default => str_starts_with($columnName, 'period_')
  39. ? $entity->aging->periods[$columnName] ?? null
  40. : '',
  41. };
  42. }
  43. return $row;
  44. }, $category);
  45. $categories[] = new ReportCategoryDTO(
  46. header: null,
  47. data: $data,
  48. summary: null,
  49. );
  50. }
  51. return $categories;
  52. }
  53. public function getOverallTotals(): array
  54. {
  55. $totals = [];
  56. foreach ($this->getColumns() as $column) {
  57. $columnName = $column->getName();
  58. $totals[$columnName] = match ($columnName) {
  59. 'entity_name' => 'Total',
  60. 'current' => $this->report->agingSummary->current,
  61. 'over_periods' => $this->report->agingSummary->overPeriods,
  62. 'total' => $this->report->agingSummary->total,
  63. default => str_starts_with($columnName, 'period_')
  64. ? $this->report->agingSummary->periods[$columnName] ?? null
  65. : '',
  66. };
  67. }
  68. return $totals;
  69. }
  70. }