{% extends'@admin/base.html.twig' %} {% block stylesheets %} {{ parent() }} {% endblock %} {% block extra_scripts %} {% endblock %} {% block subheader %}
{# --- Colonne gauche : icône + titre + breadcrumb --- #}

{% if document.type == 'commande' %}BONS DE COMMANDE CLIENT {% elseif document.type == 'facture' %}FACTURE CLIENT {% elseif document.type == 'avoir' %}AVOIR CLIENT {% elseif document.type == 'retour' %}BON DE RETOUR {% endif %}

{# --- Colonne droite : Boutons + Actions --- #}
{% set echange = false %} {% set allEchangeCanceled = true %} {% set echange_in_process = false %} {% set doc_echange = null %} {% for doc in document.documents %} {#{% if doc.type=="echange" and doc.status in ['en-attente','accepte','expedie'] %}#} {% if doc.type=="echange" %} {% set echange = true %} {% set doc_echange = doc %} {% if doc.status in ['en-attente','accepte','a-expedier','expedie'] %} {% set echange_in_process = true %} {% endif %} {% if doc.status != 'annule' %} {% set allEchangeCanceled = false %} {% endif %} {% endif %} {% endfor %}
{% endblock %} {% block breadcrumb %}{% endblock %} {% block stat %} {% endblock %} {% block bodycontent %} {# -- JS appels téléphoniques -- #} {% set echange = false %} {% set allEchangeCanceled = true %} {% set echange_in_process = false %} {% set doc_echange = null %} {% for doc in document.documents %} {#{% if doc.type=="echange" and doc.status in ['en-attente','accepte','expedie'] %}#} {% if doc.type=="echange" %} {% set echange = true %} {% set doc_echange = doc %} {% if doc.status in ['en-attente','accepte','a-expedier','expedie'] %} {% set echange_in_process = true %} {% endif %} {% if doc.status != 'annule' %} {% set allEchangeCanceled = false %} {% endif %} {% endif %} {% endfor %}
{#-- Détails cde + panneaux commentaires et historiques--#}
{#-- Détails cde --#}
{# Statut à  gauche #}
{{ document.status|replace({'-':' '})|capitalize }}
{# Icône info-bulle à  droite (si applicable) #} {% set tooltip = '' %} {% if document.status == 'annule' %} {% set tooltip = document.cancelReason ? document.cancelReason.name : 'Aucune raison d’annulation' %} {% elseif document.status in ['retourne','retour-en-cours'] %} {% set tooltip = document.returnReason ? document.returnReason.name : 'Aucune raison de retour' %} {% elseif document.status in ['a-rembourser','rembourse'] %} {% set tooltip = document.refundReason ? document.refundReason.name : 'Aucune raison de remboursement' %} {% endif %} {% if tooltip %} {% endif %}
{% if factureExistante %}Facturé (Facture N° {{ factureExistante.internalNbr }}) {% endif %}
{% if echange %} {% endif %} {% if cmdEnAttente >= 2 %} {% endif %} {#--Statut commande --#}
{#--- info clients --- #}
Info Client
{% if document.client.clientType %}
{% include '@admin/includes/_client_type_badge.html.twig' with { user: document.client } %}
{% endif %}
{{ nbCmdTotal - (cmdEnRetour + cmdAnnule) }} {% if nbBeTotal > 0 %} {{ nbBeTotal }} {% endif %} {% if cmdEnAttente > 0 %} {{ cmdEnAttente }} {% endif %} {% if cmdAnnule > 0 %} {{ cmdAnnule }} {% endif %} {% if cmdEnRetour > 0 %} {{ cmdEnRetour }} {% endif %} {% if document.client.description %} {% endif %}
Client {{ document.client.civility }} {{ document.client.firstName }}
Adresse {% if document.adress is not empty %} {{ document.adress|replace({'Tunisie': ''}) }} {% else %} {% if document.client.city is not empty %}{{ document.client.city }}{% endif %} {% if document.client.region is not empty %} {{ document.client.region }}{% endif %} {% endif %}
Téléphone {{ document.client.phone }} {% if document.client.secondPhone %} | {{ document.client.secondPhone }} {% endif %}
{% if document.client.promotion is not null and document.client.promotion.code is not null %}
Code promo {{ document.client.promotion.code }}
{% endif %} {% if document.source %}
Source {% if 'Facebook' in document.source.name %} {% elseif document.source.name == 'Instagram' %} {% elseif document.source.name == 'WhatsApp' %} {% elseif document.source.name == 'Site web' %} {% elseif document.source.name == 'TikTok' %} {% endif %} {% if document.client.links is empty %} {{ document.source.name }} {% else %} {% for link in document.client.links %} {{ document.source.name }} {% endfor %} {% endif %}
{% endif %}
{#--- info livraison --- #}
Info Livraison
Transporteur {{ document.delivery ? document.delivery.name : 'Non mentionnée' }}
Num. suivi {{ document.parcelTrackingNbr ?: '—' }}
URL suivi {% if document.urlTracking %} {{ document.urlTracking }} {% else %} — {% endif %}
Colis {{ document.packagesNbr }}
{#--- info document --- #}
Info Document
{{ document.internalNbr }}
Lien client {# Ouvrir le lien #} {# Copier le lien #}
Date {{ document.createdAt|date("d/m/Y") }}
{% if document.promisedAt %}
Liv. prévue {{ document.promisedAt|date("d/m/Y") }}
{% endif %} {% if document.shippedAt and document.status in ['expedie','livre','paye','non-paye','partiellement-paye', 'retour-en-cours', 'retourne', 'a-rembourser','rembourse'] %}
Expédié le {{ document.shippedAt|date("d/m/Y") }}
{% endif %} {% if document.deliveredAt and document.status in ['livre','paye','non-paye','partiellement-paye'] %}
Livré le {{ document.deliveredAt|date("d/m/Y") }}
{% endif %} {% if document.paidAt %}
Payé le {{ document.paidAt|date("d/m/Y") }}
{% endif %} {% if document.returnedAt and document.status == 'retourne' %}
Retourné le {{ document.returnedAt|date("d/m/Y") }}
{% endif %}
{% set __docArticlesQty = 0 %} {% for __line in document.documentDeclinationProduits %} {% set __docArticlesQty = __docArticlesQty + (__line.quantity ?? 0) %} {% endfor %}
Créé par : {{ document.user.firstName }}
Nb d'articles : {{ __docArticlesQty }}
{% if document.documentComments is not empty %} {% for key, documentComment in document.documentComments %} {% endfor %} {% endif %} {% set TotalTTC = 0 %} {% set discountPrdTotal = 0 %} {% set TotalTVA = 0 %} {% set TotalHT = 0 %} {% set __prevPackGroup = null %} {% set __prevWasPack = false %} {% for key, documentDeclinationProduit in document.documentDeclinationProduits %} {% set discountPrd = 0 %} {% set tvaRate = documentDeclinationProduit.tva is not null ? documentDeclinationProduit.tva.number : 0 %} {% set qty = documentDeclinationProduit.quantity ?? 0 %} {% set lineGrossHt = (documentDeclinationProduit.priceHT ?? 0) * qty %} {% set lineGrossTtc = lineGrossHt * (1 + (tvaRate / 100)) %} {% set lineNetTtc = documentDeclinationProduit.totalAmountTtc ?? 0 %} {% set discountPrd = lineGrossTtc - lineNetTtc %} {% if discountPrd < 0 %} {% set discountPrd = 0 %} {% endif %} {% set __isPackLine = documentDeclinationProduit.packGroup is not empty %} {% set __packGroup = __isPackLine ? documentDeclinationProduit.packGroup : null %} {% if __isPackLine and __packGroup != __prevPackGroup %} {% set __packTotal = 0 %} {% for __p in document.documentDeclinationProduits %} {% if __p.packGroup == __packGroup %} {% set __packTotal = __packTotal + (__p.totalAmountTtc ?? 0) %} {% endif %} {% endfor %} {% endif %} {% if __prevWasPack and not __isPackLine %} {% endif %} {% if documentDeclinationProduit.type == 'declinationEchange' %} {% set TotalHT = TotalHT - lineGrossHt %} {% set TotalTVA = TotalTVA - (lineGrossTtc - lineGrossHt) %} {% set TotalTTC = TotalTTC - lineGrossTtc %} {% else %} {% set TotalHT = TotalHT + lineGrossHt %} {% set TotalTVA = TotalTVA + (lineGrossTtc - lineGrossHt) %} {% set TotalTTC = TotalTTC + lineGrossTtc %} {% endif %} {% set __prevPackGroup = __packGroup %} {% set __prevWasPack = __isPackLine %} {% endfor %} {% set discountBase = TotalTTC > 0 ? TotalTTC : 0 %} {% set discount = (document.discountType == 'percent') ? ((discountBase * (document.discount ?? 0)) / 100) : (document.discount ?? 0) %} {% if discount < 0 %} {% set discount = 0 %} {% endif %} {% if discount > discountBase %} {% set discount = discountBase %} {% endif %} {% set totalDiscount = discount + discountPrdTotal %} {% set netToPayBeforeDelivery = TotalTTC - totalDiscount %} {% set netToPay = netToPayBeforeDelivery + (document.deliveryTotal ?? 0) %}
Image Référence Stock HT TVA Qte Remise TTC
{{ documentComment.description }}
Pack: {{ documentDeclinationProduit.pack ? documentDeclinationProduit.pack.name : ('Pack #' ~ __packGroup) }} {% if documentDeclinationProduit.packQty %} Qté pack: {{ documentDeclinationProduit.packQty }} {% endif %}
Mt pack: {{ __packTotal|number_format(3, ',', '') }} TND

Autres produits (hors pack)
{% set picture = '' %} {% for image in documentDeclinationProduit.produitDeclinationValue.picture %} {% if image.isSelected %} {% set picture = app.request.getSchemeAndHttpHost() ~ vich_uploader_asset(image, 'file') %} {% endif %} {% endfor %} {% set parentProduit = documentDeclinationProduit.produitDeclinationValue.produit ?? null %} {% if parentProduit %} {% else %} {% endif %} {{ documentDeclinationProduit.reference }}

{{ documentDeclinationProduit.description }}

{% if __isPackLine %}
{{ documentDeclinationProduit.pack ? documentDeclinationProduit.pack.name : 'Pack' }}
{% endif %}
{{ documentDeclinationProduit.produitDeclinationValue.getQtyAvailable() }} {{ documentDeclinationProduit.produitDeclinationValue.getQtyReserved() }} {{ documentDeclinationProduit.priceHT|number_format(3,',','') }} TND {% if documentDeclinationProduit.tva is not null %} {{ (documentDeclinationProduit.tva).number }} % {% else %} 0 % {% endif %} {% set qte = documentDeclinationProduit.quantity ?? 0 %} {% if qte > 1 %}
{{ qte }} Qte > 1
{% else %} {{ qte }} {% endif %}
{{ documentDeclinationProduit.discount|number_format(3,',','') }} {% if documentDeclinationProduit.discountType == 'percent' %} % {% else %} TND {% endif %} {% set discountPrdTotal = discountPrdTotal + discountPrd %} {{ documentDeclinationProduit.totalAmountTtc|number_format(3,',','') }} TND
{{ document.delivery ? document.delivery.name : "n'est pas mentionnée" }} 1 {{ document.deliveryDiscount }} {% if document.deliveryDiscountType == 'percent' %}%{% else %}TND{% endif %} {{ document.deliveryTotal|number_format(3, ',', '') }}TND
{# === RéCAP & PROMOTION === #}
{# --- Promotion --- #}
{% if document.promotion is not null %} {% set promo = document.promotion %} {% endif %}
{# --- Totaux --- #}
Total HT {{ TotalHT|number_format(3, ',', '') }} TND
Total TVA {{ TotalTVA|number_format(3, ',', '') }} TND
Total TTC {{ TotalTTC|number_format(3, ',', '') }} TND
Remise {% if document.discountType == 'percent' %} ({{ document.discount ~ "%" }}) {% endif %} {{ totalDiscount|number_format(3, ',', '') }} TND
Net à payer (hors frais) {{ netToPayBeforeDelivery|number_format(3, ',', '') }} TND
Frais de livraison {{ document.deliveryTotal|number_format(3, ',', '') }} TND
Net à  payer {{ document.totalAmountTtc|number_format(3, ',', '') }} TND
{#-- panneaux commentaires et historiques--#}
{# -- Historique Commentaires -- #}

{% if comments is empty %} {% endif %}
{% include 'admin/document/_comments_block.html.twig' %}
{# --- Zone de text Ajout commentaire --- #}
{# -- Historique Appels -- #}

{# === Historique des appels === #} {% include 'admin/document/_calls_block.html.twig' %}
{# -- Historique Modifications -- #}

{# 1) Fusion des activités (ancêtres → courant) #} {% set activities = document.activities %} {% if document.document is not null %} {% set activities = document.document.activities|merge(activities) %} {% if document.document.document is not null %} {% set activities = document.document.document.activities|merge(activities) %} {% if document.document.document.document is not null %} {% set activities = document.document.document.document.activities|merge(activities) %} {% endif %} {% endif %} {% endif %} {# 2) Tri décroissant (plus récentes en premier) #} {% set activities = activities|sort((a, b) => a.createdAt <=> b.createdAt)|reverse %} {# 3) Icônes & badges par type #} {% set type_icon = { 'info': 'fa fa-info-circle text-info', 'danger': 'fa fa-exclamation-triangle text-danger', 'success':'fa fa-check-circle text-success', 'warning':'fa fa-exclamation-circle text-warning' } %} {% set type_badge = { 'info': 'm-badge m-badge--info m-badge--wide', 'danger': 'm-badge m-badge--danger m-badge--wide', 'success':'m-badge m-badge--success m-badge--wide', 'warning':'m-badge m-badge--warning m-badge--wide' } %} {% if activities is empty %}
Aucun historique pour le moment.
{% else %}
    {% set currentDay = '' %} {% for activity in activities %} {% set day = activity.createdAt|date('d/m/Y') %} {# Titre de date (groupement) #} {% if day != currentDay %} {% set currentDay = day %}
  • {{ currentDay }} {% set countDay = activities|filter(a => a.createdAt|date('d/m/Y') == currentDay)|length %} {{ countDay }} action{{ countDay>1?'s':'' }}
  • {% endif %} {# Ligne activité #}
  • {{ activity.type|capitalize }} {{ activity.createdAt|date('H:i') }} {# Si l'auteur est disponible #} {% if activity.user is defined and activity.user %} — {{ activity.user.fullName ?? activity.user.username }} {% endif %}
    {{ activity.message }}
    {# Action "copier" rapide #}
  • {% endfor %}
{% endif %}
{#--Historique du document--#}

    {# — Icones & classes statuts — #} {% set icons = { 'commande': '', 'facture': '', 'avoir': '', 'retour': '', 'default': '' } %} {% set status_classes = { 'en-attente': 'alert-en-attente', 'accepte': 'alert-accepte', 'a-expedier': 'alert-a-expedier', 'expedie': 'alert-expedie', 'livre': 'alert-livre', 'paye': 'alert-paye', 'non-paye': 'alert-non-paye', 'partiellement-paye': 'alert-partiellement-paye', 'facture': 'alert-facture', 'annule': 'alert-annule', 'retour-en-cours': 'alert-retour-en-cours', 'retourne': 'alert-retourne', 'rembourse': 'alert-rembourse', 'a-rembourser': 'alert-a-rembourser' } %} {# — Affichage ancêtres verticaux — #} {% set d0 = document %} {% set d1 = d0.document %} {% set d2 = d1 is not null ? d1.document : null %} {% set d3 = d2 is not null ? d2.document : null %} {% set docs = [d3, d2, d1, d0]|filter(d => d is not null) %} {% for doc in docs %}
  • {% if not loop.first %} {% endif %}
    {{ icons[doc.type]|default(icons['default'])|raw }} N°{{ doc.internalNbr }} {{ doc.type|capitalize }} {{ doc.status|replace({'-':' '})|capitalize }} {% if doc.createdAt is defined %} {{ doc.createdAt|date('d/m/Y') }} {% endif %}
  • {% endfor %} {# — Enfants directs — #} {% if document.documents|length > 0 %}
  • {% for doc in document.documents %}
    {{ icons[doc.type]|default(icons['default'])|raw }} N°{{ doc.internalNbr }} {{ doc.type|capitalize }} {{ doc.status|replace({'-':' '})|capitalize }} {% if doc.createdAt is defined %} {{ doc.createdAt|date('d/m/Y') }} {% endif %}
    {% endfor %}
  • {% endif %}
{% include '@admin/document/_modalsCalls.html.twig' %} {{ include('@admin/includes/modals/_modal_edit_info_livraison.html.twig') }} {{ include('@admin/includes/modals/_modal_edit_user.html.twig') }} {% endblock %} {# -- Variables JS page document client -- #} {% block js %} {{ parent() }} {% endblock %}