Merge branch 'exports/filters-on-work-date' into 'master'

Feature: [exports] add filters for start and end date for accompanying period works

See merge request Chill-Projet/chill-bundles!533
This commit is contained in:
Julien Fastré 2023-05-19 09:51:06 +00:00
commit 785c70fe92
4 changed files with 256 additions and 1 deletions

View File

@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormBuilderInterface;
final readonly class AccompanyingPeriodWorkEndDateBetweenDateFilter implements FilterInterface
{
public function __construct(
private RollingDateConverterInterface $rollingDateConverter,
) {
}
public function buildForm(FormBuilderInterface $builder): void
{
$builder
->add('start_date', PickRollingDateType::class, [
'label' => 'export.filter.work.end_between_dates.start_date',
'data' => new RollingDate(RollingDate::T_TODAY),
])
->add('end_date', PickRollingDateType::class, [
'label' => 'export.filter.work.end_between_dates.end_date',
'data' => new RollingDate(RollingDate::T_TODAY),
])
->add('keep_null', CheckboxType::class, [
'label' => 'export.filter.work.end_between_dates.keep_null',
'help' => 'export.filter.work.end_between_dates.keep_null_help',
])
;
}
public function getTitle(): string
{
return 'export.filter.work.end_between_dates.title';
}
public function describeAction($data, $format = 'string'): array
{
return [
'export.filter.work.end_between_dates.Only where end date is between %endDate% and %endDate%',
[
'%startDate%' => null !== $data['start_date'] ? $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y') : '',
'%endDate%' => null !== $data['end_date'] ? $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y') : '',
]
];
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data): void
{
$as = 'acc_pe_work_end_between_filter_start';
$ae = 'acc_pe_work_end_between_filter_end';
$start = match ($data['keep_null']) {
true => $qb->expr()->orX(
$qb->expr()->lte('acpw.endDate', ':'.$ae),
$qb->expr()->isNull('acpw.endDate')
),
false => $qb->expr()->andX(
$qb->expr()->lte('acpw.endDate', ':'.$ae),
$qb->expr()->isNotNull('acpw.endDate')
),
default => throw new \LogicException("This value is not supported"),
};
$end = match ($data['keep_null']) {
true => $qb->expr()->orX(
$qb->expr()->gt('acpw.endDate', ':'.$as),
$qb->expr()->isNull('acpw.endDate')
),
false => $qb->expr()->andX(
$qb->expr()->gt('acpw.endDate', ':'.$as),
$qb->expr()->isNotNull('acpw.endDate')
),
default => throw new \LogicException("This value is not supported"),
};
if (null !== $data['start_date']) {
$qb
->andWhere($start)
->setParameter($as, $this->rollingDateConverter->convert($data['start_date']));
}
if (null !== $data['end_date']) {
$qb
->andWhere($end)
->setParameter($ae, $this->rollingDateConverter->convert($data['end_date']));
}
}
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormBuilderInterface;
final readonly class AccompanyingPeriodWorkStartDateBetweenDateFilter implements FilterInterface
{
public function __construct(
private RollingDateConverterInterface $rollingDateConverter,
) {
}
public function buildForm(FormBuilderInterface $builder): void
{
$builder
->add('start_date', PickRollingDateType::class, [
'label' => 'export.filter.work.start_between_dates.start_date',
'data' => new RollingDate(RollingDate::T_TODAY),
])
->add('end_date', PickRollingDateType::class, [
'label' => 'export.filter.work.start_between_dates.end_date',
'data' => new RollingDate(RollingDate::T_TODAY),
])
->add('keep_null', CheckboxType::class, [
'label' => 'export.filter.work.start_between_dates.keep_null',
'help' => 'export.filter.work.start_between_dates.keep_null_help',
])
;
}
public function getTitle(): string
{
return 'export.filter.work.start_between_dates.title';
}
public function describeAction($data, $format = 'string'): array
{
return [
'export.filter.work.start_between_dates.Only where start date is between %startDate% and %endDate%',
[
'%startDate%' => null !== $data['start_date'] ? $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y') : '',
'%endDate%' => null !== $data['end_date'] ? $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y') : '',
]
];
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data): void
{
$as = 'acc_pe_work_start_between_filter_start';
$ae = 'acc_pe_work_start_between_filter_end';
$start = match ($data['keep_null']) {
true => $qb->expr()->orX(
$qb->expr()->lte('acpw.startDate', ':'.$ae),
$qb->expr()->isNull('acpw.startDate')
),
false => $qb->expr()->andX(
$qb->expr()->lte('acpw.startDate', ':'.$ae),
$qb->expr()->isNotNull('acpw.startDate')
),
default => throw new \LogicException("This value is not supported"),
};
$end = match ($data['keep_null']) {
true => $qb->expr()->orX(
$qb->expr()->gt('acpw.startDate', ':'.$as),
$qb->expr()->isNull('acpw.startDate')
),
false => $qb->expr()->andX(
$qb->expr()->gt('acpw.startDate', ':'.$as),
$qb->expr()->isNotNull('acpw.startDate')
),
default => throw new \LogicException("This value is not supported"),
};
if (null !== $data['start_date']) {
$qb
->andWhere($start)
->setParameter($as, $this->rollingDateConverter->convert($data['start_date']));
}
if (null !== $data['end_date']) {
$qb
->andWhere($end)
->setParameter($ae, $this->rollingDateConverter->convert($data['end_date']));
}
}
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}

View File

@ -48,7 +48,19 @@ services:
tags:
- { name: chill.export_filter, alias: social_work_actions_current_filter }
## AGGREGATORS
Chill\PersonBundle\Export\Filter\SocialWorkFilters\AccompanyingPeriodWorkStartDateBetweenDateFilter:
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: social_work_actions_start_btw_dates_filter }
Chill\PersonBundle\Export\Filter\SocialWorkFilters\AccompanyingPeriodWorkEndDateBetweenDateFilter:
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: social_work_actions_end_btw_dates_filter }
## AGGREGATORS
chill.person.export.aggregator_action_type:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ActionTypeAggregator
autowire: true

View File

@ -1097,6 +1097,21 @@ export:
Calculation date: Date de la localisation
creator_job:
'Filtered by creator job: only %jobs%': 'Filtré par métier du créateur: seulement %jobs%'
work:
start_between_dates:
title: Filtre les actions d'accompagnement dont la date d'ouverture est entre deux dates
start_date: Date de début
end_date: Date de fin
keep_null: Conserver les actions dont la date de début n'est pas indiquée
keep_null_help: Si coché, les actions dont la date de début est vide seront prises en compte. Si non coché, elles ne seront pas comptabilisée.
Only where start date is between %startDate% and %endDate%: Seulement les actions dont la date de début est entre le %startDate% et le %endDate%
end_between_dates:
title: Filtre les actions d'accompagnement dont la date de clotûre est entre deux dates (ou l'action est toujours ouverte)
start_date: Date de début
end_date: Date de fin
keep_null: Conserver les actions dont la date de fin n'est pas indiquée (actions en cours)
keep_null_help: Si coché, les actions dont la date de fin est vide seront prises en compte. Si non coché, elles ne seront pas comptabilisée.
Only where start date is between %startDate% and %endDate%: Seulement les actions dont la date de fin est entre le %startDate% et le %endDate%
list:
person_with_acp:
List peoples having an accompanying period: Liste des usagers ayant un parcours d'accompagnement