{% extends 'report_html_purchase/reports/base.html' %}

{% block title %}Purchase Report{% endblock %}
{% from 'report_html_purchase/reports/_helpers.html' import render_purchase_table %}

{% block body %}
  {# loop will not be available in the context of scoped block #}
    <div class="container-fluid">
        {% block header %}
        <div class="row">
          <div class="col-xs-6">
              <div>
                  {% block header_logo %}
                  {% endblock %}
              </div>
          </div>
          <div class="col-xs-6">
            <div class="row">
              <div class="col-xs-12">
                <span class="h3">{% block header_title %}Purchase Report{% endblock %}</span>
              </div>
            </div>
            <div class="row" style="padding-top:20px;">
                <div class="col-xs-4">
                  <strong>Date Range:</strong>
                </div>
                <div class="col-xs-8">
                  {{ data['start_date']|dateformat }} - {{ data['end_date']|dateformat }}
                </div>
            </div>
            {% if supplier %}
              <div class="row">
                  <div class="col-xs-4">
                    <strong>Supplier:</strong>
                  </div>
                  <div class="col-xs-8 text-capitalize">
                    {{ supplier.name }}
                  </div>
              </div>
            {% endif %}
            {% if product %}
              <div class="row">
                  <div class="col-xs-4">
                    <strong>Product:</strong>
                  </div>
                  <div class="col-xs-8 text-capitalize">
                    {{ product.name }}
                  </div>
              </div>
            {% endif %}
          </div>
        </div>
        {% endblock %}
        <div class="row">
            {% block summary %}
            <div class="col-xs-12">
              <hr />
            </div>
            <div class="col-xs-4">
                <div class="h4">Number of Purchase Orders:</div>
                <div class="h4">Total Amount:</div>
            </div>
            <div class="col-xs-8">
                <div class="h4">{{ purchases|length() }}</div>
                <div class="h4">{{ purchases|sum(attribute="total_amount")|currencyformat(user.company and user.company.currency.code or 'EUR') }}</div>
            </div>
            {% endblock %}
            <div class="col-xs-12">
              <hr />
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12">
                {% block purchase_content %}
                    {{ render_purchase_table(purchases, supplier, format_number) }}
                {% endblock %}
            </div>
        </div>
    </div>
{% endblock body %}
