225 lines
8.5 KiB
JavaScript
225 lines
8.5 KiB
JavaScript
|
|
//REDIRECCION A LA PAGINA PRINCIPAL DE FACTURA
|
|
document.getElementById('verFacturas').addEventListener('click', function () {
|
|
var animacion = document.getElementsByClassName('xyz-in');
|
|
|
|
var ani = document.querySelectorAll('.xyz-in');
|
|
|
|
ani.forEach(function(animado, arrayIndex) {
|
|
animado.classList.remove('xyz-in');
|
|
animado.classList.add('xyz-out');
|
|
});
|
|
|
|
setTimeout(function(){
|
|
window.location.href = 'portal.php';
|
|
},800);
|
|
});
|
|
|
|
|
|
//INICIALIZACIÓN DE TABLA CON JQUERY PARA DATATABLES CON SUS ARGUMENTOS PARA DARLE CARACTERISTICAS
|
|
$(document).ready(function () {
|
|
var table = $('#facturasTable').DataTable({
|
|
lengthMenu: [10, 25, 50, 100],
|
|
pageLength: 10,
|
|
searching: true,
|
|
paging: true,
|
|
ordering: true,
|
|
info: true,
|
|
responsive: true,
|
|
dom: 'Blfrtip',
|
|
buttons: [
|
|
{
|
|
extend: 'excel',
|
|
text: 'Exportar a Excel',
|
|
filename: 'Solicitudes_de_cancelación',
|
|
},
|
|
{
|
|
extend: 'pdf',
|
|
className: 'btn btn-danger',
|
|
text: 'Exportar a PDF',
|
|
filename: 'Solicitudes_de_cancelación',
|
|
}],
|
|
autoWidth: false,
|
|
columnDefs: [
|
|
{ width: "5%", "targets": [0] },
|
|
{ width: "5%", "targets": [1] },
|
|
{ width: "10%", "targets": [2] },
|
|
{ width: "25%", "targets": [3] },
|
|
{ width: "10%", "targets": [4] },
|
|
{ width: "5%", "targets": [5] },
|
|
{ width: "5%", "targets": [6] },
|
|
],
|
|
columns: [
|
|
{"className": "xyz-in"},
|
|
{"className": "xyz-in"},
|
|
{"className": "xyz-in"},
|
|
{"className": "xyz-in"},
|
|
{"className": "xyz-in"},
|
|
{"className": "xyz-in"},
|
|
{"className": "xyz-in"},
|
|
],
|
|
});
|
|
|
|
//CUANDO EL DOCUMENTO ESTE LISTO, SE EJECUTA ESTE CODIGO MANDANDO A LLAMAR UNA API PARA CONSULTAS DE SOLICITUDES CON EL STATUS 4
|
|
$(document).ready(function(){
|
|
|
|
//SE ALMACENAN VARIABLES DEL ID DEL USUARIO Y EL CODIGO DE NEGOCIO
|
|
var status = 4;
|
|
var id_usuario_autoriza = document.getElementById("id_usuario").value;
|
|
var nombre_negocio = document.getElementById("nombre_negocio").value;
|
|
var api = document.getElementById("api").value;
|
|
var boton = "";
|
|
|
|
$.ajax({
|
|
data: {status:status, id_usuario_autoriza:id_usuario_autoriza, nombre_negocio:nombre_negocio}, //datos que se envian a traves de ajax
|
|
url: api+'/api/consultaSolicitudesCan', //archivo que recibe la peticion
|
|
type: 'post', //método de envio
|
|
dataType: 'json',
|
|
beforeSend: function () {
|
|
//SE MUESTRA UN MENSAJE DE CARGANDO MIENTRAS SE ESPERA UNA RESPUESTA
|
|
$("#datos_soli").html('<tr class="text-center"><td colspan="8"><div class="spinner-border" role="status"><span class="sr-only"></span></td></tr></div>');
|
|
},
|
|
success: function(response) {
|
|
//CONDICIONAL PARA CORROBORAR QUE EXISTAN DATOS EN LA BD Y PINTARLOS EN LA TABLA
|
|
if(response == "sin_datos"){
|
|
$("#datos_soli").html('<tr class="text-center"><td colspan="8">Sin datos</td></tr></div>');
|
|
|
|
}else{
|
|
setTimeout(function(){
|
|
//SE ITERA EL RESPONSE DE LA SOLICITUD CON TODOS LOS DATOS QUE MANDAMOS A TRAER DE LA API
|
|
response.forEach(function(factura, arrayIndex) {
|
|
|
|
//CREAMOS UNA FILA POR CADA MÓDULO DE DATOS
|
|
//factura - VARIABLE DONDE SE ENCUENTRA GUARDADA LA INFORMACIÓN DE LOS DATOS
|
|
//arrayIndex - VARIABLE DONDE SE ENCUENTRA GUARDADA LA POSICIÓN DE LA FILA EN LA TABLA
|
|
var fecha = factura.Fecha_solicitud;
|
|
var fecha_format = fecha.slice(0, -9);
|
|
table.row.add([
|
|
fecha_format,
|
|
factura.Nombre_solicitante,
|
|
factura.Centro,
|
|
factura.UUID,
|
|
factura.motivo,
|
|
factura.motivoSAT,
|
|
factura.denegar
|
|
]).draw(false);
|
|
})
|
|
},2000);
|
|
}
|
|
|
|
},
|
|
}).fail(function(response){ //EN CASO DE FALLO, SE PINTA UN ERROR EN CONSOLA
|
|
console.log("FAIL", response);
|
|
})
|
|
|
|
});
|
|
|
|
|
|
//SE LE DA ATRIBUTO A LA TABLA PARA DARLE ESTILO
|
|
|
|
table.buttons().container().appendTo('#facturasTable_wrapper .col-md-6:eq(0)');
|
|
|
|
var responsesArray = [];
|
|
var currentPage = 1;
|
|
|
|
//FUNCION QUE PERMITE PAGINAR LA TABLA Y NO MOSTRAR TODOS LOS DATOS A LA VEZ
|
|
$('#facturasTable').off('page.dt').on('page.dt', function () {
|
|
|
|
currentPage = table.page.info().page + 1;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//FUNCION PARA CERRAR LA SESIÓN DEL USUARIO
|
|
function logout() {
|
|
|
|
document.getElementById('logoutForm').action = 'logout.php';
|
|
|
|
document.getElementById('logoutForm').submit();
|
|
|
|
}
|
|
|
|
|
|
//FUNCION QUE SE ENCARGA DE EJECUTAR LA API DE AUTORIZACION DE CANCELACION
|
|
function rechazarCancelacion(idFactura, id_usuario_autoriza, status, id_usuario_solicitante, uuid, nombre_negocio, url, motivo, portal){
|
|
|
|
var opcion = "denegada";
|
|
//SE EJECUTA AJAX PARA EL ENVIO DE DATOS A LA API DE AUTORIZACION
|
|
alertify.confirm('Denegar solicitud',"¿Estas seguro que deseas denegar la solicitud de cancelación? No se podrán modificar los cambios posteriormente.",
|
|
function(){
|
|
$.ajax({
|
|
data: { idFactura:idFactura, id_usuario_autoriza:id_usuario_autoriza, status:status, id_usuario_solicitante:id_usuario_solicitante, uuid:uuid, nombre_negocio:nombre_negocio, url:url, opcion:opcion, motivo:motivo, portal:portal}, //datos que se envian a traves de ajax
|
|
url: 'php/autorizacionCancelacion.php', //API QUE RECIBE LA PETICION
|
|
type: 'post', //METODO DE ENVIO
|
|
beforeSend: function () {
|
|
console.log("enviando...");
|
|
},
|
|
success: function (response) { //UNA VEZ QUE EL ARCHIVO RECIBE LA PETICION LO PROCESA Y DEVUELVE UN HTML
|
|
if(response == "OK"){
|
|
alertify.success('Se ha dengeado la cancelación del folio '+ uuid + ' correctamente');
|
|
console.log(response);
|
|
setTimeout(function(){
|
|
location.reload(true);
|
|
}, 3000);
|
|
}else{
|
|
alertify.error('La solicitud no se ha completado correctamente, por favor vuelva a intentarlo.');
|
|
console.log(response);
|
|
}
|
|
|
|
|
|
},
|
|
|
|
}).fail(function(error){
|
|
alertify.error('Ha ocurrido un error' + error);
|
|
})
|
|
},
|
|
function(){
|
|
alertify.error('Se ha cancelado la solicitud');
|
|
console.log("cancel");
|
|
});
|
|
|
|
}
|
|
|
|
function aceptarCancelacion(idFactura, id_usuario_autoriza, status, id_usuario_solicitante, uuid, nombre_negocio, url, motivo, portal, motivoSAT, uuid_relacionado){
|
|
|
|
var opcion = "aceptada";
|
|
|
|
alertify.confirm('Autorizar solicitud',"¿Estas seguro que deseas autorizar la solicitud de cancelación? No se podrán modificar los cambios posteriormente.",
|
|
function(){
|
|
//SE EJECUTA AJAX PARA EL ENVIO DE DATOS A LA API DE AUTORIZACION
|
|
$.ajax({
|
|
data: { idFactura:idFactura, id_usuario_autoriza:id_usuario_autoriza, status:status, id_usuario_solicitante:id_usuario_solicitante, uuid:uuid, nombre_negocio:nombre_negocio, url:url, opcion:opcion, motivo:motivo, portal:portal, motivoSAT:motivoSAT, uuid_relacionado:uuid_relacionado}, //datos que se envian a traves de ajax
|
|
url: 'php/autorizacionCancelacion.php', //API QUE RECIBE PETICION
|
|
type: 'post', //METODO DE ENVIO
|
|
beforeSend: function () {
|
|
console.log("enviando...");
|
|
},
|
|
success: function (response) { //UNA VEZ QUE EL ARCHIVO RECIBE LA PETICION LO PROCESA Y DEVUELVE UN HTML
|
|
if(response == "OK"){
|
|
console.log(response);
|
|
alertify.success('Se ha autorizado la cancelación del folio '+ uuid + ' correctamente');
|
|
setTimeout(function(){
|
|
location.reload(true);
|
|
}, 3000);
|
|
}else{
|
|
console.log(response);
|
|
alertify.error('La solicitud no se ha completado correctamente,'+response);
|
|
|
|
}
|
|
},
|
|
|
|
}).fail(function(error){
|
|
alertify.error('Ha ocurrido un error' + error);
|
|
})
|
|
},
|
|
function(){
|
|
alertify.error('Proceso de autorización cancelado');
|
|
})
|
|
|
|
|
|
|
|
}
|