{% extends 'calaccess_campaign_browser/base.html' %}
{% load humanize %}

{% block title %}Filings - {{ committee.name }} - Committee - {{ block.super }}{% endblock %}

{% block javascript %}
    <script>
        $('.pagination').twbsPagination({
            totalPages: {{ paginator.count }},
            visiblePages: 5,
            startPage: {{ page_obj.number }},
            prev: '&laquo;',
            next: '&rsaquo;',
            onPageClick: function (event, page) {
                window.location.href = "{{ base_url }}" + page + '/';
            }
        });
    </script>
{% endblock %}

{% block content %}
{% include "calaccess_campaign_browser/committee_nav.html" %}

<div class="row">
    <div class="col-12-lg">
    <h3>
          Filings
          <div class="btn-group">
              <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                Download data <span class="caret"></span>
              </button>
              <ul class="dropdown-menu" role="menu">
                <li><a href="{% url 'committee_filing_list' committee.pk 1 %}?format=csv">Download CSV</a></li>
                <li><a href="{% url 'committee_filing_list' committee.pk 1 %}?format=json">Download JSON</a></li>
              </ul>
          </div>
    </h3>
    <p class="totals">
        Total contributions: ${{committee.total_contributions  | intcomma}}
        <br>
        Total expenditures: ${{committee.total_expenditures  | intcomma}}
    </p>
    </div>
</div>

{% include "calaccess_campaign_browser/paginator.html" %}

<div class="row">
    <div class="col-12-lg">
          <div class="table-responsive">
            <table id="datatable" class="table table-bordered table-hover"> <!-- table table-bordered table-hover -->
              <thead>
                <tr>
                  <th>Filing No.</th>
                  <th>Form</th>
                  <th>Cycle</th>
                  <th>itemized mon. contributions</th>
                  <th>unitemized mon. contributions</th>
                  <th>total mon. contributions</th>
                  <th>non mon. contributions</th>
                  <th class="success">total contributions</th>
                  <th>itemized expn</th>
                  <th>unitemized expn</th>
                  <th class="danger">total expn</th>
                  <th>outstanding debts</th>
                </tr>
              </thead>
              <tbody>
              {% for filing in committee_filings %}
                <tr>
                  <td>
                    <a href="{{ filing.get_absolute_url }}">{{ filing.filing_id_raw }}</a>
                  </td>
                  <td>{{ filing.form_id }}</td>
                  <td>{{ filing.cycle.name }}</td>
                  {% if filing.summary_set.all %}
                    {% for summary in filing.summary_set.all %}
                      <td>${{ summary.itemized_monetary_contributions | intcomma }}</td>
                      <td>${{ summary.unitemized_monetary_contributions | intcomma }}</td>
                      <td>${{ summary.total_monetary_contributions | intcomma }}</td>
                      <td>${{ summary.non_monetary_contributions | intcomma }}</td>
                      <td class="success">${{ summary.total_contributions | intcomma }}</td>
                      <td>${{ summary.itemized_expenditures | intcomma }}</td>
                      <td>${{ summary.unitemized_expenditures | intcomma }}</td>
                      <td class="danger">${{ summary.total_expenditures | intcomma }}</td>
                      <td>${{ summary.outstanding_debts | intcomma }}</td>
                    {% endfor %}
                  {% else %}
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                    <td>N/A</td>
                  {% endif %}
                </tr>
              {% endfor %}
              </tbody>
            </table>
          </div>

    </div>
  </div>
{% include "calaccess_campaign_browser/paginator.html" %}
{% endblock %}
