{% extends "base.html.twig" %}
{% block searchform_container %}{% endblock %}
{% block actionheader %}
{% endblock %}

{% block body %}

<div id="inventario-movimientos">
<div class="box pad">

    <div class="box-header">

        <i class="fa fa-history"></i>

        <h3 class="box-title">
            Movimientos de inventario
        </h3>

    </div>

    <div class="box-body">

        <div class="row">

            <div class="col-md-4">

                <strong>Codigo:</strong>

                {{ producto.reference }}

            </div>

            <div class="col-md-5">

                <strong>Producto:</strong>

                {{ producto.description }}

            </div>

            <div class="col-md-3 text-right">

                <strong>Existencia actual:</strong>

                <span style="font-size: 18px;">

                    {{ existencia }}

                </span>

            </div>

        </div>

        <hr>

        <div class="table-responsive">

            <table class="table table-condensed table-striped">

                <thead>

                    <tr>

                        <th>
                            Fecha
                        </th>

                        <th>
                            Tipo
                        </th>

                        <th class="text-right">
                            Cantidad
                        </th>

                        <th class="text-right">
                            Existencia anterior
                        </th>

                        <th class="text-right">
                            Existencia nueva
                        </th>

                        <th>
                            Motivo
                        </th>

                        <th>
                            Referencia
                        </th>

                        <th>
                            Usuario
                        </th>

                    </tr>

                </thead>

                <tbody>

                {% if movimientos|length == 0 %}

                    <tr>

                        <td colspan="8" class="text-center">

                            No existen movimientos para este producto.

                        </td>

                    </tr>

                {% endif %}

                {% for movimiento in movimientos %}

                    <tr>

                        <td>

                            {{ movimiento.fechaMovimiento|date('d/m/Y H:i') }}

                        </td>

                        <td>

                            {% if movimiento.tipo == 'ENTRADA' %}

                                <span class="label label-success">
                                    ENTRADA
                                </span>

                            {% elseif movimiento.tipo == 'SALIDA' %}

                                <span class="label label-danger">
                                    SALIDA
                                </span>

                            {% elseif movimiento.tipo == 'AJUSTE' %}

                                <span class="label label-warning">
                                    AJUSTE
                                </span>

                            {% else %}

                                <span class="label label-default">
                                    {{ movimiento.tipo }}
                                </span>

                            {% endif %}

                        </td>

                        <td class="text-right">

                           {{ movimiento.cantidad|number_format(2, '.', '') }}

                        </td>

                        <td class="text-right">

                            {{ movimiento.existenciaAnterior|number_format(2, '.', '') }}

                        </td>

                        <td class="text-right">

                            {{ movimiento.existenciaNueva|number_format(2, '.', '') }}

                        </td>

                        <td>

                            {{ movimiento.motivo }}

                        </td>

                        <td>

                            {{ movimiento.referencia }}

                        </td>

                        <td>

                            {% if movimiento.usuario %}

                                {{ movimiento.usuario.username }}

                            {% else %}

                                -

                            {% endif %}

                        </td>

                    </tr>

                {% endfor %}

                </tbody>

            </table>

        </div>

    </div>

    <div class="box-footer">

        <a
            href="{{ path('inventario_index') }}"
            class="btn btn-default"
        >

            <span class="glyphicon glyphicon-arrow-left"></span>

            Volver al inventario

        </a>

    </div>

</div>

</div>

{% endblock %}
