{#
 # This file is part of SolidInvoice package.
 #
 # (c) Pierre du Plessis <open-source@solidworx.co>
 #
 # This source file is subject to the MIT license that is bundled
 # with this source code in the file LICENSE.
 #}

{% set footerSpan = quote.tax.positive ? 3 : 2 %}

<div class="{{ containerClass is defined ? containerClass : 'widget' }}" id="quote-create">
    <div class="card invoice">
        <div class="card-body">
            {% block header %}

                <div class="col-12">
                    {% block title %}
                        <h2 class="page-header">
                            {{ "quote.title"|trans({"%id%" : quote.quoteId}) }} {{ quote_label(quote.status) }}
                        </h2>
                    {% endblock %}
                    <div class="row invoice-info">
                        <div class="col-sm-4 invoice-col">
                            From:
                            <h4>{{ company_name() }}</h4>

                            {% set vatNumber = setting('system/company/vat_number') %}
                            {% if vatNumber is not empty %}
                                <p>
                                    <strong>{{ 'tax.vat_number'|trans }}</strong> {{ vatNumber }}
                                </p>
                            {% endif %}

                            {% set email = setting('system/company/contact_details/email') %}
                            {% if email is not empty %}
                                <p>
                                    {{ icon('envelope-o') }} {{ email }}
                                </p>
                            {% endif %}

                            {% set phoneNumber = setting('system/company/contact_details/phone_number') %}
                            {% if phoneNumber is not empty %}
                                <p>
                                    {{ icon('phone') }} {{ phoneNumber }}
                                </p>
                            {% endif %}

                            {% set address = setting('system/company/contact_details/address', null, true) %}
                            {% if address is not null and address|filter(v => v) is not empty %}
                                <address>
                                    {{ icon('map-marker') }} {{ address(address)|replace({"\n": ", "}) }}
                                </address>
                            {% endif %}
                        </div>
                        <div class="col-sm-4 invoice-col">
                            To:
                            <h4>{{ quote.client }}</h4>
                            {% if quote.client.website is not empty %}
                                <p>
                                    <a href="{{ quote.client.website }}" rel="external" target="_blank">
                                        {{ quote.client.website }}
                                    </a>
                                </p>
                            {% endif %}

                            {% if quote.client.vatNumber is not empty %}
                                <p>
                                    <strong>{{ 'tax.vat_number'|trans }}</strong> {{ quote.client.vatNumber }}
                                </p>
                            {% endif %}

                            {% for address in quote.client.addresses %}
                                <address>
                                    {{ icon('map-marker') }} {{ address|replace({"\n": ", "}) }}<br/>
                                </address>
                            {% endfor %}
                            <p>
                                {% for user in quote.users %}
                                    <address class="col-6">
                                        <strong>{{ user }}</strong><br/>
                                        {{ icon('envelope-o') }} {{ 'email'|trans }}: {{ user.email }}<br/>
                                        {% for info in user.additionalContactDetails %}
                                            {{ info.type|title }}: {{ info.value }}<br>
                                        {% endfor %}
                                    </address>
                                {% endfor %}
                            </p>
                        </div>
                        <div class="col-sm-4 invoice-col">
                            <dl class="dl-horizontal">
                                <dt>{{ "quote.title"|trans({"%id%" : ''}) }}</dt>
                                <dd>{{ quote.quoteId }}</dd>
                                <dt>{{ "quote.total"|trans }}</dt>
                                <dd>{{ quote.total|formatCurrency(quote.client.currency) }}</dd>
                                <dt>{{ "quote.created"|trans }}</dt>
                                <dd>{{ quote.created | date }}</dd>
                            </dl>
                        </div>
                    </div>
                </div>
            {% endblock %}

            {% block content %}
                <div class="col-12">
                    <div class="table-responsive">
                        <table id="quote-rows" class="table table-condensed">
                            <thead>
                            <tr>
                                <th>{{ 'quote.item.heading.description'|trans }}</th>
                                <th>{{ 'quote.item.heading.price'|trans }}</th>
                                <th>{{ 'quote.item.heading.qty'|trans }}</th>
                                {% if quote.tax.positive %}
                                    <th>{{ 'quote.item.heading.tax'|trans }}</th>
                                {% endif %}
                                <th class="text-right">{{ 'quote.item.heading.total'|trans }}</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for line in quote.lines %}
                                <tr>
                                    <td class="column-description">
                                        {{ line.description|nl2br }}
                                    </td>
                                    <td class="column-price">
                                        {{ line.price|formatCurrency(quote.client.currency) }}
                                    </td>
                                    <td class="column-qty">
                                        {{ line.qty }}
                                    </td>
                                    {% if quote.tax.positive %}
                                        <td class="column-tax">
                                            {{ line.tax }}
                                        </td>
                                    {% endif %}
                                    <td class="column-total text-right">
                                        {{ line.total|formatCurrency(quote.client.currency) }}
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                            <tfoot>
                            <tr>
                                <td class="no-line"></td>
                                <td colspan="{{ footerSpan }}" class="thick-line text-right">
                                    <strong>{{ 'quote.subtotal'|trans }}</strong>
                                </td>
                                <td class="thick-line text-right">
                                    <div class="quote-sub-total">
                                        {{ quote.baseTotal|formatCurrency(quote.client.currency) }}
                                    </div>
                                </td>
                            </tr>
                            {% if quote.tax.positive %}
                                <tr>
                                    <td class="no-line"></td>
                                    <td colspan="{{ footerSpan }}" class="no-line text-right">
                                        <strong>{{ 'quote.tax'|trans }}</strong>
                                    </td>
                                    <td class="no-line text-right">
                                        <span class="text-error quote-tax">
                                            {{ quote.tax|formatCurrency(quote.client.currency) }}
                                        </span>
                                    </td>
                                </tr>
                            {% endif %}

                            {% if quote.discount.type is not empty %}
                                <tr>
                                    <td class="no-line"></td>
                                    <td colspan="{{ footerSpan }}" class="no-line text-right">
                                        <strong>{{ 'quote.discount'|trans }}</strong>
                                    </td>
                                    <td class="no-line text-right">
                                        <span class="text-danger quote-discount">
                                            -{{ discount(quote)|formatCurrency(quote.client.currency) }}
                                        </span>
                                    </td>
                                </tr>
                            {% endif %}
                            <tr>
                                <td class="no-line"></td>
                                <td colspan="{{ footerSpan }}" class="no-line text-right">
                                    <strong>
                                        {{ 'quote.total'|trans }}
                                    </strong>
                                </td>
                                <td class="no-line text-right">
                                    <div class="quote-total">
                                        {{ quote.total|formatCurrency(quote.client.currency) }}
                                    </div>
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            {% endblock %}

            {% block footer %}
                {% if quote.terms is not empty %}
                    <div class="col-6">
                        <strong>{{ 'quote.terms'|trans }}</strong>
                        <p class="text-muted well well-sm no-shadow">
                            {{ quote.terms|nl2br }}
                        </p>
                    </div>
                {% endif %}
            {% endblock %}
        </div>
    </div>
</div>
