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

{% block title %}Payroll Summary{% endblock %}

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

{% block content %}
    <div class="row">
        <div class="span12">
            <h2>Reports</h2>
            <ul class="nav nav-pills">
                <li>
                    {% if perms.timepiece.view_entry_summary %}
                        <a href='{% url 'hourly_report' %}'>Hourly</a>
                    {% endif %}
                </li>
                <li>
                    {% if perms.timepiece.view_entry_summary %}
                        <a href='{% url 'timepiece-summary' %}'>General Ledger</a>
                    {% endif %}
                </li>
                <li class="active">
                    <a href="#">Payroll Report</a>
                </li>
            </ul>
        </div>
    </div>

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

    <div class="row">
        <div class="span6">
            {% 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 %}?month={{from_date|date:"n"}}&year={{from_date|date:"Y"}}">{{ 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 %}?month={{from_date|date:"n"}}&year={{from_date|date:"Y"}}">{{ first }} {{ last }}</a></li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if not unverified and not unapproved %}
                <p>All time verified and approved</p>
            {% endif %}
        </div>
    </div>

    <div class="row">
        <div class="span12">
            <h3>Hourly Summary</h3>
            {% if monthly_totals %}
                <table class="table table-bordered table-striped table-condensed">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th colspan="2">Billable</th>
                            <th colspan="2">Non-Billable</th>
                            <th>Total Worked</th>
                            <th>Paid Leave</th>
                            <th>Grand Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for name, hours, descs, all in monthly_totals %}
                            <tr>
                                <th class='name_col'>{{ name }}</th>
                                {% for num in hours|slice:"0:2" %}
                                    <td class="hours">{{num.0|floatformat:2|default:""}}</td>
                                    <td class="hours">{% if num.1 %}({{num.1|floatformat:2}}%){% endif %}</td>
                                {% endfor %}
                                <td class="hours">{{hours.2|floatformat:2}}</td>
                                <td class="hours" style="width: 200px;">
                                {% for desc in descs %}
                                    {{desc.0}}:&nbsp;&nbsp;{{desc.1|floatformat:2}}
                                {% endfor %}
                                </td>
                                <td class="hours">{{all|floatformat:2}}</td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            {% else %}
                <p> No entries found.</p>
            {% endif %}
        </div>
    </div>

    <div class="row">
        <div class="span12">
            <h3>Weekly Summary</h3>
            {% if weekly_totals.0.0 %}
                <table class='table table-striped table-bordered table-condensed'>
                    <thead>
                        <tr>
                            <th class='name_col'>Name</th>
                            {% for date in date_headers %}
                                <th>{{date|date:"M/d"}}</th>
                            {% endfor %}
                            <th>Overtime</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for rows, totals in weekly_totals %}
                            {% for name, hours in rows %}
                                <tr>
                                    <th class='name_col'>{{name}}</th>
                                    {% for num in hours %}
                                        <td class='hours' title='{{name}}'>{{num|floatformat:2}}</td>
                                    {% endfor %}
                                </tr>
                            {% endfor %}
                        {% endfor %}
                    </tbody>
                </table>
                {% else %}
                    <p>No entries found.</p>
            {% endif %}
        </div>
    </div>
{% endblock %}

