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

{% block title %}Make Invoices{% endblock %}

{% block content %}
<h2>Outstanding Hours</h2>
<ul class='header-actions-left'>
    <li>
        Create Invoice
    </li>
    <li>
        {% if perms.timepiece.view_person_time_sheet %}
            <a href="{% url 'list_invoices' %}">Previous Invoices</a>
        {% endif %}
    </li>
</ul>


{% date_filters "months_no_range" %}
<form method="get" action="" id="date-filter" accept-charset="utf-8">
    {{ date_form }}
    <input type='submit' name='yearmonth' value="Update" id='yearmonth'/>
</form>

<div class="cal_wrapper" style='float: right;'>
    <div class="cal left"> {% show_cal to_date -1 %} </div>
    <div class="cal middle"> {% show_cal to_date 0 %} </div>
</div>

{% if unverified %}
    <p><strong>Warning:</strong> The following users have <strong>unverified</strong> time during this period:</p>
    <ul>
        {% for pk, first, last in unverified %}
            <li><a href="{% url 'view_person_time_sheet' pk %}">{{ first }} {{ last }}</a></li>
        {% endfor %}
    </ul>
{% endif %}

{% if unapproved %}
    <p><strong>Warning:</strong> The following users have <strong>unapproved</strong> time during this period:</p>
    <ul>
        {% for pk, first, last in unapproved %}
            <li><a href="{% url 'view_person_time_sheet' pk %}">{{ first }} {{ last }}</a></li>
        {% endfor %}
    </ul>
{% endif %}

{% regroup project_totals by project__type__label as type_list %}
{% for type in type_list %}
    <h3>Summary of {{ type.grouper }} Entries</h3>
    <table>
        <tr>
            <th>Project name</th>
            <th>Status</th>
            <th>Uninvoiced Hours</th>
            <th></th>
        </tr>
        {% regroup type.list by project__name as project_list %}
        {% for project in project_list %}
            <tr>
                <th>{{ project.grouper }}</th>
                <td>{{ project.list.0.project__status__label|title }}</td>
                <td class="hours">{% get_uninvoiced_hours project.list %}</td>
                <td>
                    {% if from_date %}
                        <a href="{% url 'confirm_invoice_project' project.list.0.project__pk to_date|date:'Y-m-d' from_date|date:'Y-m-d' %}">Make Invoice</a>
                    {% else %}
                        <a href="{% url 'confirm_invoice_project' project.list.0.project__pk to_date|date:'Y-m-d' %}">Make Invoice</a>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
    </table>
{% endfor %}
{% endblock %}

