<?php
namespace App\Form;
use App\Entity\Adresse;
use App\Entity\ChargeFormation;
use App\Entity\Delegation;
use App\Entity\Entreprise;
use App\Entity\Gouvernorat;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Positive;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\LessThan;
use Symfony\Component\Form\Extension\Core\Type\NumberType; // Import the NumberType class
class EntrepriseType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, ['label' => 'inscription.entreprise.email', 'required' => true, 'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],], array('attr' => array('class' => 'form-control left-line')))
->add('username', TextType::class, ['label' => 'inscription.entreprise.username', 'required' => true, 'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],], array('attr' => array('class' => 'form-control left-line')))
->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'label' => 'inscription.entreprise.password',
'mapped' => false,
'attr' => ['autocomplete' => 'new-password', 'class' => 'form-style password1'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
->add('confirmpassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'label' => 'inscription.entreprise.confirm_pass',
'mapped' => false,
'attr' => ['autocomplete' => 'new-password', 'class' => 'form-style password2'],
'constraints' => [
new Length([
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 4096,
]),
],
])
->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')))
// ->add('matricule_fiscal', TextType::class, [
// 'label' => 'Matricule fiscal',
// ])
->add('statut', ChoiceType::class, [
'required' => true, 'label' => 'inscription.entreprise.status',
'choices' => [
'inscription.entreprise.public' => 'Publique',
'inscription.entreprise.private' => 'Privée',
],
'label_attr' => ['class' => 'required'],
'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],
])
->add('Raison_sociale', TextType::class, ['label' => 'inscription.entreprise.raison_sociale'], array('attr' => array('class' => 'form-control left-line')))
->add('nom_commercial', TextType::class, ['label' => 'inscription.entreprise.commercial_name'], array('attr' => array('class' => 'form-control left-line')))
// ->add('gouvernorat', EntityType::class, array(
// 'class'=>Gouvernorat::class,
// 'label' => 'Gouvernorat*',
// 'choice_label'=>'libelle',
// 'multiple'=>false,
// ))
// ->add('delegation', EntityType::class, array(
// 'class'=>Delegation::class,
// 'label' => 'Délégation*',
// 'choice_label'=>'libelle',
// 'multiple'=>false,
// ))
// ->add('Localite', TextType::class, [
// 'label' => 'Localité*',
// 'mapped' => false,
// 'required' => false
// ])
->add('adresseSiegeSocial', TextType::class, [
'label' => 'inscription.entreprise.adresse_siege',
])
->add('adresseSiteProduction', TextType::class, [
'label' => 'inscription.entreprise.adresse_prod',
])
// ->add('code_postale', TextType::class, [
// 'label' => 'Code postal *',
// 'mapped' => false,
// 'attr'=> ['min' => 0, 'pattern'=>'[0-9]+', 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
// ])
->add('tel', TextType::class, [
'label' => 'inscription.entreprise.tel',
'required' => true,
'attr'=> ['min' => 0, 'pattern'=>'\d{8}', 'maxlength' => 8, 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],], array('attr' => array('class' => 'form-control left-line')))
->add('fax', TextType::class, [
'label' => 'inscription.entreprise.fax', 'attr' => ['min' => 0, 'pattern' => '\d{8}', 'maxlength' => 8, 'oninput' => "this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"],
], array('attr' => array('class' => 'form-control left-line')))
->add('nom_prenom_premier_responsable', TextType::class, ['label' => 'inscription.entreprise.name_responsable'], array('attr' => array('class' => 'form-control left-line')))
->add('cnsscnrps', ChoiceType::class, [
'label' => 'inscription.entreprise.CNSS/CNRPS',
'choices' => [
'CNSS' => 'CNSS',
'CNRPS' => 'CNRPS',
],
'placeholder' => 'inscription.entreprise.select',
])
->add('code_cnss', TextType::class, ['label' => 'inscription.entreprise.Code_CNSS_Code_CNRPS'
, 'attr'=> [ 'pattern'=>'[0-9]+', 'oninput'=>"this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');"]
]) ->add('secteur', TextType::class, ['label' => 'inscription.entreprise.activity_sector'], array('attr' => array('class' => 'form-control left-line')))
->add('branche', TextType::class, ['label' => 'inscription.entreprise.activity_branch'], array('attr' => array('class' => 'form-control left-line')))
->add('Produits_services_rendus', TextType::class, ['label' => 'inscription.entreprise.product'], array('attr' => array('class' => 'form-control left-line')))
->add('exportatrice', ChoiceType::class, [
'required' => true, 'label' => 'inscription.entreprise.exportatrice',
'choices' => [
'inscription.entreprise.totalement' => 'Totalement',
'inscription.entreprise.part' => 'Partiellement',
'inscription.entreprise.no' => 'Non',
],
'label_attr' => ['class' => 'required'],
'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],
])
->add('off_shore', ChoiceType::class, [
'required' => true, 'label' => 'inscription.entreprise.off_shore',
'choices' => [
'inscription.entreprise.yes' => 'Oui',
'inscription.entreprise.no' => 'Non',
],
'label_attr' => ['class' => 'required'],
'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],
])
->add('taux_TFP', ChoiceType::class, [
'required' => true, 'label' => 'inscription.entreprise.taux_TFP',
'choices' => [
'0%' => '0%',
'1%' => '1%',
'2%' => '2%',
],
'label_attr' => ['class' => 'required'],
'constraints' => [
new NotBlank([
'message' => 'Ce champs est obligatoire',
]),
],
])
->add('montant', NumberType::class, [
'label' => 'inscription.entreprise.amount_TFP',
"required" => false,
'attr' => [
'min' => 0,
'pattern'=>'[0-9,.]+',
'oninput'=>"this.value = this.value.replace(/[^0-9]/g, '.').replace(/(\..*)\./g, '$1');",
'inputmode' => "decimal",
'step' => '0.01',
],
])
->add('regime_travail', ChoiceType::class, [
'required' => true,
'label' => 'inscription.entreprise.work_regime',
'choices' => [
'inscription.entreprise.40h' => '40h',
'inscription.entreprise.48h' => '48h',
],
'label_attr' => [
'class' => 'required',
'id' => 'regime_travail_label', // Add the 'id' attribute
],
'constraints' => [
new NotBlank([
'message' => 'Ce champ est obligatoire',
]),
],
])
// ->add('TFP', TextType::class, ['label' => 'TFP*'], array('attr' => array('class' => 'form-control left-line')))
->add('adresses', CollectionType::class, [
'entry_type' => AdresseTypeEntreprise::class,
'allow_add' => true,
'allow_delete' => true,
'form_attr' => 'ok',
'label' => false,
'auto_initialize' => false,
'block_name' => null,
'compound' => true,
'by_reference' => false,
"row_attr" => ['class' => 'form_adresse'],
])
->add('charge_formations', CollectionType::class, array(
'entry_type' => ChargeFormationType::class,
'allow_add' => true,
'allow_delete' => true,
'form_attr' => 'ok',
'label' => false,
'auto_initialize' => false,
'block_name' => null,
'compound' => true,
'by_reference' => false,
'label_attr' => ['class' => 'charge_formations'],
"row_attr" => ['class' => 'form_charge_formation']
))
->add('agreeTerms', CheckboxType::class, [
'label' => 'inscription.entreprise.terms',
'label_html' => true,
'mapped' => false,
'data_class' => null,
"row_attr" => ['class' => 'accepter_cond'], 'attr' => array('id' => 'accepter_cond'),
'constraints' => [
new IsTrue([
'message' => 'Vous devez accepter nos conditions.',
]),
],
])
->add('Enregistrer', SubmitType::class, [
'label' => 'inscription.save',
'attr' => ['class' => 'save'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Entreprise::class,
]);
}
}