{% extends 'oscar/dashboard/layout.html' %}
{% load i18n %}
{% load currency_filters %}

{% block body_class %}{{ block.super }} orders{% endblock %}

{% block title %}
    {% blocktrans with number=order.number %}Order {{ number }}{% endblocktrans %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a></li>
            <li class="breadcrumb-item"><a href="{% url 'dashboard:order-list' %}">{% trans "Orders" %}</a></li>
            <li class="breadcrumb-item active" aria-current="page">#{{ order.number }}</li>
        </ol>
    </nav>
{% endblock %}

{% block headertext %}
    {% blocktrans with number=order.number %}Order #{{ number }}{% endblocktrans %}
{% endblock  %}

{% block dashboard_content %}
    {% block customer_information %}
    <table class="table table-bordered table-hover">
        <caption><i class="fas fa-user"></i> {% trans "Customer Information" %}</caption>
        {% if order.guest_email %}
            <tr>
                <th>{% trans "Name" %}</th>
                <th>{% trans "Email address" %}</th>
            </tr>
            <tr>
                <td>
                    {% trans "Customer checked out as a guest." %}
                </td>
                <td>{{ order.email }}</td>
            </tr>
        {% elif order.user %}
            <tr>
                <th>{% trans "Name" %}</th>
                <th>{% trans "Email address" %}</th>
            </tr>
            <tr>
                <td>{{ order.user.get_full_name|default:"-" }}</td>
                <td>{{ order.user.email|default:"-" }}</td>
            </tr>
        {% else %}
            <tr><td>{% trans "Customer has deleted their account." %}</td></tr>
        {% endif %}
    </table>
    {% endblock customer_information %}

    {% block order_information %}
    <table class="table table-striped table-bordered table-hover">
        <caption><i class="fas fa-shopping-cart"></i> {% trans "Order information" %}</caption>
        <tr>
            <th>{% trans "Order Total" %}</th>
            <th>{% trans "Date of purchase" %}</th>
            <th>{% trans "Time of purchase" %}</th>
            <th>{% trans "Status" %}</th>
        </tr>
        <tr>
            <td>{{ order.total_incl_tax|currency:order.currency }}</td>
            <td>{{ order.date_placed|date }}</td>
            <td>{{ order.date_placed|time }}</td>
            <td>{{ order.status|default:"N/A" }}</td>
        </tr>
    </table>
    {% endblock order_information %}

    {% block additional_order_information %}
    {% endblock additional_order_information %}

    <div class="sub-header">
        <h2>{% trans "Order Details" %}</h2>
    </div>

    <div class="tabbable dashboard">

        <ul class="nav nav-tabs mb-0" role="tablist">
            {% block nav_tabs %}
                <li class="nav-item">
                    <a class="nav-link {% if active_tab == 'lines' %}active{% endif %}" href="#lines" data-toggle="tab">
                        {% trans "Order contents" %}
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link {% if active_tab == 'shipping' %}active{% endif %}" href="#shipping" data-toggle="tab">
                        {% trans "Shipping" %}
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link {% if active_tab == 'payment' %}active{% endif %}" href="#payment" data-toggle="tab">
                        {% trans "Payment" %}
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link {% if active_tab == 'discounts' %}active{% endif %}" href="#discounts" data-toggle="tab">
                        {% trans "Discounts" %}
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link {% if active_tab == 'notes' %}active{% endif %}" href="#notes" data-toggle="tab">
                        {% trans "Notes" %}
                    </a>
                </li>
            {% endblock nav_tabs %}
        </ul>

        <div class="tab-content">
            <div class="tab-pane fade {% if active_tab == 'lines' %}show active{% endif %}" id="lines" role="tabpanel">
                <div class="table-header">
                    <h3>{% trans "Items ordered" %}</h3>
                </div>
                <form id="order_lines_form" method="post" class="form-inline">
                    {% csrf_token %}
                    {% block order_lines %}
                        <table class="table table-striped table-bordered table-hover">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th></th>
                                    <th>{% trans "Line ID" %}</th>
                                    <th>{% trans "Quantity" %}</th>
                                    <th>{% trans "Product" %}</th>
                                    <th>{% trans "UPC" %}</th>
                                    <th>{% trans "Status" %}</th>
                                    <th>{% trans "Supplier" %}</th>
                                    <th>{% trans "Supplier SKU" %}</th>
                                    <th>{% trans "Price excl tax (before discounts)" %}</th>
                                    <th>{% trans "Price inc tax (before discounts)" %}</th>
                                    <th>{% trans "Actions" %}</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for line in lines %}
                                    <tr>
                                        <td>
                                            <input type="checkbox" name="selected_line" value="{{ line.id }}" />
                                        </td>
                                        <td>
                                            <input type="text" name="selected_line_qty_{{ line.id }}" value="{{ line.quantity }}" size="2" style="width:40px" />
                                        </td>
                                        <td><a href="{% url 'dashboard:order-line-detail' number=order.number line_id=line.id %}">#{{ line.id }}</a></td>
                                        <td>{{ line.quantity }}</td>
                                        <td>
                                            {% if line.product %}
                                                <a href="{% url 'dashboard:catalogue-product' pk=line.product.id %}">{{ line.title }}</a>
                                            {% else %}
                                                {{ line.title }}
                                            {% endif %}
                                        </td>
                                        <td>{{ line.upc|default:"-" }}</td>
                                        <td>{{ line.status|default:"-" }}</td>
                                        <td>
                                            {% if line.partner %}
                                                <a href="{% url 'dashboard:partner-manage' pk=line.partner.id %}">{{ line.partner_name }}</a>
                                            {% else %}
                                                {{ line.partner_name }}
                                            {% endif %}
                                        </td>
                                        <td>{{ line.partner_sku }}</td>
                                        <td class="text-right">{{ line.line_price_before_discounts_excl_tax|currency:order.currency }}</td>
                                        <td class="text-right">{{ line.line_price_before_discounts_incl_tax|currency:order.currency }}</td>
                                        <td>
                                            <a href="{% url 'dashboard:order-line-detail' number=order.number line_id=line.id %}" class="btn btn-secondary">{% trans "View" %}</a>
                                        </td>
                                    </tr>
                                {% endfor %}

                                <tr>
                                    <td colspan="8"></td>
                                    <th>{% trans "Discount" %}</th>
                                    <td class="text-right">{{ order.total_discount_excl_tax|currency:order.currency }}</td>
                                    <td class="text-right">{{ order.total_discount_incl_tax|currency:order.currency }}</td>
                                    <td></td>
                                </tr>
                                {% with discounts=order.basket_discounts %}
                                    {% if discounts %}
                                        <tr>
                                            <td colspan="8"></td>
                                            <th>{% trans "Basket total (excl. discounts)" %}</th>
                                            <td class="text-right">{{ order.basket_total_before_discounts_excl_tax|currency:order.currency }}</td>
                                            <td class="text-right">{{ order.basket_total_before_discounts_incl_tax|currency:order.currency }}</td>
                                            <td></td>
                                        </tr>
                                        {% for discount in discounts %}
                                            <tr>
                                                <td colspan="8"></td>
                                                <td>
                                                    <span class="badge badge-success">{% trans "Discount" %}</span>
                                                    {{ discount.offer_name }}
                                                </td>
                                                <td class="text-right"></td>
                                                <td class="text-right">- {{ discount.amount|currency:order.currency }}</td>
                                                <td></td>
                                            </tr>
                                        {% endfor %}
                                        <tr>
                                            <td colspan="8"></td>
                                            <th>{% trans "Basket total (inc. discounts)" %}</th>
                                            <th class="text-right">{{ order.basket_total_excl_tax|currency:order.currency }}</th>
                                            <th class="text-right">{{ order.basket_total_incl_tax|currency:order.currency }}</th>
                                            <td></td>
                                        </tr>
                                    {% else %}
                                        <tr>
                                            <td colspan="8"></td>
                                            <th>{% trans "Basket total" %}</th>
                                            <th class="text-right">{{ order.basket_total_excl_tax|currency:order.currency }}</th>
                                            <th class="text-right">{{ order.basket_total_incl_tax|currency:order.currency }}</th>
                                            <td></td>
                                        </tr>
                                    {% endif %}
                                {% endwith %}

                                {% if order.has_shipping_discounts %}
                                    <tr>
                                        <td colspan="8"></td>
                                        <td>{% trans "Shipping total (excl. discounts)" %}</td>
                                        <td class="text-right">{{ order.shipping_before_discounts_excl_tax|currency:order.currency }}</td>
                                        <td class="text-right">{{ order.shipping_before_discounts_incl_tax|currency:order.currency }}</td>
                                        <td></td>
                                    </tr>
                                    {% for discount in order.shipping_discounts %}
                                        <tr>
                                            <td colspan="8"></td>
                                            <td>
                                                <span class="badge badge-success">{% trans "Discount" %}</span>
                                                {{ discount.offer_name }}
                                            </td>
                                            <td></td>
                                            <td class="text-right">- {{ discount.amount|currency:order.currency }}</td>
                                            <td></td>
                                        </tr>
                                    {% endfor %}
                                    <tr>
                                        <td colspan="8"></td>
                                        <th>{% trans "Shipping total (inc. discounts)" %}</th>
                                        <th class="text-right">{{ order.shipping_excl_tax|currency:order.currency }}</th>
                                        <th class="text-right">{{ order.shipping_incl_tax|currency:order.currency }}</th>
                                        <td></td>
                                    </tr>
                                {% else %}
                                    <tr>
                                        <td colspan="8"></td>
                                        <th>{% trans "Shipping total" %}</th>
                                        <th class="text-right">{{ order.shipping_excl_tax|currency:order.currency }}</th>
                                        <th class="text-right">{{ order.shipping_incl_tax|currency:order.currency }}</th>
                                        <td></td>
                                    </tr>
                                {% endif %}

                                {% with surcharges=order.surcharges.all %}
                                {% if surcharges %}
                                    {% for charge in surcharges %}
                                        <tr>
                                            <td colspan="8"></td>
                                            <th>{% blocktrans with name=charge.name %}Surcharge {{ name }}{% endblocktrans %}</th>
                                            <th class="text-right">{{ charge.excl_tax|currency:order.currency }}</th>
                                            <th class="text-right">{{ charge.incl_tax|currency:order.currency }}</th>
                                            <td></td>
                                        </tr>
                                    {% endfor %}
                                {% endif %}
                                {% endwith %}

                                <tr>
                                    <td colspan="8"></td>
                                    <th>{% trans "Order total" %}</th>
                                    <th class="text-right">{{ order.total_excl_tax|currency:order.currency }}</th>
                                    <th class="text-right">{{ order.total_incl_tax|currency:order.currency }}</th>
                                    <td></td>
                                </tr>
                            </tbody>
                        </table>
                    {% endblock order_lines %}

                    {% comment %}
                        This is the important block within this template: you will almost certainly want to
                        override this block to provide your own form widgets that suit your order processing
                        flow.  The default contents shows a range of widgets - more than is sensible really.
                    {% endcomment %}
                    {% block line_actions %}
                        <div class="card card-body bg-light">
                            <h3>{% trans "With selected lines" %}:</h3>
                            <div class="form-inline mb-sm-2">
                                <div class="form-group">
                                    <div class="form-check">
                                        <input id="line_status_check" class="form-check-input" type="radio" name="line_action" value="change_line_statuses" />
                                        <label for="line_status_check" class="form-check-label">{% trans "Change line status to" %}</label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="sr-only" for="new_status_select">{% trans "choose new status" %}</label>
                                    <select id="new_status_select" name="new_status">
                                        <option value=""> -- {% trans "choose new status" %} -- </option>
                                        {% for status in line_statuses %}
                                        <option>{{ status }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                            <div class="form-inline mb-sm-2">
                                <div class="form-group">
                                    <div class="form-check">
                                        <input id="shipping_event_check" class="form-check-input" type="radio" name="line_action" value="create_shipping_event" />
                                        <label for="shipping_event_check" class="form-check-label">{% trans "Create shipping event" %}</label>
                                    </div>
                                </div>
                                <div class="form-group mr-1">
                                    <label class="sr-only" for="shipping_event_type_select">{% trans "choose event type" %}</label>
                                    <select id="shipping_event_type_select" name="shipping_event_type">
                                        <option value=""> -- {% trans "choose event type" %} -- </option>
                                        {% for event_type in shipping_event_types %}
                                        <option value="{{ event_type.code }}">{{ event_type.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="reference_input">{% trans "with reference" %}</label>
                                    <input id="reference_input" type="text" name="reference" value="" />
                                </div>
                            </div>
                            <div class="form-inline mb-sm-2">
                                <div class="form-group">
                                    <div class="form-check">
                                        <input id="payment_event_check" class="form-check-input" type="radio" name="line_action" value="create_payment_event" />
                                        <label for="payment_event_check" class="form-check-label">{% trans "Create payment event" %}</label>
                                    </div>
                                </div>
                                <div class="form-group mr-1">
                                    <label class="sr-only" for="payment_event_type_select">{% trans "choose event type" %}</label>
                                    <select id="payment_event_type_select" name="payment_event_type">
                                        <option value=""> -- {% trans "choose event type" %} -- </option>
                                        {% for event_type in payment_event_types %}
                                        <option value="{{ event_type.code }}">{{ event_type.name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="amount_input">{% trans "with amount" %}</label>
                                    <input id="amount_input" type="text" name="amount" value="" />
                                </div>
                            </div>
                            <div class="flex-nowrap">
                                <button type="submit" class="btn btn-primary">{% trans "Go!" %}</button>
                            </div>
                        </div>
                    {% endblock line_actions %}
                </form>

                <form method="post" id="order_status_form">
                    {% csrf_token %}
                    {% block order_actions %}
                        <div class="card card-body bg-light">
                            <h3><i class="fas fa-exclamation-triangle"></i> {% trans "Change order status" %}:</h3>
                            {% if order_status_form.has_choices %}
                                {% include "oscar/dashboard/partials/form_fields.html" with form=order_status_form %}
                                <input type="hidden" value="change_order_status" name="order_action" />
                                <div class="flex-nowrap">
                                    <button type="submit" class="btn btn-primary">{% trans "Change status" %}</button>
                                </div>
                            {% else %}
                                {% trans "This order can't have its status changed." %}
                            {% endif %}
                        </div>
                    {% endblock %}
                </form>

                {% block order_status_changes %}
                    <div class="table-header">
                        <h3>{% trans "Status Changes" %}</h3>
                    </div>
                    {% with status_changes=order.status_changes.all %}
                        <table class="table table-striped table-bordered table-hover">
                            {% if status_changes %}
                                <thead>
                                    <tr>
                                        <th>{% trans "From" %}</th>
                                        <th>{% trans "To" %}</th>
                                        <th>{% trans "Date" %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for status_change in status_changes %}
                                        <tr>
                                            <td>{{ status_change.old_status }}</td>
                                            <td>{{ status_change.new_status }}</td>
                                            <td>{{ status_change.date_created }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            {% else %}
                                <tbody>
                                    <tr>
                                        <td>{% trans "No status changes." %}</td>
                                    </tr>
                                </tbody>
                            {% endif %}
                        </table>
                    {% endwith %}
                {% endblock %}

                {% block shipping_events %}
                    <div class="table-header">
                        <h3>{% trans "Shipping Events" %}</h3>
                    </div>
                    {% with events=order.shipping_events.all %}
                        <table class="table table-striped table-bordered table-hover">
                            {% if events %}
                                <thead>
                                    <tr>
                                        <th>{% trans "Date" %}</th>
                                        <th>{% trans "Event" %}</th>
                                        <th>{% trans "Lines" %}</th>
                                        <th>{% trans "Reference" %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for event in events %}
                                        {% with line_qtys=event.line_quantities.all %}
                                            <tr>
                                                <td>{{ event.date_created }}</td>
                                                <td>{{ event.event_type.name }}</td>
                                                <td>
                                                    {% for line_qty in event.line_quantities.all %}
                                                        <a href="{% url 'dashboard:order-line-detail' number=order.number line_id=line_qty.line.id %}">
                                                            {% blocktrans with title=line_qty.line.title event_qty=line_qty.quantity total_qty=line_qty.line.quantity %}
                                                                {{ title }} (quantity {{ event_qty }}/{{ total_qty }})
                                                            {% endblocktrans %}
                                                        </a>
                                                    {% endfor %}
                                                </td>
                                                <td>{{ event.notes|default:"-" }}</td>
                                            </tr>
                                        {% endwith %}
                                    {% endfor %}
                                </tbody>
                            {% else %}
                                <tbody>
                                    <tr>
                                        <td>{% trans "No shipping events." %}</td>
                                    </tr>
                                </tbody>
                            {% endif %}
                        </table>
                    {% endwith %}
                {% endblock %}

                {% block payment_events %}
                    <div class="table-header">
                        <h3 >{% trans "Payment Events" %}</h3>
                    </div>
                    {% with events=order.payment_events.all %}
                        <table class="table table-striped table-bordered table-hover">
                            {% if events %}
                                <thead>
                                    <tr>
                                        <th>{% trans "Date" %}</th>
                                        <th>{% trans "Event" %}</th>
                                        <th>{% trans "Amount" %}</th>
                                        <th>{% trans "Lines" %}</th>
                                        <th>{% trans "Reference" %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for event in events %}
                                        {% with line_qtys=event.line_quantities.all %}
                                            <tr>
                                                <td >{{ event.date_created }}</td>
                                                <td >{{ event.event_type.name }}</td>
                                                <td >{{ event.amount|currency:order.currency }}</td>
                                                <td>
                                                    {% for line_qty in event.line_quantities.all %}
                                                        {% trans "Product:" %} {{ line_qty.line.title }} - {% trans "quantity" %} {{ line_qty.quantity }}</br>
                                                    {% endfor %}
                                                </td>
                                                <td >{{ event.reference|default:"-" }}</td>
                                            </tr>
                                        {% endwith %}
                                    {% endfor %}
                                </tbody>
                            {% else %}
                                <tbody>
                                    <tr><td>{% trans "No payment events." %}</td></tr>
                                </tbody>
                            {% endif %}
                        </table>
                    {% endwith %}
                {% endblock %}
            </div>

            <div class="tab-pane fade {% if active_tab == 'shipping' %}show active{% endif %}" id="shipping" role="tabpanel">
                {% block tab_shipping %}
                    <div class="table-header">
                        <h3>{% trans "Shipping" %}</h3>
                    </div>
                    <table class="table table-striped table-bordered table-hover">
                        <tbody>
                            <tr>
                                <th>{% trans "Method name" %}</th>
                                <td>{{ order.shipping_method }}</td>
                            </tr>
                            <tr>
                                <th>{% trans "Method code" %}</th>
                                <td>{{ order.shipping_code|upper }}</td>
                            </tr>
                            <tr>
                                <th>{% trans "Charge (incl tax)" %}</th>
                                <td>{{ order.shipping_incl_tax|currency:order.currency }}</td>
                            </tr>
                            <tr>
                                <th>{% trans "Charge (excl tax)" %}</th>
                                <td>{{ order.shipping_excl_tax|currency:order.currency }}</td>
                            </tr>
                            <tr>
                                <th>{% trans "Address" %}</th>
                                <td>
                                    {% for field in order.shipping_address.active_address_fields %}
                                        {{ field }}<br/>
                                    {% endfor %}
                                    {% if order.shipping_address %}
                                        <a class="btn btn-secondary" href="{% url 'dashboard:order-shipping-address' order.number %}">
                                            {% trans "Update" %}
                                        </a>
                                    {% endif %}
                                </td>
                            </tr>
                            <tr>
                                <th>{% trans "Phone" %}</th>
                                <td>{{ order.shipping_address.phone_number|default:"-" }}</td>
                            </tr>
                            <tr>
                                <th>{% trans "Instructions" %}</th>
                                <td>{{ order.shipping_address.notes|default:"-"|linebreaks }}</td>
                            </tr>
                        </tbody>
                    </table>
                {% endblock %}
            </div>

            <div class="tab-pane fade {% if active_tab == 'payment' %}show active{% endif %}" id="payment" role="tabpanel">
                {% block tab_payment %}

                    {% if order.billing_address %}
                        <div class="sub-header">
                            <h3 >{% trans "Billing address" %}</h3>
                        </div>
                        <p>
                            {% for field in order.billing_address.active_address_fields %}
                                {{ field }}<br/>
                            {% endfor %}
                        </p>
                    {% endif %}

                    {% with sources=order.sources.all %}
                        <div class="table-header">
                            <h3 >{% trans "Payment sources" %}</h3>
                        </div>
                        {% if sources %}
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>{% trans "Source" %}</th>
                                        <th>{% trans "Allocation" %}</th>
                                        <th>{% trans "Amount debited" %}</th>
                                        <th>{% trans "Amount refunded" %}</th>
                                        <th>{% trans "Reference" %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for source in sources %}
                                        <tr>
                                            <td>{{ source.source_type }}</td>
                                            <td>{{ source.amount_allocated|currency:order.currency }}</td>
                                            <td>{{ source.amount_debited|currency:order.currency }}</td>
                                            <td>{{ source.amount_refunded|currency:order.currency }}</td>
                                            <td>{{ source.reference|default:"-" }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <table class="table table-striped table-bordered table-hover">
                                <tr><td>{% trans "No payment sources found for this order." %}</td></tr>
                            </table>
                        {% endif %}
                    {% endwith %}

                    {% block payment_transactions %}
                        {% if payment_transactions %}
                            <div class="table-header">
                                <h3>{% trans "Transactions" %}</h3>
                            </div>
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>{% trans "Source" %}</th>
                                        <th>{% trans "Amount" %}</th>
                                        <th>{% trans "Reference" %}</th>
                                        <th>{% trans "Status" %}</th>
                                        <th>{% trans "Date" %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for txn in payment_transactions %}
                                        <tr>
                                            <td>{{ txn.source.source_type }}</td>
                                            <td>{{ txn.amount|currency:order.currency }}</td>
                                            <td>{{ txn.reference|default:"-" }}</td>
                                            <td>{{ txn.status|default:"-" }}</td>
                                            <td>{{ txn.date_created }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        {% endif %}
                    {% endblock %}

                {% endblock %}
            </div>

            <div class="tab-pane fade {% if active_tab == 'discounts' %}show active{% endif %}" id="discounts" role="tabpanel">
                {% block tab_discounts %}

                    {% with discounts=order.discounts.all %}
                        <div class="table-header">
                            <h3>{% trans "Discounts" %}</h3>
                        </div>
                        {% if discounts %}
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>{% trans "Type" %}</th>
                                        <th>{% trans "Voucher" %}</th>
                                        <th>{% trans "Offer name" %}</th>
                                        <th>{% trans "Frequency" %}</th>
                                        <th>{% trans "Message" %}</th>
                                        <th>{% trans "Amount" %}</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for discount in discounts %}
                                        <tr>
                                            <td>{{ discount.get_category_display }}</td>
                                            <td>
                                                {{ discount.voucher.code|default:"-" }}
                                            </td>
                                            <td>
                                                {% if discount.offer %}
                                                    <a href="{% url 'dashboard:offer-detail' pk=discount.offer.id %}">{{ discount.offer.name }}</a>
                                                {% else %}
                                                    {{ discount.offer_name }}
                                                {% endif %}
                                            </td>
                                            <td>{{ discount.frequency }}</td>
                                            <td>{{ discount.message|default:"-" }}</td>
                                            <td>{{ discount.amount|currency:order.currency }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <table class="table table-striped table-bordered table-hover">
                                <tr><td>{% trans "No discounts were applied to this order." %}</td></tr>
                            </table>
                        {% endif %}
                    {% endwith %}

                {% endblock %}
            </div>

            <div class="tab-pane fade {% if active_tab == 'notes' %}show active{% endif %}" id="notes" role="tabpanel">
                {% block tab_notes %}
                    <div class="table-header">
                        <h3>{% trans "Notes" %}</h3>
                    </div>
                    {% with notes=order.notes.all %}
                        <table class="table table-striped table-bordered table-hover">
                            {% if notes %}
                                <tr>
                                    <th>{% trans "Date" %}</th>
                                    <th>{% trans "User" %}</th>
                                    <th>{% trans "Type" %}</th>
                                    <th>{% trans "Message" %}</th>
                                    <th>{% trans "Admin" %}</th>
                                </tr>
                                {% for note in notes %}
                                    <tr>
                                        <td>{{ note.date_created }}</td>
                                        <td>{{ note.user|default:"-" }}</td>
                                        <td>{{ note.note_type|default:"-" }}</td>
                                        <td>{{ note.message|linebreaks }}</td>
                                        <td>
                                            {% if note.is_editable %}
                                                <a href="{% url 'dashboard:order-detail-note' number=order.number note_id=note.id %}#notes" class="btn btn-info">{% trans "Edit" %}</a>
                                                <form method="post" class="float-left m-0">
                                                    {% csrf_token %}
                                                    <input type="hidden" name="order_action" value="delete_note" />
                                                    <input type="hidden" name="note_id" value="{{ note.id }}" />
                                                    <input type="submit" value="{% trans "Delete" %}" class="btn btn-danger" />
                                                </form>
                                            {% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}
                            {% else %}
                                <tr>
                                    <td>{% trans "No notes available." %}</td>
                                </tr>
                            {% endif %}
                        </table>
                    {% endwith %}

                    <form id="order_note_form" action=".?note={{ note_id }}" method="post" class="form-stacked">
                        {% csrf_token %}
                        <input type="hidden" value="save_note" name="order_action" />
                        {% include "oscar/dashboard/partials/form_fields.html" with form=note_form %}
                        <div class="form-actions">
                            <input type="submit" value="{% trans "Save note" %}" class="btn btn-primary" />
                            {% trans "Notes are only editable for 5 minutes after being saved." %}
                        </div>
                    </form>
                {% endblock %}
            </div>

            {% block extra_tabs %}{% endblock %}
        </div>
    </div>
{% endblock dashboard_content %}

{% block onbodyload %}
    {{ block.super }}
    oscar.dashboard.orders.initTabs();
    oscar.dashboard.orders.initTable();
{% endblock %}
