{% extends 'app/base.html.twig' %} {% block title %}Télédéclaration ma-cantine — GestRestoSco{% endblock %} {% block body %}
{# ── En-tête ── #}

Télédéclaration ma-cantine

Envoi des données EGAlim vers la plateforme nationale
Retour EGAlim
{# ── Sélecteur d'année ── #}
Période : {{ dateDebut }} → {{ dateFin }}
{# ── Bandeau total HT ── #}
Total achats alimentaires : {{ totaux.total_general|number_format(2, ',', ' ') }} € HT
Période : {{ dateDebut }} → {{ dateFin }} — Montants en Hors Taxes conformément à la réglementation ma-cantine EGAlim
{# ── Résumé conformité (étapes 1 & 3) ── #} {% set total_durable_hors_bio = totaux.total_durable - totaux.total_bio %} {% set pct_durable_hors_bio = totaux.total_general > 0 ? (total_durable_hors_bio / totaux.total_general * 100)|round(1) : 0 %}
Étape 1 — Total achats alimentaires

{{ totaux.total_general|number_format(2, ',', ' ') }} € HT

dont Bio : {{ totaux.total_bio|number_format(2, ',', ' ') }} € HT
Bio (objectif ≥ 20%)

{{ pct_bio|number_format(1, ',') }}%

{{ totaux.total_bio|number_format(2, ',', ' ') }} € HT {{ conforme_bio ? '✓ Conforme' : '✗ Non conforme' }}
Durables & Qualité (hors bio)

{{ pct_durable_hors_bio|number_format(1, ',') }}%

{{ total_durable_hors_bio|number_format(2, ',', ' ') }} € HT Label Rouge, AOP/IGP, HVE, Pêche, RUP…
Durables & Qualité total (objectif ≥ 50%)

{{ pct_durable|number_format(1, ',') }}%

{{ totaux.total_durable|number_format(2, ',', ' ') }} € HT {{ conforme_durable ? '✓ Conforme' : '✗ Non conforme' }}
{# ── Badge conformité globale ── #}
{% if conforme_global %} Vos achats sont conformes EGAlim pour {{ annee }}. {% else %} Vos achats ne sont pas encore conformes EGAlim pour {{ annee }}. {% if not conforme_bio %} Le seuil Bio de 20% n'est pas atteint.{% endif %} {% if not conforme_durable %} Le seuil Durables de 50% n'est pas atteint.{% endif %} {% endif %}
{# ── Matrice familles × labels ── #}
Matrice EGAlim — {{ annee }}
{# Labels EGAlim exclusifs #} {# Caractéristiques cumulables #} {# Hors EGAlim + Total #} {% set colKeys = ['bio','label_rouge','aoc_aop_igp_stg','hve','ecolabel_peche','rup','commerce_equitable','fermier','provenance_france','circuit_court','local','hors_egalim'] %} {% for familleCode, familleLabel in familles %} {% set ligneMatrice = attribute(matrice, familleCode) is defined ? attribute(matrice, familleCode) : {} %} {% for col in colKeys %} {% set val = attribute(ligneMatrice, col) is defined ? attribute(ligneMatrice, col) : 0 %} {% endfor %} {# Total ligne #} {% set totalLigne = attribute(ligneMatrice, 'total') is defined ? attribute(ligneMatrice, 'total') : 0 %} {% endfor %} {% for col in colKeys %} {% set colSum = 0 %} {% for familleCode in familles|keys %} {% set ligneMatrice = attribute(matrice, familleCode) is defined ? attribute(matrice, familleCode) : {} %} {% set v = attribute(ligneMatrice, col) is defined ? attribute(ligneMatrice, col) : 0 %} {% set colSum = colSum + v %} {% endfor %} {% endfor %}
Famille de produitsBio Label Rouge AOP/IGP HVE Pêche durable RUP Éq. équitable FermierFrance Circuit court LocalHors EGAlim Total
{{ familleLabel }} {% if val > 0 %}{{ val|number_format(2, ',', ' ') }}{% else %}{% endif %} {{ totalLigne > 0 ? totalLigne|number_format(2, ',', ' ') : '—' }}
TOTAL GÉNÉRAL{{ colSum > 0 ? colSum|number_format(2, ',', ' ') : '—' }}{{ totaux.total_general|number_format(2, ',', ' ') }}
{# ═══════════════════════════════════════════════════════════════ SECTION MA-CANTINE API ════════════════════════════════════════════════════════════════ #}
Envoi vers la plateforme ma-cantine {% if isDemo %} Mode DEMO {% endif %}
{% if not isConfigured %} {# ─── État 1 : Non configuré ─── #}
Pour envoyer vos données sur ma-cantine.agriculture.gouv.fr, configurez d'abord votre application OAuth2.
Visible dans l'URL de votre cantine sur ma-cantine.agriculture.gouv.fr
{% elseif not isAuthenticated %} {# ─── État 2 : Configuré mais non authentifié ─── #}
Application configurée. Vous devez vous connecter à ma-cantine pour autoriser l'accès.
Cantine configurée : #{{ config.canteen_pk }} — Environnement : {{ config.env ?? 'production' }}
{# Formulaire de modification (masqué par défaut) #}
{% else %} {# ─── État 3 : Authentifié ─── #}
Connecté à ma-cantine — Cantine #{{ config.canteen_pk }} {% if isDemo %}DEMO{% endif %}
{# Diagnostic existant #} {% if storedDiagPk > 0 %}
Diagnostic {{ annee }} déjà synchronisé (ID : #{{ storedDiagPk }}). Cliquez sur Envoyer à ma-cantine pour mettre à jour les données.
{% endif %}
{# Voir sur ma-cantine #}
{% endif %}{# end isAuthenticated #}
{# ── Guide d'utilisation ── #}
Guide de télédéclaration
  1. Créez votre application OAuth2 sur votre compte ma-cantine → "Développement et APIs" → "Gérer mes applications" → "Créer une application". Notez le Client ID et Client Secret.
  2. Renseignez l'URL de redirection suivante dans votre application ma-cantine : {{ baseUrl }}/app/egalim/macantine/callback
  3. Saisissez la configuration ci-dessus (Client ID, Secret, ID cantine).
  4. Connectez-vous via OAuth2 (votre navigateur s'ouvrira sur ma-cantine).
  5. Cliquez "Envoyer à ma-cantine" pour synchroniser vos données EGAlim (création du diagnostic).
  6. Finalisez la télédéclaration directement sur ma-cantine en cliquant sur le bouton "Télédéclarer" (action réservée à l'utilisateur connecté sur la plateforme).
La télédéclaration est obligatoire avant le 31 mars pour l'année N-1. Les données envoyées sont publiques sur ma-cantine.agriculture.gouv.fr.
{# ── Tokens CSRF en data attributes ── #} {% endblock %}