{% load i18n currency_filters %}
<!doctype html>
<!-- Base for this invoice template was taken from here https://github.com/sparksuite/simple-html-invoice-template -->
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>{% trans "Invoice" %}</title>

    <style>
        body {
            font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
            text-align: center;
            color: #777;
        }

        body h1 {
            font-weight: bold;
            margin-bottom: 0px;
            padding-bottom: 0px;
            color: #000;
        }

        body h3 {
            font-weight: 300;
            margin-top: 10px;
            margin-bottom: 20px;
            color: #555;
        }

        body a {
            color: #06F;
        }

        .invoice-box {
            max-width: 800px;
            margin: auto;
            padding: 30px;
            border: 1px solid #eee;
            font-size: 16px;
            line-height: 24px;
            color: #555;
        }

        .invoice-box table {
            width: 100%;
            line-height: inherit;
            text-align: left;
        }

        .invoice-box table td {
            padding: 5px;
            vertical-align: top;
        }

        .invoice-box table tr td.align-right {
            text-align: right;
        }

        .invoice-box table tr.top table td {
            padding-bottom: 20px;
        }

        .invoice-box table tr.top table td.title {
            font-size: 45px;
            line-height: 45px;
            color: #333;
        }

        .invoice-box table tr.information table td {
            padding-bottom: 40px;
        }

        .invoice-box table tr.heading td {
            background: #eee;
            border-bottom: 1px solid #ddd;
            font-weight: bold;
        }

        .invoice-box table tr.details td {
            padding-bottom: 20px;
        }

        .invoice-box table tr.item td {
            border-bottom: 1px solid #eee;
        }

        .invoice-box table tr.item.last td {
            border-bottom: none;
        }

        .invoice-box table tr.total td:nth-child(3) {
            border-top: 2px solid #eee;
            font-weight: bold;
        }

        tr.space-under > td {
            padding-bottom: 2em;
        }

        td.title img {
            width: 100%;
            max-width: 200px;
        }
    </style>
</head>

<body>
    <div class="invoice-box">
        <table cellpadding="0" cellspacing="0">
            {% block header %}
                <tr class="top space-under">
                    <td colspan="5" class="align-right">
                        <h1>{% trans "Original invoice" %} #{{ invoice.number }}</h1><br>
                        {% trans "Order" %} #{{ order.number }}<br>
                        {% trans "Date" %}: {{ order.date_placed|date:'d.m.Y' }}<br>
                    </td>
                </tr>
            {% endblock %}

            {% block legal_entity %}
                <tr class="top">
                    <td colspan="5">
                        <table>
                            <tr>
                                <td class="title">
                                    {% if legal_entity.logo %}
                                        <img src="{% if use_path %}file://{{ legal_entity.logo.path }}{% else %}{{ legal_entity.logo.url }}{% endif %}">
                                    {% else %}
                                        {{ legal_entity.shop_name }}
                                    {% endif %}
                                </td>
                                <td>
                                    {{ legal_entity.business_name }}<br>
                                    {%  if legal_entity.vat_number %}
                                      {% trans "VAT ID" %}: {{ legal_entity.vat_number }}<br>
                                    {% endif %}
                                    {%  if legal_entity.company_number %}
                                      {% trans "Company ID" %}: {{ legal_entity.company_number }}<br>
                                    {% endif %}
                                    <address>
                                        {{ legal_entity_address.summary }}<br/>
                                        {% if legal_entity_address.phone_number %}
                                            {% trans "Tel" %}: {{ legal_entity_address.phone_number }}<br/>
                                        {% endif %}
                                        {% if legal_entity_address.fax_number %}
                                            {% trans "Fax" %}: {{ legal_entity_address.fax_number }}<br/>
                                        {% endif %}
                                        {% if legal_entity_address.email %}
                                            {% trans "Email" %}: {{ legal_entity_address.email }}<br/>
                                        {% endif %}
                                        {% if legal_entity_address.web_site %}
                                            {% trans "Site" %}: {{ legal_entity_address.web_site }}<br/>
                                        {% endif %}
                                    </address>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            {% endblock %}

            {% block addresses %}
                <tr class="information">
                    <td colspan="5">
                        <table>
                            <tr>
                                <td>
                                    <h3>{% trans "Shipping address" %}:</h3>
                                    <address>
                                        {% for field in order.shipping_address.active_address_fields %}
                                            {{ field }}<br/>
                                        {% endfor %}
                                    </address>
                                </td>
                                {% if order.billing_address %}
                                    <td>
                                        <h3>{% trans "Billing address" %}:</h3>
                                        <address>
                                            {% for field in order.billing_address.active_address_fields %}
                                                {{ field }}<br/>
                                            {% endfor %}
                                        </address>
                                    </td>
                                {% endif %}
                            </tr>
                        </table>
                    </td>
                </tr>
            {% endblock %}

            <tr class="heading">
                <td>#</td>
                <td>{% trans "Description" %}</td>
                <td class="align-right">{% trans "Quantity" %}</td>
                <td class="align-right">{% trans "Unit price" %}</td>
                <td class="align-right">{% trans "Total" %}</td>
            </tr>

            {% block order_lines %}
                {% for line in order.lines.all %}
                    <tr class="item{% if forloop.last %} last{% endif %}">
                        <td>{{ forloop.counter }}</td>
                        <td>{{ line.description }}</td>
                        <td class="align-right">{{ line.quantity }}</td>
                        <td class="align-right">{{ line.unit_price_excl_tax|currency:order.currency }}</td>
                        <td class="align-right">{{ line.line_price_excl_tax|currency:order.currency }}</td>
                    </tr>
                {% endfor %}
            {% endblock %}

            {% block order_totals %}
                <tr class="total">
                    <td colspan="3"></td>
                    <td class="align-right">{% trans "Shipping charge" %}:</td>
                    <td class="align-right">{{ order.shipping_excl_tax|currency:order.currency }}</td>
                </tr>

                {% if order.basket_discounts %}
                    {% for discount in order.basket_discounts %}
                        <tr class="total">
                            <td colspan="3"></td>
                            <td class="align-right">{% trans "Discount" %} <i>{{ discount.offer }}:</i></td>
                            <td class="align-right">- {{ discount.amount|currency:order.currency }}</td>
                        </tr>
                    {% endfor %}
                {% endif %}

                {% if order.has_shipping_discounts %}
                    {% for discount in order.shipping_discounts %}
                        <tr class="total">
                            <td colspan="3"></td>
                            <td class="align-right">{% trans "Discount" %} <i>{{ discount.offer }}:</i></td>
                            <td class="align-right">- {{ discount.amount|currency:order.currency }}</td>
                        </tr>
                    {% endfor %}
                {% endif %}

                <tr class="total">
                    <td colspan="3"></td>
                    <td class="align-right">{% trans "Order tax" %}:</td>
                    <td class="align-right">{{ order.total_tax|currency:order.currency }}</td>
                </tr>

                <tr class="total space-under">
                    <td colspan="3"></td>
                    <td class="align-right">{% trans "Order total" %}:</td>
                    <td class="align-right">{{ order.total_incl_tax|currency:order.currency }}</td>
                </tr>
            {% endblock %}

            {% block terms_and_conditions %}
                {% if terms_and_conditions %}
                <tr class="information">
                    <td colspan="5">
                        <h3>{% trans "Terms and conditions" %}:</h3>
                        {{ terms_and_conditions }}
                    </td>
                </tr>
                {% endif %}
            {% endblock %}

            {% block additional_data %}
                {% if additional_data %}
                <tr class="information">
                    <td colspan="5">
                        <h3>{% trans "Notes" %}:</h3>
                        {{ additional_data }}
                    </td>
                </tr>
                {% endif %}
            {% endblock %}
        </table>
    </div>
</body>
</html>