{% extends "timepiece/time-sheet/reports/base.html" %}
{% load timepiece_tags bootstrap_toolkit %}
{% load url from future %}

{% block title %}Hourly Report{% endblock %}

{% block extrajs %}
    {{ pj_filters.media }}
{% endblock extrajs %}

{% block bodyid %}hourly-report{% endblock bodyid %}

{% block crumbs %}
    {{ block.super }}
    <li><span class="divider">/</span> <a href="{% url 'hourly_report' %}">Hourly Report</a></li>
{% endblock crumbs %}

{% block report_nav %}
    {% with 'hourly_report' as active %}
        {{ block.super }}
    {% endwith %}
{% endblock %}

{% block report_content %}
    <div class="row-fluid">
        <div class="span12">
            {% date_filters "pj_select" %}
        </div>
    </div>

    <div class="row-fluid">
        <form class="span12 form-horizontal" method="get" action="" id="pj_select" accept-charset="utf-8">
            <div class="row-fluid">
                <div class="span3">
                    {{ date_form|as_bootstrap:"horizontal" }}
                    {{ pj_filters|as_bootstrap:"horizontal" }}
                    <button type="submit" class="btn btn-primary" name="ok" id="billable">Apply Filters</button>
                    {% if perms.timepiece.export_project_time_sheet %}
                        <button type="submit" class="btn" name="export" value="True">Export as CSV</button>
                    {% endif %}
                </div>
            </div>
        </form>
    </div>

    <div class="row-fluid">
        <div class="span12">
            {% if project_totals %}
                <div class="scroll">
                    <table class="table table-bordered table-striped table-condensed">
                        <thead>
                            <tr>
                                <th class="name_col">Name</th>
                                {% for date in date_headers %}
                                    {% if trunc == "month" %}
                                        <th>{{date|date:"M Y"}}</th>
                                    {% else %}
                                        <th>{{date|date:"M/d/Y"}}</th>
                                    {% endif %}
                                {% endfor %}
                                <th>Total</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for rows, totals in project_totals %}
                                {% for name, user_id, hours in rows %}
                                    <tr>
                                        <th class="name_col">{{name}}</td>
                                        {% for num in hours %}
                                            <td class="hours" title="{{name}}">{{num|floatformat:2}}</td>
                                        {% endfor %}
                                    </tr>
                                {% endfor %}
                                <tr class="total">
                                    <th class="name_col">Total:</td>
                                    {% for total in totals %}
                                        <td class="hours">{{total|floatformat:2}}</td>
                                    {% endfor %}
                                </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            {% else %}
                <p>No entries found.</p>
            {% endif %}
        </div>
    </div>
{% endblock report_content %}
