<!DOCTYPE html>
<html lang="{{ invoice['invoice.language'] }}">
<head>
    <meta charset="utf-8">
    <title>{% block title %}{{ invoice['invoice.number'] }}-{{ invoice['customer.company']|default(invoice['customer.name'])|u.snake }}{% endblock %}</title>
    <style>
        {{ encore_entry_css_source('invoice')|raw }}
    </style>
</head>
<body class="invoice_print">
    <div class="wrapper">
        <section class="invoice">

            <div class="row">
                <div class="col-xs-12">
                    <h2 class="page-header">
                        <span contenteditable="true">{{ invoice['template.title'] }}</span>
                    </h2>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-5">
                    {{ 'invoice.to'|trans }}
                    <address contenteditable="true">
                        <strong>{{ invoice['customer.company']|default(invoice['customer.name']) }}</strong><br>
                        {{ invoice['customer.address']|nl2br }}
                        {% if invoice['customer.vat_id'] is not empty %}
                            <br>
                            {{ 'vat_id'|trans }}: {{ invoice['customer.vat_id'] }}
                        {% endif %}
                        {% if invoice['customer.number'] is not empty %}
                            <br>
                            {{ 'number'|trans }}: {{ invoice['customer.number'] }}
                        {% endif %}
                        {% if invoice['query.project.order_number'] is defined and invoice['query.project.order_number'] is not empty %}
                            <br>
                            {{ 'orderNumber'|trans }}: {{ invoice['query.project.order_number'] }}
                        {% endif %}
                    </address>
                </div>
                <div class="col-sm-2"></div>
                <div class="col-sm-5">
                    {{ 'invoice.from'|trans }}
                    <address contenteditable="true">
                        <strong>{{ invoice['template.company'] }}</strong><br>
                        {{ invoice['template.address']|trim|nl2br }}
                        {% if invoice['template.vat_id'] is not empty %}
                            <br>
                            {{ 'vat_id'|trans }}:
                            {{ invoice['template.vat_id'] }}
                        {% endif %}
                    </address>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-5">
                    <p contenteditable="true">
                        <strong>{{ 'date'|trans }}:</strong>
                        {{ invoice['invoice.date'] }}

                        <br>
                        <strong>{{ 'invoice.number'|trans }}:</strong>
                        {{ invoice['invoice.number'] }}

                        <br>
                        <strong>{{ 'invoice.due_days'|trans }}:</strong>
                        {{ invoice['invoice.due_date'] }}
                    </p>
                </div>
                <div class="col-sm-7"></div>
            </div>

            <div class="row invoice-items mt-2 mb-3">
                <div class="col-xs-12 table-responsive">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>{{ 'date'|trans }}</th>
                            <th>{{ 'description'|trans }}</th>
                            <th class="text-end">{{ 'unit_price'|trans }}</th>
                            <th class="text-end">{{ 'amount'|trans }}</th>
                            <th class="text-end">{{ 'total_rate'|trans }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for invoiceLineItem in entries %}
                            <tr>
                                <td nowrap class="text-nowrap">{{ invoiceLineItem['entry.begin'] }}</td>
                                <td contenteditable="true">
                                    {% if invoiceLineItem['entry.description'] is not empty %}
                                        {{ invoiceLineItem['entry.description']|nl2br }}
                                    {% else %}
                                        {% if invoiceLineItem['entry.activity'] is defined %}
                                            {{ invoiceLineItem['entry.activity'] }} /
                                        {% endif %}
                                        {{ invoiceLineItem['entry.project'] }}
                                    {% endif %}
                                </td>
                                <td nowrap class="text-nowrap text-end">{{ invoiceLineItem['entry.rate'] }}</td>
                                <td nowrap class="text-nowrap text-end">{{ invoiceLineItem['entry.amount'] }}</td>
                                <td nowrap class="text-nowrap text-end">{{ invoiceLineItem['entry.total'] }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                        <tfoot>
                        {% if not invoice['invoice.tax_hide'] %}
                            <tr>
                                <td colspan="4" class="text-end">
                                    {{ 'invoice.subtotal'|trans }}
                                </td>
                                <td class="text-end">{{ invoice['invoice.subtotal'] }}</td>
                            </tr>
                            <tr>
                                <td colspan="4" class="text-end">
                                    {{ 'invoice.tax'|trans }} ({{ invoice['invoice.vat'] }}%)
                                </td>
                                <td class="text-end">{{ invoice['invoice.tax'] }}</td>
                            </tr>
                        {% endif %}
                        <tr>
                            <td colspan="4" class="text-end text-nowrap">
                                <strong>{{ 'invoice.total'|trans }}</strong>
                            </td>
                            <td class="text-end">
                                <strong>{{ invoice['invoice.total'] }}</strong>
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-12">
                    {% if invoice['template.payment_terms'] is not empty %}
                        <div contenteditable="true" class="paymentTerms">
                            {{ invoice['template.payment_terms']|md2html }}
                        </div>
                    {% endif %}
                </div>
            </div>

            <footer class="footer">
                <p>
                    <strong>{{ 'address'|trans }}</strong>: {{ invoice['template.company'] }} &ndash; {{ invoice['template.address']|nl2str(' – ') }}
                    <br>
                    <strong>{{ 'invoice_bank_account'|trans }}</strong>: {{ invoice['template.payment_details']|nl2str(' – ') }}
                    <br>
                    <strong>{{ 'contact'|trans }}</strong>: {{ invoice['template.contact']|nl2str(' – ') }}
                </p>
            </footer>

        </section>
    </div>
</body>
</html>
