suivi/src/Repository/BillRepositoryQuery.php
2023-04-10 16:47:59 +02:00

70 lines
2.1 KiB
PHP

<?php
namespace App\Repository;
use App\Core\Repository\RepositoryQuery;
use App\Repository\BillRepository as Repository;
use Knp\Component\Pager\PaginatorInterface;
class BillRepositoryQuery extends RepositoryQuery
{
public function __construct(Repository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'b', $paginator);
}
protected function filterHandler(string $name, $value)
{
if ('vendor' === $name && null !== $value) {
$this
->andWhere('.vendor = :vendor')
->setParameter('vendor', $value)
;
} elseif ('amountTtcRange' === $name) {
if (null !== $value['min']) {
$this
->andWhere('.amountTtc >= :amountTtcMin')
->setParameter('amountTtcMin', $value['min'])
;
}
if (null !== $value['max']) {
$this
->andWhere('.amountTtc <= :amountTtcMax')
->setParameter('amountTtcMax', $value['max'])
;
}
} elseif ('amountHtRange' === $name) {
if (null !== $value['min']) {
$this
->andWhere('.amountHt >= :amountHtMin')
->setParameter('amountHtMin', $value['min'])
;
}
if (null !== $value['max']) {
$this
->andWhere('.amountHt <= :amountHtMax')
->setParameter('amountHtMax', $value['max'])
;
}
} elseif ('dateRange' === $name) {
if (null !== $value['min']) {
$this
->andWhere('.date >= :dateMin')
->setParameter('dateMin', $value['min'])
;
}
if (null !== $value['max']) {
$value['max']->add(new \DateInterval('PT'.(3600 * 24).'S'));
$this
->andWhere('.date <= :dateMax')
->setParameter('dateMax', $value['max'])
;
}
}
}
}