diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithoutHouseholdComposition.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithoutHouseholdComposition.php new file mode 100644 index 000000000..c4644fc11 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithoutHouseholdComposition.php @@ -0,0 +1,84 @@ +rollingDateConverter = $rollingDateConverter; + } + + public function addRole(): ?string + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $p = 'person_by_household_no_compo_filter'; + + $qb + ->andWhere( + $qb->expr()->not( + $qb->expr()->exists( + 'SELECT 1 FROM ' . HouseholdMember::class . " {$p}_hm " . + 'JOIN ' . HouseholdComposition::class . " {$p}_compo WITH {$p}_hm.household = {$p}_compo.household " . + "WHERE {$p}_hm.person = person AND {$p}_hm.shareHousehold = 'TRUE' " . + "AND ({$p}_hm.startDate <= :{$p}_date AND ({$p}_hm.endDate IS NULL OR {$p}_hm.endDate > :{$p}_date)) " . + "AND ({$p}_compo.startDate <= :{$p}_date AND ({$p}_compo.endDate IS NULL OR {$p}_compo.endDate > :{$p}_date)) " + ) + ) + ) + ->setParameter("{$p}_date", $this->rollingDateConverter->convert($data['calc_date']), Types::DATE_IMMUTABLE); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder + ->add('calc_date', PickRollingDateType::class, [ + 'label' => 'export.filter.person.by_no_composition.Date calc', + 'data' => new RollingDate(RollingDate::T_TODAY), + ]); + } + + public function describeAction($data, $format = 'string') + { + return ['export.filter.person.by_no_composition.Persons filtered by no composition at %date%', [ + '%date%' => $this->rollingDateConverter->convert($data['calc_date'])->format('d-m-Y'), + ]]; + } + + public function getTitle() + { + return 'export.filter.person.by_no_composition.Filter persons without household composition'; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index 05ae4b7b2..a8563e5ca 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -114,6 +114,10 @@ services: tags: - { name: chill.export_filter, alias: person_by_household_composition_filter } + Chill\PersonBundle\Export\Filter\PersonFilters\WithoutHouseholdComposition: + tags: + - { name: chill.export_filter, alias: person_without_household_composition_filter } + ## Aggregators chill.person.export.aggregator_nationality: class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\NationalityAggregator diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 41919fe4d..6ca594dc1 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1045,6 +1045,11 @@ export: Accepted compositions: Composition de ménages Date calc: Date de calcul 'Filtered by composition at %date%: only %compositions%': 'Filtré par composition du ménage, le %date%, seulement %compositions%' + by_no_composition: + Filter persons without household composition: Filtrer les personnes sans composition de ménage (ni ménage) + Persons filtered by no composition at %date%: Uniquement les personnes sans composition de ménage à la date du %date% + Date calc: Date de calcul + course: by_user_scope: Computation date for referrer: Date à laquelle le référent était actif