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.

AccountsReceivableAgingTransformer.php 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Transformers;
  3. use App\DTO\ClientReportDTO;
  4. use App\DTO\ReportCategoryDTO;
  5. class AccountsReceivableAgingTransformer extends BaseReportTransformer
  6. {
  7. public function getTitle(): string
  8. {
  9. return 'Accounts Receivable Aging';
  10. }
  11. /**
  12. * @return ReportCategoryDTO[]
  13. */
  14. public function getCategories(): array
  15. {
  16. $categories = [];
  17. foreach ($this->report->categories as $accountCategory) {
  18. $data = array_map(function (ClientReportDTO $client) {
  19. $row = [];
  20. foreach ($this->getColumns() as $column) {
  21. $columnName = $column->getName();
  22. $row[$columnName] = match (true) {
  23. $columnName === 'client_name' => [
  24. 'name' => $client->clientName,
  25. 'id' => $client->clientId,
  26. ],
  27. $columnName === 'current' => $client->aging->current,
  28. str_starts_with($columnName, 'period_') => $client->aging->periods[$columnName] ?? null,
  29. $columnName === 'over_periods' => $client->aging->overPeriods,
  30. $columnName === 'total' => $client->aging->total,
  31. default => '',
  32. };
  33. }
  34. return $row;
  35. }, $accountCategory);
  36. $categories[] = new ReportCategoryDTO(
  37. header: null,
  38. data: $data,
  39. summary: null,
  40. );
  41. }
  42. return $categories;
  43. }
  44. public function getOverallTotals(): array
  45. {
  46. $totals = [];
  47. foreach ($this->getColumns() as $column) {
  48. $columnName = $column->getName();
  49. $totals[$columnName] = match (true) {
  50. $columnName === 'client_name' => 'Total',
  51. $columnName === 'current' => $this->report->agingSummary->current,
  52. str_starts_with($columnName, 'period_') => $this->report->agingSummary->periods[$columnName] ?? null,
  53. $columnName === 'over_periods' => $this->report->agingSummary->overPeriods,
  54. $columnName === 'total' => $this->report->agingSummary->total,
  55. default => '',
  56. };
  57. }
  58. return $totals;
  59. }
  60. }