add bill filters
This commit is contained in:
parent
688fdd49ee
commit
ffca1b4dc4
54
src/Form/AmountRangeType.php
Normal file
54
src/Form/AmountRangeType.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class AmountRangeType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('min', NumberType::class, [
|
||||
'label' => 'Min',
|
||||
'html5' => true,
|
||||
'scale' => 2,
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'step' => 0.01,
|
||||
],
|
||||
'row_attr' => [
|
||||
'class' => 'col-md-6 pr-1',
|
||||
],
|
||||
'label_attr' => [
|
||||
'class' => 'font-weight-normal',
|
||||
],
|
||||
])
|
||||
->add('max', NumberType::class, [
|
||||
'label' => 'Max',
|
||||
'html5' => true,
|
||||
'required' => false,
|
||||
'scale' => 2,
|
||||
'attr' => [
|
||||
'step' => 0.01,
|
||||
],
|
||||
'row_attr' => [
|
||||
'class' => 'col-md-6 pl-1',
|
||||
],
|
||||
'label_attr' => [
|
||||
'class' => 'font-weight-normal',
|
||||
],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => null,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -2,20 +2,15 @@
|
|||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Bill;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\File;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use App\Entity\BillCategory;
|
||||
use App\Entity\BillPeer;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use App\Entity\BillVendor;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use App\Entity\BillCategory;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BillFilterType extends AbstractType
|
||||
{
|
||||
|
@ -60,6 +55,18 @@ class BillFilterType extends AbstractType
|
|||
'choices' => BillPeer::choices(),
|
||||
'required' => false,
|
||||
])
|
||||
->add('amountTtcRange', AmountRangeType::class, [
|
||||
'label' => 'Montant TTC',
|
||||
'attr' => [
|
||||
'class' => 'row',
|
||||
],
|
||||
])
|
||||
->add('amountHtRange', AmountRangeType::class, [
|
||||
'label' => 'Montant HT',
|
||||
'attr' => [
|
||||
'class' => 'row',
|
||||
],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,9 +17,37 @@ class BillRepositoryQuery extends RepositoryQuery
|
|||
{
|
||||
if ('vendor' === $name && null !== $value) {
|
||||
$this
|
||||
->where('.vendor = :vendor')
|
||||
->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 <= :amountHtMin')
|
||||
->setParameter('amountHtMax', $value['max'])
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue