consultar();
//Consultar all
function dataTable(){
    let guia = $("#cod_guia").val(), asignar='';
    if(guia ===''){
        asignar=0;
    }else{
        asignar=guia;
    }
    $.ajax({
        url: 'back-end/guias.php',
        type: 'GET',
        data:{asignar},
        success: function(response){
        let o = JSON.parse(response);;
            $('#guias_pend').dataTable( {
                retrieve: true,
                searchable: true,
                data : o,
                columns: [
                    {"data" : "check"}, 
                    {"data" : "guia"}, 
                    {"data" : "estado"},
                    {"data" : "cliente"},
                    {"data" : "direccion"},
                    {"data" : "fecha"}                              
                ],
                "language": {
                    url: "lib/js/es.json"
                }
            });
        
        }
    })
}
function consultar(){
    $(document).ready(function(){
        if ( $.fn.dataTable.isDataTable( '#guias_pend' ) ) {
            table = $('#guias_pend').DataTable();
            table.destroy();
            dataTable();
        }else{
            dataTable();
        }
    })
    let asignar = 1;
    $.ajax({
        url: 'back-end/usuarios.php',
        type: 'GET',
        data: {asignar},
        success: function(response){  
            $('#cod_conductor').html(response);     
        }
    })
}

function filtro_cross(){
    $("#cod_guia").val(99);
    consultar();
}

function asignar(){
    var guias_sel = new Array();
    $('input[type=checkbox]:checked').each(function() {
        guias_sel.push($(this).val());
    });
    if(guias_sel == ''){
        console.log('Error')
    }else{
        $user = $('#cod_conductor').val();
        $guias = JSON.stringify(guias_sel);

        const postData ={guias: $guias, usuario:$user}
        $.post('back-end/guias.php', postData, function(response){
            consultar();
            $('#resultado').html(response);
            $('#alerta1').delay(3000).fadeOut("slow");
            $('#list_user').modal("hide");
        });
    }
}




