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

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

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

{% block header %}
<div class="page-header">
    <h1>Order #{{ order.number }}</h1>
</div>
{% endblock header %}


{% block content %}

<div class="tabbable dashboard">
	<ul class="nav nav-tabs">
		<li class="active"><a href="#1" data-toggle="tab">Shipping Address</a></li>
		<li><a href="#2" data-toggle="tab">Shipping Method</a></li>
		<li><a href="#3" data-toggle="tab">Order Contents</a></li>
	</ul>

	<div class="tab-content">

		<div class="tab-pane active" id="1">
			<div class="sub-header">
				<h3>Profile</h3>
			</div>	
			<div class="row-fluid">
				<div class="span4">
 					<div class="well well-info">
						<h4>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>Contact Number:</h4>
						<p>{{ shipping_address.phone_number }}</p>
					</div>
				</div>
				<div class="span4">
					<div class="well well-info">
						<h4>Shipping Notes:</h4>
						<p>{{ shipping_address.notes }}</p>
					</div>
				</div>
			</div>
		</div>

		<div class="tab-pane" id="2">
			<div class="sub-header">
				<h3>Shipping method</h3>
			</div>
			<p>{{ order.shipping_method }}</p>
		</div>

		<div class="tab-pane" id="3">
			<div class="sub-header">
				<h3>Order contents</h3>
			</div>

			{% csrf_token %}
			<table class="table table-striped table-bordered">
				<tr>
					<th>Product</th>
					<th>Availability</th>
					<th>Quantity</th>
					<th>Line price excl tax</th>
					<th>Line price incl tax</th>
					<th></th>
				</tr>
				{% for line in order.lines.all %}
				<tr>
					<td><a href="{{ line.product.get_absolute_url }}">{{ line.description }}</a></td>
					<td>{{ line.product.stockrecord.availability }}</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 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">Re-order</button>
							<a class="btn btn-info" href="{% url catalogue:reviews-add line.product.slug line.product.id %}">Write a review</a>
						</form>
					</td>
				</tr>
				{% endfor %}
				{% for discount in order.discounts.all %}
				<tr>
					<td colspan="4">{{ discount.description }}</td>
					<td>-{{ discount.amount|currency }}</td>
				</tr>
				{% endfor %}
				<tr>
					<th colspan="4">Basket total (inc. tax)</th>
					<td colspan="2">{{ order.basket_total_incl_tax|currency }}</td>
				</tr>
				<tr>
					<th colspan="4">Shipping charge (inc. tax)</th>
					<td colspan="2">{{ order.shipping_incl_tax|currency }}</td>
				</tr>
				<tr>
					<th colspan="4">Order total</th>
					<td colspan="2">{{ order.total_incl_tax|currency }}</td>
				</tr>
			</table>
		</div>
	</div>
</div>
{% endblock content %}

