$(function () {

	$('.btn_anular').on('click', function() {
		$('#update_modal').modal({
			closable: false,
	    	onApprove : function() {
	    		sendForm();
		    }
  		}).modal('show');
  	});
  	
	function sendForm() {

	    var id_compra = $('#id_compra').val();
	    var id_local = $('#id_local').val();

        $.requestApi('/compra/anular', {'id_compra' : id_compra, 'id_local': id_local}, 'POST', function (resolve) {
	        if (resolve) {
	            $.showMessages(resolve, true, APP_URL+'/compra/listar');
	        }
	    });
        
        return false;
	};

	/******************************************************************************/
	/* ANULAR DEUDA
	/******************************************************************************/

	$('.btn_anular_deuda').on('click', function() {
		$('#update_modal').modal({
			closable: false,
	    	onApprove : function() {
	    		sendForm2();
		    }
  		}).modal('show');
  	});
  	
	function sendForm2() {

	    var id_compra = $('#id_compra').val();

        $.requestApi('/compra/anular_deuda', {'id_compra' : id_compra}, 'POST', function (resolve) {
	        if (resolve) {
	            $.showMessages(resolve, true, APP_URL+'/compra/listar_deuda');
	        }
	    });
        
        return false;
	};


	

});
