{% extends 'base.html.twig' %}

{% block searchform_container %}{% endblock %}

{% block title %}
    Gastos
{% endblock %}

{% block body %}

<div class="box box-primary">

    <div class="box-header with-border">

        <h3 class="box-title">
            <i class="fa fa-money"></i>
            Gastos
        </h3>

        <div class="box-tools pull-right">

           <a href="{{ path('gastos_categorias') }}" class="btn btn-default btn-sm">
    <i class="fa fa-folder"></i>
    Admin categorias
</a>

            

    <a href="{{ path('gastos_nuevo') }}" class="btn btn-primary btn-sm">
        <i class="fa fa-plus"></i>
        Nuevo gasto
    </a>



        </div>

    </div>


    {# ============================================================
       FILTRO POR FECHAS
       ============================================================ #}

    <div class="box-body" style="padding-bottom: 0;">

        <form method="get" action="{{ path('gastos_index') }}" class="form-inline">

            <div class="form-group">
                <label for="desde">Desde:</label>

                <input
                    type="date"
                    id="desde"
                    name="desde"
                    class="form-control"
                    value="{{ desde|default('') }}"
                >
            </div>

            <div class="form-group" style="margin-left: 10px;">

                <label for="hasta">Hasta:</label>

                <input
                    type="date"
                    id="hasta"
                    name="hasta"
                    class="form-control"
                    value="{{ hasta|default('') }}"
                >

            </div>

            <button
                type="submit"
                class="btn btn-primary"
                style="margin-left: 10px;"
            >
                <i class="fa fa-search"></i>
                Buscar
            </button>
            
            <a
    href="{{ path('gastos_exportar_excel', {
        desde: desde|default(''),
        hasta: hasta|default('')
    }) }}"
    class="btn btn-success"
    style="margin-left: 5px;"
>
    <i class="fa fa-file-excel-o"></i>
    Exportar Excel
</a>

            {% if desde or hasta %}

                <a
                    href="{{ path('gastos_index') }}"
                    class="btn btn-default"
                    style="margin-left: 5px;"
                >
                    <i class="fa fa-refresh"></i>
                    Limpiar
                </a>

            {% endif %}

        </form>

    </div>


    {# ============================================================
       LISTADO DE GASTOS
       ============================================================ #}

    <div class="box-body">

        {% if gastos|length > 0 %}

            <div class="table-responsive">

                <table class="table table-bordered table-striped">

                    <thead>

                        <tr>

                            <th style="width: 100px;">
                                Fecha
                            </th>

                            <th style="width: 180px;">
                                Categoria
                            </th>

                            <th>
                                Descripcion
                            </th>

                            <th style="width: 120px;" class="text-right">
                                Valor
                            </th>

                            <th>
                                Observacion
                            </th>

                            <th style="width: 100px;">
                                Acciones
                            </th>

                        </tr>

                    </thead>

                    <tbody>

                        {% for gasto in gastos %}

                            <tr>

                                <td>
                                    {{ gasto.fecha|date('d/m/Y') }}
                                </td>

                                <td>

                                    {% if gasto.categoria %}

                                        {{ gasto.categoria.nombre }}

                                    {% else %}

                                        -

                                    {% endif %}

                                </td>

                                <td>
                                    {{ gasto.descripcion }}
                                </td>

                                <td class="text-right">
                                    ${{ gasto.valor|number_format(2, '.', ',') }}
                                </td>

                                <td>

                                    {% if gasto.observacion %}

                                        {{ gasto.observacion }}

                                    {% else %}

                                        -

                                    {% endif %}

                                </td>

                                <td>

                                    <a
                                        href="{{ path('gastos_editar', {'id': gasto.id}) }}"
                                        class="btn btn-primary btn-xs"
                                        title="Editar"
                                    >
                                        <i class="fa fa-edit"></i>
                                    </a>

                                    <form
                                        method="post"
                                        action="{{ path('gastos_eliminar', {'id': gasto.id}) }}"
                                        style="display:inline;"
                                        onsubmit="return confirm('¿Está seguro de eliminar este gasto?');"
                                    >

                                        <button
                                            type="submit"
                                            class="btn btn-danger btn-xs"
                                            title="Eliminar"
                                        >
                                            <i class="fa fa-trash"></i>
                                        </button>

                                    </form>

                                </td>

                            </tr>

                        {% endfor %}

                    </tbody>

                </table>

            </div>

        {% else %}

            <div class="alert alert-info">

                <i class="fa fa-info-circle"></i>

                No existen gastos registrados para esta empresa.

            </div>

        {% endif %}

    </div>

</div>

{% endblock %}