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

{% if document.type == 'achat' %} DEMANDE D'ACHAT FOURNISSEUR {% elseif document.type == 'facture' %} FACTURE FOURNISSEUR {% elseif document.type == 'reception' %} BON DE RÉCEPTION FOURNISSEUR {% elseif document.type == 'retour' %} BON DE RETOUR FOURNISSEUR {% else %} DOCUMENT FOURNISSEUR {% endif %}

{# --- Droite : menu actions (fournisseur) --- #}
{% endblock %} {% block breadcrumb %}{% endblock %} {% block stat %} {% endblock %} {% block bodycontent %}
{#-- Détails cde + panneaux commentaires et historiques--#}
{#-- Détails cde --#}
{# ===================== GAUCHE : statut ===================== #}
{{ document.status|replace({'-':' '})|capitalize }}
{# ===================== DROITE : infos contextuelles ===================== #}
{# 1) Annulé -> afficher raison/note #} {% if document.status == 'annule' %} {% set tooltip = document.note ? ('Raison : ' ~ document.note) : 'Aucune raison renseignée' %} {% endif %} {# 2) Demande d'achat transformée -> indiquer BR + lien #} {% if document.type == 'achat' and document.status == 'transforme' %} {% set br = (document.documents is not empty) ? (document.documents|first) : null %} {% if br %} BR : {{ br.internalNbr }} {% else %} Transformé {% endif %} {% endif %} {# 3) Réception validée -> action "Payé" / annulation validation (info simple) #} {% if document.type == 'reception' and document.status == 'valide' %} Validé {% endif %} {# 4) Retour brouillon -> hint expédition #} {% if document.type == 'retour' and document.status == 'brouillon' %} À expédier {% endif %}
{#--Statut commande --#}
{# --- Info fournisseur --- #}
Info Fournisseur
Réf : {% if document.supplier is not null %} {{ document.supplier.name }} {% else %} {% endif %} {% if document.supplier is not null %} {% endif %}
{% if document.supplier is not null and document.supplier.phone %}
{{ document.supplier.phone }}
{% endif %} {% if document.supplier is not null and document.supplier.adress %}
{{ document.supplier.adress }}
{% endif %}
{# --- Info livraison --- #}
Info Livraison
Société : {{ document.delivery ? document.delivery.name : 'non mentionnée' }}
Num. suivi : {{ document.parcelTrackingNbr ?: '—' }}
URL : {% if document.urlTracking %} {{ document.urlTracking }} {% else %} {% endif %}
Nb colis : {{ document.packagesNbr ?: 1 }}
{# --- Info document --- #}
Info Document
N° Doc : {{ document.internalNbr }}
N° Frs : {{ document.externalNbr ?: '—' }}
Créé le : {{ document.createdAt|date('d/m/Y') }}
{% if document.shippedAt %}
Date B.Liv Frs : {{ document.shippedAt|date('d/m/Y') }}
{% endif %} {% if document.bonrecuAt %}
Réception : {{ document.bonrecuAt|date('d/m/Y') }}
{% endif %} {% if document.aPayerLe %}
À payer le : {{ document.aPayerLe|date('d/m/Y') }}
{% endif %} {% if document.note %}
Note :
{{ document.note|nl2br }}
{% endif %}
Créé par : {{ document.user.firstName }}
{# ✅ Commentaires (bloc 6 déjà fait, laisser tel quel si déjà présent) #} {% if document.documentComments is not empty %} {% for key, documentComment in document.documentComments %} {% endfor %} {% endif %} {% set TotalTTC = 0 %} {% set discountPrdTotal = 0 %} {% set TotalTVA = 0 %} {% for key, documentDeclinationProduit in document.documentDeclinationProduits %} {% set discountPrd = 0 %} {# Image #} {# Référence + description #} {# Stock #} {# HT #} {# TVA #} {# Qte #} {# Remise #} {# TTC #} {# ✅ calcul TotalTTC identique à ton code #} {% if documentDeclinationProduit.type == 'declinationEchange' %} {% set TotalTTC = TotalTTC - documentDeclinationProduit.totalAmountTtc %} {% else %} {% set TotalTTC = TotalTTC + documentDeclinationProduit.totalAmountTtc + discountPrd %} {% endif %} {% endfor %} {% set discount = (document.discountType=='percent') ? (((TotalTTC-document.deliveryTotal) * document.discount)/100) : document.discount %} {# Ligne livraison #}
Image Référence Stock HT TVA Qte Remise TTC
{{ documentComment.description }}
{% set picture = asset('/images/galery_placeholder_200.png') %} {% for image in documentDeclinationProduit.produitDeclinationValue.picture %} {% if image.isSelected %} {% set picture = app.request.getSchemeAndHttpHost() ~ vich_uploader_asset(image, 'file') %} {% endif %} {% endfor %} Produit {{ documentDeclinationProduit.reference }}
{{ documentDeclinationProduit.description }}
{{ documentDeclinationProduit.produitDeclinationValue.getQtyAvailable() }} {{ documentDeclinationProduit.produitDeclinationValue.getQtyReserved() }} {{ documentDeclinationProduit.priceHT|number_format(3,',','') }} TND {% if documentDeclinationProduit.tva is not null %} {% set TotalTVA = TotalTVA + ((documentDeclinationProduit.priceHT * (documentDeclinationProduit.tva).number) / 100) %} {{ (documentDeclinationProduit.tva).number }} % {% else %} 0 % {% endif %} {{ documentDeclinationProduit.quantity }} {{ documentDeclinationProduit.discount|number_format(3,',','') }} {% if documentDeclinationProduit.discountType == 'percent' %} % {% set discountPrd = (documentDeclinationProduit.priceHT * documentDeclinationProduit.discount) / 100 %} {% else %} TND {% set discountPrd = documentDeclinationProduit.discount %} {% 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
{# --- Total Qté par produit --- #}
Total Qté par produit
Aucun produit ajouté
{# --- Totaux (style client) --- #}
Total HT {{ document.totalAmountHt|number_format(3, ',', '') }} TND
Total TVA {{ document.totalTva|number_format(3, ',', '') }} TND
Total TTC {{ TotalTTC|number_format(3, ',', '') }} TND
Remise {% if document.discountType == 'percent' %} ({{ document.discount ~ "%" }}) {% endif %} {{ (discount + discountPrdTotal)|number_format(3, ',', '') }} TND
Frais de livraison {{ document.deliveryTotal|number_format(3, ',', '') }} TND
Net à payer {{ document.totalAmountTtc|number_format(3, ',', '') }} TND
{# -- Historique Commentaires -- #}

{% if comments is empty %} {% endif %}
{# ✅ même bloc commentaires que client #} {% include 'admin/document/_comments_block.html.twig' %}
{# --- Ajout commentaire --- #}
{# -- 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') }} {% if activity.user is defined and activity.user %} — {{ activity.user.fullName ?? activity.user.username }} {% endif %}
    {{ activity.message }}
  • {% endfor %}
{% endif %}
{# -- Historique du document -- #}

    {% set icons = { 'achat': '', 'reception': '', 'facture': '', 'retour': '', 'default': '' } %} {% set status_classes = { 'brouillon': 'alert-en-attente', 'en-attente': 'alert-en-attente', 'valide': 'alert-livre', 'transforme': 'alert-livre', 'paye': 'alert-paye', 'facture': 'alert-facture', 'annule': 'alert-annule', 'retour-en-cours': 'alert-retour-en-cours', 'retourne': 'alert-retourne' } %} {# Ancêtres #} {% 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 %}
{% endblock %} {% block js %} {{ parent() }} {% endblock %}