{% load static %}
<html>
    <head>
        <meta charset="utf-8">
        <link href="{% static "hbdjinvoicing/invoice.css" %}" rel="stylesheet">
        <title>Invoice</title>
        <meta name="description" content="Invoice demo sample">
    </head>
    <body>
        <aside>
            <address id="from">
                <div id="logo_container">
                    <img src="{{ object.organisation.logo.url }}" />
                </div>
                <b>{{ object.organisation.name }}</b>
                {{ object.organisation.street }}
                {{ object.organisation.zipcode }} {{ object.organisation.city }}
                {% if object.organisation.country != object.country %}{{ object.organisation.get_country_display }}{% endif %}
                {{ object.organisation.email }}
            </address>
            <address id="to">
                <b>{{ object.name }}</b>
                {{ object.street }}
                {{ object.zipcode }} {{ object.city }}
                {% if object.organisation.country != object.country %}{{ object.get_country_display }}{% endif %}
            </address>
        </aside>
        {% if object.total_vat_incl >= 0 %}
            <h1>Facture {{ object.number }}</h1>
        {% else %}
            <h1>Avoir {{ object.number }}</h1>
        {% endif %}
        <dl>
            <dt>Date</dt>
            <dd>
                {{ object.date|date:"d/m/Y" }}
            </dd>
            {% if object.reference %}
                <dt>Reference de commande</dt>
                <dd>
                    {{ object.reference }}
                </dd>
            {% endif %}
            <dt>Conditions de paiement</dt>
            <dd>
                {{ object.payment_mode }}
            </dd>
            {% if object.payment_mode == "Virement" %}
                <dt>IBAN</dt>
                <dd>
                    {{ object.organisation.iban }}
                </dd>
                <dt>BIC</dt>
                <dd>
                    {{ object.organisation.bic }}
                </dd>
            {% endif %}
        </dl>
        {% if object.customer_vat_id or object.customer_vat_id or object.chorus_service_code %}
            <h2>Détail Client</h2>
            <dl>
                {% if object.customer_vat_id %}
                    <dt>Numéro de TVA</dt>
                    <dd>
                        {{ object.customer_vat_id }}
                    </dd>
                {% endif %}
                {% if object.customer_siret %}
                    <dt>SIRET</dt>
                    <dd>
                        {{ object.customer_siret }}
                    </dd>
                {% endif %}
                {% if object.chorus_service_code %}
                    <dt>Code service CHORUS</dt>
                    <dd>
                        {{ object.chorus_service_code }}
                    </dd>
                {% endif %}
            </dl>
        {% endif %}
        <table>
            <thead>
                <tr>
                    <th>Description</th>
                    <th>Quantité</th>
                    <th>Prix unitaire HT</th>
                    <th>TVA</th>
                    <th>Montant HT</th>
                </tr>
            </thead>
            <tbody>
                {% for row in object.invoiceline_set.all %}
                    <tr>
                        <td>{{ row.title }}</td>
                        <td>{{ row.quantity }} {{ row.unit }}</td>
                        <td>{{ row.unit_price|floatformat:2 }} €</td>
                        <td>{{ row.vat_rate }} %</td>
                        <td>{{ row.price_vat_excl|floatformat:2 }} €</td>
                    </tr>
                    <tr class="description">
                        <td colspan="5">{{ row.descritiption }}</td>
                    </tr>
                {% endfor %}
                <tr class="trfooter">
                    <td colspan="4">Total HT</td>
                    <td>{{ object.total_vat_excl|floatformat:2 }} €</td>
                </tr>
                {% for vat in object.invoicevat_set.all %}
                    <tr class="trfooter">
                        <td colspan="4">TVA {{ vat.vat_rate }} %</td>
                        <td>{{ vat.price|floatformat:2 }} €</td>
                    </tr>
                {% endfor %}
                <tr class="trfooter">
                    <td colspan="4">Total TTC</td>
                    <td>{{ object.total_vat_incl|floatformat:2 }} €</td>
                </tr>
            </tbody>
        </table>
        {% if object.total_vat_incl >= 0 %}<p>{{ object.organisation.bottom_comment|linebreaks }}</p>{% endif %}
        {% if object.organisation.conditions %}
            <div class="conditions">{{ object.organisation.conditions|safe }}</div>
        {% endif %}
        <footer>
            <b>{{ object.organisation.name }}</b>
            <br />
            {{ object.organisation.legal_status }}
            <br />
            {{ object.organisation.street }} - {{ object.organisation.zipcode }} {{ object.organisation.city }}
            <br />
            {{ object.organisation.siren }} -
            SIRET {{ object.organisation.siret }} -
            TVA {{ object.organisation.vat_id }} -
            APE {{ object.organisation.ape }}
        </footer>
    </body>
</html>
