diff --git a/.changes/unreleased/Feature-20231004-120857.yaml b/.changes/unreleased/Feature-20231004-120857.yaml new file mode 100644 index 000000000..b3cff5e82 --- /dev/null +++ b/.changes/unreleased/Feature-20231004-120857.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Allow closing motives to be identified as 'canceling the accompanying period' + + don't take canceled accompanying periods into account +time: 2023-10-04T12:08:57.586865276+02:00 +custom: + Issue: "146" diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php index 128704296..352a67014 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityDuration.php @@ -14,6 +14,7 @@ namespace Chill\ActivityBundle\Export\Export\LinkedToACP; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -31,7 +32,7 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface protected EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(Activity::class); } @@ -108,6 +109,8 @@ class AvgActivityDuration implements ExportInterface, GroupedExportInterface ) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + return $qb; } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php index f1e926c64..4101408cc 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/AvgActivityVisitDuration.php @@ -14,6 +14,7 @@ namespace Chill\ActivityBundle\Export\Export\LinkedToACP; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -31,7 +32,7 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac protected EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(Activity::class); } @@ -111,6 +112,8 @@ class AvgActivityVisitDuration implements ExportInterface, GroupedExportInterfac ) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + return $qb; } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php index 28a318541..4926ecc33 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/CountActivity.php @@ -14,6 +14,7 @@ namespace Chill\ActivityBundle\Export\Export\LinkedToACP; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -31,7 +32,7 @@ class CountActivity implements ExportInterface, GroupedExportInterface protected EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(Activity::class); } @@ -105,6 +106,8 @@ class CountActivity implements ExportInterface, GroupedExportInterface ) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb->select('COUNT(DISTINCT activity.id) as export_count_activity'); return $qb; diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php index 9a226f9c3..4d57a31ec 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/ListActivity.php @@ -16,6 +16,7 @@ use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Export\Export\ListActivityHelper; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; use Chill\MainBundle\Entity\Scope; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\Helper\TranslatableStringExportLabelHelper; use Chill\MainBundle\Export\ListInterface; @@ -129,6 +130,8 @@ class ListActivity implements ListInterface, GroupedExportInterface ->addSelect('(SELECT AGGREGATE(acpScope.name) FROM ' . Scope::class . ' acpScope WHERE acpScope MEMBER OF acp.scopes) AS scopesNames') ->addGroupBy('scopesNames'); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + return $qb; } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php index 8adb3b77f..d9022f10e 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityDuration.php @@ -14,6 +14,7 @@ namespace Chill\ActivityBundle\Export\Export\LinkedToACP; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -31,7 +32,7 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface protected EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(Activity::class); } @@ -111,6 +112,8 @@ class SumActivityDuration implements ExportInterface, GroupedExportInterface ) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + return $qb; } diff --git a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php index cc424e68b..81cbddc8e 100644 --- a/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php +++ b/src/Bundle/ChillActivityBundle/Export/Export/LinkedToACP/SumActivityVisitDuration.php @@ -14,6 +14,7 @@ namespace Chill\ActivityBundle\Export\Export\LinkedToACP; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -31,7 +32,7 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac protected EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(Activity::class); } @@ -111,6 +112,8 @@ class SumActivityVisitDuration implements ExportInterface, GroupedExportInterfac ) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + return $qb; } diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php b/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php index 2a7051056..771e66504 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/CountCalendars.php @@ -13,6 +13,7 @@ namespace Chill\CalendarBundle\Export\Export; use Chill\CalendarBundle\Export\Declarations; use Chill\CalendarBundle\Repository\CalendarRepository; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -93,6 +94,9 @@ class CountCalendars implements ExportInterface, GroupedExportInterface $qb = $this->calendarRepository->createQueryBuilder('cal'); $qb->select('COUNT(cal.id) AS export_result'); + $qb->leftJoin('cal.accompanyingPeriod', 'acp'); + + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); return $qb; } diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarAvgDuration.php b/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarAvgDuration.php index 14baecb4e..3c73888d5 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarAvgDuration.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarAvgDuration.php @@ -13,6 +13,7 @@ namespace Chill\CalendarBundle\Export\Export; use Chill\CalendarBundle\Export\Declarations; use Chill\CalendarBundle\Repository\CalendarRepository; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -86,8 +87,10 @@ class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface { $qb = $this->calendarRepository->createQueryBuilder('cal'); - $qb - ->select('AVG(cal.endDate - cal.startDate) AS export_result'); + $qb->select('AVG(cal.endDate - cal.startDate) AS export_result'); + $qb->join('cal.accompanyingPeriod', 'acp'); + + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); return $qb; } diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarSumDuration.php b/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarSumDuration.php index 03e8d8a87..155cf7b69 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarSumDuration.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/StatCalendarSumDuration.php @@ -13,6 +13,7 @@ namespace Chill\CalendarBundle\Export\Export; use Chill\CalendarBundle\Export\Declarations; use Chill\CalendarBundle\Repository\CalendarRepository; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -86,8 +87,10 @@ class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface { $qb = $this->calendarRepository->createQueryBuilder('cal'); - $qb - ->select('SUM(cal.endDate - cal.startDate) AS export_result'); + $qb->select('SUM(cal.endDate - cal.startDate) AS export_result'); + $qb->join('cal.accompanyingPeriod', 'acp'); + + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); return $qb; } diff --git a/src/Bundle/ChillMainBundle/Export/AccompanyingCourseExportHelper.php b/src/Bundle/ChillMainBundle/Export/AccompanyingCourseExportHelper.php new file mode 100644 index 000000000..174548822 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Export/AccompanyingCourseExportHelper.php @@ -0,0 +1,31 @@ +leftJoin('acp.closingMotive', 'cm') + ->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('cm.isCanceledAccompanyingPeriod', 'false'), + $qb->expr()->isNull('acp.closingMotive') + ) + ); + + return $qb; + } + +} diff --git a/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php b/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php new file mode 100644 index 000000000..62af515ec --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Export/AccompanyingCourseExportHelperTest.php @@ -0,0 +1,122 @@ + + */ + private static array $entitiesToDelete = []; + + private EntityManagerInterface $em; + + private AccompanyingCourseExportHelper $accompanyingCourseExportHelper; + + protected function setUp(): void + { + self::bootKernel(); + $this->em = self::$container->get(EntityManagerInterface::class); + $this->accompanyingCourseExportHelper = self::$container->get(AccompanyingCourseExportHelper::class); + } + + public static function tearDownAfterClass(): void + { + self::bootKernel(); + $em = self::$container->get(EntityManagerInterface::class); + + foreach (self::$entitiesToDelete as [$class, $id]) { + $entity = $em->find($class, $id); + + if (null !== $entity) { + $em->remove($entity); + } + } + + $em->flush(); + } + + public function testExclusionOnClosingMotive(): void + { + [$periodA, $periodB, $periodC] = $this->prepareData(); + + $qb = $this->em->getRepository(AccompanyingPeriod::class)->createQueryBuilder('acp'); + $this->accompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + + $qb->select('acp.id'); + + $periodIdsFound = array_map(fn ($el) => $el['id'], $qb->getQuery()->getResult()); + + $periodA = $this->em->find(AccompanyingPeriod::class, $periodA->getId()); + $periodB = $this->em->find(AccompanyingPeriod::class, $periodB->getId()); + $periodC = $this->em->find(AccompanyingPeriod::class, $periodC->getId()); + + self::assertContains($periodA->getId(), $periodIdsFound, 'Period without canceled closing motive has been found'); + self::assertNotContains($periodB->getId(), $periodIdsFound, 'Period with canceled closing motive has not been found'); + self::assertNotContains($periodC->getId(), $periodIdsFound, 'Period with child canceled closing motive has not been found'); + } + + private function prepareData() + { + $cmA = new ClosingMotive(); + $cmA->setIsCanceledAccompanyingPeriod(false); + + $cmB = new ClosingMotive(); + $cmB->setIsCanceledAccompanyingPeriod(true); + + $cmChild = new ClosingMotive(); + $cmB->addChildren($cmChild); + + $this->em->persist($cmA); + $this->em->persist($cmB); + $this->em->persist($cmChild); + + $periodA = new AccompanyingPeriod(); + $periodB = new AccompanyingPeriod(); + $periodC = new AccompanyingPeriod(); + + $periodA->setClosingMotive($cmA); + $periodB->setClosingMotive($cmB); + $periodC->setClosingMotive($cmChild); + + $this->em->persist($periodA); + $this->em->persist($periodB); + $this->em->persist($periodC); + + self::$entitiesToDelete[] = [ClosingMotive::class, $cmChild]; + self::$entitiesToDelete[] = [ClosingMotive::class, $cmA]; + self::$entitiesToDelete[] = [ClosingMotive::class, $cmB]; + + self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodA]; + self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodB]; + self::$entitiesToDelete[] = [AccompanyingPeriod::class, $periodC]; + + $this->em->flush(); + $this->em->clear(); + + return [$periodA, $periodB, $periodC]; + } + +} diff --git a/src/Bundle/ChillMainBundle/config/services/export.yaml b/src/Bundle/ChillMainBundle/config/services/export.yaml index b0dbf934d..6bae6f9c0 100644 --- a/src/Bundle/ChillMainBundle/config/services/export.yaml +++ b/src/Bundle/ChillMainBundle/config/services/export.yaml @@ -52,3 +52,5 @@ services: $exportManager: '@Chill\MainBundle\Export\ExportManager' tags: - { name: chill.export_formatter, alias: 'csv_pivoted_list' } + + Chill\MainBundle\Export\AccompanyingCourseExportHelper: ~ diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php index 48adb1c6b..dbe75158d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php @@ -70,6 +70,11 @@ class ClosingMotive */ private ?ClosingMotive $parent = null; + /** + * @ORM\Column(type="boolean", nullable=false, options={"default": false}) + */ + private bool $isCanceledAccompanyingPeriod = false; + /** * ClosingMotive constructor. */ @@ -85,7 +90,7 @@ class ClosingMotive } $this->children->add($child); - $child->setParent($this); + $child->setParent($this)->setIsCanceledAccompanyingPeriod($this->getIsCanceledAccompanyingPeriod()); return $this; } @@ -128,6 +133,11 @@ class ClosingMotive return $this->parent; } + public function getIsCanceledAccompanyingPeriod(): bool + { + return $this->isCanceledAccompanyingPeriod; + } + public function hasParent(): bool { return null !== $this->parent; @@ -153,6 +163,11 @@ class ClosingMotive return $this->children->count() > 0; } + public function isCanceledAccompanyingPeriod(): bool + { + return $this->isCanceledAccompanyingPeriod; + } + public function removeChildren(ClosingMotive $child): ClosingMotive { if ($this->children->removeElement($child)) { @@ -219,4 +234,15 @@ class ClosingMotive return $this; } + + public function setIsCanceledAccompanyingPeriod(bool $isCanceledAP): ClosingMotive + { + $this->isCanceledAccompanyingPeriod = $isCanceledAP; + + foreach ($this->getChildren() as $child) { + $child->setIsCanceledAccompanyingPeriod($isCanceledAP); + } + + return $this; + } } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php index 58ef24e42..64a2bf53e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -30,7 +31,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface protected EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(AccompanyingPeriod::class); } @@ -111,6 +112,8 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb->select('COUNT(DISTINCT acp.id) AS export_result'); return $qb; diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php index 7f2972b7e..8c4052090 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingPeriodWork.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -106,6 +107,8 @@ class CountAccompanyingPeriodWork implements ExportInterface, GroupedExportInter $qb->select('COUNT(DISTINCT acpw.id) as export_result'); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php index 9ffecb519..0fea8d940 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -29,7 +30,6 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface public function buildForm(FormBuilderInterface $builder) { - // TODO: Implement buildForm() method. } public function getFormDefaultData(): array { @@ -104,6 +104,8 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface ) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb->select('COUNT(DISTINCT workeval.id) AS export_result'); return $qb; diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php index 761eaa115..e9fbd8f2b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountPersonWithAccompanyingCourse.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -30,7 +31,7 @@ class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExpor private readonly EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(AccompanyingPeriod::class); } @@ -111,6 +112,8 @@ class CountPersonWithAccompanyingCourse implements ExportInterface, GroupedExpor ) )->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb->select('COUNT(DISTINCT person.id) AS export_result'); return $qb; diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php index 4c8c0cae8..5595263d6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriod.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Export; use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Scope; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\Helper\DateTimeHelper; @@ -132,6 +133,8 @@ final readonly class ListAccompanyingPeriod implements ListInterface, GroupedExp $this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb ->addOrderBy('acp.openingDate') ->addOrderBy('acp.closingDate') diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php index 0b34899b9..2fb748b16 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListAccompanyingPeriodWork.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\Helper\AggregateStringHelper; @@ -207,6 +208,8 @@ class ListAccompanyingPeriodWork implements ListInterface, GroupedExportInterfac ->setParameter('authorized_centers', $centers) ->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); return $qb; diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php b/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php index 34646dbd0..181b14a3a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListEvaluation.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\Helper\AggregateStringHelper; @@ -199,6 +200,8 @@ class ListEvaluation implements ListInterface, GroupedExportInterface ->setParameter('authorized_centers', $centers) ->setParameter('calc_date', $this->rollingDateConverter->convert($data['calc_date'])); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $this->addSelectClauses($qb, $this->rollingDateConverter->convert($data['calc_date'])); return $qb; diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php index 71d36381a..c94637028 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonHavingAccompanyingPeriod.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -176,6 +177,8 @@ class ListPersonHavingAccompanyingPeriod implements ExportElementValidatedInterf $this->listPersonHelper->addSelect($qb, $fields, $data['address_date']); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb ->addOrderBy('person.lastName') ->addOrderBy('person.firstName') diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php index 66d4d1530..958d52111 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonWithAccompanyingPeriodDetails.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -133,6 +134,8 @@ final readonly class ListPersonWithAccompanyingPeriodDetails implements ListInte $this->listPersonHelper->addSelect($qb, ListPersonHelper::FIELDS, $this->rollingDateConverter->convert($data['address_date'])); $this->listAccompanyingPeriodHelper->addSelectClauses($qb, $this->rollingDateConverter->convert($data['address_date'])); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + $qb ->addOrderBy('person.lastName') ->addOrderBy('person.firstName') diff --git a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php index a34d1c801..19fb1e744 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Export; +use Chill\MainBundle\Export\AccompanyingCourseExportHelper; use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; @@ -32,7 +33,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn private readonly EntityRepository $repository; public function __construct( - EntityManagerInterface $em + EntityManagerInterface $em, ) { $this->repository = $em->getRepository(AccompanyingPeriod::class); } @@ -133,6 +134,8 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT) ->setParameter('authorized_centers', $centers); + AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + return $qb; } diff --git a/src/Bundle/ChillPersonBundle/Form/ClosingMotiveType.php b/src/Bundle/ChillPersonBundle/Form/ClosingMotiveType.php index 35dc502b9..251044e9e 100644 --- a/src/Bundle/ChillPersonBundle/Form/ClosingMotiveType.php +++ b/src/Bundle/ChillPersonBundle/Form/ClosingMotiveType.php @@ -19,12 +19,20 @@ use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Class ClosingMotiveType. */ class ClosingMotiveType extends AbstractType { + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + public function buildForm(FormBuilderInterface $builder, array $options) { $builder @@ -46,6 +54,11 @@ class ClosingMotiveType extends AbstractType 'placeholder' => 'closing_motive.any parent', 'multiple' => false, 'only_leaf' => false, + ]) + ->add('isCanceledAccompanyingPeriod', CheckboxType::class, [ + 'label' => $this->translator->trans('Consider canceled'), + 'required' => false, + 'help' => $this->translator->trans('Canceled parcours help') ]); } diff --git a/src/Bundle/ChillPersonBundle/Templating/Entity/ClosingMotiveRender.php b/src/Bundle/ChillPersonBundle/Templating/Entity/ClosingMotiveRender.php index 2a4682315..558c2eb2c 100644 --- a/src/Bundle/ChillPersonBundle/Templating/Entity/ClosingMotiveRender.php +++ b/src/Bundle/ChillPersonBundle/Templating/Entity/ClosingMotiveRender.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait; use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Render closing motive. @@ -54,6 +55,7 @@ class ClosingMotiveRender implements ChillEntityRenderInterface private function renderStringRecursive(ClosingMotive $motive, string $existing, array $options) { $newExisting = $this->translatableStringHelper->localize($motive->getName()); + $isCancled = $motive->getIsCanceledAccompanyingPeriod() ? $this->translator->trans('( Canceled period )') : ''; if ($motive->hasParent()) { if ('' !== $existing) { @@ -62,7 +64,7 @@ class ClosingMotiveRender implements ChillEntityRenderInterface return $this->renderStringRecursive( $motive->getParent(), - $newExisting, + $newExisting . ' ' . $isCancled, $options ); } @@ -71,6 +73,6 @@ class ClosingMotiveRender implements ChillEntityRenderInterface return $newExisting . self::SEPARATOR . $existing; } - return $newExisting; + return $newExisting . ' ' . $isCancled; } } diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20230918115305.php b/src/Bundle/ChillPersonBundle/migrations/Version20230918115305.php new file mode 100644 index 000000000..3e3a3c643 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20230918115305.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE chill_person_accompanying_period_closingmotive ADD isCanceledAccompanyingPeriod BOOLEAN DEFAULT FALSE NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_accompanying_period_closingmotive DROP isCanceledAccompanyingPeriod'); + } +} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 0a8371f38..35c4416d4 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -347,6 +347,9 @@ CHILL_PERSON_HOUSEHOLD_STATS: Statistiques sur les ménages #period Period closed!: Parcours clôturé! Pediod closing form is not valide: Le formulaire de fermeture n'est pas valide +Consider canceled: Permet de considérer les parcours comme annulés +Canceled parcours help: Si coché, les parcours avec ce motif de cloture seront considérés comme annulés et ne seront pas pris en compte pour les statistiques. La modification se reflétera pour tous les motifs enfants +( Canceled period ): ( annulé ) #widget