diff --git a/sources/AppBundle/Accounting/Model/Invoicing.php b/sources/AppBundle/Accounting/Model/Invoicing.php index 2914f8a1f..dd5c4fe8d 100644 --- a/sources/AppBundle/Accounting/Model/Invoicing.php +++ b/sources/AppBundle/Accounting/Model/Invoicing.php @@ -10,6 +10,7 @@ use CCMBenchmark\Ting\Entity\NotifyProperty; use CCMBenchmark\Ting\Entity\NotifyPropertyInterface; use DateTime; +use Symfony\Component\Validator\Constraints as Assert; class Invoicing implements NotifyPropertyInterface { @@ -39,6 +40,7 @@ class Invoicing implements NotifyPropertyInterface private ?DateTime $paymentDate = null; private ?InvoicingCurrency $currency = null; /** @var InvoicingDetail[] */ + #[Assert\Valid] private array $details = []; private ?float $price = null; diff --git a/sources/AppBundle/Accounting/Model/InvoicingDetail.php b/sources/AppBundle/Accounting/Model/InvoicingDetail.php index 8a90a8547..2afc5f791 100644 --- a/sources/AppBundle/Accounting/Model/InvoicingDetail.php +++ b/sources/AppBundle/Accounting/Model/InvoicingDetail.php @@ -6,6 +6,7 @@ use CCMBenchmark\Ting\Entity\NotifyProperty; use CCMBenchmark\Ting\Entity\NotifyPropertyInterface; +use Symfony\Component\Validator\Constraints as Assert; class InvoicingDetail implements NotifyPropertyInterface { @@ -13,10 +14,22 @@ class InvoicingDetail implements NotifyPropertyInterface private ?int $id = null; private ?int $invoicingId = null; + + #[Assert\NotBlank] + #[Assert\Length(max: 20)] private ?string $reference = null; + + #[Assert\NotBlank] + #[Assert\Length(max: 100)] private ?string $designation = null; + + #[Assert\NotBlank] private ?float $quantity = null; + + #[Assert\NotBlank] private ?float $unitPrice = null; + + #[Assert\NotBlank] private ?float $tva = null; public function getId(): ?int diff --git a/sources/AppBundle/Controller/Admin/Accounting/Quotation/AddQuotationAction.php b/sources/AppBundle/Controller/Admin/Accounting/Quotation/AddQuotationAction.php index 38019d2ce..d84092380 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/Quotation/AddQuotationAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/Quotation/AddQuotationAction.php @@ -11,6 +11,7 @@ use AppBundle\Accounting\Model\InvoicingDetail; use AppBundle\Accounting\Model\Repository\InvoicingDetailRepository; use AppBundle\Accounting\Model\Repository\InvoicingRepository; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -22,6 +23,7 @@ public function __construct( private readonly InvoicingNumberGenerator $numberGenerator, private readonly InvoicingDetailRepository $invoicingDetailRepository, private readonly ProduitRepository $produitRepository, + private readonly LoggerInterface $logger, ) {} public function __invoke(Request $request): Response @@ -41,8 +43,9 @@ public function __invoke(Request $request): Response $this->invoicingRepository->commit(); $this->addFlash('success', 'L\'écriture a été ajoutée'); return $this->redirectToRoute('admin_accounting_quotations_list'); - } catch (\Exception) { + } catch (\Exception $e) { $this->invoicingRepository->rollback(); + $this->logger->error('Échec de l\'ajout d\'un devis : ' . $e->getMessage(), ['exception' => $e]); $this->addFlash('error', 'L\'écriture n\'a pas pu être enregistrée'); } } diff --git a/sources/AppBundle/Controller/Admin/Accounting/Quotation/EditQuotationAction.php b/sources/AppBundle/Controller/Admin/Accounting/Quotation/EditQuotationAction.php index 3c21300be..58156dfec 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/Quotation/EditQuotationAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/Quotation/EditQuotationAction.php @@ -8,6 +8,7 @@ use AppBundle\Accounting\Form\QuotationType; use AppBundle\Accounting\Model\Repository\InvoicingDetailRepository; use AppBundle\Accounting\Model\Repository\InvoicingRepository; +use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -18,6 +19,7 @@ public function __construct( private readonly InvoicingRepository $invoicingRepository, private readonly InvoicingDetailRepository $invoicingDetailRepository, private readonly ProduitRepository $produitRepository, + private readonly LoggerInterface $logger, ) {} public function __invoke(Request $request): Response @@ -51,8 +53,9 @@ public function __invoke(Request $request): Response $this->invoicingRepository->commit(); $this->addFlash('success', 'L\'écriture a été modifiée'); return $this->redirectToRoute('admin_accounting_quotations_list'); - } catch (\Exception) { + } catch (\Exception $e) { $this->invoicingRepository->rollback(); + $this->logger->error('Échec de la modification d\'un devis : ' . $e->getMessage(), ['exception' => $e]); $this->addFlash('error', 'L\'écriture n\'a pas pu être enregistrée'); } } diff --git a/templates/admin/accounting/quotation/form.html.twig b/templates/admin/accounting/quotation/form.html.twig index 655781018..bd35f9783 100644 --- a/templates/admin/accounting/quotation/form.html.twig +++ b/templates/admin/accounting/quotation/form.html.twig @@ -1,4 +1,4 @@ -{% form_theme form 'form_theme_admin.html.twig' %} +{% form_theme form 'admin/accounting/quotation/_form_theme.html.twig' %} {{ form_start(form) }} {{ form_errors(form) }}