{% import "macros/widgets.html.twig" as widgets %}
{% import "macros/datatables.html.twig" as tables %}
{% extends 'invoice/layout.html.twig' %}

{% block title %}{{ 'menu.export'|trans }}{% endblock %}
{% block invoice %}
    {% set decimal = decimal|default(false) %}
    {% set showUserColumn = true %}
    {% if query.user %}
        {% set showUserColumn = false %}
    {% endif %}

    <div class="row">
        <div class="col-xs-12">
            <h2 class="page-header">
                {% if not showUserColumn %}
                    {{ widgets.username(query.user) }}:
                {% endif %}
                {% if query.begin is not empty %}
                    {{ query.begin|date_short }}
                {% else %}
                    {% set last = entries|last %}
                    {{ last.begin|date_short }}
                {% endif %}
                &ndash;
                {% if query.end is not empty %}
                    {{ query.end|date_short }}
                {% else %}
                    {% set first = entries|first %}
                    {{ first.end|date_short }}
                {% endif %}
            </h2>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12 table-responsive">
            <table class="table">
                <thead>
                <tr>
                    <th>{{ 'label.date'|trans }}</th>
                    {% if showUserColumn %}
                        <th>{{ 'label.username'|trans }}</th>
                    {% endif %}
                    <th>{{ 'label.description'|trans }}</th>
                    {% for field in metaColumns %}
                        <th class="text-nowrap">{{ field.label|trans }}</th>
                    {% endfor %}
                    <th>{{ 'label.hours'|trans }}</th>
                </tr>
                </thead>
                <tbody>
                {% set timeWorked = 0 %}
                {% for entry in entries %}
                    {% set timeWorked = timeWorked + entry.duration %}
                    <tr>
                        <td class="text-nowrap">{{ entry.begin|date_short }}</td>
                        {% if showUserColumn %}
                            <td>{{ widgets.username(entry.user) }}</td>
                        {% endif %}
                        <td>
                            {% if entry.description is not empty %}
                                <div>
                                    {{ entry.description|escape|desc2html }}
                                </div>
                            {% endif %}
                            <span class="small">
                                {% if entry.activity is not null %}{{ 'label.activity'|trans }}: {{ entry.activity.name }} |{% endif %}
                                {{ 'label.project'|trans }}: {{ entry.project.name }} |
                                {{ 'label.customer'|trans }}: {{ entry.project.customer.name }}
                            </span>
                        </td>
                        {% for field in metaColumns %}
                            <td>{{ tables.datatable_meta_column(entry, field) }}</td>
                        {% endfor %}
                        <td class="text-nowrap">{{ entry.duration|duration(decimal) }}</td>
                    </tr>
                {% endfor %}
                </tbody>
                <tfoot>
                <tr>
                    <th></th>
                    {% if showUserColumn %}
                        <th></th>
                    {% endif %}
                    {% for field in metaColumns %}
                        <th></th>
                    {% endfor %}
                    <th>{{ 'invoice.total_working_time'|trans }}</th>
                    <th class="text-nowrap">{{ timeWorked|duration(decimal) }}</th>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>

{% endblock %}

{% block print_button %}{% endblock %}