{% load i18n currency_filters compress static wagtailcore_tags wagtailsettings_tags %}{% if not settings %}{% get_settings %}{% endif %}
<!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>
    {% compress css inline %}
        <link rel="stylesheet" type="text/x-scss" href="{% static 'communications/invoice.scss' %}">
    {% endcompress %}
    <style type="text/css">
        {% if order.total_order_discount_incl_tax %}
            .invoice-box table .heading td small {
                font-size: 10px;
            }
        {% else %}
            .optional {
                display: none;
            }
        {% endif %}
    </style>
</head>

<body>
<div class="invoice-box">
    <table cellpadding="0" cellspacing="0">
        {% block header %}
            <tr class="top">
                <td colspan="10">
                    <table class="address-table fixed-table">
                        <tr>
                            <td colspan="2">
                                {% if legal_entity.logo %}
                                    <img src="{% if use_path %}file://{{ legal_entity.logo.path }}{% else %}{{ legal_entity.logo.url }}{% endif %}">
                                {% else %}
                                    <h1 class="primary-color invoice invoice_header">{{ legal_entity.shop_name }}</h1>
                                {% endif %}
                            </td>
                            {% block legal_entity %}
                                <td class="" colspan="2" rowspan="2">
                                    <b class="primary-color">{{ legal_entity.business_name }}</b><br>
                                    {% if legal_entity.web_site %}
                                        {{ legal_entity.shop_name }}
                                    {% endif %}
                                    <address>
                                        {% if legal_entity_address.first_name %}
                                            {{ legal_entity_address.first_name }}
                                        {% endif %}
                                        {% if legal_entity_address.last_name %}
                                            {{ legal_entity_address.last_name }} <br/>
                                        {% endif %}
                                        {{ legal_entity_address.line1 }}<br>
                                        {% if legal_entity_address.postcode %}
                                            {{ legal_entity_address.postcode }}
                                        {% endif %}
                                        {% if legal_entity_address.city %}
                                            {{ legal_entity_address.city }}<br>
                                        {% endif %}
                                        {% if legal_entity_address.state %}
                                            {{ legal_entity_address.state }}<br>
                                        {% endif %}
                                        {{ legal_entity_address.country }} <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.email %}
                                            {{ legal_entity.email }}<br/>
                                        {% endif %}
                                        {% trans "VAT" %}: {{ legal_entity.vat_number }}<br>
                                        {% if legal_entity_address.line2 %}
                                            {{ legal_entity_address.line2 }}<br>
                                        {% endif %}
                                        {% if legal_entity_address.line3 %}
                                            {{ legal_entity_address.line3 }}<br>
                                        {% endif %}
                                        {% if legal_entity.iban %}
                                            {% trans "IBAN" %}: {{ legal_entity.iban }}<br>
                                        {% endif %}
                                        {% if legal_entity.bic %}
                                            {% trans "BIC" %}: {{ legal_entity.bic }}
                                        {% endif %}
                                    </address>
                                </td>
                            {% endblock %}
                        </tr>
                        <tr class="header">
                            <td colspan="2">
                                <h1 class="invoice">{% trans 'Invoice' %}</h1>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        {% endblock %}

        {% block addresses %}
            <tr class="information space-under">
                <td colspan="10">
                    <table class="order-info-table">
                        <tr>
                            {% if order.billing_address %}
                                <td>
                                    <b class="primary-color">{% trans "Billing address" %}:</b>
                                    <address>
                                        {% for field in order.billing_address.ordered_active_address_fields %}
                                            {{ field }}<br/>
                                        {% endfor %}
                                        {% if order.vat_entry %}
                                        {% trans 'VAT' %}: {{ order.vat_entry.vat_number }}
                                        {% endif %}
                                    </address>
                            {% else %}
                                <td>
                                    <b class="primary-color">{% trans "Billing address" %}:</b>
                                    <address>
                                        {% for field in order.shipping_address.ordered_active_address_fields %}
                                            {{ field }}<br>
                                        {% endfor %}
                                        {{ order.email }}<br>
                                        {{ order.shipping_address.phone_number }}
                                        {% if order.vat_entry %}
                                        {% trans 'VAT' %}: {{ order.vat_entry.vat_number }}
                                        {% endif %}
                                    </address>
                            {% endif %}
                                </td>

                            <td class="p-12">
                                <b class="primary-color">{% trans "Shipping address" %}:</b>
                                <address>
                                    {% for field in order.shipping_address.ordered_active_address_fields %}
                                        {{ field }}<br>
                                    {% endfor %}
                                    {{ order.email }}<br>
                                    {{ order.shipping_address.phone_number }}
                                </address>
                            </td>

                            <td class="text-right">
                                <b class="primary-color">{% trans "Original invoice" %}</b><br>
                                <span class="underline">#{{ invoice.number }}</span><br>
                                <b class="primary-color">{% trans "Invoice date" %}</b><br>
                                {% now 'd F Y' %}<br>
                                <b class="primary-color">{% trans "Ordernumber" %}</b><br>
                                #{{ order.number }}<br>
                                <b class="primary-color">{% trans "Orderdate" %}</b><br>
                                {{ order.date_placed|date:'d F Y' }}
                                {% if order.vat_entry and order.total_tax == 0 %}
                                <br><b class="primary-color">{% trans "intra-Community supply" %}</b><br>
                                artikel 138, lid 1, Richtlijn 2006/112
                                {% endif %}
                            </td>
                        </tr>
                        <tr class="information space-under">
                            <td>
                                <b class="d-block primary-color">{% trans "Payment method" %}</b>
                                {% for source in order.sources.all %}
                                    {% blocktrans with type=source.source_type.name %}
                                        {{ type }}
                                    {% endblocktrans %}
                                {% empty %}
                                    {% trans "No payment was required for this order." %}
                                {% endfor %}
                            </td>
                            <td class="p-12">
                                <b class="d-block primary-color">{% trans "Shipping method" %}</b>
                                {{ order.shipping_method }}
                            </td>
                            <td class="text-right">
                                {% if order.shipping_address.notes %}
                                    <b class="d-block primary-color">{% trans "Comment" %}</b>
                                    {{ order.shipping_address.notes }}
                                {% endif %}
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        {% endblock %}
        
        {% block order_line_header %}
            <tr class="heading text-center">
                <td>{% trans "Description" %}</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>{% trans "Unit price" %}&nbsp;</td>
                <td>{% trans "Quantity" %}&nbsp;</td>
                <td class="optional">{% trans "Price" %}</td>
                <td class="optional">{% trans "Discount" %}</td>
                <td>{% trans "Tax invoice column" %}</td>
                <td>{% trans "Total excl. tax invoice column" %}</td>
                <td>{% trans "Total" %}</td>
            </tr>
        {% endblock %}

        {% block order_lines %}
            {% for line in order.lines.all %}
                <tr class="item{% if forloop.last %} last{% endif %} text-center">
                    <td colspan="3">
                        <b>{{ line.title }}</b>{% if line.attributes.exists %}
                        <ul class="option-list">
                            {% for option in line.attributes.all %}
                                <li><b>{{ option.option.name }}:</b> <span
                                        class="option-value">{{ option.display_value }}</span></li>
                            {% endfor %}</ul>{% endif %}
                    </td>
                    <td>{{ line.unit_price_incl_tax|currency:order.currency }}</td>
                    <td>{{ line.quantity }}</td>
                    <td class="optional">{{ line.line_price_before_discounts_incl_tax|currency:order.currency }}</td>
                    <td class="optional">{% if line.discount_incl_tax %}
                        {{ line.discount_incl_tax.copy_negate|currency:order.currency }}{% else %}-{% endif %}</td>
                    <td>{{ line.line_price_tax|currency:order.currency }}</td>
                    <td>{{ line.line_price_excl_tax|currency:order.currency }}</td>
                    <td>{{ line.line_price_incl_tax|currency:order.currency }}</td>
                </tr>
            {% endfor %}
        {% endblock %}

        {% block order_totals %}
            {% if order.lines.count > 1 %}
                <tr class="item first-total text-center">
                    <td colspan="5">{% trans "Subtotal" %}</td>
                    <td class="optional">{{ order.basket_total_before_discounts_incl_tax|currency:order.currency }}</td>
                    <td class="optional">{% if order.basket_discount_incl_tax %}
                        {{ order.basket_discount_incl_tax.copy_negate|currency:order.currency }}{% else %}
                        -{% endif %}</td>
                    <td>{{ order.basket_total_tax|currency:order.currency }}</td>
                    <td>{{ order.basket_total_excl_tax|currency:order.currency }}</td>
                    <td>{{ order.basket_total_incl_tax|currency:order.currency }}</td>
                </tr>
            {% endif %}

            <tr class="item text-center">
                <th class="normal" colspan="5">{% trans "Shipping charge" %}</th>
                <td class="optional">{{ order.shipping_before_discounts_incl_tax|currency:order.currency }}</td>
                <td class="optional">{% if order.shipping_discount_incl_tax %}
                    {{ order.shipping_discount_incl_tax.copy_negate|currency:order.currency }}{% else %}
                    -{% endif %}</td>
                <td>{{ order.shipping_tax|currency:order.currency }}</td>
                <td>{{ order.shipping_excl_tax|currency:order.currency }}</td>
                <td>{{ order.shipping_incl_tax|currency:order.currency }}</td>
            </tr>

            {% with surcharges=order.surcharges.all %}
                {% if surcharges %}
                    {% for charge in surcharges %}
                        <tr class="item text-center">
                            <th class="normal" colspan="5">{{ charge.name }}</th>
                            <td class="optional">{{ charge.incl_tax|currency:order.currency }}</td>
                            <td class="optional">-</td>
                            <td>{{ charge.tax|currency:order.currency }}</td>
                            <td>{{ charge.excl_tax|currency:order.currency }}</td>
                            <td>{{ charge.incl_tax|currency:order.currency }}</td>
                        </tr>
                    {% endfor %}
                {% endif %}
            {% endwith %}

            <tr class="item last first-total text-center">
                <th colspan="5"><b>{% trans "Total" %}</b></th>
                <td class="optional">{{ order.total_before_discounts_incl_tax|currency:order.currency }}</td>
                <td class="optional">{% if order.total_order_discount_incl_tax %}
                    {{ order.total_order_discount_incl_tax.copy_negate|currency:order.currency }}{% else %}
                    -{% endif %}</td>
                <td><b>{{ order.total_tax|currency:order.currency }}</b></td>
                <td><b>{{ order.total_excl_tax|currency:order.currency }}</b></td>
                <td><b>{{ order.total_incl_tax|currency:order.currency }}</b></td>
            </tr>
        {% endblock %}

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

        {% block additional_data %}
            {% if additional_data %}
                <tr class="information">
                    <td colspan="10">
                        <h3>{% trans "Notes" %}:</h3>
                        {{ additional_data }}
                    </td>
                </tr>
            {% endif %}
        {% endblock %}
        <tr class="footer">
            <td colspan="10">
                {{ settings.ocyan_plugin_wagtail.OcyanSettings.invoice_footer_text|richtext }}
            </td>
        </tr>
    </table>
</div>
</body>
</html>
