suivi/src/Form/BillType.php
2023-04-08 17:47:43 +02:00

107 lines
3.7 KiB
PHP

<?php
namespace App\Form;
use App\Entity\Bill;
use App\Entity\BillVendor;
use Doctrine\ORM\EntityRepository;
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\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use App\Entity\BillPeer;
class BillType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if (null === $builder->getData()->getId()) {
$builder->add('file', FileType::class, [
'label' => 'Fichier',
'constraints' => [
new File([
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
'image/png',
'image/jpeg',
],
'mimeTypesMessage' => 'Le fichier doit être au format PDF ou une image.',
]),
],
]);
} else {
$builder
->add('reference', null, [
'label' => 'Numéro de facture',
'constraints' => [
new NotBlank(),
],
])
->add('vendor', EntityType::class, [
'label' => 'Fournisseur',
'required' => false,
'class' => BillVendor::class,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('v')
->orderBy('v.label', 'ASC')
;
},
'attr' => [
'data-jschoice' => '',
],
])
->add('customVendor', null, [
'label' => 'Ajouter un fournisseur',
'label_attr' => [
'class' => 'font-weight-normal',
],
'required' => false,
'mapped' => false,
])
->add('date', null, [
'html5' => true,
'widget' => 'single_text',
'label_attr' => [
'class' => 'mt-3',
],
])
->add('paymentDeadlineDate', null, [
'label' => 'Date limite de paiement',
'html5' => true,
'widget' => 'single_text',
])
->add('amountTtc', NumberType::class, [
'label' => 'Montant TTC',
'html5' => true,
'label_attr' => [
'class' => 'mt-3',
],
])
->add('amountHt', NumberType::class, [
'label' => 'Montant HT',
'html5' => true,
])
->add('status', ChoiceType::class, [
'choices' => BillPeer::choices(),
'label_attr' => [
'class' => 'mt-3',
],
])
;
}
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Bill::class,
]);
}
}