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

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

{% block content %}
<h2>Payroll Report</h2>

{% date_filters "months" %}

<form method="get" action="" id="date-filter" accept-charset="utf-8">
    <ul id='ledger-date-fieldlist'>
        {{ form.as_ul }}
        <li>
            <input type='submit' name='submit' value='Update' id='id_date_form_submit_btn'/>
        </li>
        <li>
            <input type='button' name='clear' value='Clear' id='id_date_form_clear_btn'/>
        </li>
    </ul>
</form>

<div style='float: right;'>
{% for cal in cals %}
{{ cal|safe }}
{% endfor %}
</div>

<h3>Weekly Summary</h3>

<table>
    <tr>
        <th>&nbsp;</th>
        {% for week in all_weeks %}
            <th>{{ week|date:"n/j" }}</th>
        {% endfor %}
        <th>Overtime</th>
    </tr>
    {% for period in periods %}
        {% with period.user as user %}
            <tr{% if user.overtime > 40.00 %} class='overtime'{% endif %}>
                <th>{{ user.first_name }} {{ user.last_name }}</th>
                {% for week in all_weeks %}
                    <td>{% weekly_hours_worked period week %}</td>
                {% endfor %}
                <td>{% monthly_overtime period from_date %}
            </tr>
        {% endwith %}
    {% endfor %}
</table>

<h3>Hourly Summary</h3>

<table>
    <tr>
        <th>&nbsp;</th>
        <th>Billable</th>
        <th>Non-Billable</th>
        <th>Total Worked</th>
        <th>Paid Leave</th>
        <th>Grand Total</th>
    </tr>
    {% for period in periods %}
        {% with period.user as user %}
            <tr>
                <th>{{ user.first_name }} {{ user.last_name }}</th>
                {% if user.summary %}
                    <td>{% if user.summary.billable %}{{ user.summary.billable }} ({% widthratio user.summary.billable user.summary.total_worked 100 %}%){% endif %}</td>
                    <td>{% if user.summary.non_billable %}{{ user.summary.non_billable }} ({% widthratio user.summary.non_billable user.summary.total_worked 100 %}%){% endif %}</td>
                    <td>{% if user.summary.total_worked %}{{ user.summary.total_worked }}{% endif %}</td>
                    <td>
                    {% for leave_type, leave_hours in user.summary.paid_leave.iteritems %}
                        {% if leave_hours %}
                        {{ leave_type|capfirst }}: {{ leave_hours }}<br/>
                        {% endif %}
                    {% endfor %}
                    </td>
                    <td>{{ user.summary.total|default_if_none:'' }}</td>
                {% else %}
                    <td colspan='5'>&nbsp;</td>
                {% endif %}
            </tr>
        {% endwith %}
    {% endfor %}
</table>
{% endblock %}

