exports: add on_date parameter on Composition Filter/Aggregator

This commit is contained in:
2022-08-10 16:50:59 +02:00
parent c693dfde66
commit bc5d610f80
3 changed files with 58 additions and 15 deletions

View File

@@ -3,9 +3,12 @@
namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
@@ -54,7 +57,9 @@ class CompositionAggregator implements AggregatorInterface
*/
public function buildForm(FormBuilderInterface $builder)
{
// TODO: Implement buildForm() method.
$builder->add('on_date', ChillDateType::class, [
'data' => new \DateTime('now'),
]);
}
/**
@@ -87,6 +92,26 @@ class CompositionAggregator implements AggregatorInterface
} else {
$qb->groupBy('composition_aggregator');
}
// add date in where clause
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->lte('composition.startDate', ':ondate'),
$qb->expr()->orX(
$qb->expr()->gt('composition.endDate', ':ondate'),
$qb->expr()->isNull('composition.endDate')
)
);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE);
}
/**