<?php
namespace App\Form\Client;
use App\Entity\Client;
use App\Entity\Company;
use App\Entity\Contact;
use App\Entity\Contract;
use App\Entity\Product;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
class BillingInfosType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
/* @var Client\BillingInfos $billingDatas */
$billingDatas = $event->getData() ;
$form = $event->getForm();
$form->add('billingMode', ChoiceType::class, [
'label' => 'Type de facturation',
'data' => $billingDatas && $billingDatas->getBillingMode() ? $billingDatas->getBillingMode() : Client\BillingInfos::BILLING_MODE_TTC,
'required' => false,
'placeholder' => 'Type de facturation',
'choices'=> [
'TTC' => Client\BillingInfos::BILLING_MODE_TTC,
'HT + TVA' => Client\BillingInfos::BILLING_MODE_HT,
]
]);
$form->add('company',EntityType::class, [
'label' => 'Société facturante',
'class' => Company::class,
'attr'=> [
'placeholder' => 'Selectionnez une société',
],
'data' => $billingDatas && $billingDatas->getCompany() ? $billingDatas->getCompany() : $options['defaultCompany'],
'label_attr' => array('class' => ''),
]);
});
$builder
->add('email',TextType::class, [
'label' => 'Mail facturation',
'attr'=> [
'placeholder' => 'Entrer un email',
],
'required' => false,
'label_attr' => array('class' => ''),
])
->add('phone',TextType::class, [
'label' => 'Tel facturation',
'attr'=> [
'placeholder' => 'Entrer un téléphone',
],
'required' => false,
'label_attr' => array('class' => ''),
])
->add('discount',IntegerType::class, [
'label' => 'Remise en %',
'attr'=> [
'placeholder' => 'Entrer une remise',
],
// 'data' => 0,
'required' => false,
'label_attr' => array('class' => ''),
])
->add('sendMode', ChoiceType::class, [
'label' => 'Mode envoi facture',
'required' => false,
'placeholder' => 'Mode envoi facture',
'empty_data' => Client\BillingInfos::SEND_MODE_EMAIL,
'choices'=> [
'Email' => Client\BillingInfos::SEND_MODE_EMAIL,
'Courrier' => Client\BillingInfos::SEND_MODE_COURRIER,
]
])
// ->add('esthetique', ChoiceType::class, [
// 'label' => 'Esthétique FS',
// 'required' => false,
// 'placeholder' => null,
// 'choices'=> [
// 'Non' => false,
// 'Oui' => true,
// ]
// ])
->add('payMode', ChoiceType::class, [
'label' => 'Mode de règlement',
'required' => false,
'placeholder' => 'Mode de règlement',
'choices'=> [
'Prélèvement SEPA' => Client\BillingInfos::PAY_MODE_SEPA,
'CB' => Client\BillingInfos::PAY_MODE_CB,
'VIREMENT' => Client\BillingInfos::PAY_MODE_VIREMENT,
'CHEQUES' => Client\BillingInfos::PAY_MODE_CHEQUES,
]
])
->add('account',TextType::class, [
'label' => 'Compte comptable',
'attr'=> [
'placeholder' => 'Entrer un compte',
],
'required' => false,
'label_attr' => array('class' => ''),
])
->add('bankName',TextType::class, [
'label' => 'Nom de la banque',
'attr'=> [
'placeholder' => 'Entrer un nom de banque',
'class' => $options['show_sepa'] ? '': 'hide hiddenFields'
],
'required' => false,
'label_attr' => array('class' => $options['show_sepa'] ? '': 'hide hiddenFields'),
])
->add('iban',TextType::class, [
'label' => 'IBAN',
'attr'=> [
'placeholder' => 'Entrer un IBAN',
'class' => $options['show_sepa'] ? '': 'hide hiddenFields'
],
'required' => false,
'label_attr' => array('class' => $options['show_sepa'] ? '': 'hide hiddenFields'),
])
->add('bic',TextType::class, [
'label' => 'BIC',
'attr'=> [
'placeholder' => 'Entrer un BIC',
'class' => $options['show_sepa'] ? '': 'hide hiddenFields'
],
'required' => false,
'label_attr' => array('class' => $options['show_sepa'] ? '': 'hide hiddenFields'),
])
->add('rum',TextType::class, [
'label' => 'RUM',
'attr'=> [
'placeholder' => 'Entrer un RUM',
'class' => $options['show_sepa'] ? '': 'hide hiddenFields'
],
'required' => false,
'label_attr' => array('class' => $options['show_sepa'] ? '': 'hide hiddenFields'),
])
->add('dateSignatureMandat',DateType::class, [
'label' => 'Date de mandat',
'attr'=> [
'placeholder' => 'Entrer une date de mandat',
'class' => $options['show_sepa'] ? '': 'hide hiddenFields'
],
'required' => false,
'label_attr' => array('class' => $options['show_sepa'] ? '': 'hide hiddenFields'),
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Client\BillingInfos::class,
'show_sepa' => false,
'defaultCompany' => null
]);
$resolver->setAllowedTypes('show_sepa', 'bool');
}
}