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,65 +2,72 @@
|
||||||
|
|
||||||
namespace App\Form;
|
namespace App\Form;
|
||||||
|
|
||||||
use App\Entity\Bill;
|
use App\Entity\BillCategory;
|
||||||
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\BillPeer;
|
use App\Entity\BillPeer;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
|
||||||
use App\Entity\BillVendor;
|
use App\Entity\BillVendor;
|
||||||
use Doctrine\ORM\EntityRepository;
|
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
|
class BillFilterType extends AbstractType
|
||||||
{
|
{
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add('reference', null, [
|
->add('reference', null, [
|
||||||
'label' => 'Numéro de facture',
|
'label' => 'Numéro de facture',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
->add('vendor', null, [
|
->add('vendor', null, [
|
||||||
'label' => 'Fournisseur',
|
'label' => 'Fournisseur',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
->add('vendor', EntityType::class, [
|
->add('vendor', EntityType::class, [
|
||||||
'label' => 'Fournisseur',
|
'label' => 'Fournisseur',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'class' => BillVendor::class,
|
'class' => BillVendor::class,
|
||||||
'query_builder' => function (EntityRepository $er) {
|
'query_builder' => function (EntityRepository $er) {
|
||||||
return $er->createQueryBuilder('v')
|
return $er->createQueryBuilder('v')
|
||||||
->orderBy('v.label', 'ASC')
|
->orderBy('v.label', 'ASC')
|
||||||
;
|
;
|
||||||
},
|
},
|
||||||
'attr' => [
|
'attr' => [
|
||||||
'data-jschoice' => '',
|
'data-jschoice' => '',
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
->add('category', EntityType::class, [
|
->add('category', EntityType::class, [
|
||||||
'label' => 'Catégorie',
|
'label' => 'Catégorie',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'class' => BillCategory::class,
|
'class' => BillCategory::class,
|
||||||
'query_builder' => function (EntityRepository $er) {
|
'query_builder' => function (EntityRepository $er) {
|
||||||
return $er->createQueryBuilder('v')
|
return $er->createQueryBuilder('v')
|
||||||
->orderBy('v.label', 'ASC')
|
->orderBy('v.label', 'ASC')
|
||||||
;
|
;
|
||||||
},
|
},
|
||||||
'attr' => [
|
'attr' => [
|
||||||
'data-jschoice' => '',
|
'data-jschoice' => '',
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
->add('status', ChoiceType::class, [
|
->add('status', ChoiceType::class, [
|
||||||
'choices' => BillPeer::choices(),
|
'choices' => BillPeer::choices(),
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
;
|
->add('amountTtcRange', AmountRangeType::class, [
|
||||||
|
'label' => 'Montant TTC',
|
||||||
|
'attr' => [
|
||||||
|
'class' => 'row',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->add('amountHtRange', AmountRangeType::class, [
|
||||||
|
'label' => 'Montant HT',
|
||||||
|
'attr' => [
|
||||||
|
'class' => 'row',
|
||||||
|
],
|
||||||
|
])
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver): void
|
public function configureOptions(OptionsResolver $resolver): void
|
||||||
|
|
|
@ -17,9 +17,37 @@ class BillRepositoryQuery extends RepositoryQuery
|
||||||
{
|
{
|
||||||
if ('vendor' === $name && null !== $value) {
|
if ('vendor' === $name && null !== $value) {
|
||||||
$this
|
$this
|
||||||
->where('.vendor = :vendor')
|
->andWhere('.vendor = :vendor')
|
||||||
->setParameter('vendor', $value)
|
->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