src/Form/ExpensiveType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Expensive;
  4. use App\Entity\Tiers;
  5. use App\Entity\categorieDepense;
  6. use Symfony\Component\Form\AbstractType;
  7. use Symfony\Component\Form\FormBuilderInterface;
  8. use Symfony\Component\OptionsResolver\OptionsResolver;
  9. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  10. use Symfony\Component\Form\Extension\Core\Type\DateType;
  11. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  12. use Doctrine\ORM\EntityRepository;
  13. class ExpensiveType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $boutique $options['boutique'];
  18.         $builder
  19.         
  20.             ->add('laDate',  DateType::class, [
  21.                 'widget' => 'single_text',
  22.                 'label' => 'admin.la_date',
  23.                  'attr' => [
  24.                 'class' => 'input-xs form-control',
  25.             ]])
  26.             ->add('piece',  null, [ 
  27.                 'label' => 'admin.expensives.piece',
  28.                  'attr' => [
  29.                 'class' => 'input-xs form-control',
  30.             ]])
  31.             
  32.             ->add('tiers'EntityType::class, [
  33.                 'attr' => [
  34.                     'class' => 'form-select'
  35.                 ],
  36.                 // looks for choices from this entity
  37.                 'class' => Tiers::class,
  38.                 'label' => 'admin.third.label',
  39.                 'placeholder' =>'admin.third.choisir_un_tiers',
  40.                 
  41.                 
  42.                 'query_builder' => function (EntityRepository $er) use($boutique){
  43.                     return $er->createQueryBuilder('t')
  44.                         ->leftJoin ('t.boutique''b')
  45.                         ->addSelect('b')
  46.                         ->where('b.id =:boutique')
  47.                         ->setParameters(
  48.                             array('boutique' => $boutique)
  49.                         )
  50.                         ->orderBy('t.nom''ASC');
  51.         
  52.                     },
  53.                 // uses the User.username property as the visible option string
  54.                 'choice_label' => 'nom',
  55.                 // used to render a select box, check boxes or radios
  56.                 // 'multiple' => true,
  57.                 // 'expanded' => true,
  58.             ])
  59.              ->add('categorieDepense'EntityType::class, [
  60.                 'attr' => [
  61.                     'class' => 'form-select'
  62.                 ],
  63.                 // looks for choices from this entity
  64.                 'class' => CategorieDepense::class,
  65.                 'label' => 'admin.categorie_depense.categorie_depense_ou_poste_budgetaire',
  66.                 'placeholder' =>'admin.categorie_depense.categorie_depense',
  67.                 
  68.                 
  69.                 'query_builder' => function (EntityRepository $er) use($boutique){
  70.                     return $er->createQueryBuilder('t')
  71.                         ->leftJoin ('t.boutique''b')
  72.                         ->addSelect('b')
  73.                         ->where('b.id =:boutique')
  74.                         ->setParameters(
  75.                             array('boutique' => $boutique)
  76.                         )
  77.                         ->orderBy('t.nom''ASC');
  78.         
  79.                     },
  80.                 // uses the User.username property as the visible option string
  81.                 'choice_label' => 'nom',
  82.                 // used to render a select box, check boxes or radios
  83.                 // 'multiple' => true,
  84.                 // 'expanded' => true,
  85.             ])
  86.             ->add('montant'NumberType::class, ['label' => 'admin.expensives.montant''attr' => [
  87.                 'class' => 'form-control',
  88.                 'step' => '0.01'
  89.             ],
  90.             'html5' => true,
  91.         
  92.             ])
  93.             ->add('detail'null, ['label' => 'admin.detail''attr' => [
  94.                 'class' => 'form-control',
  95.             ]])
  96.         ;
  97.     }
  98.     public function configureOptions(OptionsResolver $resolver)
  99.     {
  100.         $resolver->setDefaults([
  101.             'data_class' => Expensive::class,
  102.             'boutique' => null
  103.         ]);
  104.     }
  105. }