{% extends "pdf/base.twig" %}

{% block title %}{{ translate("Bill") }} n°{{ number }}{% endblock %}

{% block content %}
<table class="layout-table">
    <tr>
        <td class="half">
            {{ include('blocks/company-address.twig', {
                company: company,
                showLegalNumbers: true,
                showLogo: true,
            }) }}
        </td>
        <td class="half">
            <h2 class="box center">{{ translate('billTitle', [currencyName, number]) }}</h2>
            <table class="layout-table">
                <tr>
                    <td class="size12">{{ translate('on-date', date|format_date('short', locale=locale)) }}</td>
                    <td class="size12 right">{{ translate('page', 1) }}</td>
                </tr>
            </table>
            <p>
                {{ translate('beneficiary') }}
            </p>
            <h2 class="vspace10 indent5">
                {{ include('blocks/beneficiary-address.twig', { person: event['beneficiaries'][0] }) }}
            </h2>
        </td>
    </tr>
</table>

<div class="vspace5">
    <p>{{ translate('event', [event['title']]) }}</p>
    <p class="strong">
        {% if event['start_date'] == event['end_date'] %}
        {{ translate('on-date', [event['start_date']|format_date('full', locale=locale)]) }},
        {% else %}
        {{ translate('fromToDates', [event['start_date']|format_date('full', locale=locale), event['end_date']|format_date('full', locale=locale)]) }},
        {% endif %}
        {% if event['location'] %}
        {{ translate('inLocation', [event['location']]) }}
        {% endif %}
    </p>
    <table>
        <thead>
            <tr>
                <th class="left">{{ translate('category') }}</th>
                <th>{{ translate('quantity') }}</th>
                <th>{{ translate(vatRate > 0 ? 'totalDayExclVat' : 'totalDay') }}</th>
            </tr>
        </thead>
        <tbody>
            {% for category in categoriesSubTotals %}
            <tr>
                <td>{{ category['name'] }}</td>
                <td class="center">{{ plural('itemsCount', category['quantity']) }}</td>
                <td class="right">
                    {{ category['subTotal']|format_currency(currency, formatCurrencyOptions, locale) }}
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <p class="size8 lighter">{{ translate('billNoteDetailNextPage') }}</p>
</div>

<div class="vspace5 size8">
    <table>
        <thead>
            <tr>
                <th>{{ translate(vatRate > 0 ? 'dailyAmountExclVat' : 'dailyAmount') }}</th>
                <th>{{ translate('discountRate') }}</th>
                <th>{{ translate('totalDay') }}</th>
                <th>{{ translate('degressiveRate') }}</th>
                <th colspan="2">{{ translate('totals') }}</th>
            </tr>
        </thead>
        <tbody>
            <tr class="center">
                <td rowspan="{{ vatRate > 0 ? 3 : 1 }}" style="border-bottom: 1pt solid #888;">
                    <div class="vspace2">
                        {{ dailyAmount|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                    <div class="vspace2 lighter">
                        {{ translate('discountableTotal') }}<br>
                        {{ discountableDailyAmount|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                </td>
                <td rowspan="{{ vatRate > 0 ? 3 : 1 }}" style="border-bottom: 1pt solid #888;">
                    <div class="vspace2">
                        {% if discountRate > 0 %}
                        {{ discountRate|format_percent_number({fraction_digit: 4}) }}<br><br>
                        - {{ discountAmount|format_currency(currency, formatCurrencyOptions, locale) }}
                        {% else %}
                        <span class="lighter">{{ translate('noDiscount') }}</span>
                        {% endif %}
                    </div>
                </td>
                <td rowspan="{{ vatRate > 0 ? 3 : 1 }}" style="border-bottom: 1pt solid #888;">
                    {% if vatRate > 0 %}
                    <div class="vspace2 right">
                        {{ translate('exclVat') }}<br>
                        {{ totalDailyExclVat|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                    <div class="vspace2 right lighter">
                        {{ translate('vat') }} ({{ vatRate|format_percent_number({fraction_digit: 1}) }})<br>
                        {{ vatAmount|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                    {% endif %}
                    <div class="vspace2 right">
                        {% if vatRate > 0 %}{{ translate('inclVat') }}<br>{% endif %}
                        {{ totalDailyInclVat|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                </td>
                <td rowspan="{{ vatRate > 0 ? 3 : 1 }}" style="border-bottom: 1pt solid #888;">
                    <div class="vspace2">
                        ×&nbsp;<strong>{{ degressiveRate|format_number }}</strong><br><br>
                        <span class="lighter">
                            ({{ plural('numberOfDays', daysCount) }})
                        </span>
                    </div>
                </td>
                {% if vatRate > 0 %}
                <td>
                    <div class="vspace2 strong center">{{ translate('totalExclVat') }}</div>
                </td>
                <td>
                    <div class="vspace2 right">
                        {{ totalExclVat|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                </td>
                {% endif %}
                {% if vatRate == 0 %}
                <td rowspan="1">
                    <div class="vspace2 strong size10 center">
                        {{ translate('totalDue') }}
                    </div>
                    <div class="vspace2 size9 center">
                        {{ translate('vatNotApplicable') }}
                    </div>
                </td>
                <td rowspan="1">
                    <div class="vspace2 size10 strong right">
                        {{ totalInclVat|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                </td>
                {% endif %}
            </tr>
            {% if vatRate > 0 %}
            <tr>
                <td>
                    <div class="vspace2 strong center">{{ translate('totalInclVat') }}</div>
                </td>
                <td>
                    <div class="vspace2 right">
                        {{ totalInclVat|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="vspace2 strong size10 center">
                        {{ translate('totalDue') }}
                    </div>
                </td>
                <td>
                    <div class="vspace2 size10 strong right">
                        {{ totalInclVat|format_currency(currency, formatCurrencyOptions, locale) }}
                    </div>
                </td>
            </tr>
            {% endif %}
        </tbody>
    </table>
</div>

<div class="changePage vspace5">
    <table class="layout-table">
        <tr>
            <td class="half">
                {{ include('blocks/company-address.twig', {
                    company: company,
                    showLegalNumbers: false,
                    showLogo: true,
                }) }}
            </td>
            <td class="half">
                <h2 class="box center">{{ translate('billDetailsTitle', [number]) }}</h2>
                <table class="layout-table">
                    <tr>
                        <td class="size12">{{ translate('on-date', date|format_date('short', locale=locale)) }}</td>
                        <td class="size12 right">{{ translate('page', 2) }}</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>

<table class="listing-table">
    <thead>
        <tr>
            <th>{{ translate('ref') }}</th>
            <th>{{ translate('designation') }}</th>
            <th>{{ translate('qty') }}</th>
            <th>{{ translate(vatRate > 0 ? 'unitPriceExclVat' : 'unitPrice') }}</th>
            <th>{{ translate('replacement-value') }}</th>
            <th>{{ translate(vatRate > 0 ? 'totalExclVat' : 'total') }}</th>
        </tr>
    </thead>
    <tbody>
        {% for subCategory in materialList %}
            <tr>
                <td class="section-title" colspan="6">
                    {% if subCategory['name'] is not empty %}
                    {{ subCategory['category'] }} - {{ subCategory['name'] }}
                    {% else %}
                    {{ subCategory['category'] }} - {{ translate('otherMaterials') }}
                    {% endif %}
                </td>
            </tr>
            {% for material in subCategory['materials'] %}
                {{ include('blocks/materials/line-bill-estimate.twig', { material: material }) }}
            {% endfor %}
        {% endfor %}
    </tbody>
</table>
{% endblock %}