{% extends 'inventory/base_inventory_minimal.html' %}
{% block inventory_title %}Партии поступлений{% endblock %}
{% block breadcrumb_current %}Партии поступлений{% endblock %}
{% block inventory_content %}
<div class="card">
    <div class="card-header">
        <div class="d-flex justify-content-between align-items-center">
            <h4 class="mb-0">Партии поступлений товара</h4>
            <a href="{% url 'inventory:incoming-create' %}" class="btn btn-primary btn-sm">
                <i class="bi bi-plus-circle"></i> Новое поступление
            </a>
        </div>
    </div>
    <div class="card-body">
        {% if batches %}
        <div class="table-responsive">
            <table class="table table-hover table-sm">
                <thead>
                    <tr>
                        <th>Номер документа</th>
                        <th>Склад</th>
                        <th>Тип</th>
                        <th>Поставщик</th>
                        <th>Товары</th>
                        <th>Кол-во</th>
                        <th>Дата создания</th>
                        <th>Действия</th>
                    </tr>
                </thead>
                <tbody>
                    {% for batch in batches %}
                    <tr>
                        <td><strong>{{ batch.document_number }}</strong></td>
                        <td>{{ batch.warehouse.name }}</td>
                        <td>
                            <span class="badge bg-{% if batch.receipt_type == 'supplier' %}primary{% elif batch.receipt_type == 'inventory' %}info{% else %}success{% endif %}">
                                {{ batch.get_receipt_type_display }}
                            </span>
                        </td>
                        <td>{{ batch.supplier_name|default:"—" }}</td>
                        <td>
                            <small>
                                {% for item in batch.items.all %}
                                    {{ item.product.name }}{% if not forloop.last %}<br>{% endif %}
                                {% endfor %}
                            </small>
                        </td>
                        <td>
                            <span class="badge bg-info">{{ batch.items_count }}</span>
                        </td>
                        <td>{{ batch.created_at|date:"d.m.Y H:i" }}</td>
                        <td>
                            <a href="{% url 'inventory:incoming-batch-detail' batch.pk %}" class="btn btn-sm btn-outline-info" title="Просмотр партии">
                                <i class="bi bi-eye"></i>
                            </a>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% else %}
        <div class="alert alert-info">Партий поступлений не найдено.</div>
        {% endif %}
    </div>
</div>
{% endblock %}
