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

{% block title %}
  Invoice {{ records|join('# ', 'number') }}
{% endblock %}

{% block main %}
    {% for invoice in records %}
      <div class="container-fluid {% if not loop.first %}page-break{% endif %}">
        <div class="row">
          <div class="col-xs-12">
            <table class="table no-border">
              <tr>
                {% block header %}
                {% include header%}
                {% endblock %}
              </tr>
              <tr>
                <td>
                  <span><strong>Invoice#</strong> {{ invoice.number or '' }}</span><br />
                  <span><strong>Date:</strong> {{ (invoice.invoice_date or datetime.date.today())|dateformat }}</span>
                </td>
              </tr>
              <tr>
                <td>
                  <strong>Sold To:</strong>
                </td>
                <td style="border-left: 1px solid #ddd">
                  <strong>Sold By:</strong>
                </td>
              </tr>
              <tr style="border-bottom: 1px solid #ddd">
                <td>
                  {% if invoice.invoice_address %}
                    {% for line in invoice.invoice_address.full_address.split('\n') %}
                      {{ line }}<br/>
                    {% endfor %}
                    {% if invoice.party.phone %}
                      <br/>Phone: {{ invoice.party.phone }}
                    {% endif %}
                    {% if invoice.party.fax %}
                      <br/>Fax: {{ invoice.party.fax }}
                    {% endif %}
                    {% if invoice.party.email %}
                      <br/>Email: {{ invoice.party.email }}
                    {% endif %}
                  {% endif %}
                </td>
                <td style="border-left: 1px solid #ddd">
                  {% set company_party = user.company.party %}
                  {% for line in company_party.addresses[0].full_address.split('\n') %}
                    {{ line }}<br/>
                  {% endfor %}
                  {% if company_party.phone %}
                    <br/>Phone: {{ company_party.phone }}
                  {% endif %}
                  {% if company_party.fax %}
                    <br/>Fax: {{ company_party.fax }}
                  {% endif %}
                  {% if company_party.email %}
                    <br/>Email: {{ company_party.email }}
                  {% endif %}
                </td>
              </tr>
            </table>
            <table class="table borderless bottom2px top2px">
              <thead>
                <th nowrap>Product</th>
                <th nowrap>SKU</th>
                <th class="text-right" nowrap>Qty</th>
                <th class="text-right" nowrap>Unit Price</th>
                <th class="text-right" nowrap>Amount</th>
              </thead>
              <tbody>
                {% for line in invoice.lines %}
                  <tr>
                    <td>{{ line.product and line.product.name or line.description }}</td>
                    <td>{{ line.product and line.product.code or '-' }}</td>
                    <td class="text-right">{{ formatLang(line.quantity, invoice.party.lang, digits=line.unit_digits) }}</td>
                    <td class="text-right">{{ line.unit_price|currencyformat(invoice.currency.code) }}</td>
                    <td class="text-right">{{ line.amount|currencyformat(invoice.currency.code)   }}</td>
                  </tr>
                {% endfor %}
                <tr class="b-hide">
                  <td colspan="8"></td>
                </tr>
              </tbody>
            </table>
          </div>
          <div class="col-xs-5 col-xs-offset-7">
            <table class="table borderless bottom2px">
              <tbody>
                {% for tax in invoice.taxes|sorted_tax_lines %}
                  <tr>
                    <td class="base-tax-padding">
                      {{ "Base %s" % (tax.tax.rate * 100)|round|int|string + '%' }}
                    </td>
                    <td class="text-right base-tax-padding">
                      {{ tax.base|currencyformat(invoice.currency.code) }}
                    </td>
                    <td class="text-right base-tax-padding">
                      {{ tax.amount|currencyformat(invoice.currency.code) }}
                    </td>
                    <td class="text-right base-tax-padding">
                      {{ (tax.base + tax.amount)|currencyformat(invoice.currency.code) }}
                    </td>
                  </tr>
                {% endfor %}
              </tbody>
            </table>
          </div>
          <div class="col-xs-6 col-xs-offset-6">
            <table class="table borderless bottom2px">
              <tr>
                <td class="text-right" style="width:100%;">
                  Total (excl. tax)
                </td>
                <td class="text-right">
                  {{ invoice.untaxed_amount|currencyformat(invoice.currency.code) }}
                </td>
              </tr>
              <tr>
                <td class="text-right" style="width:100%;">
                  Tax
                </td>
                <td class="text-right">
                  {{ invoice.tax_amount|currencyformat(invoice.currency.code) }}
                </td>
              </tr>
              <tr class="font-bold">
                <td class="text-right text12" style="width:100%;">
                  Total (incl. tax)
                </td>
                <td class="text-right text12">
                  {{ invoice.total_amount|currencyformat(invoice.currency.code) }}
                </td>
              </tr>
            </table>
          </div>
        </div>
      </div>
    {% endfor %}
{% endblock %}
