您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

EntityPaymentPerformanceReportTransformer.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 EntityPaymentPerformanceReportTransformer 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->getPaymentPerformanceReportTitle();
  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_documents' => $entity->paymentMetrics->totalDocuments,
  35. 'on_time_count' => $entity->paymentMetrics->onTimeCount,
  36. 'late_count' => $entity->paymentMetrics->lateCount,
  37. 'avg_days_to_pay' => $entity->paymentMetrics->avgDaysToPay,
  38. 'avg_days_late' => $entity->paymentMetrics->avgDaysLate,
  39. 'on_time_payment_rate' => $entity->paymentMetrics->onTimePaymentRate,
  40. default => '',
  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. $totals[$column->getName()] = match ($column->getName()) {
  58. 'entity_name' => 'Overall Totals',
  59. 'total_documents' => $this->report->overallPaymentMetrics->totalDocuments,
  60. 'on_time_count' => $this->report->overallPaymentMetrics->onTimeCount,
  61. 'late_count' => $this->report->overallPaymentMetrics->lateCount,
  62. 'avg_days_to_pay' => $this->report->overallPaymentMetrics->avgDaysToPay,
  63. 'avg_days_late' => $this->report->overallPaymentMetrics->avgDaysLate,
  64. 'on_time_payment_rate' => $this->report->overallPaymentMetrics->onTimePaymentRate,
  65. default => '',
  66. };
  67. }
  68. return $totals;
  69. }
  70. }