From 4d72933edb472aa964c54940814650cfd748f768 Mon Sep 17 00:00:00 2001 From: LenaertsJ Date: Wed, 20 Dec 2023 10:46:29 +0000 Subject: [PATCH] Add condition to household export queries to exclude accompanying periods that are in draft. --- .changes/unreleased/Fixed-20231218-162157.yaml | 6 ++++++ .../Export/Export/CountHouseholdInPeriod.php | 5 ++++- .../Export/Export/ListHouseholdInPeriod.php | 5 ++++- .../Tests/Controller/RelationshipApiControllerTest.php | 6 +++--- 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231218-162157.yaml diff --git a/.changes/unreleased/Fixed-20231218-162157.yaml b/.changes/unreleased/Fixed-20231218-162157.yaml new file mode 100644 index 000000000..198134c3e --- /dev/null +++ b/.changes/unreleased/Fixed-20231218-162157.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Fix the household export query to exclude accompanying periods that are in draft + state. +time: 2023-12-18T16:21:57.827287397+01:00 +custom: + Issue: "" diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountHouseholdInPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/CountHouseholdInPeriod.php index 8b56be371..a65dcb217 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountHouseholdInPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountHouseholdInPeriod.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Export\Declarations; @@ -121,7 +122,9 @@ class CountHouseholdInPeriod implements ExportInterface, GroupedExportInterface ->join('acppart.accompanyingPeriod', 'acp') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') - ->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])); + ->andWhere('acp.step != :count_acp_step') + ->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])) + ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT); $qb ->select('COUNT(DISTINCT household.id) AS household_export_result') diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php b/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php index 46770fab8..21f7a5923 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListHouseholdInPeriod.php @@ -20,6 +20,7 @@ use Chill\MainBundle\Export\ListInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\HouseholdComposition; use Chill\PersonBundle\Entity\Household\HouseholdMember; @@ -144,7 +145,9 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface ->join('acppart.accompanyingPeriod', 'acp') ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere('hmember.startDate <= :count_household_at_date AND (hmember.endDate IS NULL OR hmember.endDate > :count_household_at_date)') - ->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])); + ->andWhere('acp.step != :list_acp_step') + ->setParameter('count_household_at_date', $this->rollingDateConverter->convert($data['calc_date'])) + ->setParameter('list_acp_step', AccompanyingPeriod::STEP_DRAFT); if ($this->filterStatsByCenters) { $qb diff --git a/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php index 171dedacb..626e1469b 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Controller/RelationshipApiControllerTest.php @@ -50,7 +50,7 @@ final class RelationshipApiControllerTest extends WebTestCase ->join('p.centerCurrent', 'center_current') ->join('center_current.center', 'c') ->where('c.name LIKE :name') - ->andWhere('EXISTS (SELECT 1 FROM ' . Relationship::class . ' r WHERE r.fromPerson = p OR r.toPerson = p)') + ->andWhere('EXISTS (SELECT 1 FROM '.Relationship::class.' r WHERE r.fromPerson = p OR r.toPerson = p)') ->setParameter('name', 'Center A') ->getQuery() ->setMaxResults(1) @@ -62,7 +62,7 @@ final class RelationshipApiControllerTest extends WebTestCase ->join('p.centerCurrent', 'center_current') ->join('center_current.center', 'c') ->where('c.name LIKE :name') - ->andWhere('NOT EXISTS (SELECT 1 FROM ' . Relationship::class . ' r WHERE r.fromPerson = p OR r.toPerson = p)') + ->andWhere('NOT EXISTS (SELECT 1 FROM '.Relationship::class.' r WHERE r.fromPerson = p OR r.toPerson = p)') ->setParameter('name', 'Center A') ->getQuery() ->setMaxResults(1) @@ -85,7 +85,7 @@ final class RelationshipApiControllerTest extends WebTestCase ->join('p.centerCurrent', 'center_current') ->join('center_current.center', 'c') ->where('c.name LIKE :name') - ->andWhere('NOT EXISTS (SELECT 1 FROM ' . Relationship::class . ' r WHERE r.fromPerson = p OR r.toPerson = p)') + ->andWhere('NOT EXISTS (SELECT 1 FROM '.Relationship::class.' r WHERE r.fromPerson = p OR r.toPerson = p)') ->setParameter('name', 'Center A') ->getQuery() ->setMaxResults(2)