{% extends "base.html" %}
{% load i18n %}
{% block main %}
    <h1>{% trans "cBOM download" %}</h1>
    <p>{% trans "Select a cBOM, that you can then download as BOM or cBOM csv file." %}</p>
    {% if object %}
        <h2>
            {% blocktrans with description=object.description %}
                Contents of cBOM "{{ description }}" converted into a BOM
            {% endblocktrans %}
        </h2>
        <table>
            <tr>
                <th>{% trans "Position" %}</th>
                <th>{% trans "IPN" %}</th>
                <th>{% trans "Description" %}</th>
                <th>{% trans "QTY" %}</th>
                <th>{% trans "Unit" %}</th>
                <th>{% trans "Shape" %}</th>
            </tr>
            {% for item in bom_items %}
                <tr>
                    <td>{{ item.position }}</td>
                    <td>{{ item.ipn.code }}</td>
                    <td>{{ item.ipn.name }}</td>
                    <td>{{ item.qty }}</td>
                    <td>{{ item.unit.code }}</td>
                    <td>{{ item.ipn.shape.code }}</td>
                </tr>
            {% endfor %}
        </table>
        <p><a href="{{ bom_file }}">Download BOM.csv</a></p>
        <h2>{% trans "Content of the cBOM" %}</h2>
        <table>
            <tr>
                <th>{% trans "Position" %}</th>
                <th>{% trans "EPN" %}</th>
                <th>{% trans "Description" %}</th>
                <th>{% trans "Quantity" %}</th>
                <th>{% trans "Unit" %}</th>
                <th>{% trans "Consign" %}</th>
            </tr>
            {% for item in object.cbomitems.all %}
                <tr>
                    <td>{{ item.position }}</td>
                    <td>{{ item.epn.epn }}</td>
                    <td>{{ item.epn.description }}</td>
                    <td>{{ item.qty }}</td>
                    <td>{{ item.unit.code }}</td>
                    <td>{{ item.consign|add:0 }}</td>
                </tr>
            {% endfor %}
        </table>
        <p><a href="{{ cbom_file }}">Download cBOM.csv</a></p>
    {% endif %}

    <h2>{% trans "All cBOMs" %}</h2>
    <table>
        <tr>
            <th>{% trans "Customer" %}</th>
            <th>{% trans "Description" %}</th>
            <th>{% trans "HTML link" %}</th>
            <th>{% trans "Product" %}</th>
            <th>{% trans "Version date" %}</th>
        </tr>
        {% for cbom in cboms %}
            <tr>
                <td><a href="{% url "aps_bom_cbom_download" cbom_pk=cbom.pk %}">{{ cbom.customer.description }}</a></td>
                <td>{{ cbom.description }}</td>
                <td><a href="{{ cbom.html_link }}">{{ cbom.html_link }}</a></td>
                <td>{{ cbom.product }}</td>
                <td>{{ cbom.version_date }}</td>
            </tr>
        {% endfor %}
    </table>
{% endblock %}
