2023-04-08 17:47:43 +02:00
|
|
|
<?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;
|
2023-04-09 17:56:15 +02:00
|
|
|
use App\Entity\BillCategory;
|
2023-04-08 17:47:43 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
])
|
2023-04-09 17:56:15 +02:00
|
|
|
->add('category', EntityType::class, [
|
|
|
|
'label' => 'Catégorie',
|
|
|
|
'required' => false,
|
|
|
|
'class' => BillCategory::class,
|
|
|
|
'label_attr' => [
|
|
|
|
'class' => 'mt-3',
|
|
|
|
],
|
|
|
|
'query_builder' => function (EntityRepository $er) {
|
|
|
|
return $er->createQueryBuilder('v')
|
|
|
|
->orderBy('v.label', 'ASC')
|
|
|
|
;
|
|
|
|
},
|
|
|
|
'attr' => [
|
|
|
|
'data-jschoice' => '',
|
|
|
|
],
|
|
|
|
])
|
|
|
|
->add('customCategory', null, [
|
|
|
|
'label' => 'Ajouter une catégorie',
|
|
|
|
'label_attr' => [
|
|
|
|
'class' => 'font-weight-normal',
|
|
|
|
],
|
|
|
|
'required' => false,
|
|
|
|
'mapped' => false,
|
|
|
|
])
|
2023-04-08 17:47:43 +02:00
|
|
|
->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,
|
2023-04-09 17:56:15 +02:00
|
|
|
'scale' => 2,
|
2023-04-08 17:47:43 +02:00
|
|
|
'label_attr' => [
|
|
|
|
'class' => 'mt-3',
|
|
|
|
],
|
2023-04-09 17:56:15 +02:00
|
|
|
'attr' => [
|
|
|
|
'step' => 0.01,
|
|
|
|
],
|
2023-04-08 17:47:43 +02:00
|
|
|
])
|
|
|
|
->add('amountHt', NumberType::class, [
|
|
|
|
'label' => 'Montant HT',
|
2023-04-09 17:56:15 +02:00
|
|
|
'scale' => 2,
|
2023-04-08 17:47:43 +02:00
|
|
|
'html5' => true,
|
2023-04-09 17:56:15 +02:00
|
|
|
'attr' => [
|
|
|
|
'step' => 0.01,
|
|
|
|
],
|
2023-04-08 17:47:43 +02:00
|
|
|
])
|
|
|
|
->add('status', ChoiceType::class, [
|
|
|
|
'choices' => BillPeer::choices(),
|
2023-04-10 16:47:59 +02:00
|
|
|
'help' => 'Modifier cette valeur manuellement ne permet pas d\'envoyer des notifications par mail',
|
2023-04-08 17:47:43 +02:00
|
|
|
'label_attr' => [
|
|
|
|
'class' => 'mt-3',
|
|
|
|
],
|
|
|
|
])
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver): void
|
|
|
|
{
|
|
|
|
$resolver->setDefaults([
|
|
|
|
'data_class' => Bill::class,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|