{% extends 'timepiece/time-sheet/base.html' %}
{% load timepiece_tags %}

{% block title %}{{ project }} Time Sheet{% endblock %}

{% block content %}
<h2>{{ project }} Time Sheet ({{ window.date|date:"N j" }} &mdash; {{ window.end_date|date:"N j" }})</h2>
<ul class='header-actions-left'>
    <li><a href='{% url view_project project.id %}'>Project Information</a></li>
    <li>
        {% if window.previous %}
            <a href='{% url project_time_sheet project.id,window.previous.id %}'>Previous Time Sheet</a>
        {% else %}
            Previous Time Sheet
        {% endif %}
    </li>
    <li>
        {% if window.next %}
            <a href='{% url project_time_sheet project.id,window.next.id %}'>Next Time Sheet</a>
        {% else %}
            Next Time Sheet
        {% endif %}
    </li>
    {% if perms.timepiece.export_project_time_sheet %}
    <li><a href='{% url export_project_time_sheet project.id,window.id %}'>Export as CSV</a></li>
    {% endif %}
</ul>

{% if entries %}
    <table>
        <tr>
            <th>Date</th>
            <th>Person</th>
            <th>Activity</th>
            <th>Location</th>
            <th>Time In</th>
            <th>Time Out</th>
            <th>Breaks</th>
            <th>Hours</th>
        </tr>
        {% for entry in entries %}
        <tr{% if entry.comments %} title='{{ entry.comments }}'{% endif %}>
            <td>{{ entry.start_time|date:"m/d/Y (D)" }}</td>
            <td>{{ entry.user.get_full_name }}</td>
            <td>{{ entry.activity }}</td>
            <td>{{ entry.location }}</td>
            <td>{{ entry.start_time|date:"P" }}</td>
            <td>{{ entry.end_time|date:"P" }}</td>
            <td>{{ entry.seconds_paused|seconds_to_hours }}</td>
            <td>{{ entry.hours }}</td>
        </tr>
        {% endfor %}
        <tr>
            <th colspan='6'>Total:</th>
            <td>{{ total|floatformat:2 }}</td>
        </tr>
    </table>
{% else %}
    <p>No entries exist for this time sheet.</p>
{% endif %}

{% if user_entries %}
    <table id='person-summary'>
        <caption>Person Summary</caption>
    {% for entry in user_entries %}
        <tr>
            <td>{{ entry.user__first_name }} {{ entry.user__last_name }}</td>
            <td>{{ entry.sum }}</td>
        </tr>
    {% endfor %}        
    </table>
{% endif %}

{% if activity_entries %}
    <table id='activity-summary'>
        <caption>Activity Summary</caption>
    {% for row in activity_entries %}
        <tr>
            <td>{{ row.activity__name }}</td>
            <td>{{ row.sum }}</td>
        </tr>
    {% endfor %}  
    </table>
{% endif %}

<br style='clear: both' />

{% endblock %}
