src/Form/EntrepriseType.php line 32

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