{% extends '@kohinos/block/onetransaction.html.twig' %}
{# Cotisation obligatoire pour les adhérents #}
{% set cotisation_required = KOH_ALLOW_COTISATION|default('false') == 'true' and KOH_COTISATION_ADHERENT_MANDATORY|default('false') == 'true' and false == isCotisationValid(app.user) %}
{# DISABLE ALL TRANSACTIONS IF USER HAS NO COTISATION VALID #}
{% block blocktoggle %}{% if not cotisation_required %}collapse{% endif %}{% endblock blocktoggle %}
{% block blocktitle %}
{{'Virement vers un adhérent'|trans }}
{% endblock blocktitle %}
{% block blockcontent %}
{% if cotisation_required %}
{% include '@kohinos/block/_cotisation_required_message.html.twig' with {'operation_label': 'les virements vers les adhérents'} %}
{% else %}
{% set form = getTransactionAdherentAdherentForm(app.user) %}
{{ form_start(form) }}
{% if form.expediteur is defined %}
{{ form_row(form.expediteur) }}
{% endif %}
{% if form.destinataire is defined %}
{# Render destinataire field with favorites partial #}
{# Build favorites array of IDs in a Twig-compatible way #}
{% set favorites = [] %}
{% for fav in app.user.getFavoriteAdherents %}
{% set favorites = favorites|merge([fav.id]) %}
{% endfor %}
{# Debug information #}
{# Pass the field to the template but don't render it directly to avoid duplicate IDs #}
{% include '@kohinos/block/_favorite_adherent_select.html.twig' with {form: form, favorites: favorites} %}
{# Mark the field as rendered to prevent automatic rendering at form_end #}
{% do form.destinataire.setRendered() %}
{% endif %}
{% if form.montant is defined %}
{{ form_row(form.montant) }}
{% endif %}
{% if form.moyen is defined %}
{{ form_row(form.moyen) }}
{% endif %}
{% if form.reference is defined %}
{{ form_row(form.reference) }}
{% endif %}
{% if form.save is defined %}
{{ form_row(form.save) }}
{% endif %}
{{ form_end(form) }}
{% endif %}
{% endblock blockcontent %}