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

{% block buttons %}
  <a class="btn btn-default" href="{% url 'epic:warehouse_detail' warehouse %}">
    Up <i class="glyphicon glyphicon-chevron-up"></i>
  </a>
{% 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>Warehouse</strong></td>
	<td>{{ inventory.warehouse.name }}</td>
      </tr>
    </table>
  </div>
  <div class="col-md-6">
    <table class="table table-bordered table-hover table-striped"
	   style="background-color: white">
      <tr>
	<td><strong>Inventory Date</strong></td>
	<td>{{ inventory.ts|date:"Y‑m‑d h:i A" }}</td>
      </tr>
    </table>
  </div>
</div>

<p>
  {% if has_relative_deltas %}

  <div class="panel panel-warning">
  <div class="panel-heading">
    <h2 class="panel-title">Warning</h2>
  </div>
    <div class="panel-body">
      This inventory has relative adjustments which are not editable
      in this version of EPIC.  Please create an equivalent
      Inter-Warehouse Shipment instead.
    </div>
  </div>

  {% else %}
  <a class="btn btn-primary"
     href="{% url 'epic:warehouse_inventory_edit' warehouse pk %}">
    Edit <i class="glyphicon glyphicon-edit"></i></a>
  {% endif %}

  <a class="btn btn-danger"
     href="{% url 'epic:warehouse_inventory_delete' warehouse pk %}"
     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">
    {{ inventory.notes|linebreaksbr }}
  </div>
</div>

<div class="panel panel-default">
  <div class="panel-heading clearfix">
    <h2 class="panel-title pull-left">Inventory Items</h2>
    <div class="pull-right">
      <a class="btn btn-default"
	 href="{% url 'epic:warehouse_inventory_export' warehouse pk %}">
	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>Part #</th><th>Manufacturer Part #</th>
	<th>New Qty</th><th>Old Qty</th><th>Qty Change</th><th>Value Change</th>
      </thead>
      {% for item in inventory_items %}
      <tr class="{% if item.is_relative %}warning{% endif %}">
	<td>{{ item.part.html_link|safe }}</td>
	<td>{{ item.part.mfg }} {{ item.part.mfg_pn }}</td>
	<td class="text-right">
	  {% for qty_new in item.qty_new_list %}
	  {{   qty_new.0|intcomma }}
	  {%   if item.qty_new_list|length > 1 or qty_new.1 != item.part %}
	         &times;{{ qty_new.1.html_link|safe }}<br>
	  {%   endif %}
	  {% endfor %}
	</td>
	<td class="text-right">
	  {% for qty_old in item.qty_old_list %}
	  {{   qty_old.0|intcomma }}
	  {%   if item.qty_old_list|length > 1 or qty_old.1 != item.part %}
	         &times;{{ qty_old.1.html_link|safe }}<br>
	  {%   endif %}
	  {% endfor %}
	</td>
	<td class="text-right">
	  {% for qty_dif in item.qty_dif_list %}
	    <span class="{% if qty_dif.0 > 0 %}epic_excess
			 {% else %}epic_shortage{% endif %}">
	      {{ qty_dif.0|intcomma }}
	    </span>
	    {%   if item.qty_dif_list|length > 1 or qty_dif.1 != item.part %}
	          &times;{{ qty_dif.1.html_link|safe }}<br>
	    {%   endif %}
	  {% endfor %}
	</td>
	<td class="text-right">
	  $&nbsp;{{ item.value_diff|floatformat:2|intcomma }}
	</td>
      </tr>
      {% endfor %}
      <tr>
	<th colspan="5" class="text-right">
	  <strong>Total Inventory Value Change</strong>
	</th>
	<th class="text-right">
	  <strong>
	    $&nbsp;{{ total_value_change|floatformat:2|intcomma }}
	  </strong>
	</th>
      </tr>
    </table>
  </div>
</div>

</div>

<br>

{% endblock content %}
