src/Form/EntrepriseType.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Adresse;
  4. use App\Entity\ChargeFormation;
  5. use App\Entity\Delegation;
  6. use App\Entity\Entreprise;
  7. use App\Entity\Gouvernorat;
  8. use Symfony\Component\Form\AbstractType;
  9. use Symfony\Component\Form\FormBuilderInterface;
  10. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  11. use Symfony\Component\Validator\Constraints\IsTrue;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. use Symfony\Component\Validator\Constraints\Positive;
  15. use Symfony\Component\OptionsResolver\OptionsResolver;
  16. use Symfony\Component\Form\Extension\Core\Type\TextType;
  17. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  18. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  19. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  20. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  21. use Symfony\Component\Form\Extension\Core\Type\IntegerType;
  22. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  23. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  24. use Symfony\Component\Validator\Constraints\GreaterThan;
  25. use Symfony\Component\Validator\Constraints\LessThan;
  26. use Symfony\Component\Form\Extension\Core\Type\NumberType;  // Import the NumberType class
  27. class EntrepriseType extends AbstractType
  28. {
  29.     public function buildForm(FormBuilderInterface $builder, array $options): void
  30.     {
  31.         $builder
  32.             ->add('email'EmailType::class, ['label' => 'inscription.entreprise.email''required' => true'constraints' => [
  33.                 new NotBlank([
  34.                     'message' => 'Ce champs est obligatoire',
  35.                 ]),
  36.             ],], array('attr' => array('class' => 'form-control left-line')))
  37.             ->add('username'TextType::class, ['label' => 'inscription.entreprise.username''required' => true'constraints' => [
  38.                 new NotBlank([
  39.                     'message' => 'Ce champs est obligatoire',
  40.                 ]),
  41.             ],], array('attr' => array('class' => 'form-control left-line')))
  42.             ->add('plainPassword'PasswordType::class, [
  43.                 // instead of being set onto the object directly,
  44.                 // this is read and encoded in the controller
  45.                 'label' => 'inscription.entreprise.password',
  46.                 'mapped' => false,
  47.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password1'],
  48.                 'constraints' => [
  49.                     new NotBlank([
  50.                         'message' => 'Please enter a password',
  51.                     ]),
  52.                     new Length([
  53.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  54.                         // max length allowed by Symfony for security reasons
  55.                         'max' => 4096,
  56.                     ]),
  57.                 ],
  58.             ])
  59.             ->add('confirmpassword'PasswordType::class, [
  60.                 // instead of being set onto the object directly,
  61.                 // this is read and encoded in the controller
  62.                 'label' => 'inscription.entreprise.confirm_pass',
  63.                 'mapped' => false,
  64.                 'attr' => ['autocomplete' => 'new-password''class' => 'form-style password2'],
  65.                 'constraints' => [
  66.                     new Length([
  67.                         'minMessage' => 'Your password should be at least {{ limit }} characters',
  68.                         // max length allowed by Symfony for security reasons
  69.                         'max' => 4096,
  70.                     ]),
  71.                 ],
  72.             ])
  73.             ->add('matricule_fiscal'TextType::class, ['label' => 'inscription.entreprise.matricule_fiscal','attr' =>['pattern' => '^[0-9]{7}[A-Za-z]{3}[0-9]{3}$']], array('attr' => array('class' => 'form-control left-line')))
  74.             // ->add('matricule_fiscal', TextType::class, [
  75.             //     'label' => 'Matricule fiscal',
  76.             // ])
  77.             ->add('statut'ChoiceType::class, [
  78.                 'required' => true'label' => 'inscription.entreprise.status',
  79.                 'choices'  => [
  80.                     'inscription.entreprise.public' => 'Publique',
  81.                     'inscription.entreprise.private' => 'Privée',
  82.                 ],
  83.                 'label_attr' => ['class' => 'required'],
  84.                 'constraints' => [
  85.                     new NotBlank([
  86.                         'message' => 'Ce champs est obligatoire',
  87.                     ]),
  88.                 ],
  89.             ])
  90.             ->add('Raison_sociale'TextType::class, ['label' => 'inscription.entreprise.raison_sociale'], array('attr' => array('class' => 'form-control left-line')))
  91.             ->add('nom_commercial'TextType::class, ['label' => 'inscription.entreprise.commercial_name'], array('attr' => array('class' => 'form-control left-line')))
  92.             //    ->add('gouvernorat', EntityType::class, array(
  93.             //         'class'=>Gouvernorat::class,
  94.             //         'label' => 'Gouvernorat*',
  95.             //         'choice_label'=>'libelle',
  96.             //         'multiple'=>false,
  97.             //     ))
  98.             // ->add('delegation', EntityType::class, array(
  99.             //     'class'=>Delegation::class,
  100.             //     'label' => 'Délégation*',
  101.             //     'choice_label'=>'libelle',
  102.             //     'multiple'=>false,
  103.             // ))
  104.             // ->add('Localite', TextType::class, [
  105.             //     'label' => 'Localité*',
  106.             //     'mapped' => false,
  107.             //     'required' => false
  108.             // ])
  109.             ->add('adresseSiegeSocial'TextType::class, [
  110.                 'label' => 'inscription.entreprise.adresse_siege',
  111.             ])
  112.             ->add('adresseSiteProduction'TextType::class, [
  113.                 'label' => 'inscription.entreprise.adresse_prod',
  114.             ])
  115.             // ->add('code_postale', TextType::class, [
  116.             //     'label' => 'Code postal *',
  117.             //     'mapped' => false,
  118.             //     'attr'=> ['min' => 0, 'pattern'=>'[0-9]+', 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  119.             // ])
  120.             ->add('tel'TextType::class, [
  121.                 'label' => 'inscription.entreprise.tel',
  122.                 'required' => true,
  123.                 'attr'=> ['min' => 0'pattern'=>'\d{8}''maxlength' => 8'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  124.                  'constraints' => [
  125.                 new NotBlank([
  126.                     'message' => 'Ce champs est obligatoire',
  127.                 ]),
  128.             ],], array('attr' => array('class' => 'form-control left-line')))
  129.             ->add('fax'TextType::class, [ 
  130.                 'label' => 'inscription.entreprise.fax',            'attr' => ['min' => 0'pattern' => '\d{8}',  'maxlength' => 8'oninput' => "this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
  131.             ], array('attr' => array('class' => 'form-control left-line')))
  132.             ->add('nom_prenom_premier_responsable'TextType::class, ['label' => 'inscription.entreprise.name_responsable'], array('attr' => array('class' => 'form-control left-line')))
  133.             ->add('cnsscnrps'ChoiceType::class, [
  134.                 'label' => 'inscription.entreprise.CNSS/CNRPS',
  135.                 'choices' => [
  136.                     'CNSS' => 'CNSS',
  137.                     'CNRPS' => 'CNRPS',
  138.                 
  139.                 ],
  140.                 'placeholder' => 'inscription.entreprise.select',
  141.                 
  142.             ])
  143.             ->add('code_cnss'TextType::class, ['label' => 'inscription.entreprise.Code_CNSS_Code_CNRPS' 
  144.             ,  'attr'=> [ 'pattern'=>'[0-9]+''oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"]
  145.             ])            ->add('secteur'TextType::class, ['label' => 'inscription.entreprise.activity_sector'], array('attr' => array('class' => 'form-control left-line')))
  146.             ->add('branche'TextType::class, ['label' => 'inscription.entreprise.activity_branch'], array('attr' => array('class' => 'form-control left-line')))
  147.             ->add('Produits_services_rendus'TextType::class, ['label' => 'inscription.entreprise.product'], array('attr' => array('class' => 'form-control left-line')))
  148.             ->add('exportatrice'ChoiceType::class, [
  149.                 'required' => true'label' => 'inscription.entreprise.exportatrice',
  150.                 'choices'  => [
  151.                     'inscription.entreprise.totalement' => 'Totalement',
  152.                     'inscription.entreprise.part' => 'Partiellement',
  153.                     'inscription.entreprise.no' => 'Non',
  154.                 ],
  155.                 'label_attr' => ['class' => 'required'],
  156.                 'constraints' => [
  157.                     new NotBlank([
  158.                         'message' => 'Ce champs est obligatoire',
  159.                     ]),
  160.                 ],
  161.             ])
  162.             ->add('off_shore'ChoiceType::class, [
  163.                 'required' => true'label' => 'inscription.entreprise.off_shore',
  164.                 'choices'  => [
  165.                     'inscription.entreprise.yes' => 'Oui',
  166.                     'inscription.entreprise.no' => 'Non',
  167.                 ],
  168.                 'label_attr' => ['class' => 'required'],
  169.                 'constraints' => [
  170.                     new NotBlank([
  171.                         'message' => 'Ce champs est obligatoire',
  172.                     ]),
  173.                 ],
  174.             ])
  175.             ->add('taux_TFP'ChoiceType::class, [
  176.                 'required' => true'label' => 'inscription.entreprise.taux_TFP',
  177.                 'choices'  => [
  178.                     '0%' => '0%',
  179.                     '1%' => '1%',
  180.                     '2%' => '2%',
  181.                 ],
  182.                 'label_attr' => ['class' => 'required'],
  183.                 'constraints' => [
  184.                     new NotBlank([
  185.                         'message' => 'Ce champs est obligatoire',
  186.                     ]),
  187.                 ],
  188.             ])
  189.             ->add('montant'NumberType::class, [
  190.                 'label' => 'inscription.entreprise.amount_TFP',
  191.                 "required" => false,
  192.                 'attr' => [
  193.                     'min' => 0,
  194.                     'pattern'=>'[0-9,.]+',
  195.                     'oninput'=>"this.value = this.value.replace(/[^0-9]/g, '.').replace(/(\..*)\./g, '$1');",
  196.                     'inputmode' => "decimal",
  197.                     'step' => '0.01',
  198.                 ],
  199.             ])
  200.             ->add('regime_travail'ChoiceType::class, [
  201.                 'required' => true,
  202.                 'label' => 'inscription.entreprise.work_regime',
  203.                 'choices'  => [
  204.                     'inscription.entreprise.40h' => '40h',
  205.                     'inscription.entreprise.48h' => '48h',
  206.                 ],
  207.                 'label_attr' => [
  208.                     'class' => 'required',
  209.                     'id' => 'regime_travail_label'// Add the 'id' attribute
  210.                 ],
  211.                 'constraints' => [
  212.                     new NotBlank([
  213.                         'message' => 'Ce champ est obligatoire',
  214.                     ]),
  215.                 ],
  216.             ])
  217.             
  218.             // ->add('TFP', TextType::class,  ['label' => 'TFP*'], array('attr' => array('class' => 'form-control left-line')))
  219.     
  220.             ->add('adresses'CollectionType::class, [
  221.                 'entry_type' => AdresseTypeEntreprise::class,
  222.                 'allow_add' => true,
  223.                 'allow_delete' => true,
  224.                 'form_attr' => 'ok',
  225.                 'label' => false,
  226.                 'auto_initialize' => false,
  227.                 'block_name' => null,
  228.                 'compound' => true,
  229.                 'by_reference' => false,
  230.                 "row_attr" => ['class' => 'form_adresse'],
  231.             ])
  232.             ->add('charge_formations'CollectionType::class, array(
  233.                 'entry_type' => ChargeFormationType::class,
  234.                 'allow_add' => true,
  235.                 'allow_delete' => true,
  236.                 'form_attr' => 'ok',
  237.                 'label' => false,
  238.                 'auto_initialize' => false,
  239.                 'block_name' => null,
  240.                 'compound' => true,
  241.                 'by_reference' => false,
  242.                 'label_attr' => ['class' => 'charge_formations'],
  243.                 "row_attr" => ['class' => 'form_charge_formation']
  244.             ))
  245.             ->add('agreeTerms'CheckboxType::class, [
  246.                 'label' => 'inscription.entreprise.terms',
  247.                 'label_html' => true,
  248.                 'mapped' => false,
  249.                 'data_class' => null,
  250.                 "row_attr" => ['class' => 'accepter_cond'], 'attr' => array('id' => 'accepter_cond'),
  251.                 'constraints' => [
  252.                     new IsTrue([
  253.                         'message' => 'Vous devez accepter nos conditions.',
  254.                     ]),
  255.                 ],
  256.             ])
  257.             ->add('Enregistrer'SubmitType::class, [
  258.                 'label' => 'inscription.save',
  259.                 'attr' => ['class' => 'save'],
  260.             ]);
  261.     }
  262.     public function configureOptions(OptionsResolver $resolver): void
  263.     {
  264.         $resolver->setDefaults([
  265.             'data_class' => Entreprise::class,
  266.         ]);
  267.     }
  268. }