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

{% block title %}Projection Summary{% endblock %}

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

{% block content %}
    <div class="row">
        <div class="span12">
            <h2>Projection Summary</h2>
        </div>
    </div>

    <div class="row">
        <div class="span12">
            {% date_filters "months" %}
        </div>
    </div>

    <div class="row">
        <div class="span4">
            <form class="form-vertical" method="get" action="" id="date-filter" accept-charset="utf-8">
                {{ form }}
                <br />
                <input class="btn" type='submit' name='submit' value='Update' id='id_date_form_submit_btn'/>
                <input class="btn" type='button' name='clear' value='Clear' id='id_date_form_clear_btn'/>
            </form>
        </div>
    </div>

    <div class="row">
        <div class="span12">
            <table class="table table-bordered table-condensed">
                {% for contract in contracts %}
                    <tr>
                        <th colspan="{{ weeks.count }}" class='contract'>{{ contract }} (Due {{ contract.end_date|date:"n/j" }}) - Remaining: {{ contract.hours_remaining }}, Allocated: {{ contract.hours_allocated }}</th>
                    </tr>
                    <tr>
                        <th>&nbsp;</th>
                        <th class='assigned'>Assigned</th>
                        <th class='worked'>Worked</th>
                        {% for week in weeks %}
                            <th>{{ week|date:"n/j" }}</th>
                        {% endfor %}
                        <th>Allocated</th>
                    </tr>
                    {% for assignment in contract.assignments.select_related %}
                        <tr>
                            <td>{{ assignment.user }}</td>
                            <td class='assigned'>{{ assignment.num_hours }}{% if assignment.min_hours_per_week %}({{ assignment.min_hours_per_week }}){% endif %}</td>
                            <td class='worked'>{{ assignment.hours_worked }}</td>
                            {% for week in weeks %}
                                <td>{% hours_for_assignment assignment week %}</td>
                            {% endfor %}
                            <td class='allocated'>{% total_allocated assignment %}</td>
                        </tr>
                    {% endfor %}
                {% endfor %}
                <tr>
                    <th>&nbsp;</th>
                    <th colspan="{{ weeks.count }}">&nbsp;</th>
                </tr>
                <tr>
                    <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        {% for week in weeks %}
                            <th>{{ week|date:"m/j" }}</th>
                        {% endfor %}
                <tr/>
                {% for user in users %}
                    <tr>
                        <th>{{ user }}</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        {% for week in weeks %}
                            <td>{% hours_for_week user week %}</td>
                        {% endfor %}
                     </tr>
                {% endfor %}
            </table>
        </div>
    </div>
{% endblock %}

