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

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

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

{% block content %}
    <div class="row-fluid">
        <div class="span12">
            <h2>Outstanding Hours</h2>
            <ul class="nav nav-pills">
                {# Not sure why the below is here if it doesn't link to anywhere. Adding inline styling for now until that question is answered. #}
                <li style="padding: 8px;">
                    Create Invoice
                </li>
                <li>
                    {% if perms.timepiece.view_entry_group %}
                        <a href="{% url 'list_invoices' %}">Previous Invoices</a>
                    {% endif %}
                </li>
            </ul>
        </div>
    </div>

    <div class="row-fluid">
        <div class="span12">
            {% date_filters "date-filter" "months" 0 %}
        </div>
    </div>

    <div class="row-fluid">
        <div class="span4">
            <form class="form-inline" method="get" action="" id="date-filter" accept-charset="utf-8">
                {{ date_form|as_bootstrap:"inline" }}
                <input class="btn" type='submit' name='yearmonth' value="Update" id='yearmonth'/>
            </form>
        </div>
    </div>

    <div class="row-fluid">
        <div class="span12">
            {% regroup project_totals by project__type__label as type_list %}
            {% for type in type_list %}
                <h3>Summary of {{ type.grouper }} Entries</h3>
                <table class="table table-bordered table-condensed table-striped">
                    <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>
                            <td><a href="{% timesheet_url 'project' project.list.0.project__pk to_date %}">{{ project.grouper }}</a></td>
                            <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 %}
        </div>
    </div>
{% endblock %}

