{% extends "layout.html" %}
{% load currency_filters %}
{% load i18n %}

{% block title %}
{% trans 'Order' %} {{ order.number }} | {{ block.super }}
{% endblock %}

{% block body_class %}account-pages{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
        <a href="{% url promotions:home %}">{% trans 'Home' %}</a>
        <span class="divider">/</span>
    </li>
    <li>
        <a href="{% url customer:summary %}">{% trans 'Account' %}</a>
        <span class="divider">/</span>
    </li>
    <li>
        <a href="{% url customer:order-list %}">{% trans 'Order history' %}</a>
        <span class="divider">/</span>
    </li>
    <li class="active">{% blocktrans with number=order.number %}Order #{{ number }}{% endblocktrans %}</li>
</ul>
{% endblock %}

{% block headertext %}
{% trans 'Account' %}
{% endblock %}

{% block subnavigation %}
    {% include "partials/nav_profile.html" with order_history="active" %}
{% endblock %}

{% block subheader %}
<div class="sub-header">
    <h2>{% blocktrans with number=order.number %}Order #{{ number }}{% endblocktrans %}</h2>
</div>
{% endblock subheader %}

{% block content %}

<div class="row-fluid">
    <div class="span3">
        <ul class="nav nav-tabs nav-stacked">
            <li class="active"><a href="#1" data-toggle="tab">{% trans 'Order contents' %} <i class="icon-chevron-right pull-right"></i></a></li>
            <li><a href="#2" data-toggle="tab">{% trans 'Shipping Method' %} <i class="icon-chevron-right pull-right"></i></a></li>
            <li><a href="#3" data-toggle="tab">{% trans 'Shipping Address' %} <i class="icon-chevron-right pull-right"></i></a></li>
        </ul>
    </div>
    <div class="span9">
        <div class="tab-content">
            <div class="tab-pane active" id="1">
                <table class="table table-striped table-bordered">
				<thead>
					<tr>
						<th>{% trans 'Product' %}</th>
						<th>{% trans 'Dispatch date' %}</th>
						<th>{% trans 'Quantity' %}</th>
						<th>{% trans 'Line price excl tax' %}</th>
						<th>{% trans 'Line price incl tax' %}</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
					{% for line in order.lines.all %}
					<tr>
						<td><a href="{{ line.product.get_absolute_url }}">{{ line.description }}</a></td>
						<td>{{ line.est_dispatch_date|default:"-" }}</td>
						<td>{{ line.quantity }}</td>
						<td>{{ line.line_price_before_discounts_excl_tax|currency }}</td>
						<td>{{ line.line_price_before_discounts_incl_tax|currency }}</td>
						<td>
							<form id="line_form_{{ line.id }}" action="{% url customer:order-line order.number line.id %}" method="POST">
								{% csrf_token %}
								<input type="hidden" name="action" value="reorder" />
								<button class="btn btn-success" type="submit">{% trans 'Re-order' %}</button>
								<a class="btn btn-info" href="{% url catalogue:reviews-add line.product.slug line.product.id %}">{% trans 'Write a review' %}</a>
							</form>
						</td>
					</tr>
					{% endfor %}

                    {% with discounts=order.basket_discounts %}
                        {% if discounts %}
                            <tr>
                                <td colspan="4">{% trans "Basket total (excl. discounts)" %}</td>
                                <td colspan="2">{{ order.basket_total_before_discounts_incl_tax|currency }}</td>
                            </tr>
                            {% for discount in discounts %}
                            <tr>
                                <td colspan="4">
                                    <span class="label label-success">{% trans "Discount" %}</span>
                                    {{ discount.offer_name }}
                                </td>
                                <td colspan="2">- {{ discount.amount|currency }}</td>
                            </tr>
                            {% endfor %}
                            <tr>
                                <th colspan="4">{% trans "Basket total (inc. discounts)" %}</th>
                                <td colspan="2">{{ order.basket_total_incl_tax|currency }}</td>
                            </tr>
                        {% else %}
                            <tr>
                                <th colspan="4">{% trans "Basket total" %}</th>
                                <td colspan="2">{{ order.basket_total_incl_tax|currency }}</td>
                            </tr>
                        {% endif %}
                    {% endwith %}

                    {% if order.has_shipping_discounts %}
                        <tr>
                            <td colspan="4">{% trans "Shipping total (excl. discounts)" %}</td>
                            <td colspan="2">{{ order.shipping_before_discounts_incl_tax|currency }}</td>
                        </tr>
                        {% for discount in order.shipping_discounts %}
                        <tr>
                            <td colspan="4">
                                <span class="label label-success">{% trans "Discount" %}</span>
                                {{ discount.offer_name }}
                            </td>
                            <td colspan="2">- {{ discount.amount|currency }}</td>
                        </tr>
                        {% endfor %}
                        <tr>
                            <th colspan="4">{% trans "Shipping total (inc. discounts)" %}</th>
                            <td colspan="2">{{ order.shipping_incl_tax|currency }}</td>
                        </tr>
                    {% else %}
                        <tr>
                            <th colspan="4">{% trans "Shipping total" %}</th>
                            <td colspan="2">{{ order.shipping_incl_Tax|currency }}</td>
                        </tr>
                    {% endif %}

					<tr>
						<th colspan="4">{% trans 'Order total' %}</th>
						<td colspan="2">{{ order.total_incl_tax|currency }}</td>
					</tr>
				</tbody>
                </table>
            </div>

            <div class="tab-pane" id="2">
                <p>{{ order.shipping_method }}</p>
            </div>

            <div class="tab-pane" id="3">
			<div class="row-fluid">
                    <div class="span4">
                        <div class="well well-info">
                            <h4>{% trans 'Address:' %}</h4>
                            <p>{% for field in order.shipping_address.active_address_fields %}
                            {{ field }}<br/>
                            {% endfor %}</p>
                        </div>
                    </div>
                    <div class="span4">
                        <div class="well well-info">
                            <h4>{% trans 'Contact Number:' %}</h4>
                            <p>{{ shipping_address.phone_number }}</p>
                        </div>
                    </div>
                    <div class="span4">
                        <div class="well well-info">
                            <h4>{% trans 'Shipping Notes:' %}</h4>
                            <p>{{ shipping_address.notes }}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



{% endblock content %}

