{# Title #}

Code promotionnel client

{# Formulaire d’application #} {{ form_start(form, { attr: { class: 'promo-form', novalidate: 'novalidate' } }) }}
{{ form_widget(form.promotion, { attr: { class: 'form-select select2 w-100' } }) }}
{# STOP #} {% if user.promotion %} {% endif %} {# APPLIQUER CODE #} {# HISTORIQUE #}
{{ form_end(form) }} {% if user.promotion %} {% set now = date() %} {% set promo = user.promotion %} {# === Jours restants (peut être négatif)=== #} {% set joursRestants = ((promo.endAt|date('U') - now|date('U')) / 86400)|round(0, 'ceil') %} {# ==== Validité temporelle === #} {% set dateValide = promo.startAt <= now and promo.endAt >= now %} {# === Validité quantité TOTALE ==== #} {% if promo.totalQuantity is null %} {% set quantiteTotaleValide = true %} {% set resteTotal = null %} {% else %} {% set usedTotal = totalUsedAll is defined ? totalUsedAll : 0 %} {% set quantiteTotaleValide = usedTotal < promo.totalQuantity %} {% set resteTotal = promo.totalQuantity - usedTotal %} {% endif %} {# === Validité quantité PAR CLIENT ==== #} {% if promo.quantityUser is null %} {% set quantiteClientValide = true %} {% set resteClient = null %} {% else %} {% set usedClient = nbUsesClient is defined ? nbUsesClient : 0 %} {% set quantiteClientValide = usedClient < promo.quantityUser %} {% set resteClient = promo.quantityUser - usedClient %} {% endif %} {# ==== État global du code === #} {% set codeValide = dateValide and quantiteTotaleValide and quantiteClientValide %} {# ==== Données exposées au JS si besoin==== #} {# ==== AFFICHAGE ÉTAT==== #}
{% if not dateValide %} Code expiré (période dépassée). {% elseif not quantiteTotaleValide %} Code encore valide en date {% if joursRestants > 0 %} ({{ joursRestants }} jour{% if joursRestants > 1 %}s{% endif %} restants) {% endif %} mais le nombre d’utilisations **totales** autorisées est atteint. {% elseif not quantiteClientValide %} Code encore valide en date {% if joursRestants > 0 %} ({{ joursRestants }} jour{% if joursRestants > 1 %}s{% endif %} restants) {% endif %} mais le nombre d’utilisations **par client** autorisées est atteint. {% else %} Code actif – {{ joursRestants }} jour{% if joursRestants > 1 %}s{% endif %} restants {% if resteTotal is not null %} · {{ resteTotal }} utilisation{% if resteTotal > 1 %}s{% endif %} totale{% if resteTotal > 1 %}s{% endif %} restante{% if resteTotal > 1 %}s{% endif %} {% endif %} {% if resteClient is not null %} · {{ resteClient }} utilisation{% if resteClient > 1 %}s{% endif %} restante{% if resteClient > 1 %}s{% endif %} pour ce client {% endif %} {% endif %}
{# --- Bloc Détails du code promotionnel --- #}
Détails du code promotionnel
Nom
{{ promo.name }}
Remise
{{ promo.discountValue }} {{ promo.discountType == 'percent' ? '%' : 'TND' }}
Description
{{ promo.description }}
Créé le
{{ promo.createdAt|date("d/m/Y H:i") }}
Début
{{ promo.startAt|date("d/m/Y H:i") }}
Fin
{{ promo.endAt|date("d/m/Y H:i") }}
{# Bloc utilisations sur une ligne entière, bien espacé #}
Utilisations (ce client)
{{ nbUsesClient }} {% if totalAllowed %} / {{ totalAllowed }} (Restant : {{ nbRemaining }}) {% else %} Illimité {% endif %}
{% else %} {% endif %}
{#-- Modale fin de promotion --#} {#-- Modale de la liste de document d'une promotition --#} {# Récupération de l'historique #} {% set histories = userPromotionHistories ?? [] %}