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

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

{% block content %}


<h2>Reports</h2>
<ul class='header-actions-left'>
    <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>
        Payroll Report        
    </li>
</ul>

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

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


<h3>Weekly Summary</h3>
{% if weekly_totals.0.0 %}
    <table class='project'>
        <tr class="header">
            <th class='name_col'>Name</th>
            {% for date in date_headers %}
                <th>{{date|date:"M/d"}}</th>
            {% endfor %}
            <th>Overtime</th>
        </tr>
        {% for rows, totals in weekly_totals %}
            {% for name, hours in rows %}
                <tr class="{% cycle 'odd' 'even' %}">           
                    <th class='name_col'>{{name}}</th>
                    {% for num in hours %}
                        <td class='hours' title='{{name}}'>{{num}}</td>
                    {% endfor %}
                </tr>                
            {% endfor %}
        {% endfor %}
    </table>
    {% else %}
        <p>No entries found.</p>
{% endif %}

<h3>Hourly Summary</h3>
{% if monthly_totals %}
    <table>
        <tr class="header">
            <th>Name</th>
            <th colspan="2">Billable</th>
            <th colspan="2">Non-Billable</th>
            <th>Total Worked</th>
            <th style="text-align:right;">Paid Leave</th>
            <th>Grand Total</th>
        </tr>
        {% for name, hours, descs, all in monthly_totals %}
            <tr class="{% cycle 'odd' 'even' %}">           
                <th class='name_col'>{{name.1}} {{name.0}}</th>
                {% for num in hours|slice:"0:2" %}
                    <td class="hours">{{num.0|default:""}}</td>
                    <td class="hours">{% if num.1 %}({{num.1}}%){% endif %}</td>
                {% endfor %}
                <td class="hours">{{hours.2}}</td>
                <td class="hours" style="width: 200px;">
                {% for desc in descs %}
                    {{desc.0}}:&nbsp;&nbsp;{{desc.1}}
                {% endfor %}
                </td>
                <td class="hours">{{all}}</td>
            </tr>
        {% endfor %}
    </table>
{% else %}
    <p> No entries found.</p>
{% endif %}
{% endblock %}

