diff --git a/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php b/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php index 826a302a8..97c25cf1e 100644 --- a/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php +++ b/src/Bundle/ChillEventBundle/Entity/EventBudgetElement.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\EventBundle\Entity; +use Chill\EventBundle\Repository\EventThemeRepository; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; diff --git a/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php b/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php index 66e407a09..c905b4c8f 100644 --- a/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php +++ b/src/Bundle/ChillEventBundle/Export/Export/ListEvents.php @@ -11,8 +11,8 @@ declare(strict_types=1); namespace Chill\EventBundle\Export\Export; +use Chill\EventBundle\Entity\BudgetTypeEnum; use Chill\EventBundle\Entity\Event; -use Chill\EventBundle\Entity\EventBudgetElement; use Chill\EventBundle\Export\Declarations; use Chill\EventBundle\Repository\EventBudgetElementRepository; use Chill\EventBundle\Repository\EventThemeRepository; @@ -45,7 +45,8 @@ class ListEvents implements ListInterface, GroupedExportInterface 'event_moderator', 'event_participants_count', 'event_location', - 'event_budget_elements', + 'event_budget_resources', + 'event_budget_charges', 'event_animators', 'event_themes', ]; @@ -136,33 +137,6 @@ class ListEvents implements ListInterface, GroupedExportInterface 'event_moderator' => fn ($value) => '_header' === $value ? 'Moderator' : $value, 'event_participants_count' => fn ($value) => '_header' === $value ? 'Participants Count' : $value, 'event_location' => fn ($value) => '_header' === $value ? 'Location' : $value, - 'event_budget_elements' => function ($value) use ($key) { - if ('_header' === $value) { - return 'export.event.list.'.$key; - } - - if (null === $value || '' === $value) { - return ''; - } - - $ids = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR); - - if (!is_array($ids)) { - return ''; - } - - $elements = $this->eventBudgetElementRepository->findBy(['id' => $ids]); - - return implode( - ' | ', - array_map(function ($element) { - $kindName = $this->translatableStringHelper->localize($element->getKind()->getName()); - $amount = number_format($element->getAmount(), 2, '.', ''); - - return sprintf('%s: %s€', $kindName, $amount); - }, $elements) - ); - }, 'event_animators' => $this->labelThirdPartyHelper->getLabelMulti($key, $values, 'export.list.acp.'.$key), 'event_themes' => function ($value) use ($key) { if ('_header' === $value) { @@ -181,6 +155,49 @@ class ListEvents implements ListInterface, GroupedExportInterface ) ); }, + 'event_budget_resources' => function ($value) { + if ('_header' === $value) { + return 'Resources Budget'; + } + + if (!$value) { + return ''; + } + + $ids = explode(',', $value); + $ids = json_decode($value, true, 512, JSON_THROW_ON_ERROR); + $elements = $this->eventBudgetElementRepository->findBy(['id' => $ids]); + + return implode('|', array_map(function ($element) { + $name = $this->translatableStringHelper->localize($element->getKind()->getName()); + $amount = number_format($element->getAmount(), 2, '.', ''); + + return $name.': '.$amount; + }, $elements)); + }, + + 'event_budget_charges' => function ($value) { + if ('_header' === $value) { + return 'Charges Budget'; + } + + if (!$value) { + return ''; + } + + $ids = explode(',', $value); + $ids = json_decode($value, true, 512, JSON_THROW_ON_ERROR); + + $elements = $this->eventBudgetElementRepository->findBy(['id' => $ids]); + + return implode('|', array_map(function ($element) { + $name = $this->translatableStringHelper->localize($element->getKind()->getName()); + $amount = number_format($element->getAmount(), 2, '.', ''); + + return $name.': '.$amount; + }, $elements)); + }, + default => fn ($value) => '_header' === $value ? $key : $value, }; @@ -284,16 +301,29 @@ class ListEvents implements ListInterface, GroupedExportInterface ); break; - case 'event_budget_elements': + case 'event_budget_resources': $qb->addSelect( - '(SELECT AGGREGATE(e.id) FROM Chill\EventBundle\Entity\EventBudgetElement e WHERE e.event = event.id) AS event_budget_elements' + '(SELECT AGGREGATE(ebr.id) + FROM Chill\EventBundle\Entity\EventBudgetElement ebr + JOIN ebr.kind kr + WHERE ebr.event = event.id AND kr.type = :resource_type) AS event_budget_resources' ); + $qb->setParameter('resource_type', BudgetTypeEnum::RESOURCE->value); + break; + + case 'event_budget_charges': + $qb->addSelect( + '(SELECT AGGREGATE(ebc.id) + FROM Chill\EventBundle\Entity\EventBudgetElement ebc + JOIN ebc.kind kc + WHERE ebc.event = event.id AND kc.type = :charge_type) AS event_budget_charges' + ); + $qb->setParameter('charge_type', BudgetTypeEnum::CHARGE->value); break; } } } - return $qb; }