From 8c96f1a0b843cf01dc4aa66e6eda4520f8f36116 Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Mon, 16 Feb 2026 09:48:53 +0100 Subject: [PATCH] add webhooks for refused signature contrat --- src/Controller/ReserverController.php | 32 +++++++++++++++- templates/dashboard/contrats/view.twig | 53 ++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 10 deletions(-) diff --git a/src/Controller/ReserverController.php b/src/Controller/ReserverController.php index e6fab23..1999bfd 100644 --- a/src/Controller/ReserverController.php +++ b/src/Controller/ReserverController.php @@ -128,6 +128,7 @@ class ReserverController extends AbstractController $runningTotalHT += $formulaBasePrice; } + $products = []; if (!empty($ids)) { $products = $productRepository->findBy(['id' => $ids]); $processedProductIds = []; @@ -196,7 +197,7 @@ class ReserverController extends AbstractController } $promoData = $session->getPromotion(); - if ($promoData && $runningTotalHT > 0) { + if ($promoData && $runningTotalHT > 0 && $this->isDiscountAllowed($products)) { $discount = $runningTotalHT * ($promoData['percentage'] / 100); $promoLine = new DevisLine(); $promoLine->setProduct("Promotion : " . $promoData['name'] . " (-" . $promoData['percentage'] . "%)"); @@ -1451,7 +1452,8 @@ class ReserverController extends AbstractController } $discountAmount = 0; - if ($promotion) { + // Application de la remise seulement si autorisée (pas uniquement des produits 2-7 Ans) + if ($promotion && $this->isDiscountAllowed($products)) { $discountAmount = $totalHT * ($promotion->getPercentage() / 100); $totalHT -= $discountAmount; } @@ -1473,4 +1475,30 @@ class ReserverController extends AbstractController 'tvaEnabled' => $tvaEnabled ]; } + + /** + * Vérifie si la remise doit être appliquée. + * Si le panier ne contient QUE des produits de la catégorie '2-7 Ans', la remise est refusée. + * S'il y a un mélange ou d'autres produits, elle est acceptée. + */ + private function isDiscountAllowed(array $products): bool + { + if (empty($products)) { + return true; + } + + $hasOnlyExcluded = true; + foreach ($products as $product) { + $cat = $product->getCategory(); + // Handle both object (Category entity) and string cases for robustness + $catName = is_object($cat) && method_exists($cat, 'getName') ? $cat->getName() : (string)$cat; + + if ($catName !== '2-7 Ans') { + $hasOnlyExcluded = false; + break; + } + } + + return !$hasOnlyExcluded; + } } diff --git a/templates/dashboard/contrats/view.twig b/templates/dashboard/contrats/view.twig index 742e110..5680278 100644 --- a/templates/dashboard/contrats/view.twig +++ b/templates/dashboard/contrats/view.twig @@ -14,6 +14,21 @@ Générer la Facture {% endif %} + + {# --- BOUTON RENVOYER LIEN SIGNATURE (Caché si signé ou refusé) --- #} + {# Note: contrat.signed semble être utilisé dans le snippet original, mais list.twig utilise isSigned. Je vérifie les deux ou je suppose isSigned correct si c'est l'entité. #} + {# Dans le doute, j'utilise la logique cohérente avec le statut #} + {% if not contrat.signed and not contrat.refused %} + + + + + Renvoyer le lien + + {% endif %} + {% if contrat.signed %} @@ -49,11 +64,33 @@
+ {# --- BANNIÈRE DE REFUS (Prioritaire) --- #} + {% if contrat.refused %} +
+
+
+ +
+
+

CONTRAT REFUSÉ PAR LE CLIENT

+

+ Motif du refus : "{{ contrat.refusedRaison|default('Aucune raison spécifiée') }}" +

+
+
+
+ Action Requise +
+
+ {% endif %} + {# --- 1. BANDEAU DE STATUT RAPIDE --- #} -
+
État Juridique - {% if contrat.signed %} + {% if contrat.refused %} + REFUSÉ + {% elseif contrat.signed %} SIGNÉ {% else %} EN ATTENTE @@ -89,7 +126,7 @@
{# --- 2. INFOS CLIENT & ÉVÉNEMENT --- #} -
+
@@ -98,7 +135,7 @@
-

{{ contrat.customer.surname }} {{ contrat.customer.name }}

+

{{ contrat.customer.surname }} {{ contrat.customer.name }}

Locataire

@@ -131,7 +168,7 @@ {# --- 3. SECTION LOGISTIQUE & ÉTAT DES LIEUX --- #} {% if contrat.etatLieux %} -
+

Logistique & État des lieux

{% if contrat.etatLieux.status == 'edl_return_refused' %} @@ -225,7 +262,7 @@ {% endif %} {# --- 4. ÉTAT DES PAIEMENTS --- #} -
+
{# ACOMPTE #}
@@ -305,7 +342,7 @@
{# --- 5. PRODUITS ET OPTIONS --- #} -
+

Équipements loués

@@ -340,7 +377,7 @@
{# --- 6. HISTORIQUE FINANCIER --- #} -
+

Historique des transactions