From 5f84cc938f477ecc4a54d81432ea124d69710d81 Mon Sep 17 00:00:00 2001 From: vgreb Date: Sat, 1 Aug 2026 14:46:43 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20gestion=20d'erreur=20des=20?= =?UTF-8?q?devis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBundle/Accounting/Model/Invoicing.php | 2 ++ .../Accounting/Model/InvoicingDetail.php | 13 +++++++++ .../Quotation/AddQuotationAction.php | 5 +++- .../Quotation/EditQuotationAction.php | 5 +++- .../quotation/_form_theme.html.twig | 28 +++++++++++++++++++ .../admin/accounting/quotation/form.html.twig | 2 +- 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 templates/admin/accounting/quotation/_form_theme.html.twig 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_theme.html.twig b/templates/admin/accounting/quotation/_form_theme.html.twig new file mode 100644 index 000000000..ad2c62ce8 --- /dev/null +++ b/templates/admin/accounting/quotation/_form_theme.html.twig @@ -0,0 +1,28 @@ +{% use 'form_theme_admin.html.twig' %} + +{%- block form_row -%} +
+ {{ form_label(form) }} +
+
+ {{ form_widget(form) }} +
+ {{ form_errors(form) }} + {% if help is not empty %} +
+ {{ form_help(form) }} +
+ {% endif %} +
+
+{%- endblock form_row -%} + +{%- block form_errors -%} + {%- if errors|length > 0 -%} +
+ {%- for error in errors -%} + {{ error.message }}{% if not loop.last %}
{% endif %} + {%- endfor -%} +
+ {%- endif -%} +{%- endblock form_errors -%} 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) }}