<?php $__env->startSection('title', 'Vencimientos'); ?>
<?php $__env->startSection('style'); ?>
<style type="text/css" media="screen">
    .chosen-container{
        width: 100% !important;
        font-size: 10px !important;

    }

    .chosen-container-single .chosen-search input[type="text"]{
        width: 80%;
        font-size: 10px !important;
    }

    .chosen-search-input{
        font-size: 10px !important;
    }

    table .form-control, table .chosen-container, table .select{
        font-size: 10px !important;
        line-height: 1.25 !important;
    }

    .chosen-container-single .chosen-single div:after{
        left: -0.1rem !important;
        height: 1.5rem !important;
    }
</style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<div class="col-sm-12 col-md-9 col-lg-10 col-xl-10">
    <h3 class="text-center titulo">Vencimientos</h3>
    <table class="table table-striped table-condensed table-bordered" id="table" data-toggle="dataTable" data-form="deleteForm">
        <thead>
            <tr>
                <th>Año</th>
                <th>Mes</th>
                <th>Fecha</th>
                <th>Tipo</th>
                <th width="7%"></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <form id="form-table" method="post" accept-charset="utf-8" action="<?php echo e(route('GuardarVencimiento')); ?>" novalidate="">
                    <?php echo e(csrf_field()); ?>

                    <td width="15%">
                        <input type="text" name="txtAnno" id="txtAnno" class="form-control tamaño-letra" required="required" title="Ingrese año" placeholder="Año" style="width: 80%;">
                    </td>
                    <td>
                        <select name="sltMes" id="sltMes" class="form-control select" title="Selecione mes">
                            <option value="">Mes</option>
                            <?php $__currentLoopData = $mes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($row->id_unico); ?>"><?php echo e("$row->numero $row->mes"); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </td>
                    <td>
                        <input type="text" name="txtFecha" id="txtFecha" class="form-control fecha" required="required" title="Ingrese fecha" placeholder="Fecha" style="width: 90%;">
                    </td>
                    <td>
                        <select name="sltTipo" id="sltTipo" class="form-control select" title="Selecione tipo">
                            <option value="">Tipo DI</option>
                            <?php $__currentLoopData = $tipo; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($row->id_unico); ?>"><?php echo e("$row->nombre"); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </td>
                    <td>
                        <button type="submit" id="submit" class="btn-sin icons cursor fa fa-save superior2"></button>
                    </td>
                </form>
            </tr>
            <?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($row->anno); ?></td>
                    <td><?php echo e("$row->numero - $row->mes"); ?></td>
                    <td><?php echo e($row->fecha); ?></td>
                    <td><?php echo e($row->tipo); ?></td>
                    <td>
                        <a href="" class="fa fa-pencil icons" data-toggle="modal" data-target="#modalUpdate" data-ven="<?php echo e($row->id_unico); ?>" data-anno="<?php echo e($row->anno); ?>" data-mes="<?php echo e($row->mesid); ?>" data-date="<?php echo e($row->fecha); ?>" data-tipo="<?php echo e($row->tpoDI); ?>"></a>
                        <?php echo Form::model($data, ['method' => 'post', 'route' => ['EliminarVencimiento', encrypt($row->id_unico)], 'class' => 'form-tabla form-delete']); ?>

                        <?php echo Form::button(trans(''), ['class' => 'fa fa-trash icons btn-sin cursor', 'type' => 'submit']); ?>

                        <?php echo Form::hidden('id_unico', encrypt($row->id_unico)); ?>

                        <?php echo Form::close(); ?>

                    </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
    </table>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('vencimiento.vencimientoUpdate', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php echo $__env->make('modal-confirm', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->startSection('script'); ?>
<script>
    $('table[data-form="deleteForm"]').on('click', '.form-delete', function(e){
        e.preventDefault();
        var $form=$(this);
        $('#confirm').modal({ backdrop: 'static', keyboard: false })
            .on('click', '#delete-btn', function(){
                $form.submit();
            });
    });

    $("#form-table").submit(function(e){
        var anno  = $("#txtAnno").val();
        var mes   = $("#sltMes").val();
        var fecha = $("#txtFecha").val();
        var tipo  = $("#sltTipo").val();

        if(anno.length > 0){
            $("#txtAnno").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtAnno").addClass('is-invalid').removeClass('is-valid');
        }

        if(mes.length > 0){
            $("#sltMes_chosen").removeClass('borde-error');
        }else{
            e.preventDefault();
            $("#sltMes_chosen").addClass('borde-error');
        }

        if(fecha.length > 0){
            $("#txtFecha").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtFecha").addClass('is-invalid').removeClass('is-valid');
        }

        if(tipo.length > 0){
            $("#sltTipo_chosen").removeClass('borde-error');
        }else{
            e.preventDefault();
            $("#sltTipo_chosen").addClass('borde-error');
        }
    });

    $("#modalUpdate").on('show.bs.modal', function(e){
        var btn   = $(e.relatedTarget);
        var modal = $(this);
        var ven   = btn.data('ven');
        var anno  = btn.data('anno');
        var mes   = btn.data('mes');
        var date  = btn.data('date');
        var tipo  = btn.data('tipo');

        $("#txtId_unico").val(ven);
        modal.find('.modal-body #txtAnio').val(anno);
        modal.find('.modal-body #sltMesM option[value='+mes+']').attr('selected', true);
        modal.find(".modal-body #sltMesM").trigger("chosen:updated");
        modal.find('.modal-body #txtDate').val(date);
        modal.find('.modal-body #sltTipoD option[value='+tipo+']').attr('selected', true);
        modal.find(".modal-body #sltTipoD").trigger("chosen:updated");
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>