@extends('template.layout')

@section('content')
    @include('sweet::alert')

    <div class="portlet light portlet-fit portlet-datatable bordered">
        <div class="portlet-title">
            <div class="caption">
                <span class="caption-subject font-green sbold uppercase"> Notas por alumno </span>
            </div>
        </div>

        <div class="portlet-body">

            <div style="padding-top: 2%;padding-bottom: 2%">
                <div class="row">
                    <div class="col-lg-12">
                        <div>
                            <h1>Generar consolidado de notas</h1>
                        </div>

                        <div class="col-lg-3">
                            <span class="caption-subject uppercase">Grupo: </span>
                            <select class="bs-select form-control" id="selectGrupo">
                                @foreach($grupo as $group)
                                    <option value="{{$group->id}}">{{$group->nombre}}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="col-lg-3">
                            <span class="caption-subject uppercase">Carrera: </span>
                            <select class="bs-select form-control" id="selectCarreras">
                                @foreach($especialidades as $esp)
                                    <option value="{{$esp->id}}">{{$esp->nombre}}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="col-lg-3">
                            <span class="caption-subject uppercase">Semestre: </span>
                            <select class="bs-select form-control" id="selectPeriodo">
                                @foreach($periodo as $per)
                                    <option value="{{$per->id}}">{{$per->nombre}}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="col-lg-3">
                            <a class="btn btn-primary Crear" style="margin-top: 20px; text-align: center;"
                               onclick="GenerarExcel()">
                                <i class="fa fa-file-excel-o"></i> <span class="hidden-xs"> Generar Consolidado </span>
                            </a>
                        </div>

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

            <div class="Forum-ForumTopicList row" style="margin:20px">
                <div class="col-lg-12" id="divTable">
                    @if(count($alumnos) > 0)

                        <table class="table table-striped table-bordered table-hover table-bg tbAlumnos"
                               id="tbAlumnos"
                               width="100%" role="grid" aria-describedby="tbAlumnos_info">
                            <thead class="thead-default">
                            <tr>
                                <th>Código alumno</th>
                                <th>Nombre</th>
                                <th>Especialidad</th>
                                <th>Opciones</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($alumnos as $item)
                                <tr>
                                    <td> {{ $item->codigo }}</td>
                                    <td> {{ $item->nombre_completo }}</td>
                                    <td> {{ $item->nombre }}</td>
                                    <td>
                                        <a href="{{url('reportesnotas/alumnos/cursos',['id' => $item->userid ])}}"
                                           class="btn btn-outline btn-circle btn-sm blue">
                                            Ver notas
                                        </a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    @else
                        <div class="well" style="text-align: center;"> No se encontraron alumnos registradas</div>
                    @endif
                </div>
            </div>


        </div>

    </div>


@endsection
@section('scripts')
    <script>

        function GenerarExcel() {
            var carreraID = $("#selectCarreras").val();
            var periodoID = $("#selectPeriodo").val();
            var grupoID = $("#selectGrupo").val();

            window.location.href = "{{url('acta')}}" + "/" + carreraID + "/" + periodoID+ "/" + grupoID;

        }

        var tbAlumnos = $('#tbAlumnos').DataTable({
            "lengthMenu": [[25, 20, 50, -1], [25, 20, 50, "Todas"]],
            bFilter: true,
            "bLengthChange": false,
            bInfo: true,
            responsive: true,
            "autoWidth": true,
            "language": {
                "lengthMenu": "Mostrar _MENU_ Entradas",
                "zeroRecords": "No se encontraron registros",
                "info": "Mostrando la página _PAGE_ de _PAGES_",
                "infoEmpty": "No hay registros disponibles",
                "infoFiltered": "(filtrado de _MAX_ registros totales)",
                "search": "Buscar: ",
                "paginate": {
                    "first": "Primero",
                    "last": "Último",
                    "next": "Siguiente",
                    "previous": "Anterior"
                },
            },
            "order": [],
            "aoColumns": [
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": false},
            ],
            "columns": [
                {"orderable": true},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
            ],
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: [0, 1, 2]
                    },
                    title: 'Reporte de alumnos'
                }, {
                    extend: 'pdf',
                    exportOptions: {
                        columns: [0, 1, 2]
                    },
                    pageSize: 'LEGAL',
                    customize: function (doc) {
                        //pageMargins [left, top, right, bottom]
                        doc.pageMargins = [120, 20, 20, 20];
                    },
                    title: 'Reporte de alumnos'
                }

            ]
        });

        $("#selectCarrera").change(function () {
            tbAlumnos.column(2)
                .search($("#selectCarrera").val() ? '^' + $("#selectCarrera").val() + '$' : '', true, false)
                .draw();
        });

    </script>
@endsection
