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

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

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

<div class="row">
    <div class="col-12-lg">
        <h3>Totals</h3>
        <p class="totals">Contributions: ${{committee.total_contributions  | intcomma}}
        <br>
        Expenditures: ${{committee.total_expenditures | intcomma}}</p>
    </div>
</div>

<div class="row">
  <div class="col-12-lg">
    <h3>
          <a href="{% url 'committee_filing_list' committee.pk 1 %}">Filings</a>
          <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>Latest filings (limit of 25)</p>
  </div>
</div>

<div class="row">
  <div class="col-12-lg">
      <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th colspan=3>Filing</th>
                <th colspan="3">Monetary contributions</th>
                <th>Non-monetary contributions</th>
                <th>All contributions</th>
                <th colspan="3">Expenditures</th>
                <th>Debts</th>
            </tr>
            <tr>
                <th>No.</th>
                <th>Form</th>
                <th>Cycle</th>
                <th>Itemized</th>
                <th>Unitemized</th>
                <th>Total</th>
                <th>Total</th>
                <th class="success">Total</th>
                <th>Itemized</th>
                <th>Unitemized</th>
                <th class="danger">Total</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        {% for filing in filing_set_short %}
          <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>
    {% if filing_set|length > 25 %}
        <p class="view-more"><a href="{% url 'committee_filing_list' committee.pk 1 %}">View more... </a></p>
    {% endif %}
  </div>
</div>

<div class="row">
<div class="col-12-lg">
    <h3>
          <a href="{% url 'committee_contribution_list' committee.pk 1 %}">Contributions </a>
          <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_contribution_list' committee.pk 1 %}?format=csv">Download CSV</a></li>
                <li><a href="{% url 'committee_contribution_list' committee.pk 1 %}?format=json">Download JSON</a></li>
              </ul>
          </div>
    </h3>
    <p>Top 25 contributions by amount</p>
      <div class="table-responsive">
        <table class="table table-bordered table-hover"> <!-- table table-bordered table-hover -->
          <thead>
            <tr>
                <th>cycle</th>
                <th>filing</th>
                <th>raw_org_name</th>
                <th class="success">amount</th>
                <!-- <th>person_flag</th> -->
            </tr>
          </thead>
          <tbody>
              {% for contribution in contribution_set_short %}
                <tr>
                    <td>{{ contribution.cycle }}</td>
                    <td><a href="{{ contribution.filing.get_absolute_url }}">{{ contribution.filing.pk }}</a></td>
                    <td>{{ contribution.raw_org_name }}</td>
                    <td class="success">${{ contribution.amount | intcomma }}</td>
                    <!-- <td>{{ contribution.person_flag }}</td> -->
                </tr>
              {% endfor %}
          </tbody>
        </table>
      </div>
      {% if contribution_set|length > 25 %}
        <p class="view-more"><a href="{% url 'committee_contribution_list' committee.pk 1 %}">View more... </a></p>
      {% endif %}
</div>
</div>

<div class="row">
<div class="col-12-lg">
  <h3>
        <a href="{% url 'committee_expenditure_list' committee.pk 1 %}">Expenditures </a>
        <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_expenditure_list' committee.pk 1 %}?format=csv">Download CSV</a></li>
              <li><a href="{% url 'committee_expenditure_list' committee.pk 1 %}?format=json">Download JSON</a></li>
            </ul>
        </div>
  </h3>
  <p>Top 25 expenditures by amount</p>
    <div class="table-responsive">
      <table class="table table-bordered table-hover"> <!-- table table-bordered table-hover -->
        <thead>
          <tr>
              <th>date</th>
              <th>exp code</th>
              <th>cycle</th>
              <th>filing</th>
              <th>name</th>
              <th class="danger">amount</th>
              <!-- <th>person_flag</th> -->
          </tr>
        </thead>
        <tbody>
            {% for expenditure in expenditure_set_short %}
              <tr>
                  <td>{{expenditure.expn_date}}</td>
                  <td>{{expenditure.expn_code}}</td>
                  <td>{{ expenditure.cycle }}</td>
                  <td><a href="{{ expenditure.filing.get_absolute_url }}">{{ expenditure.filing.pk }}</a></td>
                  <td>{{ expenditure.name }}</td>
                  <td class="danger">${{ expenditure.amount  | intcomma}}</td>
                  <!-- <td>{{ expenditure.person_flag }}</td> -->
              </tr>
            {% endfor %}
        </tbody>
      </table>
    </div>
    {% if expenditure_set|length > 25 %}
        <p class="view-more"><a href="{% url 'committee_expenditure_list' committee.pk 1 %}">View more... </a></p>
    {% endif %}
</div>
</div>
{% endblock %}
