{% extends 'base.html' %} {% load static %} {% block title %}Work History | Fox Fitt{% endblock %} {% block content %}
{# === PAGE HEADER with view toggle and export === #}

Work History

{# View toggle — List vs Calendar #} {# CSV Export button — keeps the current filters in the export URL #} Export CSV Back
{# === FILTER BAR === #}
{# Preserve current view mode when filtering #} {% if view_mode == 'calendar' %} {# Preserve current calendar month when filtering #} {% endif %} {# Filter by Worker #}
{# Filter by Project #}
{# Filter by Payment Status #}
{# Filter + Clear Buttons #}
{% if has_active_filters %} Clear {% endif %}
{# === Active Filter Feedback === #} {# Shows a results counter when filters are active so the user can see the filter is working #} {% if has_active_filters %}
Showing {{ filtered_log_count }} of {{ total_log_count }} work log{{ total_log_count|pluralize }} {# Show which filters are active as small badges #} {% if selected_worker %} {% for w in filter_workers %}{% if w.id|stringformat:"d" == selected_worker %}{{ w.name }}{% endif %}{% endfor %} {% endif %} {% if selected_project %} {% for p in filter_projects %}{% if p.id|stringformat:"d" == selected_project %}{{ p.name }}{% endif %}{% endfor %} {% endif %} {% if selected_status %} {{ selected_status|capfirst }} {% endif %}
{% endif %}
{% if view_mode == 'calendar' %} {# =============================================================== #} {# === CALENDAR VIEW === #} {# =============================================================== #} {# Month navigation header #}
{{ month_name }}
{# Calendar grid #}
{# Day-of-week header row #}
Mon
Tue
Wed
Thu
Fri
Sat
Sun
{# Calendar weeks — each row is 7 day cells #} {% for week in calendar_weeks %}
{% for day in week %}
0 %}data-date="{{ day.date|date:'Y-m-d' }}"{% endif %}> {# Day number + badge count #}
{{ day.day }} {% if day.count > 0 %} {{ day.count }} {% endif %}
{# Mini log indicators (show first 3 entries) #} {% for log in day.records|slice:":3" %}
{% if log.payroll_records.exists %} {% else %} {% endif %} {{ log.project.name }}
{% endfor %} {# "and X more" indicator #} {% if day.count > 3 %}
+{{ day.count|add:"-3" }} more
{% endif %}
{% endfor %}
{% endfor %}
{# === Day Detail Panel === #} {# Hidden by default. Click day cells to select them — shows combined details with totals. #}
Details
{# Hint text for multi-select #} Click more days to add them to the selection
{# Content built by JavaScript #}
{# === Totals Footer (admin only, shown when days are selected) === #} {% if is_admin %} {% endif %}
{# Pass calendar detail data to JavaScript safely using json_script #} {{ calendar_detail|json_script:"calDetailJson" }} {# Calendar-specific CSS #} {% else %} {# =============================================================== #} {# === LIST VIEW (TABLE) === #} {# =============================================================== #}
{% if is_admin %}{% endif %} {% for log in logs %} {% if is_admin %} {% endif %} {% empty %} {% endfor %}
Date Project Workers Overtime StatusAmountSupervisor
{{ log.date }} {{ log.project.name }} {# When filtering by a specific worker, show only that worker. Otherwise show all workers. #} {% if filtered_worker_obj %} {{ filtered_worker_obj.name }} {% else %} {% for w in log.workers.all %} {{ w.name }} {% endfor %} {{ log.workers.count }} {% endif %} {% if log.overtime_amount > 0 %} {{ log.get_overtime_amount_display }} {% else %} - {% endif %} {# Payment status — a WorkLog is "paid" if it has at least one PayrollRecord #} {% if log.payroll_records.exists %} Paid {% else %} Unpaid {% endif %} {# Daily cost — worker's rate when filtered, otherwise total for all workers #} {% if filtered_worker_obj %} R {{ filtered_worker_obj.daily_rate }} {% else %} R {{ log.display_amount }} {% endif %} {% if log.supervisor %} {{ log.supervisor.get_full_name|default:log.supervisor.username }} {% else %} - {% endif %}
No work history found. {% if selected_worker or selected_project or selected_status %}
Try adjusting your filters. {% endif %}
{% endif %}
{% endblock %}