{% extends '@kohinos/common/layout.html.twig' %}

{% block content %}
<div class='container operations mt-5 mb-5'>
    {% include '@kohinos/block/breadcrumb.html.twig' with {'label' : 'Opérations du compte'|trans } %}
    <div class='card'>
        <div class="card-header"><h3>{{ 'Opérations du compte'|trans }} <b>{{ getCurrencyName(currency) }}</b></h3></div>
        <div class="card-body">
            <div class="card-text">
                {{ form_start(searchForm) }}
                {{ form_row(searchForm._token) }}
                <div class='container row'>
                    <div class='col-4'>{{ form_row(searchForm.moyen) }}</div>
                    <div class='col-4'>{{ form_row(searchForm.datemin) }}</div>
                    <div class='col-4'>{{ form_row(searchForm.datemax) }}</div>
                    {% if searchForm.showMonAPurchaseOnly is defined and ssa_friendly_flux_type_names %}
                        <div class='col-4'>{{ form_row(searchForm.showMonAPurchaseOnly) }}</div>
                        <div class='col-8 text-right'>{{ form_row(searchForm.submit) }}</div>
                    {% else %}
                        <div class='col-12 text-right'>{{ form_row(searchForm.submit) }}</div>
                    {% endif %}
                </div>
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                          <tr>
                            <th scope="col">{{ 'Date'|trans }}</th>
                            <th scope="col">{{ 'Montant'|trans }}</th>
                            <th scope="col">{{ 'Type'|trans }}</th>
                            <th scope="col">{{ 'Moyen'|trans }}</th>
                            <th scope="col">{{ 'Operation'|trans }}</th>
                            <th scope="col">{{ 'Référence'|trans }}</th>
                          </tr>
                        </thead>
                        <tbody>
                        {% for operation in operations %}
                            <tr>
                                <td><span data-toggle="tooltip" data-placement="bottom" title="{{ operation.createdAt|date('d/m/Y H:i') }}">{{ operation.createdAt|date('d/m/Y') }}</span></td>
                                <td class='text-right'><span class='font-weight-bold {{ (operation.montant < 0)? '':'text-primary' }}'>{{ (operation.montant < 0)? '- ':'+ ' }} {{ operation.montant|abs|number_format(2) }}</span></td>
                                <td>{{ ((isCurrentAccountable(app.user, operation.flux.expediteur) ? 'exp' : 'des')~'_'~operation.flux.parenttype)|trans({}, 'flux') }}</td>
                                <td>{{ operation.flux.moyen|trans }}</td>
                                <td>
                                    <span>
                                        {% if not isCurrentAccountable(app.user, operation.flux.expediteur)  %}
                                            {{ operation.flux.expediteur }}
                                        {% elseif not isCurrentAccountable(app.user, operation.flux.destinataire)  %}
                                            {{ operation.flux.destinataire }}
                                        {% endif %}
                                    </span>
                                </td>
                                <td>{{ operation.flux.reference }}</td>
                            </tr>
                        {% endfor %}
                      </tbody>
                    </table>
                </div>
                {% if operations|length > 0 %}
                    <div class="kohpagination">
                        {{ knp_pagination_render(operations) }}
                    </div>
                    <div class="btn-group d-block text-center">
                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" data-toggle="dropdown" id="dropdownMenuLink">
                            <i class="fa fa-share-square-o" aria-hidden="true"></i>
                            {{ 'Exporter les opérations'|trans }}
                            <span class="caret"></span>
                        </button>
                        <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                            <button type="submit" id="formListOperations_json" name="formListOperations[json]" class="dropdown-item">
                                <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                JSON
                            </button>
                            <button type="submit" id="formListOperations_xml" name="formListOperations[xml]" class="dropdown-item">
                                <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                XML
                            </button>
                            <button type="submit" id="formListOperations_csv" name="formListOperations[csv]" class="dropdown-item">
                                <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                CSV
                            </button>
                            <button type="submit" id="formListOperations_xls" name="formListOperations[xls]" class="dropdown-item">
                                <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                XLS
                            </button>
                        </div>
                    </div>
                {% endif %}
                </form>
            </div>
        </div>
    </div>
</div>
</div>
{% endblock %}
