
{% extends 'base.html.twig' %}

{% block preloader %}{% endblock %}

{% block title %}Ordenes de Compra{% endblock %}

{% block body %}

    <div class="container pb-5">

        <h2 class="my-4 text-primary">
            Ordenes de Compra
        </h2>

    <div class="row my-4">
        <div class="col-md-12">

            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead class="bg-primary text-white">
                        <tr class="text-center">
                            <th scope="col">Nro</th>
                            <th scope="col">Servicio</th>
                            <th scope="col">Duracion</th>
                            <th scope="col">Costo</th>
                            <th scope="col">Estatus</th>
                            <th scope="col">Opciones</th>
                        </tr>
                    </thead>

                    <tbody>

                        {% if ordenes %}
                            {% for orden in ordenes %}
                                <tr>
                                    {% set ordenH = orden.ordenHosting|first %}
                                    {% set ordenD = orden.ordenDominio|first %}

                                    <th class="text-center">{{ orden.correlativo }}</th>
                                    <td>
                                        <div>
                                            {% if ordenH.planDestino is defined %}
                                                Hosting: <strong>{{ ordenH.planDestino.nombre }}</strong>
                                            {% endif %}
                                        </div>
                                        <div>
                                            {% if ordenD.nombre is defined %}
                                                Dominio: <strong>{{ ordenD.nombre }}.{{ ordenD.extension.nombre }}</strong>
                                            {% endif %}
                                        </div>
                                    </td>
                                    <td class="text-center">
                                        <div>
                                            {% if ordenH.planDestino is defined %}
                                                {{ ordenH.duracion }} Año(s)
                                            {% endif %}
                                        </div>
                                        <div>
                                            {% if ordenD.duracion is defined %}
                                                {{ ordenD.duracion }} Año(s)
                                            {% endif %}
                                        </div>
                                    </td>
                                    <td class="text-center">
                                        <div>
                                            {% if ordenH.planDestino is defined %}
                                                <span class="text-primary">${{ ordenH.costo|number_format }}<span>
                                            {% endif %}
                                        </div>
                                        <div>
                                            {% if ordenD.costo is defined %}
                                                <span class="text-primary">${{ ordenD.costo|number_format }}<span>
                                            {% endif %}
                                        </div>
                                    </td>

    <td class="text-center align-middle estatus-orden-{{ orden.id }}">
        {% include 'all/orden/_estatus.html.twig' with {'estatus':orden.estatus} %}
    </td>

    <td class="text-center align-middle">
        {% if orden.estatus == constant('ESTATUS_PENDIENTE', orden) %}
            <a
            id="link-anular-{{ orden.id }}"
            data-id="{{ orden.id }}"
            data-correlativo="{{ orden.correlativo }}"
            data-url="{{ path('orden_anular', {'id': orden.id}) }}"
            data-target="#modal-anular-orden"
            data-toggle="modal"
            title="Anular"
            class="not-decoration text-dark">
                <i class="fas fa-ban fa-lg link-anular-orden"></i>
            </a>
            <a class="not-decoration text-dark" href="{{ path('orden_pagar', {'id': orden.id}) }}" title="Pagar">
                <i class="fas fa-cash-register fa-lg"></i>
            </a>
        {% endif %}
        <a class="not-decoration text-dark" href="{{ path('orden_ver', {'id': orden.id}) }}">
            <i class="fas fa-eye fa-lg" data-toggle="tooltip" title="Ver"></i>
        </a>
    </td>


                                </tr>
                            {% endfor %}
                        {% else %}
                            <tr>
                                <th colspan="6" class="text-center">No tiene ordenes de Compras</th>
                            </tr>
                        {% endif %}

                    </tbody>
                </table>
            </div>

        </div>
    </div>
 </div>

    <div class="modal fade" id="modal-anular-orden" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
            <div class="modal-header bg-warning">
                <h5 class="modal-title text-dark">¿Esta seguro?</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <span>Si anula la Orden de compra <strong>#<span id="orden-nro-eliminar"></span></strong> no podra activarla nuevamente. Debera crear una Orden nueva.</span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
                <button id="btn-anular-orden" data-id="" data-url="" type="button" class="btn btn-primary">Anular</button>
            </div>
            </div>
        </div>
    </div>

{% endblock %}


    {% block javascripts %}
        <script src={{ asset('build/js/orden-usuario.js') }}></script>
    {% endblock %}
