@extends('template.layout')

@section('content')
    <div class="portlet light portlet-fit portlet-datatable bordered">
        <div class="portlet-title">
            <div class="caption">
                <span class="caption-subject font-green sbold uppercase">
                    <a href="{!! URL::previous() !!}" class="icon-action-undo"></a>
                         Lista de alumnos por curso </span>
            </div>
        </div>
        <div class="portlet-body">


            <div class="Forum-ForumTopicList row" style="margin:20px">

                <div style="padding-bottom: 1%; padding-top: 3%;" class="col-lg-5">
                    <div class="row">

                        <div class="col-lg-6">
                            <span class="caption-subject uppercase">Filtro por año: </span>

                            <select class="bs-select form-control" id="selectAnio">
                                <option value="">Todos</option>
                                @foreach($anios as $anio)
                                    <option value="{{$anio->anios}}">{{$anio->anios}}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="col-lg-6">
                            <span class="caption-subject uppercase">Filtro por mes: </span>

                            <select class="bs-select form-control" id="selectMes">
                                <option value="">Todos</option>
                                @foreach($meses as $mes)
                                    <option value="{{$mes->mes}}">{{$mes->mes}}</option>
                                @endforeach
                            </select>
                        </div>


                    </div>
                </div>
                <table class="table table-hover nowrap dataTable dtr-inline collapsed tbAsistencia"
                       id="tbAsistencia"
                       width="100%" role="grid" aria-describedby="tbAsistencia_info">
                    <thead class="thead-default">
                    <tr>
                        <th>N°</th>
                        <th>Codigo</th>
                        <th>Nombre completo</th>
                        <th>Año</th>
                        <th>Mes</th>
                        <th>Día</th>
                        <th>Fecha</th>
                        <th>Estado</th>
                    </tr>
                    </thead>
                    <tbody>
                    @php ($count = 1)
                    @foreach($historialAsistenciaCurso as $item)
                        <tr>
                            <td> {{ $count }} </td>
                            <td> {{ $item->codigo }}</td>
                            <td> {{ $item->apellido_paterno }} {{ $item->apellido_materno }}, {{ $item->nombres }}</td>
                            <td> {{ $item->anio }}</td>
                            <td> {{ $item->mes }} </td>
                            <td>{{ $item->dia }}</td>
                            <td>{{ \Carbon\Carbon::parse( $item->fecha)->format('d-m-Y') }}</td>
                            <td style="text-align: center;">
                                @if($item->estado == "Asistio")
                                    <span class="label label-success">  {{$item->estado}}  </span>
                                @elseif($item->estado == "Tardanza")
                                    <span class="label label-warning">  {{$item->estado}}  </span>

                                @else
                                    <span class="label label-danger">  Falto  </span>
                                @endif
                            </td>
                        </tr>
                        @php ($count++)
                    @endforeach
                    </tbody>
                </table>

            </div>

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


        var tbAsistencia = $('#tbAsistencia').DataTable({
            "pageLength": 31,
            "bLengthChange": false,
            bFilter: true,
            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": false},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": false},
                {"bSearchable": false},
                {"bSearchable": false},
            ],
            "columns": [
                {"orderable": false},
                {"orderable": true},
                {"orderable": true},
                {"orderable": true},
                {"orderable": true},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
                {"orderable": false},
                {"orderable": false},
            ],
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'excel',
                    exportOptions: {
                        columns: [ 0, 1, 2 ,3,4,5,6,7,8]
                    },
                    title: 'Reporte de asistencia alumno por curso'
                },{
                    extend: 'pdf',
                    exportOptions: {
                        columns: [ 0, 1, 2 ,3,4,5,6,7,8]
                    },
                    pageSize: 'LEGAL',
                    customize: function(doc) {
                        //pageMargins [left, top, right, bottom]
                        doc.pageMargins = [ 120, 20, 20, 20 ];
                    },
                    title: 'Reporte de asistencia alumno por curso'
                }

            ]
        });


        $("#selectAnio").change(function () {
            tbAsistencia.column(3)
                .search($("#selectAnio").val() ? '^' + $("#selectAnio").val() + '$' : '', true, false)
                .draw();
        });

        $("#selectMes").change(function () {
            tbAsistencia.column(4)
                .search($("#selectMes").val() ? '^' + $("#selectMes").val() + '$' : '', true, false)
                .draw();
        });

    </script>
@endsection
