{% extends "core/base.jinja" %}

{% macro monthly(objects) %}
  <div>
    <table>
      <thead>
        <tr>
          <td>{% trans %}Year{% endtrans %}</td>
          <td>{% trans %}Month{% endtrans %}</td>
          <td>{% trans %}Total{% endtrans %}</td>
        </tr>
      </thead>
      <tbody>
        {% for object in objects %}
          {% set link=url(
          'core:user_account_detail',
          user_id=profile.id,
          year=object['grouped_date'].year,
          month=object['grouped_date'].month
          ) %}
          <tr>
            <td><a href="{{ link }}">{{ object["grouped_date"]|date("Y") }}</a></td>
            <td><a href="{{ link }}">{{ object["grouped_date"]|date("E") }}</a></td>
            <td><a href="{{ link }}">{{ "%.2f"|format(object["total"]) }} €</a></td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
{% endmacro %}

{% block title %}
  {% trans user_name=profile.get_display_name() %}{{ user_name }}'s account{% endtrans %}
{% endblock %}

{% block content %}
  {% if customer %}
    <h3>{% trans %}User account{% endtrans %}</h3>
    <p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>
    <div id="drop">
      {% if buyings_month %}
        <h5>{% trans %}Account purchases{% endtrans %}</h5>
        {{ monthly(buyings_month) }}
      {% endif %}
      {% if refilling_month %}
        <h5>{% trans %}Reloads{% endtrans %}</h5>
        {{ monthly(refilling_month) }}
      {% endif %}
      {% if invoices_month %}
        <h5>{% trans %}Eboutic invoices{% endtrans %}</h5>
        {{ monthly(invoices_month) }}
      {% endif %}
      {% if etickets %}
        <h4>{% trans %}Etickets{% endtrans %}</h4>
        <div>
          <ul>
            {% for s in etickets %}
              <li>
                <a href="{{ url('counter:eticket_pdf', selling_id=s.id) }}">
                  {{ s.quantity }} x {{ s.product.eticket }}
                </a>
              </li>
            {% endfor %}
          </ul>
        </div>
      {% endif %}
    </div>
  {% else %}
    <p>{% trans %}User has no account{% endtrans %}</p>
  {% endif %}
{% endblock %}

{% block script %}
  {{ super() }}
  <script>
    $(function(){
      $("#drop").accordion({
        heightStyle: "content"
      });
    });
  </script>
{% endblock %}


