{% extends "epic/base_layout.html" %}
{% load crispy_forms_tags %}
{% load humanize %}

{% block buttons %}
  <a class="btn btn-default" href="{% url 'epic:order_list' %}">
    Up <i class="glyphicon glyphicon-chevron-up"></i>
  </a>

  {{ page_nav|safe }}
{% endblock buttons %}

{% block content %}
{{ block.super }}

<div class="row">
  <div class="col-md-6">
    <table class="table table-bordered table-hover table-striped"
	   style="background-color: white">
      <tr>
	<td><strong>PO #</strong></td><td>{{ order.id }}</td>
      </tr>
      <tr>
	<td><strong>Vendor</strong></td>
	<td>{{ order.vendor.html_link|safe }}</td>
      </tr>
      <tr>
	<td><strong>Ship-To</strong></td>
	<td>{{ order.warehouse.html_link|safe }}</td>
      </tr>
    </table>
  </div>

  <div class="col-md-6">
    <table class="table table-bordered table-hover table-striped"
	   style="background-color: white">
      {% for field in fields %}
      <tr>
	<td><strong>{{ field.0 }}</strong></td><td>{{ field.1|safe }}</td>
      </tr>
      {% endfor %}
    </table>
  </div>
</div>

<p>
  <a class="btn btn-primary"
     href="{% url 'epic:order_edit' order.id %}">
    Edit <i class="glyphicon glyphicon-edit"></i></a>

  {% if order.is_open %}
  <a class="btn btn-default"
     href="{% url 'epic:order_add_shipment' order.id %}">
    Add Shipment <i class="glyphicon glyphicon-plus"></i></a>
  {% endif %}

  {% if order.assembly_line_items %}
  <a class="btn btn-default"
     {% if order.is_open %}{% else %}disabled="disabled"{% endif %}
     href="{% url 'epic:order_check_stock' order.id %}">
    Check Stock <i class="glyphicon glyphicon-check"></i></a>
  {% endif %}

  <a class="btn btn-danger" href="{% url 'epic:order_delete' order.id %}"
     onclick="return confirm ('Are you sure you want to delete this order?')">
    Delete <i class="glyphicon glyphicon-remove"></i></a>
</p>

<div class="panel panel-default">
  <div class="panel-heading">
    <h2 class="panel-title">Notes</h2>
  </div>
  <div class="panel-body">
    {{ order.notes|linebreaksbr }}
  </div>
</div>

<div class="panel panel-default">
  <div class="panel-heading">
    <h2 class="panel-title">Associated Shipments</h2>
  </div>
  <div class="panel-body">
    {{ shipments|safe }}.
  </div>
</div>

<div class="panel panel-default">
  <div class="panel-heading clearfix">
    <h2 class="panel-title pull-left">Order Items</h2>
    <div class="pull-right">
      <a class="btn btn-default"
	 href="{% url 'epic:order_export' order.id %}">
	Export <i class="glyphicon glyphicon-export"></i></a>
    </div>
  </div>
  <div class="panel-body">
    <table class="table table-bordered table-hover table-striped"
	   style="background-color: white">
      <thead>
	<th>Idx</th><th>Qty</th><th>Part #</th>
	<th>Vendor Part #</th><th>Manufacturer Part #</th>
	<th>Price</th><th>Amount</th><th>Qty remaining<br>to ship</th>
      </thead>
      {% for item in order_items %}
      <tr>
	<td class="text-right">{{ item.index }}</td>
	<td class="text-right">{{ item.qty|intcomma }}</td>
	<td>{{ item.part.html_link|safe }}</td>
	<td>{{ item.vendor_part.html_link|safe }}</td>
	<td>{{ item.part.mfg }} {{ item.part.mfg_pn }}</td>
	<td class="text-right">
	  $&nbsp;{{ item.part_cost|floatformat:6|intcomma }}</td>
	<td class="text-right">
	  $&nbsp;{{ item.line_cost|floatformat:2|intcomma }}</td>
	<td class="text-right">{{ item.qty_remaining_to_ship|intcomma }}</td>
      </tr>
      {% endfor %}
      <tr>
	<th colspan="6" class="text-right">Order Total</th>
	<th class="text-right">
	  $&nbsp;{{ order.total_cost|floatformat:2|intcomma }}</th>
	<th></th>
      </tr>
    </table>
  </div>
</div>

<br>

{% endblock content %}
