|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace AppBundle\Accounting\Form; |
| 6 | + |
| 7 | +use Afup\Site\Utils\Pays; |
| 8 | +use AppBundle\Accounting\InvoicingCurrency; |
| 9 | +use AppBundle\Accounting\InvoicingPaymentStatus; |
| 10 | +use Symfony\Component\Form\AbstractType; |
| 11 | +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
| 12 | +use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
| 13 | +use Symfony\Component\Form\Extension\Core\Type\DateType; |
| 14 | +use Symfony\Component\Form\Extension\Core\Type\EmailType; |
| 15 | +use Symfony\Component\Form\Extension\Core\Type\EnumType; |
| 16 | +use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
| 17 | +use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 18 | +use Symfony\Component\Form\FormBuilderInterface; |
| 19 | +use Symfony\Component\Validator\Constraints as Assert; |
| 20 | + |
| 21 | +class InvoiceType extends AbstractType |
| 22 | +{ |
| 23 | + public function __construct(private readonly Pays $pays) {} |
| 24 | + |
| 25 | + public function buildForm(FormBuilderInterface $builder, array $options): void |
| 26 | + { |
| 27 | + $builder->add('invoiceDate', DateType::class, [ |
| 28 | + 'label' => 'Date facture', |
| 29 | + 'widget' => 'single_text', |
| 30 | + ])->add('company', TextType::class, [ |
| 31 | + 'label' => 'Société', |
| 32 | + 'constraints' => [ |
| 33 | + new Assert\NotBlank(), |
| 34 | + new Assert\Length(max: 50), |
| 35 | + ], |
| 36 | + ])->add('service', TextType::class, [ |
| 37 | + 'label' => 'Service', |
| 38 | + 'required' => false, |
| 39 | + 'empty_data' => '', |
| 40 | + 'constraints' => [ |
| 41 | + new Assert\Length(max: 50), |
| 42 | + ], |
| 43 | + ])->add('address', TextareaType::class, [ |
| 44 | + 'label' => 'Adresse', |
| 45 | + ])->add('zipcode', TextType::class, [ |
| 46 | + 'label' => 'Code postal', |
| 47 | + 'constraints' => [ |
| 48 | + new Assert\NotBlank(), |
| 49 | + new Assert\Length(max: 10), |
| 50 | + ], |
| 51 | + ])->add('city', TextType::class, [ |
| 52 | + 'label' => 'Ville', |
| 53 | + 'constraints' => [ |
| 54 | + new Assert\NotBlank(), |
| 55 | + new Assert\Length(max: 50), |
| 56 | + ], |
| 57 | + ])->add('countryId', ChoiceType::class, [ |
| 58 | + 'label' => 'Pays', |
| 59 | + 'choices' => array_flip($this->pays->obtenirPays()), |
| 60 | + ])->add('lastname', TextType::class, [ |
| 61 | + 'label' => 'Nom', |
| 62 | + 'required' => false, |
| 63 | + 'empty_data' => '', |
| 64 | + 'constraints' => [ |
| 65 | + new Assert\Length(max: 50), |
| 66 | + ], |
| 67 | + ])->add('firstname', TextType::class, [ |
| 68 | + 'label' => 'Prénom', |
| 69 | + 'required' => false, |
| 70 | + 'empty_data' => '', |
| 71 | + 'constraints' => [ |
| 72 | + new Assert\Length(max: 50), |
| 73 | + ], |
| 74 | + ])->add('phone', TextType::class, [ |
| 75 | + 'label' => 'Tel', |
| 76 | + 'required' => false, |
| 77 | + 'empty_data' => '', |
| 78 | + 'constraints' => [ |
| 79 | + new Assert\Length(max: 30), |
| 80 | + ], |
| 81 | + ])->add('email', EmailType::class, [ |
| 82 | + 'label' => 'Email (facture)', |
| 83 | + 'constraints' => [ |
| 84 | + new Assert\NotBlank(), |
| 85 | + new Assert\Length(max: 100), |
| 86 | + ], |
| 87 | + ])->add('tvaIntra', TextType::class, [ |
| 88 | + 'label' => 'TVA intracommunautaire (facture)', |
| 89 | + 'required' => false, |
| 90 | + 'constraints' => [ |
| 91 | + new Assert\Length(max: 20), |
| 92 | + ], |
| 93 | + ])->add('refClt1', TextType::class, [ |
| 94 | + 'label' => 'Référence client', |
| 95 | + 'required' => false, |
| 96 | + 'empty_data' => '', |
| 97 | + 'constraints' => [ |
| 98 | + new Assert\Length(max: 50), |
| 99 | + ], |
| 100 | + ])->add('refClt2', TextType::class, [ |
| 101 | + 'label' => 'Référence client 2', |
| 102 | + 'required' => false, |
| 103 | + 'empty_data' => '', |
| 104 | + 'constraints' => [ |
| 105 | + new Assert\Length(max: 50), |
| 106 | + ], |
| 107 | + ])->add('refClt3', TextType::class, [ |
| 108 | + 'label' => 'Référence client 3', |
| 109 | + 'required' => false, |
| 110 | + 'empty_data' => '', |
| 111 | + 'constraints' => [ |
| 112 | + new Assert\Length(max: 50), |
| 113 | + ], |
| 114 | + ])->add('observation', TextareaType::class, [ |
| 115 | + 'required' => false, |
| 116 | + 'empty_data' => '', |
| 117 | + 'label' => 'Observation', |
| 118 | + ])->add('currency', EnumType::class, [ |
| 119 | + 'required' => false, |
| 120 | + 'class' => InvoicingCurrency::class, |
| 121 | + 'attr' => ['size' => count(InvoicingCurrency::cases())], |
| 122 | + 'label' => 'Monnaie de la facture', |
| 123 | + 'placeholder' => false, |
| 124 | + ])->add('details', CollectionType::class, [ |
| 125 | + 'entry_type' => InvoicingRowType::class, |
| 126 | + 'keep_as_list' => true, |
| 127 | + 'allow_add' => false, |
| 128 | + 'allow_delete' => false, |
| 129 | + 'entry_options' => ['disabled' => true], |
| 130 | + ])->add('quotationNumber', TextType::class, [ |
| 131 | + 'label' => 'Numéro de devis', |
| 132 | + 'required' => false, |
| 133 | + 'attr' => ['readonly' => 'readonly'], |
| 134 | + 'constraints' => [ |
| 135 | + new Assert\Length(max: 50), |
| 136 | + ], |
| 137 | + ])->add('invoiceNumber', TextType::class, [ |
| 138 | + 'label' => 'Numéro facture', |
| 139 | + 'required' => false, |
| 140 | + 'attr' => ['readonly' => 'readonly'], |
| 141 | + 'constraints' => [ |
| 142 | + new Assert\Length(max: 50), |
| 143 | + ], |
| 144 | + ])->add('paymentStatus', EnumType::class, [ |
| 145 | + 'required' => false, |
| 146 | + 'class' => InvoicingPaymentStatus::class, |
| 147 | + 'attr' => ['size' => count(InvoicingPaymentStatus::cases())], |
| 148 | + 'label' => 'État paiement', |
| 149 | + 'placeholder' => false, |
| 150 | + 'choice_label' => fn(InvoicingPaymentStatus $choice, string $key, mixed $value): string => $choice->label(), |
| 151 | + ]) |
| 152 | + ->add('paymentDate', DateType::class, [ |
| 153 | + 'label' => 'Date de paiement', |
| 154 | + 'required' => false, |
| 155 | + 'widget' => 'single_text', |
| 156 | + ]); |
| 157 | + } |
| 158 | +} |
0 commit comments