src/Form/Client/BillingInfosType.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Form\Client;
  3. use App\Entity\Client;
  4. use App\Entity\Company;
  5. use App\Entity\Contact;
  6. use App\Entity\Contract;
  7. use App\Entity\Product;
  8. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  9. use Symfony\Component\Form\AbstractType;
  10. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  11. use Symfony\Component\Form\Extension\Core\Type\DateType;
  12. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  13. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  14. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  15. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Form\FormBuilderInterface;
  18. use Symfony\Component\Form\FormEvent;
  19. use Symfony\Component\Form\FormEvents;
  20. use Symfony\Component\OptionsResolver\OptionsResolver;
  21. class BillingInfosType extends AbstractType
  22. {
  23.     public function buildForm(FormBuilderInterface $builder, array $options)
  24.     {
  25.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
  26.             /* @var Client\BillingInfos $billingDatas */
  27.             $billingDatas $event->getData() ;
  28.             $form $event->getForm();
  29.             $form->add('billingMode'ChoiceType::class, [
  30.                 'label' => 'Type de facturation',
  31.                 'data' => $billingDatas && $billingDatas->getBillingMode() ?  $billingDatas->getBillingMode() : Client\BillingInfos::BILLING_MODE_TTC,
  32.                 'required' => false,
  33.                 'placeholder' => 'Type de facturation',
  34.                 'choices'=> [
  35.                     'TTC' => Client\BillingInfos::BILLING_MODE_TTC,
  36.                     'HT + TVA' => Client\BillingInfos::BILLING_MODE_HT,
  37.                 ]
  38.             ]);
  39.             $form->add('company',EntityType::class, [
  40.                 'label' => 'Société facturante',
  41.                 'class' => Company::class,
  42.                 'attr'=> [
  43.                     'placeholder' => 'Selectionnez une société',
  44.                 ],
  45.                 'data' => $billingDatas && $billingDatas->getCompany() ?  $billingDatas->getCompany() : $options['defaultCompany'],
  46.                 'label_attr' => array('class' => ''),
  47.             ]);
  48.         });
  49.         $builder
  50.             ->add('email',TextType::class, [
  51.                 'label' => 'Mail facturation',
  52.                 'attr'=> [
  53.                     'placeholder' => 'Entrer un email',
  54.                 ],
  55.                 'required' => false,
  56.                 'label_attr' => array('class' => ''),
  57.             ])
  58.             ->add('phone',TextType::class, [
  59.                 'label' => 'Tel facturation',
  60.                 'attr'=> [
  61.                     'placeholder' => 'Entrer un téléphone',
  62.                 ],
  63.                 'required' => false,
  64.                 'label_attr' => array('class' => ''),
  65.             ])
  66.             ->add('discount',IntegerType::class, [
  67.                 'label' => 'Remise en %',
  68.                 'attr'=> [
  69.                     'placeholder' => 'Entrer une remise',
  70.                 ],
  71.                 //  'data' => 0,
  72.                 'required' => false,
  73.                 'label_attr' => array('class' => ''),
  74.             ])
  75.             ->add('sendMode'ChoiceType::class, [
  76.                 'label' => 'Mode envoi facture',
  77.                 'required' => false,
  78.                 'placeholder' => 'Mode envoi facture',
  79.                 'empty_data' => Client\BillingInfos::SEND_MODE_EMAIL,
  80.                 'choices'=> [
  81.                     'Email' => Client\BillingInfos::SEND_MODE_EMAIL,
  82.                     'Courrier' => Client\BillingInfos::SEND_MODE_COURRIER,
  83.                 ]
  84.             ])
  85.             // ->add('esthetique', ChoiceType::class, [
  86.             //     'label' => 'Esthétique FS',
  87.             //     'required' => false,
  88.             //     'placeholder' => null,
  89.             //     'choices'=> [
  90.             //         'Non' => false,
  91.             //         'Oui' => true,
  92.             //     ]
  93.             // ])
  94.             ->add('payMode'ChoiceType::class, [
  95.                 'label' => 'Mode de règlement',
  96.                 'required' => false,
  97.                 'placeholder' => 'Mode de règlement',
  98.                 'choices'=> [
  99.                     'Prélèvement SEPA' => Client\BillingInfos::PAY_MODE_SEPA,
  100.                     'CB' => Client\BillingInfos::PAY_MODE_CB,
  101.                     'VIREMENT' => Client\BillingInfos::PAY_MODE_VIREMENT,
  102.                     'CHEQUES' => Client\BillingInfos::PAY_MODE_CHEQUES,
  103.                 ]
  104.             ])
  105.             ->add('account',TextType::class, [
  106.                 'label' => 'Compte comptable',
  107.                 'attr'=> [
  108.                     'placeholder' => 'Entrer un compte',
  109.                 ],
  110.                 'required' => false,
  111.                 'label_attr' => array('class' => ''),
  112.             ])
  113.             ->add('bankName',TextType::class, [
  114.                 'label' => 'Nom de la banque',
  115.                 'attr'=> [
  116.                     'placeholder' => 'Entrer un nom de banque',
  117.                     'class' => $options['show_sepa'] ? '''hide hiddenFields'
  118.                 ],
  119.                 'required' => false,
  120.                 'label_attr' => array('class' => $options['show_sepa'] ? '''hide hiddenFields'),
  121.             ])
  122.             ->add('iban',TextType::class, [
  123.                 'label' => 'IBAN',
  124.                 'attr'=> [
  125.                     'placeholder' => 'Entrer un IBAN',
  126.                     'class' => $options['show_sepa'] ? '''hide hiddenFields'
  127.                 ],
  128.                 'required' => false,
  129.                 'label_attr' => array('class' => $options['show_sepa'] ? '''hide hiddenFields'),
  130.             ])
  131.             ->add('bic',TextType::class, [
  132.                 'label' => 'BIC',
  133.                 'attr'=> [
  134.                     'placeholder' => 'Entrer un BIC',
  135.                     'class' => $options['show_sepa'] ? '''hide hiddenFields'
  136.                 ],
  137.                 'required' => false,
  138.                 'label_attr' => array('class' => $options['show_sepa'] ? '''hide hiddenFields'),
  139.             ])
  140.             ->add('rum',TextType::class, [
  141.                 'label' => 'RUM',
  142.                 'attr'=> [
  143.                     'placeholder' => 'Entrer un RUM',
  144.                     'class' => $options['show_sepa'] ? '''hide hiddenFields'
  145.                 ],
  146.                 'required' => false,
  147.                 'label_attr' => array('class' => $options['show_sepa'] ? '''hide hiddenFields'),
  148.             ])
  149.             ->add('dateSignatureMandat',DateType::class, [
  150.                 'label' => 'Date de mandat',
  151.                 'attr'=> [
  152.                     'placeholder' => 'Entrer une date de mandat',
  153.                     'class' => $options['show_sepa'] ? '''hide hiddenFields'
  154.                 ],
  155.                 'required' => false,
  156.                 'label_attr' => array('class' => $options['show_sepa'] ? '''hide hiddenFields'),
  157.             ])
  158.         ;
  159.     }
  160.     public function configureOptions(OptionsResolver $resolver)
  161.     {
  162.         $resolver->setDefaults([
  163.             'data_class' => Client\BillingInfos::class,
  164.             'show_sepa' => false,
  165.             'defaultCompany' => null
  166.         ]);
  167.         $resolver->setAllowedTypes('show_sepa''bool');
  168.     }
  169. }