$(function () {
    
    $('.btn_anular').on('click', function() {

        var id = $(this).data("id");
    
        $('#delete_modal').modal({
            closable: false,
            onApprove : function() {
                sendDelete(id);
            }
        }).modal('show');  
    });       

    function sendDelete(id) {

        var data = {id_guia_remision : id};

        $.requestApi('/guia/anular', data, 'POST', function (resolve) {
            if (resolve) {
                $.showMessages(resolve, true, APP_URL+'/guia/listar');
            }
        }); 
        
        return false;
    };

    $('.btn_imprimir').on('click', function() {
        var id = $(this).data("id");
        window.open(APP_URL+'/../pdf/imprimeGuia.php?id_guia='+id, '_blank');
    }); 

    //Para ENVIO REST 2.0
    $('.btn_reenviar').on('click', function() {
        var id = $(this).data("id"); 
        $.requestApi('/xml/reenviarGuia2', {"id" : id}, 'GET', function (resolve) {
            if (resolve) {
                $.showMessages(resolve, true, APP_URL+'/guia/detalles_electronico/'+id );
            }
        });
        return false;
    });
    
    $('.btn_cdr').on('click', function() {
        var id = $(this).data("id"); 
        $.requestApi('/xml/consultaCdrGuia', {"id" : id}, 'GET', function (resolve) {
            if (resolve) {
                $.showMessages(resolve, true, APP_URL+'/guia/detalles_electronico/'+id );
            }
        });
        return false;
    });


  	

});



