{% trans_default_domain 'retencion' %}
{% set table_columns = 8 %}

{% if not table_selectable is defined %}
    {# This variable MUST be explicitly set to false to hide checkboxes         #}
    {# If you set this to false and you have a second listing that display them #}
    {# set explicitly to true in the second listing.                            #}
    {% set table_selectable = true %}
    {% set table_columns = table_columns + 1 %}
{% endif %}
{% if not paginatable is defined %}
    {% set paginatable = true %}
{% endif %}
{% if not sortable is defined %}
    {% set sortable = true %}
{% endif %}

{% if table_selectable %}
    {{ form_start(list_form) }}

<div class="box pad">
    <div class="box-header">
        <i class="fa fa-list-ul"></i>
        <h3 class="box-title">Retenciones</h3>
        <!-- tools box -->
        &nbsp;&nbsp;
       {# <div class="btn-group">
            <button type="submit" name="delete" class="btn btn-default"
                    title="{% trans %}list.bulk_delete{% endtrans %}"
                    data-confirm="{% trans %}list.bulk_delete_confirm{% endtrans %}"><span
                        class="glyphicon glyphicon-trash"></span></button>
            <button type="submit" name="print" class="btn btn-default" title="{% trans %}list.bulk_print{% endtrans %}">
                <span class="glyphicon glyphicon-print"></span></button>
            <button type="submit" name="pdf" class="btn btn-default" title="{% trans %}list.bulk_pdf{% endtrans %}">
                <span class="glyphicon glyphicon-download-alt"></span></button>
            <button type="submit" name="email" class="btn btn-default" title="{% trans %}list.bulk_email{% endtrans %}">
                <span class="glyphicon glyphicon-envelope"></span></button>
        </div>
        #}
        <!-- /. tools -->


    </div>
    <div class="box-body">


        {% endif %}

        <table class="table table-condensed table-striped align-middle" data-type="invoices">
            <thead>
            <tr>
                {% if table_selectable %}
                    {#<th class="cell-size-tiny cell-align-center">
                        {# <input type="checkbox" name="all" />#
                    </th>
                    #}
                {% endif %}
                <th class="cell-size-medium">
                    Serie
                </th>
                <th class="cell-size-medium">
                    {% if sortable %}
                        {{ knp_pagination_sortable(invoices, 'list.number'|trans, 'i.number') }}
                    {% else %}
                        {% trans %}list.number{% endtrans %}
                    {% endif %}
                </th>
                <th>
                    {% if sortable %}
                        {{ knp_pagination_sortable(invoices, 'Ambiente', 'i.ambiente') }}
                    {% else %}
                        Ambiente
                    {% endif %}
                </th>
                <th>
                    {% if sortable %}
                        {{ knp_pagination_sortable(invoices, 'Proveedor', 'i.provider_name') }}
                    {% else %}
                        {% trans %}list.provider{% endtrans %}
                    {% endif %}
                </th>
                <th class="cell-size-medium">
                    {% if sortable %}
                        {{ knp_pagination_sortable(invoices, 'list.issue_date'|trans, 'i.issue_date') }}
                    {% else %}
                        {% trans %}list.issue_date{% endtrans %}
                    {% endif %}
                </th>
                {#
                <th class="cell-size-medium">
                  {% if sortable %}
                  {{ knp_pagination_sortable(invoices, 'list.due_date'|trans, 'i.due_date') }}
                  {% else %}
                  {% trans %}list.due_date{% endtrans %}
                  {% endif %}
                </th>
                #}
                <th class="cell-size-small-medium cell-align-center">
                    {% if sortable %}
                        {{ knp_pagination_sortable(invoices, 'list.status'|trans, 'i.status') }}
                    {% else %}
                        {% trans %}list.status{% endtrans %}
                    {% endif %}
                </th>
                {#<th class="cell-size-medium cell-align-right">
                  {% if sortable %}
                  {{ knp_pagination_sortable(invoices, 'list.due_amount'|trans, 'due_amount') }}
                  {% else %}
                  {% trans %}list.due_amount{% endtrans %}
                  {% endif %}
                </th>
                #}
                <th class="cell-size-medium cell-align-right">
                    {% if sortable %}
                        {{ knp_pagination_sortable(invoices, 'Retenido', 'i.gross_amount') }}
                    {% else %}
                        {% trans %}list.gross_amount{% endtrans %}
                    {% endif %}
                </th>
                {#<th class="cell-size-medium"></th>#}
            </tr>
            </thead>
            <tbody>
            {% if invoices|length == 0 %}
                <tr>
                    <td colspan="{{ table_columns }}">{% trans %}list.no_results{% endtrans %}</td>
                </tr>
            {% endif %}
            {% set total = 0 %}
            {% for key, result in invoices %}
                {% set entity = result %}
                <tr data-link="{{ path('retencion_show', { 'id': entity.id , 'slug': entity.slug}) }}">
                    {% if table_selectable %}
                        {#<td class="table-action cell-align-center no-link">
                            {% if entity.ambiente == 1 %}
                                {{ form_row(list_form.invoices[key]) }}
                            {% else %}
                                <div class="col-md-1 clearfix" style="display: none; visibility: hidden;">
                                    {{ form_row(list_form.invoices[key]) }}
                                </div>
                            {% endif %}
                        </td>
                        #}
                        <td class="table-action cell-align-center no-link" style="display: none">
                            {{ form_row(list_form.invoices[key]) }}
                        </td>
                    {% endif %}
                    <td class="cell-size-medium">{{ entity.serie('retencion.draft_label'|trans) }}</td>
                    <td class="cell-size-medium">{{ entity.label('retencion.draft_label'|trans) }}</td>
                    <td class="cell-size-medium">{{ entity.labelAmbiente }}</td>
                    <td>{{ entity.getProviderName }}</td>
                    <td>{{ entity.issueDate|date("d/m/Y") }}</td>
                    <td class="cell-align-center">
                        {% if entity.anulado == true %}
                            <span class="label overdue">Anulado</span>
                        {% else %}
                            {% if entity.estado == 'A' %}
                                <span class="label closed">Autorizado</span>
                            {% else %}
                                <span class="label opened">No Autorizado</span>
                            {% endif%}
                        {% endif %}

                    </td>
                    <td class="cell-align-right">{{ entity.grossAmount|localizedcurrency(currency, app.request.locale) }}</td>
                </tr>

                {% set total = total+ entity.grossAmount %}
            {% endfor %}

            </tbody>
        </table>

        {% if table_selectable %}
    </div>
    {{ form_end(list_form) }}
    {% endif %}
    {% if paginatable %}
        <div class="navigation">
            {{ knp_pagination_render(invoices) }}
        </div>
    {% endif %}
</div>

<div id="payment-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="payments-modal-title">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="{% trans %}list.payments_modal_close{% endtrans %}"><span
                            aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="payments-modal-title">{% trans %}list.payments{% endtrans %}</h4></div>
            <div class="modal-body"></div>
        </div>
    </div>
</div>
