src/Form/PieceSearchType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Client;
  4. use App\Entity\Piece;
  5. use App\Entity\User;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\Extension\Core\Type\DateType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Form\Extension\Core\Type\TextType;
  11. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  12. use Doctrine\ORM\EntityRepository;
  13. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  14. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  15. class PieceSearchType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options)
  18.     {
  19.         $responsable=$options['responsable'];
  20.         $piece=new Piece();
  21.         if($responsable->isSuperAdmin()) {
  22.             $builder->add('user'EntityType::class, [
  23.                 'class' => User::class,
  24.                 'query_builder' => function (EntityRepository $er) {
  25.                     return $er->createQueryBuilder('r')
  26.                         ->orderBy('r.firstName''ASC')
  27.                         ->orderBy('r.lastName''ASC');
  28.                 },
  29.                 'choice_label' => 'nomComplet',
  30.                 'placeholder' => 'Collaborateur',
  31.                 'label' => 'Collaborateur',
  32.                 'required' => false
  33.             ]);
  34.         }
  35.         $builder
  36.             ->add('code'TextType::class, [
  37.                 "label" => "Code",
  38.                 "required" => false,
  39.                 'attr' => [
  40.                     'autocomplete' => 'off',
  41.                     'placeholder' => 'Code']
  42.             ])
  43.             ->add('client'EntityType::class, [
  44.                 'class' => Client::class,
  45.                 'query_builder' => function (EntityRepository $er)use($responsable) {
  46.                     if($responsable->isSuperAdmin()) {
  47.                         return $er->createQueryBuilder('r')
  48.                             ->orderBy('r.firstName''ASC')
  49.                             ->addOrderBy('r.lastName''ASC');
  50.                     }else{
  51.                         return $er->createQueryBuilder('r')
  52.                             ->andWhere('r.user = :user')
  53.                             ->setParameter('user',$responsable)
  54.                             ->orderBy('r.firstName''ASC')
  55.                             ->addOrderBy('r.lastName''ASC');
  56.                     }
  57.                 },
  58.                 'choice_label' => 'nomComplet',
  59.                 'placeholder' => 'Client',
  60.                 'label' => 'Client',
  61.                 'required' => false,
  62.             ])
  63.             ->add('client'EntityType::class, [
  64.                 'class' => Client::class,
  65.                 'query_builder' => function (EntityRepository $er)use($responsable) {
  66.                     if($responsable->isSuperAdmin()) {
  67.                         return $er->createQueryBuilder('r')
  68.                             ->orderBy('r.firstName''ASC')
  69.                             ->addOrderBy('r.lastName''ASC');
  70.                     }else{
  71.                         return $er->createQueryBuilder('r')
  72.                             ->andWhere('r.user = :user')
  73.                             ->setParameter('user',$responsable)
  74.                             ->orderBy('r.firstName''ASC')
  75.                             ->addOrderBy('r.lastName''ASC');
  76.                     }
  77.                 },
  78.                 'choice_label' => 'nomComplet',
  79.                 'placeholder' => 'Client',
  80.                 'label' => 'Client',
  81.                 'required' => false,
  82.             ])
  83.             ->add('dateDu'DateType::class, [
  84.                 "label" => "Date Du",
  85.                 "required" => false,
  86.                 'empty_data'=>'',
  87.                 'widget' => 'single_text',
  88.                 'attr' => [
  89.                     'autocomplete' => 'off',
  90.                     'placeholder' => "jj/mm/aaaa",
  91.                 ]
  92.             ])
  93.             ->add('dateAu'DateType::class, [
  94.                 "label" => "Date Au",
  95.                 "required" => false,
  96.                 'empty_data'=>'',
  97.                 'widget' => 'single_text',
  98.                 'attr' => [
  99.                     'autocomplete' => 'off',
  100.                     'placeholder' => "jj/mm/aaaa",
  101.                 ]
  102.             ])
  103.             ->add('amountHTMin'TextType::class, [
  104.                 "label" => "Montant HT min",
  105.                 "required" => false,
  106.                 'attr' => [
  107.                     'autocomplete' => 'off',
  108.                     'placeholder' => 'Montant HT min']
  109.             ])
  110.             ->add('amountHTMax'TextType::class, [
  111.                 "label" => "Montant HT max",
  112.                 "required" => false,
  113.                 'attr' => [
  114.                     'autocomplete' => 'off',
  115.                     'placeholder' => 'Montant HT max']
  116.             ])
  117.             ->add('amountTVAMin'TextType::class, [
  118.                 "label" => "Montant TVA min",
  119.                 "required" => false,
  120.                 'attr' => [
  121.                     'autocomplete' => 'off',
  122.                     'placeholder' => 'Montant TVA min']
  123.             ])
  124.             ->add('amountTVAMax'TextType::class, [
  125.                 "label" => "Montant TVA max",
  126.                 "required" => false,
  127.                 'attr' => [
  128.                     'autocomplete' => 'off',
  129.                     'placeholder' => 'Montant TVA max']
  130.             ])
  131.             ->add('amountDiscountMin'TextType::class, [
  132.                 "label" => "Montant remise min",
  133.                 "required" => false,
  134.                 'attr' => [
  135.                     'autocomplete' => 'off',
  136.                     'placeholder' => 'Montant remise min']
  137.             ])
  138.             ->add('amountDiscountMax'TextType::class, [
  139.                 "label" => "Montant remise max",
  140.                 "required" => false,
  141.                 'attr' => [
  142.                     'autocomplete' => 'off',
  143.                     'placeholder' => 'Montant remise max']
  144.             ])
  145.             ->add('amountTTCMin'TextType::class, [
  146.                 "label" => "Montant TTC min",
  147.                 "required" => false,
  148.                 'attr' => [
  149.                     'autocomplete' => 'off',
  150.                     'placeholder' => 'Montant TTC min']
  151.             ])
  152.             ->add('amountTTCMax'TextType::class, [
  153.                 "label" => "Montant TTC max",
  154.                 "required" => false,
  155.                 'attr' => [
  156.                     'autocomplete' => 'off',
  157.                     'placeholder' => 'Montant TTC max']
  158.             ])
  159.             ->add('discountMin'TextType::class, [
  160.                 "label" => "Remise min",
  161.                 "required" => false,
  162.                 'attr' => [
  163.                     'autocomplete' => 'off',
  164.                     'placeholder' => 'Remise min']
  165.             ])
  166.             ->add('discountMax'TextType::class, [
  167.                 "label" => "Remise max",
  168.                 "required" => false,
  169.                 'attr' => [
  170.                     'autocomplete' => 'off',
  171.                     'placeholder' => 'Remise max']
  172.             ])
  173.             ->add('soldeMin'TextType::class, [
  174.                 "label" => "Solde min",
  175.                 "required" => false,
  176.                 'attr' => [
  177.                     'autocomplete' => 'off',
  178.                     'placeholder' => 'Solde min']
  179.             ])
  180.             ->add('soldeMax'TextType::class, [
  181.                 "label" => "Solde max",
  182.                 "required" => false,
  183.                 'attr' => [
  184.                     'autocomplete' => 'off',
  185.                     'placeholder' => 'Solde max']
  186.             ])
  187.         ;
  188.     }
  189.     public function configureOptions(OptionsResolver $resolver)
  190.     {
  191.         $resolver->setDefaults([
  192.             'responsable'=>null
  193.         ]);
  194.     }
  195. }