{% extends 'dashboard/layout.html' %}
{% load currency_filters %}
{% load i18n %}

{% block body_class %}catalogue{% endblock %}

{% block title %}
{% trans "Catalogue management" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
    <li>
	<a href="{% url dashboard:index %}">{% trans "Dashboard" %}</a>
        <span class="divider">/</span>
    </li>
	<li class="active"><a href=".">{% trans "Catalogue" %}</a></li>
</ul>
{% endblock %}

{% block header %}
<div class="page-header action">
	<h1>{% trans "Catalogue management" %}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}

<div class="well well-info">
	<h3 class="app-ico ico_expand icon">Create new product</h3>
    <form action="{% url dashboard:catalogue-product-create %}" method="get" class="form-inline">
		<label for="id_promotion_type">{% trans "Create a new product of type" %}</label>
		<select id="id_promotion_type" name="product_class">
			<option> -- choose type --</option>
			{% for product_class in product_classes %}
			<option value="{{ product_class.id }}">{{ product_class.name }}</option>
			{% endfor %}
		</select>
		<input type="submit" value="{% trans "New Product" %}" class="btn-primary" />
    </form>
</div>

<div class="well well-danger">
    <h3 class="app-ico ico_magnify icon">Search Products</h3>
    <form action="." method="get" class="form-inline">
		{% include "partials/form_fields_inline.html" with form=form %}
		<button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
    </form>
</div>

<div class="sub-header">
    <h2>{{ queryset_description }}</h2>
</div>
{% if products %}
<form action="." method="post">
    {% csrf_token %}
<table class="table table-striped table-bordered">
    <tr>
		<th>{% trans "UPC" %}</th>
		<th>{% trans "Title" %}</th>
		<th>{% trans "Product class" %}</th>
		<th>{% trans "Status" %}</th>
		<th>{% trans "Partner" %}</th>
		<th>{% trans "Partner SKU" %}</th>
		<th>{% trans "Price excl. tax" %}</th>
		<th>{% trans "Price incl. tax" %}</th>
		<th>{% trans "Number in stock" %}</th>
		<th>{% trans "Number allocated" %}</th>
        <th></th>
    </tr>
    {% for product in products %}
    <tr>
		<td>{{ product.upc|default:"-" }}</td>
        <td>{{ product.get_title }}</td>
		<td>{{ product.product_class.name }}</td>
		<td>{{ product.status|default:"-" }}</td>
		{% with stockrecord=product.stockrecord %}
			<td>{{ stockrecord.partner.name }}</td>
			<td>{{ stockrecord.partner_sku }}</td>
			<td>{{ stockrecord.price_excl_tax|currency }}</td>
			<td>{{ stockrecord.price_incl_tax|currency }}</td>
			<td>{{ stockrecord.num_in_stock }}</td>
			<td>{{ stockrecord.num_allocated }}</td>
		{% endwith %}
		<td>
			<a class="btn btn-info" href="{% url dashboard:catalogue-product product.id %}">{% trans "Edit" %}</a>
			<a class="btn btn-success" href="{{ product.get_absolute_url }}">{% trans "View on site" %}</a>
		</td>
    </tr>
    {% endfor %}
</table>

{% if page_obj %}
    {% include "catalogue/partials/pagination.html" %}
{% endif %}

</form>

{% else %}

<p>{% trans "No products found." %}</p>

{% endif %}

{% endblock dashboard_content %}
