{% extends "admin/base_site.html" %}

{% load i18n l10n %}
{% load admin_urls %}

{% block breadcrumbs %}
  <div class="breadcrumbs">
    <a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> ›
    <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_label|capfirst }}</a> ›
    <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a> › Monthly Providers Reports
  </div>
{% endblock %}

{% block content %}

<form action="" method="post">
    {% csrf_token %}
    <ul>
        {% for provider, ptotals in totals.items %}
            {% if ptotals %}
            <li> <b>{{ provider }}</b> <br>
                <ul>
                {% for doc_name, totals_and_draft in ptotals.items %}
                    <li>
                        {% for entry, item_value in totals_and_draft.items %}
                            {% if forloop.first %}
                                <b> {{ doc_name }} </b> (total draft: {{ item_value }})
                            {% else %}
                                {% if item_value|length %}
                                    <table>
                                        <tr> 
                                            <th> Month </th>
                                            <th> Total </th>
                                            <th> Paid </th>
                                            <th> Unpaid </th>
                                        </tr>
                                        {% for month, totals_value in item_value.items %}
                                        <tr> 
                                            <td> {{ month }} </td> 
                                            {% for name, value in totals_value.items %}
                                                    <td> {{ value }} </td>
                                            {% endfor %}
                                            </tr>
                                        {% endfor %}
                                    </table>
                                {% endif %}
                            {% endif%}
                        {% endfor %}
                    </li>
                    <br>
                {% endfor %}
                </ul>
            </li>
            <br>
            {% endif %}
        {% endfor %}
    </ul>

    <div>
        <input type="hidden" name="action" value="generate_monthly_totals" />
        <input type="hidden" name="post" value="yes" />
        <a href="#" onclick="window.history.back(); return false;" class="button cancel-link">{% trans "Back" %}</a>
    </div>
</form>
{% endblock content %}
