{% extends 'Admin/layout.html.twig' %}

{% trans_default_domain 'form' %}

{% set constDemandePEEStateInscrit = constant('AppBundle\\Enum\\DemandePEEState::REGISTERED') %}
{% set constDemandePEEStatePreinscrit = constant('AppBundle\\Enum\\DemandePEEState::PREREGISTERED') %}
{% set constDemandePEEStateAttente = constant('AppBundle\\Enum\\DemandePEEState::WAITING') %}
{% set constDemandePEEStateDesistement = constant('AppBundle\\Enum\\DemandePEEState::WITHDRAWAL') %}

{% block body %}
    {{ knp_menu_render('actions_stats_opes_pee') }}

    <form action="{{ path('admin_statistics_pee_operation') }}" class="search-admin" method="get">
        <fieldset>
            <div class="search-fields">
                <p>
                    <label for="ope_datemin">Date de début</label>
                    <input id="ope_datemin" type="text" value="{{ ope_datemin ? ope_datemin|date('d/m/Y') : '' }}" class="date" name="ope_datemin"/>
                </p>
                <p>
                    <label for="ope_datemax">Date de fin</label>
                    <input id="ope_datemax" type="text" value="{{ ope_datemax ? ope_datemax|date('d/m/Y') : '' }}" class="date" name="ope_datemax"/>
                </p>
                <p>
                    <label for="ope_company">Entreprise et site</label>
                    <input id="ope_company" type="text" value="{{ ope_company }}" name="ope_company"/>
                </p>
                <p>
                    <label for="ope_state">{{ 'form.state.label'|trans }}</label>
                    <select id="ope_state" name="ope_state">
                        <option value="">- Tous -</option>
                        {% for key, value in ope_states %}
                            <option value="{{ key }}"{% if key == ope_state_selected %} selected="selected"{% endif %}>{{ value }}</option>
                        {% endfor %}
                    </select>
                </p>
                <p>
                    <label for="ope_academy">{{ 'form.academy.label'|trans }}</label>
                    <select id="ope_academy" name="ope_academy">
                        <option value="">- Toutes -</option>
                        {% for academy in ope_academies %}
                            <option value="{{ academy }}"{% if academy == ope_academy %} selected="selected"{% endif %}>{{ academy }}</option>
                        {% endfor %}
                    </select>
                </p>
            </div>
        </fieldset>
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}"/>
        </p>
    </form>
    
    {% set title_additional = nb_pages > 1 ? " (pour les " ~ nb_pages ~ " pages de résultats)" : "" %}
    <table class="tableBo">
        <thead>
            <tr>
                <td colspan="7">Opération PEE</td>
                <td colspan="4">Nombre de participants</td>
            </tr>
            <tr>
                <td>{{ 'form.date.visit.label'|trans }}</td>
                <td>Entreprise et site</td>
                <td>{{ 'form.state.label'|trans }}</td>
                <td>{{ 'form.city.label'|trans }}</td>
                <td>{{ 'form.academy.label'|trans }}</td>
                <td>Participants acceptés</td>
                <td>Taux de remplissage</td>
                <td>Inscrits</td>
                <td>Pré-inscrits</td>
                <td>Liste d'attente</td>
                <td>Désistements</td>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td colspan="5" class="right">Total{{ title_additional }}</td>
                <td class="center" title="{{ inscrits.total.participants }} participants{{ title_additional }}">
                    {{ inscrits.total.participants }}
                </td>
                <td>&nbsp;</td>
                <td class="center" title="{{ inscrits.total[constDemandePEEStateInscrit].nb }} participants inscrits{{ title_additional }}">
                    {{ inscrits.total[constDemandePEEStateInscrit].nb }}
                </td>
                <td class="center" title="{{ inscrits.total[constDemandePEEStatePreinscrit].nb }} participants pré-inscrits{{ title_additional }}">
                    {{ inscrits.total[constDemandePEEStatePreinscrit].nb }}
                </td>
                <td class="center" title="{{ inscrits.total[constDemandePEEStateAttente].nb }} participants en liste d'attente{{ title_additional }}">
                    {{ inscrits.total[constDemandePEEStateAttente].nb }}
                </td>
                <td class="center" title="{{ inscrits.total[constDemandePEEStateDesistement].nb }} participants se sont désistés{{ title_additional }}">
                    {{ inscrits.total[constDemandePEEStateDesistement].nb }}
                </td>
            </tr>
            <tr>
                <td colspan="5" class="right">Moyenne{{ title_additional }}</td>
                <td>&nbsp;</td>
                <td class="center" title="{{ inscrits.total[constDemandePEEStateInscrit].participation_rate }}% de taux moyen de remplissage{{ title_additional }}">
                    {{ inscrits.total[constDemandePEEStateInscrit].participation_rate }}%
                </td>
                <td colspan="4">&nbsp;</td>
            </tr>
        </tfoot>
        <tbody>
            {% for operation in ope_paginated %}
                <tr>
                    <td class="center">{{ operation.datevisite|date('d/m/Y') }}</td>
                    <td>{{ operation.company }} {{ operation.site }}</td>
                    <td>{{ ('word.state.operationPEE.' ~ operation.state ~ '.label')|trans({}, 'word') }}</td>
                    <td>{{ operation.city }}</td>
                    <td>{{ operation.academy }}</td>
                    <td class="center">{{ operation.nbpeople }}</td>
                    <td class="center">{{ inscrits[loop.index0].participation_rate }}%</td>
                    <td class="center">{{ inscrits[loop.index0][constDemandePEEStateInscrit] }}</td>
                    <td class="center">{{ inscrits[loop.index0][constDemandePEEStatePreinscrit] }}</td>
                    <td class="center">{{ inscrits[loop.index0][constDemandePEEStateAttente] }}</td>
                    <td class="center">{{ inscrits[loop.index0][constDemandePEEStateDesistement] }}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
    
    {{ include('Admin/Paginator/pagination.html.twig', {pages:nb_pages}) }}
{% endblock %}