<html>
<head>
    {% if html is not defined %}
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" rel="stylesheet"
              integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy"
              crossorigin="anonymous">
        <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"
              integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN"
              crossorigin="anonymous">
    {% endif %}

    <style>
        body.pdf {
            font: 16px/26px Garamond-Regular, Arial;
            height: 100%;
            margin: 0;
            background-color: #FFFFFF;
        }

        p {
            font: 16px/26px Garamond-Regular, Arial;
        }

        .content.pdf {
            width: 100%;
            margin: 0 auto;
            margin-top: 10px;

        }

        .content.pdf .table {
            border-collapse: collapse;
        }

        .content.pdf .table td, .content.pdf .table th {
            border-color: #000000;
        }

        .content.pdf .table thead th {
            border-bottom: 1px solid #000000;
        }

        .content.pdf .table th {
            text-align: center;
        }

        .content.pdf .table td {
            text-align: center;
        }

        .content.pdf .table td.background, .table th.background {
            background-color: #CDCDCD;
        }

        .content.pdf .table td.left {
            text-align: left;
        }

        .content.pdf .title {
            text-align: center;
            border-bottom: 2px solid #000000;
            margin-bottom: 10px;
        }

        .content.pdf td.no-border {
            border: none !important;
        }

        .content.pdf h1 {
            margin: 0;
            padding: 0;
            font-size: 32px;
            line-height: 35px;
            margin-bottom: 20px;
        }

        .content.pdf h2 {
            font-size: 28px;
        }

        .content.pdf .text-header {
            margin-bottom: 40px;
        }

        .content.pdf .text-footer {
            text-align: left;
            font-size: 12px;
            margin-bottom: 40px;
        }

        .content.pdf p {
            line-height: 16px;
            margin: 0;
        }

        .content.pdf .address {
            text-align: left;
            padding-left: 30px;
        }

        .content.pdf .image img {
            width: 250px;
            margin: 0 auto;
        }

        .content.pdf .img-company {
            text-align: center;
        }

        .content.pdf .img-company img {
            width: 250px;
            margin-bottom: 20px;
            text-align: center;
        }
    </style>
</head>
<body class="pdf">
{% set tax = 'TTC' %}
{% if cart.viewHT %}
    {% set tax =  'HT' %}
{% endif %}
<div class="content pdf">
    <div class="title">
        {% if contact.image %}
            <div class="img-company">
                <img src="{{ asset(contact.image.path)|imagine_filter('logo_email_filter') }}">
            </div>
        {% endif %}
        <h2>{% trans %} order.purchase_order {% endtrans %}</h2>
    </div>
    <div class="text-header">
        <div class="row">
            <div class="address col-4 col-md-4">
                <h5>{% trans %} shop.address_invoice {% endtrans %}</h5>
                {% if cart.invoiceAddress.company %}
                    <p>{{ cart.invoiceAddress.company }}</p>
                {% endif %}
                {% if cart.invoiceAddress.tvaNumber %}
                    <p>TVA : {{ cart.invoiceAddress.tvaNumber }}</p>
                {% endif %}
                <p>{{ cart.invoiceAddress.lastname }} {{ cart.invoiceAddress.firstname }}</p>
                <p>{{ cart.invoiceAddress.street }}</p>
                <p>{{ cart.invoiceAddress.postalCode }}  {{ cart.invoiceAddress.city }}</p>
                <p>{{ cart.invoiceAddress.countryName }} </p> <br/>
                <p><i class="fa fa-envelope-o" aria-hidden="true"></i> {{ cart.invoiceAddress.email }}</p>
                <p><i class="fa fa-phone" aria-hidden="true"></i> {{ cart.invoiceAddress.phone }}</p>
                <br/>
                {% if cart.cartCheckout.payedAt %}
                    <p><strong>Date :</strong> {{ cart.cartCheckout.payedAt|date("d-m-Y H:i") }}</p>
                {% else %}
                    <p><strong>Date :</strong> {{ cart.cartCheckout.createdAt|date("d-m-Y H:i") }}</p>
                {% endif %}
                <p><strong>{% trans %} order.ref_order {% endtrans %} :</strong> {{ cart.token|upper }}</p>
            </div>
            <div class="address col-4 col-md-4">
                {% if cart.deliveryMethod is null or cart.deliveryMethod and cart.deliveryMethod.category.disabledShippingAddress == false %}
                    <h5>{% trans %} shop.address_shipping {% endtrans %}</h5>
                    <p>{{ cart.deliveryAddress.lastname }} {{ cart.deliveryAddress.firstname }}</p>
                    <p>{{ cart.deliveryAddress.street }}</p>
                    <p>{{ cart.deliveryAddress.postalCode }}  {{ cart.deliveryAddress.city }}</p>
                    <p>{{ cart.deliveryAddress.countryName }} </p> <br/>
                    {% if cart.deliveryAddress.email %} <p><i class="fa fa-envelope-o"
                                                              aria-hidden="true"></i> {{ cart.deliveryAddress.email }}
                        </p>{% endif %}
                    {% if cart.deliveryAddress.phone %}<p><i class="fa fa-phone"
                                                             aria-hidden="true"></i> {{ cart.deliveryAddress.phone }}
                        </p>{% endif %}
                    <br/>
                {% endif %}
                {% if cart.deliveryMethod %}
                    <p><strong>{% trans %} order.delivery_method {% endtrans %} : </strong></p>
                    <p>{{ cart.deliveryMethod.category.name }} : {{ cart.deliveryMethod.name }}</p>
                    {% if cart.deliveryMethod.viewCounties %}
                        <p>{% trans with {'%count%': cart.deliveryMethod.counties|length } %}order.county{% endtrans %}
                            : ({% for county in cart.deliveryMethod.counties %}
                            {{ county .code }} {% if loop.last == false %}-{% endif %}
                            {% endfor %})</p>
                    {% endif %}
                {% else %}
                    <p><strong>{% trans %} order.delivery_method {% endtrans %} : </strong></p>
                    <p>{% trans %} order.delivery_by_carrier {% endtrans %}</p>
                {% endif %}
            </div>
            <div class="col-4 col-md-4">
                <p><strong>{{ contact.company | upper }}</strong></p>
                <p><strong>{{ contact.address }}</strong></p>
                <p><strong>{{ contact.postal }} {{ contact.city|upper }} </strong></p> <br/>
                <p><i class="fa fa-envelope-o" aria-hidden="true"></i> {{ contact.emailToShop }} </p>
                <p><i class="fa fa-phone" aria-hidden="true"></i> {{ contact.phone1 }}</p>
                {% if contact.phone2 is defined %}
                    <p><i class="fa fa-phone" aria-hidden="true"></i> {{ contact.phone2 }}</p>
                {% endif %}
            </div>
        </div>
    </div>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th scope="col" colspan="3"></th>
            <th scope="col" class="background">{% trans %} shop.quantity {% endtrans %}</th>
            <th scope="col" class="background">{% trans %} shop.price {% endtrans %} {{ tax }}</th>
            <th scope="col" class="background">{% trans %} shop.total {% endtrans %} {{ tax }}</th>
        </tr>
        </thead>
        <tbody>
        {% for item in cart.items %}
            <tr class="background">
                <td class="left background"
                    colspan="3">{{ item.variant.name|striptags }} {{ item.variant.type.volume }} {{ item.variant.type.unity }}</td>
                <td style="text-align: center;">{{ item.quantity }}</td>
                <td style="text-align: center;">{{ (item.price/100)| number_format(2) }} €</td>
                <td style="text-align: center;">{{ (item.total/100)| number_format(2) }} €</td>
            </tr>
        {% endfor %}
        <tr>
            <td colspan="4" class="no-border"></td>
            <td class="no-border">{% trans %} shop.total_product {% endtrans %}</td>
            <td>{{ (cart.itemsTotal/100) | number_format(2) }} € {{ tax }}</td>
        </tr>
        {% if cart.promoValuePercent %}
            <tr>
                <td colspan="4" class="no-border"></td>
                <td class="no-border">{% trans %} shop.discount {% endtrans %} ( {{ cart.promo }} )</td>
                <td>-{{ (cart.promoValuePercent*100) | number_format(2) }} %</td>
            </tr>
        {% endif %}
        {% if cart.promoValueAmount %}
            <tr>
                <td colspan="4" class="no-border"></td>
                <td class="no-border">{% trans %} shop.discount {% endtrans %} ( {{ cart.promo }} )</td>
                <td>-{{ (cart.promoValueAmount/100) | number_format(2) }} € {{ tax }}</td>
            </tr>
        {% endif %}
        {% if cart.degressiveValue %}
            <tr>
                <td colspan="4" class="no-border"></td>
                <td class="no-border">{% trans %}shop.degressive{% endtrans %} </td>
                <td>-{{ (cart.degressiveValue / 100) | number_format(2) }} € {{ tax }}</td>
            </tr>
        {% endif %}
        <tr>
            <td colspan="4" class="no-border"></td>
            <td class="no-border">{% trans %} shop.total_shipping {% endtrans %}</td>
            <td>{{ (cart.shipping/100) | number_format(2) }} € {{ tax }}</td>
        </tr>
        <tr>
            <td colspan="4" class="no-border"></td>
            <td class="no-border">{% trans %} shop.total {% endtrans %}</td>
            <td>
                {% if cart.viewHT %}
                    {{ (cart.totalWithoutTax/100) | number_format(2) }} € {{ tax }}
                {% else %}
                    {{ (cart.total/100) | number_format(2) }} € {{ tax }}
                {% endif %}
            </td>
        </tr>
        {% if cart.viewHT %}
            <tr>
                <td colspan="4" class="no-border"></td>
                <td class="no-border">{% trans %} shop.tax {% endtrans %} {{ cart.tax*100 }} % :</td>
                <td>{{ (cart.totalTax/100) | number_format(2) }} €</td>
            </tr>
            <tr>
                <td colspan="4" class="no-border"></td>
                <td class="no-border">Total TTC :</td>
                <td>{{ (cart.total/100) | number_format(2) }} € TTC</td>
            </tr>
        {% endif %}
        </tbody>
    </table>
    {% if admin %}
        {% if cart.groupCode %}
            <p>{% trans %}Grille tarifaire{% endtrans %} : {{ cart.groupCode }} </p><br/>
        {% endif %}
        <br/>
    {% endif %}
    {% if cart.promo %}
        <p>{% trans %}shop.discount_code{% endtrans %} : {{ cart.promo }}</p><br/>
    {% endif %}
    <p>
        {% if admin %}
        {% set codeError = null %}
        {% set paysCard = null %}
        {% set paysCode = null %}
        {% set ipCard = null %}
        {% if cart.cartCheckout.response is not empty %}
            {% if cart.paymentMethod.method == "systempay" or cart.paymentMethod.method == "sogecommerce" %}
                {% if cart.cartCheckout.response.vads_card_country is defined and cart.cartCheckout.response.vads_card_country is not null %}
                    {% set paysCard = cart.cartCheckout.response.vads_card_country|country_name %}
                    {% set paysCode = cart.cartCheckout.response.vads_card_country %}
                {% endif %}
                {% if cart.cartCheckout.response.vads_pays_ip is defined and cart.cartCheckout.response.vads_pays_ip is not null %}
                    {% set ipCard = cart.cartCheckout.response.vads_pays_ip|country_name %}
                {% endif %}
                {% if cart.cartCheckout.response.vads_payment_error is defined and cart.cartCheckout.response.vads_result != 00 %}
                    {% set codeError = cart.cartCheckout.response.vads_payment_error %}
                {% endif %}
            {% elseif  cart.paymentMethod.method == "e-transactions" %}
                {% if cart.cartCheckout.response.Pays is defined and cart.cartCheckout.response.Pays is not null %}
                    {% set paysCard = cart.cartCheckout.response.Pays|country_name_alpha3 %}
                    {% set paysCode = cart.cartCheckout.response.Pays %}
                {% endif %}
                {% if cart.cartCheckout.response.Ip is defined and cart.cartCheckout.response.Ip is not null %}
                    {% set ipCard = cart.cartCheckout.response.Ip|country_name_alpha3 %}
                {% endif %}
                {% if cart.cartCheckout.response.Erreur is defined and cart.cartCheckout.response.Erreur != 000000 %}
                    {% set codeError = cart.cartCheckout.response.Erreur %}
                {% endif %}
            {% elseif  cart.paymentMethod.method == "monetico" %}
                {% if cart.cartCheckout.response.originecb is defined and cart.cartCheckout.response.originecb != "ZZZ" %}
                    {% set paysCard = cart.cartCheckout.response.originecb|country_name_alpha3 %}
                    {% set paysCode = cart.cartCheckout.response.originecb %}
                {% endif %}
                {% if cart.cartCheckout.response.originetr is defined and cart.cartCheckout.response.originetr != "ZZZ" %}
                    {% set ipCard = cart.cartCheckout.response.originetr|country_name_alpha3 %}
                {% endif %}
                {% if cart.cartCheckout.response.vads_result is defined and cart.cartCheckout.response.vads_result != 00 %}
                    {% set codeError = cart.cartCheckout.response.vads_payment_error %}
                {% endif %}
            {% elseif  cart.paymentMethod.method == "sherlock2" or cart.paymentMethod.method == "sherlock" %}
                {% if cart.cartCheckout.response.Data is defined and cart.cartCheckout.response.Data is not null %}
                    {% set data = [] %}
                    {% for item in cart.cartCheckout.response.Data|split('|')|map((value, key) => value|split('=')) %}
                        {% set row = { (item[0]): (item[1]) } %}
                        {% set data = data|merge(row) %}
                    {% endfor %}
                    {% if data['issuerCountryCode'] is defined and data['issuerCountryCode'] != 'null' %}
                        {% set paysCard = (data['issuerCountryCode'])|country_name_alpha3 %}
                        {% set paysCode = data['issuerCountryCode'] %}
                    {% endif %}
                    {% if data['responseCode'] is defined and data['responseCode'] != 00 %}
                        {% set codeError = data['responseCode'] %}
                    {% endif %}
                {% endif %}
            {% elseif  cart.paymentMethod.method == "axepta" %}

            {% endif %}
            <strong>{% if paysCard is not null %}Pays émetteur de la CB utilisée :</strong> {{ paysCard }}{% endif %}
            <br/>
            <strong>{% if ipCard is not null %}Commande passée depuis :</strong> {{ ipCard }}{% endif %}
            <br/>
            {% if paysCard is not null and paysCard != cart.invoiceAddress.country|country_name and paysCode not in ['DE','DEU','FR','FRA','BE','BEL','MC','MCO','IT','ITA','GB','GBR','LU','LUX'] %}
                <span class="warning" style="color: #DC143C;"><strong><i class="fas fa-exclamation"></i> Ce paiement peut sembler suspect, veuillez faire les vérifications nécessaires avant d'envoyer la commande !  </strong></span>
            {% endif %}
            <br>
        {% endif %}
    </p>
    <p>{% trans %} order.method_payment {% endtrans %} : {{ cart.cartCheckout.paymentMethod.configuration['name'] }}</p>
    <p>
        {% if  cart.cartCheckout.payedAt is null %}
            {% trans %} order.not_paid {% endtrans %}
        {% else %}
            {% trans %} order.paid {% endtrans %} : {{ cart.cartCheckout.payedAt | date('d-m-Y H:i') }}
        {% endif %}
    </p><br/>
<br>

    {% if codeError is not null %}
        <strong>Code Erreur :</strong> {{ codeError }}
    {% endif %}
<br/>
    {% endif %}
    {% if cart.cartCheckout.paymentMethod.method == "banktransfert" %}
        <p>{{ 'shop.text_pay_banktransfert'|trans({'%amount%': (cart.total/100) | number_format(2)})|raw }} : </p>
        <p>{{ cart.cartCheckout.paymentMethod.configuration['text']|raw }}</p>
    {% endif %}
    {% if cart.cartCheckout.paymentMethod.method == "check" %}
        <p>{{ cart.cartCheckout.paymentMethod.configuration['text']|raw }}</p>
    {% endif %}
    <h4>{% trans %} shop.form.comment {% endtrans %} :</h4>
    <p>{% if cart.comment %}{{ cart.comment }}{% endif %}</p>
    <br/>
    <div class="text-footer">
        <h4>{% trans %} order.cgv {% endtrans %}</h4>
        <p><strong>{% trans %} order.cgv_order_title {% endtrans %}
                :</strong> {% trans %} order.cgv_order {% endtrans %}.</p>
        <p><strong>{% trans %} order.cgv_shipping_title {% endtrans %}
                :</strong> {% trans %} order.cgv_shipping {% endtrans %}.</p>
        <p><strong>{% trans %} order.cgv_payment_title {% endtrans %}
                :</strong> {% trans %} order.cgv_payment {% endtrans %}.</p>
        <p><strong>{% trans %} order.cgv_interest_title {% endtrans %}
                :</strong> {% trans %} order.cgv_interest {% endtrans %}.</p>
    </div>
</div>

</body>
</html>
