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.

ClientBalanceSummaryReportTransformer.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Transformers;
  3. use App\DTO\ClientReportDTO;
  4. use App\DTO\ReportCategoryDTO;
  5. class ClientBalanceSummaryReportTransformer extends BaseReportTransformer
  6. {
  7. public function getTitle(): string
  8. {
  9. return 'Client Balance Summary';
  10. }
  11. /**
  12. * @return ReportCategoryDTO[]
  13. */
  14. public function getCategories(): array
  15. {
  16. $categories = [];
  17. foreach ($this->report->categories as $categoryName => $category) {
  18. $data = array_map(function (ClientReportDTO $client) {
  19. $row = [];
  20. foreach ($this->getColumns() as $column) {
  21. $row[$column->getName()] = match ($column->getName()) {
  22. 'client_name' => [
  23. 'name' => $client->clientName,
  24. 'id' => $client->clientId,
  25. ],
  26. 'total_balance' => $client->balance->totalBalance,
  27. 'paid_balance' => $client->balance->paidBalance,
  28. 'unpaid_balance' => $client->balance->unpaidBalance,
  29. default => '',
  30. };
  31. }
  32. return $row;
  33. }, $category);
  34. $categories[] = new ReportCategoryDTO(
  35. header: null,
  36. data: $data,
  37. summary: null,
  38. );
  39. }
  40. return $categories;
  41. }
  42. public function getOverallTotals(): array
  43. {
  44. $totals = [];
  45. foreach ($this->getColumns() as $column) {
  46. $totals[$column->getName()] = match ($column->getName()) {
  47. 'client_name' => 'Total for all clients',
  48. 'total_balance' => $this->report->clientBalanceTotal->totalBalance,
  49. 'paid_balance' => $this->report->clientBalanceTotal->paidBalance,
  50. 'unpaid_balance' => $this->report->clientBalanceTotal->unpaidBalance,
  51. default => '',
  52. };
  53. }
  54. return $totals;
  55. }
  56. }