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

{% block buttons %}
  <a class="btn btn-default" href="{% url 'epic:ship_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>SO #</strong></td><td>{{ shipment.id }}</td>
      </tr>
      <tr>
	{% if shipment.from_warehouse %}
	{% else %}
	<td><strong>PO #</strong></td>
	<td>{{ shipment.ordr.html_link|safe }}</td>
	{% endif %}
      </tr>
      <tr>
	{% if shipment.from_warehouse %}
	<td><strong>Ship-From</strong></td>
	<td>{{ shipment.from_warehouse.html_link|safe }}</td>
	{% else %}
	<td><strong>Vendor</strong></td>
	<td>{{ shipment.ordr.vendor.html_link|safe }}</td>
	{% endif %}
      </tr>
    </table>
  </div>

  <div class="col-md-6">
    <table class="table table-bordered table-hover table-striped"
	   style="background-color: white">
      <tr>
	<td><strong>Ship Date</strong></td>
	<td>{{ shipment.ts|date:"Y‑m‑d" }}</td>
      </tr>
      <tr>
	<td><strong>Ship-To</strong></td>
	<td>{{ shipment.warehouse.html_link|safe }}</td>
      </tr>
      <tr>
	<td><strong>Tracking #s</strong></td>
	<td>{{ shipment.html_tracking_links|safe }}</td>
      </tr>
    </table>
  </div>
</div>

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

  <a class="btn btn-danger" href="{% url 'epic:ship_delete' shipment.id %}"
     onclick="return confirm ('Are you sure you want to delete this shipment?')">
    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">
    {{ shipment.notes|linebreaksbr }}
  </div>
</div>

<div class="panel panel-default">
  <div class="panel-heading clearfix">
    <h2 class="panel-title pull-left">Shipment Items</h2>
    <div class="pull-right">
      <a class="btn btn-default"
	 href="{% url 'epic:ship_export' shipment.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>Ship Qty</th>
	{% if shipment.from_warehouse %}
	{% else %}
	<th>Order Qty</th>
	{% endif %}
	<th>Part #</th>
	<th>Manufacturer Part #</th>
	{% if shipment.from_warehouse %}
	{% else %}
	<th>Vendor Part #</th>
	<th>Price</th>
	{% endif %}
	<th>Amount</th>
      </thead>
      {% for item in line_items %}
      <tr>
	<td class="text-right">{{ item.index }}</td>
	<td class="text-right">{{ item.qty|intcomma }}</td>
	{% if shipment.from_warehouse %}
	{% else %}
	<td class="text-right">{{ item.order_line_item.qty|intcomma }}</td>
	{% endif %}
	<td>{{ item.part.html_link|safe }}</td>
	<td>{{ item.part.mfg }} {{ item.part.mfg_pn }}</td>
	{% if shipment.from_warehouse %}
	<td></td>	<!-- amount -->
	{% else %}
	<td>{{ item.order_line_item.vendor_part.html_link|safe }}</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>
	{% endif %}
      </tr>
      {% endfor %}
      <tr>
	<th colspan="{% if shipment.from_warehouse %}4{% else %}7{% endif %}"
	    class="text-right">Freight Cost</th>
	<th class="text-right">
	  $&nbsp;{{ shipment.cost_freight|floatformat:2|intcomma }}</th>
      </tr>
      <tr>
	<th colspan="{% if shipment.from_warehouse %}4{% else %}7{% endif %}"
	    class="text-right">Other Costs</th>
	<th class="text-right">
	  $&nbsp;{{ shipment.cost_other|floatformat:2|intcomma }}</th>
      </tr>
      <tr>
	<th colspan="{% if shipment.from_warehouse %}4{% else %}7{% endif %}"
	    class="text-right">Discounts</th>
	<th class="text-right">
	  $&nbsp;{{ shipment.cost_discount|floatformat:2|intcomma }}</th>
      </tr>
      <tr>
	<th colspan="{% if shipment.from_warehouse %}4{% else %}7{% endif %}"
	    class="text-right">Total</th>
	<th class="text-right">
	  $&nbsp;{{ shipment.total_cost|floatformat:2|intcomma }}</th>
      </tr>
    </table>
  </div>
</div>

</div>

<p></p>

{% endblock content %}
