Primer Commit
This commit is contained in:
499
js/pagos/dist/dt.dev.js
vendored
Normal file
499
js/pagos/dist/dt.dev.js
vendored
Normal file
@@ -0,0 +1,499 @@
|
||||
"use strict";
|
||||
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
var p = document.getElementById("p_errores");
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.getElementById('fileInput').addEventListener('change', function () {
|
||||
cadenaB64 = '';
|
||||
fileInput = this;
|
||||
file = fileInput.files[0]; // Obtener el primer archivo seleccionado
|
||||
|
||||
if (file) {
|
||||
if (file.type !== 'application/pdf') {
|
||||
alertify.error('Solo se admiten archivos PDF');
|
||||
fileInput.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
reader.onload = function () {
|
||||
cadenaB64 = reader.result.split(',')[1]; // Obtener la parte Base64
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).ready(function () {
|
||||
document.getElementById('searchInput').addEventListener('input', function (event) {
|
||||
showResults(event.target.value);
|
||||
});
|
||||
construyeDT();
|
||||
obtenerViaPago();
|
||||
$('#buttons-container').on('click', '#getSelectedRows', function () {
|
||||
var dataTable = $('#pagosDT').DataTable(); // Asegúrate de obtener la instancia de DataTable por su ID
|
||||
|
||||
var filas = [];
|
||||
dataTable.rows().every(function () {
|
||||
var data = this.data();
|
||||
var rowNode = this.node();
|
||||
var isChecked = $(rowNode).find('.row-check').is(':checked');
|
||||
|
||||
if (isChecked) {
|
||||
filas.push(data);
|
||||
}
|
||||
}); // Muestra el modal y pasa los datos seleccionados a la función facturasPagar
|
||||
|
||||
$('#modalPagar').modal('show');
|
||||
facturasPagar(filas); // console.log(filas); // Aquí puedes manejar los datos seleccionados como necesites
|
||||
});
|
||||
|
||||
function construyeDT() {
|
||||
var columns = [{
|
||||
data: null,
|
||||
defaultContent: '<input type="checkbox" class="row-check">',
|
||||
orderable: false,
|
||||
title: '--'
|
||||
}, {
|
||||
data: 'factura_id',
|
||||
visible: false
|
||||
}, {
|
||||
data: 'UUID',
|
||||
title: 'UUID'
|
||||
}, {
|
||||
data: 'TOTAL',
|
||||
title: 'Total Factura'
|
||||
}, {
|
||||
data: 'parcialidad',
|
||||
title: 'Parcialidad',
|
||||
render: function render(data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
data: 'saldo_insoluto',
|
||||
title: 'Saldo insoluto'
|
||||
}, {
|
||||
data: 'fecha_venta',
|
||||
title: 'Fecha'
|
||||
}]; // Destruye la DataTable si ya existe
|
||||
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
} // Construye la DataTable
|
||||
|
||||
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-success'
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
}); // Agrega un mensaje si no hay datos en la DataTable
|
||||
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>'); // Agrega el botón #getSelectedRows al contenedor de botones
|
||||
|
||||
$('#buttons-container').append('<button id="getSelectedRows" style="width: -webkit-fill-available;" class="btn btn-info">Agregar filas</button>');
|
||||
}
|
||||
|
||||
dataTable.on('draw.dt', function () {
|
||||
$('#pagosDT tbody tr').each(function () {
|
||||
var estatus = $(this).find('td:eq(4)').text(); // Ajusta el índice según la posición de 'estatus'
|
||||
// console.log('estatus', estatus)
|
||||
|
||||
if (estatus === '0') {
|
||||
$(this).find('td:eq(0)').html('<span class="badge badge-success">Pagada</span>'); // Cambia el contenido de la celda
|
||||
} else {
|
||||
$(this).find('td:eq(36)').html('<span class="badge badge-warning">Bloqueado</span>'); // Cambia el contenido de la celda
|
||||
}
|
||||
});
|
||||
});
|
||||
dtTemp = dataTable;
|
||||
traerDeudores(dataTable);
|
||||
}); // Función para construir la DataTable
|
||||
|
||||
function inicializarDataTable(cliente, dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
opcion: '7',
|
||||
cliente: cliente
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function success(data) {
|
||||
if (data.length > 0) {
|
||||
// console.log('Agregar filas')
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
},
|
||||
error: function error(_error) {
|
||||
console.error('Error en la llamada AJAX', _error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function facturasPagar(data) {
|
||||
var columns = [{
|
||||
data: 'factura_id',
|
||||
visible: false
|
||||
}, {
|
||||
data: 'UUID',
|
||||
title: 'UUID',
|
||||
width: '20%'
|
||||
}, // Ejemplo de ancho específico
|
||||
{
|
||||
data: 'parcialidad',
|
||||
title: 'Parcialidad',
|
||||
render: function render(data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
data: 'saldo_insoluto',
|
||||
title: 'Saldo insoluto',
|
||||
width: '20%'
|
||||
}, // Ejemplo de ancho del 20%
|
||||
{
|
||||
data: null,
|
||||
render: function render(data, type, row) {
|
||||
return "<input type=\"number\" class=\"form-control custom-input\" oninput=\"calcular('".concat(row.saldo_insoluto, "',this);\" value=\"").concat(row.saldo_insoluto, "\" >");
|
||||
}
|
||||
}];
|
||||
dataTable = $('#facturasPagar').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-danger' // Agregar la clase btn-danger al botón
|
||||
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-success' // Agregar la clase btn-danger al botón de Excel
|
||||
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
$('#facturasPagar').css('width', '-webkit-fill-available');
|
||||
recalcularTotales(); // $('#facturasPagar').on('input', '.custom-input', function () {
|
||||
// console.log('Funcion');
|
||||
// var inputValue = parseFloat($(this).val());
|
||||
// var saldo = parseFloat($(this).data('saldo'));
|
||||
// if (inputValue > saldo) {
|
||||
// console.log('MUESTRA SALDO')
|
||||
// mostrarDialogo(this);
|
||||
// } else {
|
||||
// // Ocultar el cuadro de diálogo si ya está visible
|
||||
// $(this).next('.custom-dialog').remove();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
var deudores = [];
|
||||
|
||||
function dialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
var dialogHtml = "\n <div class=\"custom-dialog-excede alert alert-danger\" role=\"alert\">\n Pago excede el saldo insoluto.\n </div>\n ";
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function dialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
var dialogHtml = "\n <div class=\"custom-dialog alert alert-warning\" role=\"alert\">\n Pago no debe ser menor al saldo insoluto.\n </div>\n ";
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function eliminarDialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
}
|
||||
|
||||
function eliminarDialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
}
|
||||
|
||||
function calcular(saldo, input) {
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
var pago = parseFloat(parseFloat(input.value).toFixed(2));
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
var saldo_insoluto = parseFloat(parseFloat(saldo).toFixed(2)); // console.log('Pago', pago)
|
||||
// console.log('saldo', saldo_insoluto)
|
||||
|
||||
if (pago > saldo_insoluto && pago != 'NaN') {
|
||||
dialogoExcede(input);
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (pago == saldo_insoluto || pago < saldo_insoluto || pago == 'NaN') {
|
||||
eliminarDialogoExcede(input);
|
||||
}
|
||||
|
||||
recalcularTotales(input);
|
||||
}
|
||||
|
||||
function recalcularTotales(input) {
|
||||
var deposito = parseFloat(document.getElementById('deposito').value) || 0;
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
var textoError = document.getElementById('p-error');
|
||||
|
||||
if (deposito == '') {
|
||||
textoError.style.display = 'none';
|
||||
}
|
||||
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
var sumaTotal = 0;
|
||||
var insoluto_t = 0;
|
||||
var bandera = 0;
|
||||
$('#facturasPagar tbody tr').each(function () {
|
||||
pagoTemp = $(this).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(this).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto;
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
});
|
||||
document.getElementById('saldo_suma').value = sumaTotal; // console.log('DT', datos)
|
||||
|
||||
if (sumaTotal > deposito || sumaTotal < deposito) {
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (sumaTotal == deposito && bandera == 0) {
|
||||
textoError.style.display = 'none';
|
||||
guardarPagosBtn.removeAttribute('disabled');
|
||||
}
|
||||
|
||||
if (deposito > insoluto_t) {
|
||||
// console.log('Deposito', deposito);
|
||||
// console.log('Excede el limite');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (deposito == '' || deposito == '0' || deposito == '0.00') {
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
|
||||
function generarSolicitud() {
|
||||
var datos = [];
|
||||
var acum = 0;
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
$('#facturasPagar tbody tr').each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});
|
||||
var fechaInput = document.getElementById('fecha');
|
||||
var fechaSeleccionada = fechaInput.value;
|
||||
|
||||
if (fechaSeleccionada == '') {
|
||||
alertify.error('Selecciona una fecha');
|
||||
return;
|
||||
} // if (cadenaB64 == '') {
|
||||
// alertify.error('Selecciona un archivo');
|
||||
// return
|
||||
// }
|
||||
|
||||
|
||||
var email = document.getElementById('email').value.replace(/\s+$/, '');
|
||||
|
||||
if (email == '') {
|
||||
alertify.error('Llene un correo');
|
||||
return;
|
||||
}
|
||||
|
||||
var folio = document.getElementById('folioP').value;
|
||||
var email = document.getElementById('email').value;
|
||||
var deposito = document.getElementById('deposito').value;
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
|
||||
if (formaPago == '' || formaPago == 'Forma de pago') {
|
||||
alertify.error('Seleccione una forma de pago');
|
||||
return;
|
||||
}
|
||||
|
||||
if (deposito === '' || deposito === '0') {
|
||||
alertify.error('Monto no debe ir vacio');
|
||||
return;
|
||||
}
|
||||
|
||||
var pagos = {
|
||||
folio: folio,
|
||||
archivo: cadenaB64,
|
||||
fecha_ppd: fechaSeleccionada,
|
||||
cliente: clienteTemp,
|
||||
email: email,
|
||||
monto: deposito,
|
||||
filas: datos,
|
||||
forma_pago: formaPago
|
||||
}; // console.log(pagos);
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/inserta_solicitud.php',
|
||||
data: pagos,
|
||||
dataType: 'json',
|
||||
success: function success(data) {
|
||||
// console.log(data)
|
||||
if (data.code == '201') {
|
||||
alertify.success('Registrado con exito!');
|
||||
dataTable = dtTemp;
|
||||
inicializarDataTable(clienteTemp, dtTemp);
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
document.getElementById('deposito').value = '';
|
||||
$('#modalPagar').modal('hide');
|
||||
document.getElementById('saldo_suma').value = '';
|
||||
} else {
|
||||
p.innerText = data.messsage;
|
||||
$('#errores').modal('show');
|
||||
}
|
||||
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
obtenerFolio();
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
table.clear().draw();
|
||||
},
|
||||
error: function error(_error2) {
|
||||
console.log('Error', _error2);
|
||||
p.innerText = 'Error al cargar los datos, consulte a soporte';
|
||||
$('#errores').modal('show');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apagaBoton() {
|
||||
// console.log('Btn')
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
function traerDeudores(dataTable) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
data: {
|
||||
opcion: '6'
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function success(data) {
|
||||
lista_clientes = data;
|
||||
showResults('');
|
||||
},
|
||||
error: function error(_error3) {
|
||||
console.log('Error ajax', _error3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showResults(searchText) {
|
||||
var searchResults = document.getElementById('searchResults');
|
||||
searchResults.innerHTML = '';
|
||||
lista_clientes.forEach(function (option) {
|
||||
if (option.CLIENTE.toLowerCase().includes(searchText.toLowerCase())) {
|
||||
var li = document.createElement('li');
|
||||
li.textContent = option.CLIENTE;
|
||||
li.className = 'list-group-item';
|
||||
li.setAttribute('onclick', 'seleccionado(' + JSON.stringify(option) + ')');
|
||||
searchResults.appendChild(li);
|
||||
}
|
||||
});
|
||||
|
||||
if (searchText === '' || searchResults.children.length === 0) {
|
||||
searchResults.style.display = 'none';
|
||||
} else {
|
||||
searchResults.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function seleccionado(cliente) {
|
||||
var clienteInput = $("#searchInput");
|
||||
clienteInput.val(cliente.CLIENTE).attr('data-custom-value', cliente.ID_CLIENTE);
|
||||
textoCliente = cliente.CLIENTE;
|
||||
clienteTemp = cliente.ID_CLIENTE;
|
||||
searchResults.style.display = 'none';
|
||||
inicializarDataTable(cliente.ID_CLIENTE, dtTemp);
|
||||
}
|
||||
197
js/pagos/dist/timbrar.dev.js
vendored
Normal file
197
js/pagos/dist/timbrar.dev.js
vendored
Normal file
@@ -0,0 +1,197 @@
|
||||
"use strict";
|
||||
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
$(document).ready(function () {
|
||||
construyeDT();
|
||||
inicializarDataTable(dataTable);
|
||||
});
|
||||
|
||||
function construyeDT() {
|
||||
var columns = [{
|
||||
data: 'folio',
|
||||
title: 'Folio'
|
||||
}, {
|
||||
data: 'fecha_ppd',
|
||||
title: 'Fecha pago'
|
||||
}, {
|
||||
data: 'fecha_creacion',
|
||||
title: 'Fecha solicitud'
|
||||
}, {
|
||||
data: 'unidad',
|
||||
title: 'Unidad Venta'
|
||||
}, {
|
||||
data: 'cliente',
|
||||
title: 'Cliente'
|
||||
}, {
|
||||
data: 'monto',
|
||||
title: 'Monto pagado'
|
||||
}, {
|
||||
data: 'email',
|
||||
title: 'Correo'
|
||||
}, {
|
||||
data: 'forma_pago',
|
||||
visible: false
|
||||
}, {
|
||||
data: 'descripcion_pago',
|
||||
title: 'Forma Pago'
|
||||
}, {
|
||||
data: 'id',
|
||||
title: 'Accion',
|
||||
render: function render(data, type, row) {
|
||||
if (row.estatus == '2') {
|
||||
return '<button class="badge badge-info" onclick=\'timbra(' + JSON.stringify(row) + ')\'>Timbrar</button>';
|
||||
} else if (row.estatus == '4') {
|
||||
return '<span class="badge badge-success">Timbrado</span>';
|
||||
}
|
||||
}
|
||||
}, {
|
||||
data: 'UUID',
|
||||
title: 'UUID'
|
||||
}]; // Destruye la DataTable si ya existe
|
||||
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
} // Construye la DataTable
|
||||
|
||||
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-success'
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
}); // Agrega un mensaje si no hay datos en la DataTable
|
||||
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>'); // Agrega el botón #getSelectedRows al contenedor de botones
|
||||
}
|
||||
|
||||
function timbra(data) {
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
title: 'Mensaje',
|
||||
text: '¿Desea timbrar este pago?',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Aceptar',
|
||||
cancelButtonText: 'Cancelar'
|
||||
}).then(function (result) {
|
||||
if (result.isConfirmed) {
|
||||
toggleLoader4();
|
||||
var centro = data.id_unidad;
|
||||
var fecha_pago = data.fecha_ppd;
|
||||
var monto = data.monto;
|
||||
var email = data.email;
|
||||
var id_solicitud = data.id;
|
||||
var id_cliente = data.id_cliente;
|
||||
var folio = data.folio;
|
||||
var formaPago = data.forma_pago;
|
||||
var solicitud = {
|
||||
unidad_negocio: centro,
|
||||
fecha_pago: fecha_pago,
|
||||
pagado: monto,
|
||||
email: email,
|
||||
solicitud: id_solicitud,
|
||||
folioP: folio,
|
||||
id_cliente: id_cliente,
|
||||
formaPago: formaPago
|
||||
};
|
||||
var titulo = document.getElementById('titulo_modal');
|
||||
var mensaje = document.getElementById('p_errores');
|
||||
$.ajax({
|
||||
url: 'php/Timbrado/pagos_api.php',
|
||||
type: 'POST',
|
||||
data: solicitud,
|
||||
dataType: 'json',
|
||||
success: function success(data) {
|
||||
console.log('Respuesta', data);
|
||||
|
||||
if (data.code == "200") {
|
||||
titulo.innerText = '¡Timbrado!';
|
||||
mensaje.innerHTML = data.message + '<br>UUID: ' + data.uuid;
|
||||
inicializarDataTable(dataTable);
|
||||
} else {
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = data.message;
|
||||
}
|
||||
|
||||
$('#mensajes').modal('show');
|
||||
toggleLoader4();
|
||||
},
|
||||
error: function error(_error) {
|
||||
console.log(_error);
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = 'No es posible realizar timbrado, consulte a soporte';
|
||||
$('#mensajes').modal('show');
|
||||
toggleLoader4();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function inicializarDataTable(dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
opcion: '8'
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function success(data) {
|
||||
// console.log(data)
|
||||
if (data.length > 0) {
|
||||
console.log('Agregar filas');
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
},
|
||||
error: function error(_error2) {
|
||||
console.error('Error en la llamada AJAX', _error2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function toggleLoader4() {
|
||||
console.log('ENTRA');
|
||||
var loaderWrapper = document.getElementById("loaderWrapper4");
|
||||
|
||||
if (loaderWrapper.classList.contains("hidden")) {
|
||||
loaderWrapper.classList.remove("hidden");
|
||||
$('#overlay').removeClass('hidden');
|
||||
} else {
|
||||
loaderWrapper.classList.add("hidden");
|
||||
$('#overlay').addClass('hidden');
|
||||
}
|
||||
}
|
||||
612
js/pagos/dt.js
Normal file
612
js/pagos/dt.js
Normal file
@@ -0,0 +1,612 @@
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
|
||||
|
||||
var verDup=0;
|
||||
|
||||
const p = document.getElementById("p_errores")
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.getElementById('fileInput').addEventListener('change', function () {
|
||||
cadenaB64 = '';
|
||||
fileInput = this;
|
||||
file = fileInput.files[0]; // Obtener el primer archivo seleccionado
|
||||
|
||||
if (file) {
|
||||
if (file.type !== 'application/pdf') {
|
||||
alertify.error('Solo se admiten archivos PDF');
|
||||
fileInput.value = '';
|
||||
return;
|
||||
}
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
cadenaB64 = reader.result.split(',')[1]; // Obtener la parte Base64
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
document.getElementById('searchInput').addEventListener('input', function (event) {
|
||||
showResults(event.target.value);
|
||||
});
|
||||
construyeDT();
|
||||
obtenerViaPago();
|
||||
$('#buttons-container').on('click', '#getSelectedRows', function () {
|
||||
var dataTable = $('#pagosDT').DataTable(); // Asegúrate de obtener la instancia de DataTable por su ID
|
||||
var filas = [];
|
||||
dataTable.rows().every(function () {
|
||||
var data = this.data();
|
||||
var rowNode = this.node();
|
||||
var isChecked = $(rowNode).find('.row-check').is(':checked');
|
||||
if (isChecked) {
|
||||
filas.push(data);
|
||||
//console.log(data);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Muestra el modal y pasa los datos seleccionados a la función facturasPagar
|
||||
$('#modalPagar').modal('show');
|
||||
console.log(filas);
|
||||
facturasPagar(filas);
|
||||
// console.log(filas); // Aquí puedes manejar los datos seleccionados como necesites
|
||||
});
|
||||
|
||||
function construyeDT() {
|
||||
var columns = [
|
||||
{ data: null, defaultContent: '<input type="checkbox" class="row-check">', orderable: false, title: '--' },
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID' },
|
||||
{ data: 'TOTAL', title: 'Total Factura' },
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto' },
|
||||
{ data: 'fecha_venta', title: 'Fecha' },
|
||||
|
||||
];
|
||||
|
||||
// Destruye la DataTable si ya existe
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
}
|
||||
|
||||
// Construye la DataTable
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-success'
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
// Agrega un mensaje si no hay datos en la DataTable
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>');
|
||||
|
||||
// Agrega el botón #getSelectedRows al contenedor de botones
|
||||
$('#buttons-container').append('<button id="getSelectedRows" style="width: -webkit-fill-available;" class="btn btn-info">Agregar facturas</button>');
|
||||
}
|
||||
dataTable.on('draw.dt', function () {
|
||||
$('#pagosDT tbody tr').each(function () {
|
||||
var estatus = $(this).find('td:eq(4)').text(); // Ajusta el índice según la posición de 'estatus'
|
||||
// console.log('estatus', estatus)
|
||||
|
||||
if (estatus === '0') {
|
||||
$(this).find('td:eq(0)').html('<span class="badge badge-success">Pagada</span>'); // Cambia el contenido de la celda
|
||||
} else {
|
||||
$(this).find('td:eq(36)').html('<span class="badge badge-warning">Bloqueado</span>'); // Cambia el contenido de la celda
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
dtTemp = dataTable;
|
||||
traerDeudores(dataTable);
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Función para construir la DataTable
|
||||
|
||||
|
||||
function inicializarDataTable(cliente, dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: { opcion: '7', cliente: cliente },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
if (data.length > 0) {
|
||||
// console.log('Agregar filas')
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.error('Error en la llamada AJAX', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function facturasPagar(data) {
|
||||
$('#formaPago option[value="4"]').hide();//agregar para eliminar el por definir
|
||||
var columns = [
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID', width: '20%' }, // Ejemplo de ancho específico
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto', width: '20%' }, // Ejemplo de ancho del 20%
|
||||
{
|
||||
data: null,
|
||||
render: function (data, type, row) {
|
||||
return `<input type="number" class="form-control custom-input" oninput="calcular('${row.saldo_insoluto}',this);" value="${row.saldo_insoluto}" >`;
|
||||
}
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
dataTable = $('#facturasPagar').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-danger' // Agregar la clase btn-danger al botón
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
},
|
||||
},
|
||||
className: 'btn-success' // Agregar la clase btn-danger al botón de Excel
|
||||
},
|
||||
|
||||
],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
$('#facturasPagar').css('width', '-webkit-fill-available');
|
||||
recalcularTotales();
|
||||
|
||||
// $('#facturasPagar').on('input', '.custom-input', function () {
|
||||
// console.log('Funcion');
|
||||
// var inputValue = parseFloat($(this).val());
|
||||
// var saldo = parseFloat($(this).data('saldo'));
|
||||
// if (inputValue > saldo) {
|
||||
// console.log('MUESTRA SALDO')
|
||||
// mostrarDialogo(this);
|
||||
// } else {
|
||||
// // Ocultar el cuadro de diálogo si ya está visible
|
||||
// $(this).next('.custom-dialog').remove();
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
let deudores = [];
|
||||
|
||||
function dialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog-excede alert alert-danger" role="alert">
|
||||
Pago excede el saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function dialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog alert alert-warning" role="alert">
|
||||
Pago no debe ser menor al saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function eliminarDialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
}
|
||||
|
||||
|
||||
function eliminarDialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
}
|
||||
|
||||
function calcular(saldo, input) {
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var pago = parseFloat(parseFloat(input.value).toFixed(2));
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
var saldo_insoluto = parseFloat(parseFloat(saldo).toFixed(2));
|
||||
|
||||
console.log('Saldo', saldo);
|
||||
// console.log('saldo', saldo_insoluto)
|
||||
if (pago > saldo_insoluto && pago != 'NaN') {
|
||||
dialogoExcede(input);
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (pago == saldo_insoluto || pago < saldo_insoluto || pago == 'NaN') {
|
||||
eliminarDialogoExcede(input);
|
||||
}
|
||||
|
||||
recalcularTotales(input);
|
||||
}
|
||||
|
||||
|
||||
function recalcularTotales(input) {
|
||||
var deposito = parseFloat(document.getElementById('deposito').value) || 0;
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var textoError = document.getElementById('p-error');
|
||||
if (deposito == '') {
|
||||
textoError.style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
|
||||
var sumaTotal = 0;
|
||||
|
||||
|
||||
var insoluto_t = 0;
|
||||
|
||||
var bandera = 0;
|
||||
|
||||
/*$('#facturasPagar tbody tr').each(function () {
|
||||
pagoTemp = $(this).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(this).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto;
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
|
||||
});*/
|
||||
|
||||
//----------------------------------------------------------------
|
||||
//Modificacion LASI para obtener todos los datos de la tabla Facturas a pagar
|
||||
//para que se haga el calculo aun cuando no estan visisbles.
|
||||
|
||||
var total = table.column(3).data() // Obtiene todos los datos, no solo los visibles
|
||||
.reduce(function(a, b,index) {
|
||||
|
||||
var pagoTemp = $(table.row(index).node()).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(table.row(index).node()).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto.toFixed(2);
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
|
||||
return sumaTotal;
|
||||
|
||||
}, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------
|
||||
|
||||
|
||||
document.getElementById('saldo_suma').value = sumaTotal;
|
||||
|
||||
// console.log('DT', datos)
|
||||
console.log('suma total: '+sumaTotal);
|
||||
console.log('deposito: '+deposito);
|
||||
if (sumaTotal > deposito || sumaTotal < deposito) {
|
||||
console.log('no es igual');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (sumaTotal == deposito && bandera == 0) {
|
||||
console.log('es igual');
|
||||
textoError.style.display = 'none';
|
||||
guardarPagosBtn.removeAttribute('disabled');
|
||||
console.log('removido');
|
||||
}
|
||||
|
||||
|
||||
if (deposito > insoluto_t) {
|
||||
// console.log('Deposito', deposito);
|
||||
console.log('insoluto: '+insoluto_t);
|
||||
console.log('Deposito: '+ deposito);
|
||||
console.log('Excede el limite');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (deposito == '' || deposito == '0' || deposito == '0.00') {
|
||||
console.log('Excede el limite 2');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//csubir a prd verificar duplicidad
|
||||
function verDuplicidad(val)
|
||||
{
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'php/consultaRef.php?val='+val,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
lista_clientes = data.message;
|
||||
console.log(lista_clientes);
|
||||
if(lista_clientes==0)
|
||||
{
|
||||
verDup=0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
verDup=1;
|
||||
}
|
||||
|
||||
}, error: function (error) {
|
||||
console.log('Error ajax', error)
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function generarSolicitud() {
|
||||
var datos = [];
|
||||
var acum = 0;
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
table.search("").draw();//modificacion lasi 11/12/2024, para liberar el search y gaurde todos los registros
|
||||
var allData = table.rows().data().toArray();
|
||||
/*$('#facturasPagar tbody tr').each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});*/
|
||||
//modificacion LASI para obtener todos los datos de la tabla, aun esten ocultos por paginacion
|
||||
var allRows = table.rows({ search: 'applied' }).nodes(); // Incluye filas ocultas
|
||||
|
||||
$(allRows).each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});
|
||||
console.log(datos);
|
||||
var fechaInput = document.getElementById('fecha');
|
||||
var fechaSeleccionada = fechaInput.value;
|
||||
if (fechaSeleccionada == '') {
|
||||
alertify.error('Selecciona una fecha');
|
||||
return
|
||||
}
|
||||
// if (cadenaB64 == '') {
|
||||
// alertify.error('Selecciona un archivo');
|
||||
// return
|
||||
// }
|
||||
|
||||
var email = document.getElementById('email').value.replace(/\s+$/, '');
|
||||
if (email == '') {
|
||||
alertify.error('Llene un correo');
|
||||
return;
|
||||
}
|
||||
|
||||
var folio = document.getElementById('folioP').value;
|
||||
var email = document.getElementById('email').value;
|
||||
var deposito = document.getElementById('deposito').value;
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
//agregar referencia de pago bancaria
|
||||
var refBancaria=document.getElementById('refBancaria').value;
|
||||
var unidad_negocio=document.getElementById('unidadNegocio').value;
|
||||
|
||||
|
||||
if (formaPago == '' || formaPago == 'Forma de pago') {
|
||||
alertify.error('Seleccione una forma de pago');
|
||||
return;
|
||||
}
|
||||
|
||||
if (deposito === '' || deposito === '0') {
|
||||
alertify.error('Monto no debe ir vacio');
|
||||
return;
|
||||
}
|
||||
if(refBancaria=='')
|
||||
{
|
||||
alertify.error('Debe agregar la referencia bancaria');
|
||||
return;
|
||||
}
|
||||
if(verDup==1)
|
||||
{
|
||||
alertify.error('Ya hay un folio con la misma referencia bancaria');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var pagos = {
|
||||
folio: folio,
|
||||
archivo: cadenaB64,
|
||||
fecha_ppd: fechaSeleccionada,
|
||||
cliente: clienteTemp,
|
||||
email: email,
|
||||
monto: deposito,
|
||||
filas: datos,
|
||||
forma_pago: formaPago,
|
||||
referBancaria : refBancaria,
|
||||
unidad_negocio: unidad_negocio
|
||||
};
|
||||
|
||||
// console.log(pagos);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/inserta_solicitud.php',
|
||||
data: pagos,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
// console.log(data)
|
||||
if (data.code == '201') {
|
||||
alertify.success('Registrado con exito!');
|
||||
dataTable = dtTemp;
|
||||
inicializarDataTable(clienteTemp, dtTemp)
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
document.getElementById('deposito').value = '';
|
||||
$('#modalPagar').modal('hide');
|
||||
document.getElementById('saldo_suma').value = '';
|
||||
} else {
|
||||
p.innerText = data.messsage
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
obtenerFolio();
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
table.clear().draw();
|
||||
}, error: function (error) {
|
||||
console.log('Error', error)
|
||||
p.innerText = 'Error al cargar los datos, consulte a soporte'
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apagaBoton() {
|
||||
// console.log('Btn')
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
function traerDeudores(dataTable) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
data: { opcion: '6' },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
lista_clientes = data;
|
||||
showResults('');
|
||||
console.log('deudores');
|
||||
console.log(lista_clientes);
|
||||
|
||||
}, error: function (error) {
|
||||
console.log('Error ajax', error)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showResults(searchText) {
|
||||
const searchResults = document.getElementById('searchResults');
|
||||
searchResults.innerHTML = '';
|
||||
lista_clientes.forEach(option => {
|
||||
if (option.CLIENTE.toLowerCase().includes(searchText.toLowerCase())) {
|
||||
const li = document.createElement('li');
|
||||
|
||||
li.textContent = option.CLIENTE;
|
||||
li.className = 'list-group-item';
|
||||
li.setAttribute('onclick', 'seleccionado(' + JSON.stringify(option) + ')');
|
||||
searchResults.appendChild(li);
|
||||
}
|
||||
});
|
||||
|
||||
if (searchText === '' || searchResults.children.length === 0) {
|
||||
searchResults.style.display = 'none';
|
||||
} else {
|
||||
searchResults.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function seleccionado(cliente) {
|
||||
var clienteInput = $("#searchInput");
|
||||
clienteInput.val(cliente.CLIENTE).attr('data-custom-value', cliente.ID_CLIENTE);
|
||||
textoCliente = cliente.CLIENTE;
|
||||
clienteTemp = cliente.ID_CLIENTE;
|
||||
searchResults.style.display = 'none';
|
||||
inicializarDataTable(cliente.ID_CLIENTE, dtTemp)
|
||||
}
|
||||
|
||||
|
||||
|
||||
508
js/pagos/dt_(08.10.2024 07.09.43 p. m.).js
Normal file
508
js/pagos/dt_(08.10.2024 07.09.43 p. m.).js
Normal file
@@ -0,0 +1,508 @@
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
|
||||
const p = document.getElementById("p_errores")
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.getElementById('fileInput').addEventListener('change', function () {
|
||||
cadenaB64 = '';
|
||||
fileInput = this;
|
||||
file = fileInput.files[0]; // Obtener el primer archivo seleccionado
|
||||
|
||||
if (file) {
|
||||
if (file.type !== 'application/pdf') {
|
||||
alertify.error('Solo se admiten archivos PDF');
|
||||
fileInput.value = '';
|
||||
return;
|
||||
}
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
cadenaB64 = reader.result.split(',')[1]; // Obtener la parte Base64
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
document.getElementById('searchInput').addEventListener('input', function (event) {
|
||||
showResults(event.target.value);
|
||||
});
|
||||
construyeDT();
|
||||
obtenerViaPago();
|
||||
$('#buttons-container').on('click', '#getSelectedRows', function () {
|
||||
var dataTable = $('#pagosDT').DataTable(); // Asegúrate de obtener la instancia de DataTable por su ID
|
||||
var filas = [];
|
||||
dataTable.rows().every(function () {
|
||||
var data = this.data();
|
||||
var rowNode = this.node();
|
||||
var isChecked = $(rowNode).find('.row-check').is(':checked');
|
||||
if (isChecked) {
|
||||
filas.push(data);
|
||||
}
|
||||
});
|
||||
// Muestra el modal y pasa los datos seleccionados a la función facturasPagar
|
||||
$('#modalPagar').modal('show');
|
||||
facturasPagar(filas);
|
||||
// console.log(filas); // Aquí puedes manejar los datos seleccionados como necesites
|
||||
});
|
||||
|
||||
function construyeDT() {
|
||||
var columns = [
|
||||
{ data: null, defaultContent: '<input type="checkbox" class="row-check">', orderable: false, title: '--' },
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID' },
|
||||
{ data: 'TOTAL', title: 'Total Factura' },
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto' },
|
||||
{ data: 'fecha_venta', title: 'Fecha' },
|
||||
|
||||
];
|
||||
|
||||
// Destruye la DataTable si ya existe
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
}
|
||||
|
||||
// Construye la DataTable
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-success'
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
// Agrega un mensaje si no hay datos en la DataTable
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>');
|
||||
|
||||
// Agrega el botón #getSelectedRows al contenedor de botones
|
||||
$('#buttons-container').append('<button id="getSelectedRows" style="width: -webkit-fill-available;" class="btn btn-info">Agregar facturas</button>');
|
||||
}
|
||||
dataTable.on('draw.dt', function () {
|
||||
$('#pagosDT tbody tr').each(function () {
|
||||
var estatus = $(this).find('td:eq(4)').text(); // Ajusta el índice según la posición de 'estatus'
|
||||
// console.log('estatus', estatus)
|
||||
|
||||
if (estatus === '0') {
|
||||
$(this).find('td:eq(0)').html('<span class="badge badge-success">Pagada</span>'); // Cambia el contenido de la celda
|
||||
} else {
|
||||
$(this).find('td:eq(36)').html('<span class="badge badge-warning">Bloqueado</span>'); // Cambia el contenido de la celda
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
dtTemp = dataTable;
|
||||
traerDeudores(dataTable);
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Función para construir la DataTable
|
||||
|
||||
|
||||
function inicializarDataTable(cliente, dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: { opcion: '7', cliente: cliente },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
if (data.length > 0) {
|
||||
// console.log('Agregar filas')
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.error('Error en la llamada AJAX', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function facturasPagar(data) {
|
||||
|
||||
var columns = [
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID', width: '20%' }, // Ejemplo de ancho específico
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto', width: '20%' }, // Ejemplo de ancho del 20%
|
||||
{
|
||||
data: null,
|
||||
render: function (data, type, row) {
|
||||
return `<input type="number" class="form-control custom-input" oninput="calcular('${row.saldo_insoluto}',this);" value="${row.saldo_insoluto}" >`;
|
||||
}
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
dataTable = $('#facturasPagar').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-danger' // Agregar la clase btn-danger al botón
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
},
|
||||
},
|
||||
className: 'btn-success' // Agregar la clase btn-danger al botón de Excel
|
||||
},
|
||||
|
||||
],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
$('#facturasPagar').css('width', '-webkit-fill-available');
|
||||
recalcularTotales();
|
||||
|
||||
// $('#facturasPagar').on('input', '.custom-input', function () {
|
||||
// console.log('Funcion');
|
||||
// var inputValue = parseFloat($(this).val());
|
||||
// var saldo = parseFloat($(this).data('saldo'));
|
||||
// if (inputValue > saldo) {
|
||||
// console.log('MUESTRA SALDO')
|
||||
// mostrarDialogo(this);
|
||||
// } else {
|
||||
// // Ocultar el cuadro de diálogo si ya está visible
|
||||
// $(this).next('.custom-dialog').remove();
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
let deudores = [];
|
||||
|
||||
function dialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog-excede alert alert-danger" role="alert">
|
||||
Pago excede el saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function dialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog alert alert-warning" role="alert">
|
||||
Pago no debe ser menor al saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function eliminarDialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
}
|
||||
|
||||
|
||||
function eliminarDialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
}
|
||||
|
||||
function calcular(saldo, input) {
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var pago = parseFloat(parseFloat(input.value).toFixed(2));
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
var saldo_insoluto = parseFloat(parseFloat(saldo).toFixed(2));
|
||||
|
||||
// console.log('Pago', pago)
|
||||
// console.log('saldo', saldo_insoluto)
|
||||
if (pago > saldo_insoluto && pago != 'NaN') {
|
||||
dialogoExcede(input);
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (pago == saldo_insoluto || pago < saldo_insoluto || pago == 'NaN') {
|
||||
eliminarDialogoExcede(input);
|
||||
}
|
||||
|
||||
recalcularTotales(input);
|
||||
}
|
||||
|
||||
|
||||
function recalcularTotales(input) {
|
||||
var deposito = parseFloat(document.getElementById('deposito').value) || 0;
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var textoError = document.getElementById('p-error');
|
||||
if (deposito == '') {
|
||||
textoError.style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
|
||||
var sumaTotal = 0;
|
||||
|
||||
|
||||
var insoluto_t = 0;
|
||||
|
||||
var bandera = 0;
|
||||
$('#facturasPagar tbody tr').each(function () {
|
||||
pagoTemp = $(this).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(this).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto;
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
document.getElementById('saldo_suma').value = sumaTotal;
|
||||
|
||||
// console.log('DT', datos)
|
||||
|
||||
if (sumaTotal > deposito || sumaTotal < deposito) {
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (sumaTotal == deposito && bandera == 0) {
|
||||
textoError.style.display = 'none';
|
||||
guardarPagosBtn.removeAttribute('disabled');
|
||||
}
|
||||
|
||||
|
||||
if (deposito > insoluto_t) {
|
||||
// console.log('Deposito', deposito);
|
||||
// console.log('Excede el limite');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (deposito == '' || deposito == '0' || deposito == '0.00') {
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function generarSolicitud() {
|
||||
var datos = [];
|
||||
var acum = 0;
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
$('#facturasPagar tbody tr').each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});
|
||||
|
||||
var fechaInput = document.getElementById('fecha');
|
||||
var fechaSeleccionada = fechaInput.value;
|
||||
if (fechaSeleccionada == '') {
|
||||
alertify.error('Selecciona una fecha');
|
||||
return
|
||||
}
|
||||
// if (cadenaB64 == '') {
|
||||
// alertify.error('Selecciona un archivo');
|
||||
// return
|
||||
// }
|
||||
|
||||
var email = document.getElementById('email').value.replace(/\s+$/, '');
|
||||
if (email == '') {
|
||||
alertify.error('Llene un correo');
|
||||
return;
|
||||
}
|
||||
|
||||
var folio = document.getElementById('folioP').value;
|
||||
var email = document.getElementById('email').value;
|
||||
var deposito = document.getElementById('deposito').value;
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
|
||||
|
||||
if (formaPago == '' || formaPago == 'Forma de pago') {
|
||||
alertify.error('Seleccione una forma de pago');
|
||||
return;
|
||||
}
|
||||
|
||||
if (deposito === '' || deposito === '0') {
|
||||
alertify.error('Monto no debe ir vacio');
|
||||
return;
|
||||
}
|
||||
|
||||
var pagos = {
|
||||
folio: folio,
|
||||
archivo: cadenaB64,
|
||||
fecha_ppd: fechaSeleccionada,
|
||||
cliente: clienteTemp,
|
||||
email: email,
|
||||
monto: deposito,
|
||||
filas: datos,
|
||||
forma_pago: formaPago
|
||||
};
|
||||
|
||||
// console.log(pagos);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/inserta_solicitud.php',
|
||||
data: pagos,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
// console.log(data)
|
||||
if (data.code == '201') {
|
||||
alertify.success('Registrado con exito!');
|
||||
dataTable = dtTemp;
|
||||
inicializarDataTable(clienteTemp, dtTemp)
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
document.getElementById('deposito').value = '';
|
||||
$('#modalPagar').modal('hide');
|
||||
document.getElementById('saldo_suma').value = '';
|
||||
} else {
|
||||
p.innerText = data.messsage
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
obtenerFolio();
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
table.clear().draw();
|
||||
}, error: function (error) {
|
||||
console.log('Error', error)
|
||||
p.innerText = 'Error al cargar los datos, consulte a soporte'
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apagaBoton() {
|
||||
// console.log('Btn')
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
function traerDeudores(dataTable) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
data: { opcion: '6' },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
lista_clientes = data;
|
||||
showResults('');
|
||||
|
||||
}, error: function (error) {
|
||||
console.log('Error ajax', error)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showResults(searchText) {
|
||||
const searchResults = document.getElementById('searchResults');
|
||||
searchResults.innerHTML = '';
|
||||
lista_clientes.forEach(option => {
|
||||
if (option.CLIENTE.toLowerCase().includes(searchText.toLowerCase())) {
|
||||
const li = document.createElement('li');
|
||||
|
||||
li.textContent = option.CLIENTE;
|
||||
li.className = 'list-group-item';
|
||||
li.setAttribute('onclick', 'seleccionado(' + JSON.stringify(option) + ')');
|
||||
searchResults.appendChild(li);
|
||||
}
|
||||
});
|
||||
|
||||
if (searchText === '' || searchResults.children.length === 0) {
|
||||
searchResults.style.display = 'none';
|
||||
} else {
|
||||
searchResults.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function seleccionado(cliente) {
|
||||
var clienteInput = $("#searchInput");
|
||||
clienteInput.val(cliente.CLIENTE).attr('data-custom-value', cliente.ID_CLIENTE);
|
||||
textoCliente = cliente.CLIENTE;
|
||||
clienteTemp = cliente.ID_CLIENTE;
|
||||
searchResults.style.display = 'none';
|
||||
inicializarDataTable(cliente.ID_CLIENTE, dtTemp)
|
||||
}
|
||||
|
||||
|
||||
|
||||
566
js/pagos/dt_(19.12.2024 03.40.14 p. m.).js
Normal file
566
js/pagos/dt_(19.12.2024 03.40.14 p. m.).js
Normal file
@@ -0,0 +1,566 @@
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
|
||||
const p = document.getElementById("p_errores")
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.getElementById('fileInput').addEventListener('change', function () {
|
||||
cadenaB64 = '';
|
||||
fileInput = this;
|
||||
file = fileInput.files[0]; // Obtener el primer archivo seleccionado
|
||||
|
||||
if (file) {
|
||||
if (file.type !== 'application/pdf') {
|
||||
alertify.error('Solo se admiten archivos PDF');
|
||||
fileInput.value = '';
|
||||
return;
|
||||
}
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
cadenaB64 = reader.result.split(',')[1]; // Obtener la parte Base64
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
document.getElementById('searchInput').addEventListener('input', function (event) {
|
||||
showResults(event.target.value);
|
||||
});
|
||||
construyeDT();
|
||||
obtenerViaPago();
|
||||
$('#buttons-container').on('click', '#getSelectedRows', function () {
|
||||
var dataTable = $('#pagosDT').DataTable(); // Asegúrate de obtener la instancia de DataTable por su ID
|
||||
var filas = [];
|
||||
dataTable.rows().every(function () {
|
||||
var data = this.data();
|
||||
var rowNode = this.node();
|
||||
var isChecked = $(rowNode).find('.row-check').is(':checked');
|
||||
if (isChecked) {
|
||||
filas.push(data);
|
||||
//console.log(data);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Muestra el modal y pasa los datos seleccionados a la función facturasPagar
|
||||
$('#modalPagar').modal('show');
|
||||
console.log(filas);
|
||||
facturasPagar(filas);
|
||||
// console.log(filas); // Aquí puedes manejar los datos seleccionados como necesites
|
||||
});
|
||||
|
||||
function construyeDT() {
|
||||
var columns = [
|
||||
{ data: null, defaultContent: '<input type="checkbox" class="row-check">', orderable: false, title: '--' },
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID' },
|
||||
{ data: 'TOTAL', title: 'Total Factura' },
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto' },
|
||||
{ data: 'fecha_venta', title: 'Fecha' },
|
||||
|
||||
];
|
||||
|
||||
// Destruye la DataTable si ya existe
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
}
|
||||
|
||||
// Construye la DataTable
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-success'
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
// Agrega un mensaje si no hay datos en la DataTable
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>');
|
||||
|
||||
// Agrega el botón #getSelectedRows al contenedor de botones
|
||||
$('#buttons-container').append('<button id="getSelectedRows" style="width: -webkit-fill-available;" class="btn btn-info">Agregar facturas</button>');
|
||||
}
|
||||
dataTable.on('draw.dt', function () {
|
||||
$('#pagosDT tbody tr').each(function () {
|
||||
var estatus = $(this).find('td:eq(4)').text(); // Ajusta el índice según la posición de 'estatus'
|
||||
// console.log('estatus', estatus)
|
||||
|
||||
if (estatus === '0') {
|
||||
$(this).find('td:eq(0)').html('<span class="badge badge-success">Pagada</span>'); // Cambia el contenido de la celda
|
||||
} else {
|
||||
$(this).find('td:eq(36)').html('<span class="badge badge-warning">Bloqueado</span>'); // Cambia el contenido de la celda
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
dtTemp = dataTable;
|
||||
traerDeudores(dataTable);
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Función para construir la DataTable
|
||||
|
||||
|
||||
function inicializarDataTable(cliente, dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: { opcion: '7', cliente: cliente },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
if (data.length > 0) {
|
||||
// console.log('Agregar filas')
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.error('Error en la llamada AJAX', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function facturasPagar(data) {
|
||||
$('#formaPago option[value="4"]').hide();//agregar para eliminar el por definir
|
||||
var columns = [
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID', width: '20%' }, // Ejemplo de ancho específico
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto', width: '20%' }, // Ejemplo de ancho del 20%
|
||||
{
|
||||
data: null,
|
||||
render: function (data, type, row) {
|
||||
return `<input type="number" class="form-control custom-input" oninput="calcular('${row.saldo_insoluto}',this);" value="${row.saldo_insoluto}" >`;
|
||||
}
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
dataTable = $('#facturasPagar').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-danger' // Agregar la clase btn-danger al botón
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
},
|
||||
},
|
||||
className: 'btn-success' // Agregar la clase btn-danger al botón de Excel
|
||||
},
|
||||
|
||||
],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
$('#facturasPagar').css('width', '-webkit-fill-available');
|
||||
recalcularTotales();
|
||||
|
||||
// $('#facturasPagar').on('input', '.custom-input', function () {
|
||||
// console.log('Funcion');
|
||||
// var inputValue = parseFloat($(this).val());
|
||||
// var saldo = parseFloat($(this).data('saldo'));
|
||||
// if (inputValue > saldo) {
|
||||
// console.log('MUESTRA SALDO')
|
||||
// mostrarDialogo(this);
|
||||
// } else {
|
||||
// // Ocultar el cuadro de diálogo si ya está visible
|
||||
// $(this).next('.custom-dialog').remove();
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
let deudores = [];
|
||||
|
||||
function dialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog-excede alert alert-danger" role="alert">
|
||||
Pago excede el saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function dialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog alert alert-warning" role="alert">
|
||||
Pago no debe ser menor al saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function eliminarDialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
}
|
||||
|
||||
|
||||
function eliminarDialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
}
|
||||
|
||||
function calcular(saldo, input) {
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var pago = parseFloat(parseFloat(input.value).toFixed(2));
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
var saldo_insoluto = parseFloat(parseFloat(saldo).toFixed(2));
|
||||
|
||||
console.log('Saldo', saldo);
|
||||
// console.log('saldo', saldo_insoluto)
|
||||
if (pago > saldo_insoluto && pago != 'NaN') {
|
||||
dialogoExcede(input);
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (pago == saldo_insoluto || pago < saldo_insoluto || pago == 'NaN') {
|
||||
eliminarDialogoExcede(input);
|
||||
}
|
||||
|
||||
recalcularTotales(input);
|
||||
}
|
||||
|
||||
|
||||
function recalcularTotales(input) {
|
||||
var deposito = parseFloat(document.getElementById('deposito').value) || 0;
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var textoError = document.getElementById('p-error');
|
||||
if (deposito == '') {
|
||||
textoError.style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
|
||||
var sumaTotal = 0;
|
||||
|
||||
|
||||
var insoluto_t = 0;
|
||||
|
||||
var bandera = 0;
|
||||
|
||||
/*$('#facturasPagar tbody tr').each(function () {
|
||||
pagoTemp = $(this).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(this).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto;
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
|
||||
});*/
|
||||
|
||||
//----------------------------------------------------------------
|
||||
//Modificacion LASI para obtener todos los datos de la tabla Facturas a pagar
|
||||
//para que se haga el calculo aun cuando no estan visisbles.
|
||||
|
||||
var total = table.column(3).data() // Obtiene todos los datos, no solo los visibles
|
||||
.reduce(function(a, b,index) {
|
||||
|
||||
var pagoTemp = $(table.row(index).node()).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(table.row(index).node()).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto.toFixed(2);
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
|
||||
return sumaTotal;
|
||||
|
||||
}, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------
|
||||
|
||||
|
||||
document.getElementById('saldo_suma').value = sumaTotal;
|
||||
|
||||
// console.log('DT', datos)
|
||||
console.log('suma total: '+sumaTotal);
|
||||
console.log('deposito: '+deposito);
|
||||
if (sumaTotal > deposito || sumaTotal < deposito) {
|
||||
console.log('no es igual');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (sumaTotal == deposito && bandera == 0) {
|
||||
console.log('es igual');
|
||||
textoError.style.display = 'none';
|
||||
guardarPagosBtn.removeAttribute('disabled');
|
||||
console.log('removido');
|
||||
}
|
||||
|
||||
|
||||
if (deposito > insoluto_t) {
|
||||
// console.log('Deposito', deposito);
|
||||
console.log('insoluto: '+insoluto_t);
|
||||
console.log('Deposito: '+ deposito);
|
||||
console.log('Excede el limite');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (deposito == '' || deposito == '0' || deposito == '0.00') {
|
||||
console.log('Excede el limite 2');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function generarSolicitud() {
|
||||
var datos = [];
|
||||
var acum = 0;
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
table.search("").draw();//modificacion lasi 11/12/2024, para liberar el search y gaurde todos los registros
|
||||
var allData = table.rows().data().toArray();
|
||||
/*$('#facturasPagar tbody tr').each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});*/
|
||||
//modificacion LASI para obtener todos los datos de la tabla, aun esten ocultos por paginacion
|
||||
var allRows = table.rows({ search: 'applied' }).nodes(); // Incluye filas ocultas
|
||||
|
||||
$(allRows).each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});
|
||||
console.log(datos);
|
||||
var fechaInput = document.getElementById('fecha');
|
||||
var fechaSeleccionada = fechaInput.value;
|
||||
if (fechaSeleccionada == '') {
|
||||
alertify.error('Selecciona una fecha');
|
||||
return
|
||||
}
|
||||
// if (cadenaB64 == '') {
|
||||
// alertify.error('Selecciona un archivo');
|
||||
// return
|
||||
// }
|
||||
|
||||
var email = document.getElementById('email').value.replace(/\s+$/, '');
|
||||
if (email == '') {
|
||||
alertify.error('Llene un correo');
|
||||
return;
|
||||
}
|
||||
|
||||
var folio = document.getElementById('folioP').value;
|
||||
var email = document.getElementById('email').value;
|
||||
var deposito = document.getElementById('deposito').value;
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
|
||||
|
||||
if (formaPago == '' || formaPago == 'Forma de pago') {
|
||||
alertify.error('Seleccione una forma de pago');
|
||||
return;
|
||||
}
|
||||
|
||||
if (deposito === '' || deposito === '0') {
|
||||
alertify.error('Monto no debe ir vacio');
|
||||
return;
|
||||
}
|
||||
|
||||
var pagos = {
|
||||
folio: folio,
|
||||
archivo: cadenaB64,
|
||||
fecha_ppd: fechaSeleccionada,
|
||||
cliente: clienteTemp,
|
||||
email: email,
|
||||
monto: deposito,
|
||||
filas: datos,
|
||||
forma_pago: formaPago
|
||||
};
|
||||
|
||||
// console.log(pagos);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/inserta_solicitud.php',
|
||||
data: pagos,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
// console.log(data)
|
||||
if (data.code == '201') {
|
||||
alertify.success('Registrado con exito!');
|
||||
dataTable = dtTemp;
|
||||
inicializarDataTable(clienteTemp, dtTemp)
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
document.getElementById('deposito').value = '';
|
||||
$('#modalPagar').modal('hide');
|
||||
document.getElementById('saldo_suma').value = '';
|
||||
} else {
|
||||
p.innerText = data.messsage
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
obtenerFolio();
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
table.clear().draw();
|
||||
}, error: function (error) {
|
||||
console.log('Error', error)
|
||||
p.innerText = 'Error al cargar los datos, consulte a soporte'
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apagaBoton() {
|
||||
// console.log('Btn')
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
function traerDeudores(dataTable) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
data: { opcion: '6' },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
lista_clientes = data;
|
||||
showResults('');
|
||||
console.log('deudores');
|
||||
console.log(lista_clientes);
|
||||
|
||||
}, error: function (error) {
|
||||
console.log('Error ajax', error)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showResults(searchText) {
|
||||
const searchResults = document.getElementById('searchResults');
|
||||
searchResults.innerHTML = '';
|
||||
lista_clientes.forEach(option => {
|
||||
if (option.CLIENTE.toLowerCase().includes(searchText.toLowerCase())) {
|
||||
const li = document.createElement('li');
|
||||
|
||||
li.textContent = option.CLIENTE;
|
||||
li.className = 'list-group-item';
|
||||
li.setAttribute('onclick', 'seleccionado(' + JSON.stringify(option) + ')');
|
||||
searchResults.appendChild(li);
|
||||
}
|
||||
});
|
||||
|
||||
if (searchText === '' || searchResults.children.length === 0) {
|
||||
searchResults.style.display = 'none';
|
||||
} else {
|
||||
searchResults.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function seleccionado(cliente) {
|
||||
var clienteInput = $("#searchInput");
|
||||
clienteInput.val(cliente.CLIENTE).attr('data-custom-value', cliente.ID_CLIENTE);
|
||||
textoCliente = cliente.CLIENTE;
|
||||
clienteTemp = cliente.ID_CLIENTE;
|
||||
searchResults.style.display = 'none';
|
||||
inicializarDataTable(cliente.ID_CLIENTE, dtTemp)
|
||||
}
|
||||
|
||||
|
||||
|
||||
565
js/pagos/dt_(25.11.2024 12.45.08 p. m.).js
Normal file
565
js/pagos/dt_(25.11.2024 12.45.08 p. m.).js
Normal file
@@ -0,0 +1,565 @@
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
|
||||
const p = document.getElementById("p_errores")
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
document.getElementById('fileInput').addEventListener('change', function () {
|
||||
cadenaB64 = '';
|
||||
fileInput = this;
|
||||
file = fileInput.files[0]; // Obtener el primer archivo seleccionado
|
||||
|
||||
if (file) {
|
||||
if (file.type !== 'application/pdf') {
|
||||
alertify.error('Solo se admiten archivos PDF');
|
||||
fileInput.value = '';
|
||||
return;
|
||||
}
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
cadenaB64 = reader.result.split(',')[1]; // Obtener la parte Base64
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
document.getElementById('searchInput').addEventListener('input', function (event) {
|
||||
showResults(event.target.value);
|
||||
});
|
||||
construyeDT();
|
||||
obtenerViaPago();
|
||||
$('#buttons-container').on('click', '#getSelectedRows', function () {
|
||||
var dataTable = $('#pagosDT').DataTable(); // Asegúrate de obtener la instancia de DataTable por su ID
|
||||
var filas = [];
|
||||
dataTable.rows().every(function () {
|
||||
var data = this.data();
|
||||
var rowNode = this.node();
|
||||
var isChecked = $(rowNode).find('.row-check').is(':checked');
|
||||
if (isChecked) {
|
||||
filas.push(data);
|
||||
//console.log(data);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Muestra el modal y pasa los datos seleccionados a la función facturasPagar
|
||||
$('#modalPagar').modal('show');
|
||||
console.log(filas);
|
||||
facturasPagar(filas);
|
||||
// console.log(filas); // Aquí puedes manejar los datos seleccionados como necesites
|
||||
});
|
||||
|
||||
function construyeDT() {
|
||||
var columns = [
|
||||
{ data: null, defaultContent: '<input type="checkbox" class="row-check">', orderable: false, title: '--' },
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID' },
|
||||
{ data: 'TOTAL', title: 'Total Factura' },
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto' },
|
||||
{ data: 'fecha_venta', title: 'Fecha' },
|
||||
|
||||
];
|
||||
|
||||
// Destruye la DataTable si ya existe
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
}
|
||||
|
||||
// Construye la DataTable
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-success'
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
// Agrega un mensaje si no hay datos en la DataTable
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>');
|
||||
|
||||
// Agrega el botón #getSelectedRows al contenedor de botones
|
||||
$('#buttons-container').append('<button id="getSelectedRows" style="width: -webkit-fill-available;" class="btn btn-info">Agregar facturas</button>');
|
||||
}
|
||||
dataTable.on('draw.dt', function () {
|
||||
$('#pagosDT tbody tr').each(function () {
|
||||
var estatus = $(this).find('td:eq(4)').text(); // Ajusta el índice según la posición de 'estatus'
|
||||
// console.log('estatus', estatus)
|
||||
|
||||
if (estatus === '0') {
|
||||
$(this).find('td:eq(0)').html('<span class="badge badge-success">Pagada</span>'); // Cambia el contenido de la celda
|
||||
} else {
|
||||
$(this).find('td:eq(36)').html('<span class="badge badge-warning">Bloqueado</span>'); // Cambia el contenido de la celda
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
dtTemp = dataTable;
|
||||
traerDeudores(dataTable);
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Función para construir la DataTable
|
||||
|
||||
|
||||
function inicializarDataTable(cliente, dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: { opcion: '7', cliente: cliente },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
if (data.length > 0) {
|
||||
// console.log('Agregar filas')
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.error('Error en la llamada AJAX', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function facturasPagar(data) {
|
||||
|
||||
var columns = [
|
||||
{ data: 'factura_id', visible: false },
|
||||
{ data: 'UUID', title: 'UUID', width: '20%' }, // Ejemplo de ancho específico
|
||||
{
|
||||
data: 'parcialidad', title: 'Parcialidad',
|
||||
render: function (data, type, row) {
|
||||
var parcialidad = parseFloat(parseFloat(row.parcialidad).toFixed(2));
|
||||
var saldo_insoluto = parseFloat(parseFloat(row.saldo_insoluto).toFixed(2));
|
||||
var total = parseFloat(parseFloat(row.TOTAL).toFixed(2));
|
||||
if (saldo_insoluto == total) {
|
||||
return '1';
|
||||
} else if (saldo_insoluto < total && saldo_insoluto != 0) {
|
||||
parcialidad = parcialidad + 1;
|
||||
return parcialidad;
|
||||
} else if (saldo_insoluto == 0) {
|
||||
return parcialidad;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'saldo_insoluto', title: 'Saldo insoluto', width: '20%' }, // Ejemplo de ancho del 20%
|
||||
{
|
||||
data: null,
|
||||
render: function (data, type, row) {
|
||||
return `<input type="number" class="form-control custom-input" oninput="calcular('${row.saldo_insoluto}',this);" value="${row.saldo_insoluto}" >`;
|
||||
}
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
dataTable = $('#facturasPagar').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Bfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
}
|
||||
},
|
||||
className: 'btn-danger' // Agregar la clase btn-danger al botón
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: {
|
||||
modifier: {
|
||||
page: 'current'
|
||||
},
|
||||
},
|
||||
className: 'btn-success' // Agregar la clase btn-danger al botón de Excel
|
||||
},
|
||||
|
||||
],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
$('#facturasPagar').css('width', '-webkit-fill-available');
|
||||
recalcularTotales();
|
||||
|
||||
// $('#facturasPagar').on('input', '.custom-input', function () {
|
||||
// console.log('Funcion');
|
||||
// var inputValue = parseFloat($(this).val());
|
||||
// var saldo = parseFloat($(this).data('saldo'));
|
||||
// if (inputValue > saldo) {
|
||||
// console.log('MUESTRA SALDO')
|
||||
// mostrarDialogo(this);
|
||||
// } else {
|
||||
// // Ocultar el cuadro de diálogo si ya está visible
|
||||
// $(this).next('.custom-dialog').remove();
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
let deudores = [];
|
||||
|
||||
function dialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog-excede alert alert-danger" role="alert">
|
||||
Pago excede el saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function dialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
var dialogHtml = `
|
||||
<div class="custom-dialog alert alert-warning" role="alert">
|
||||
Pago no debe ser menor al saldo insoluto.
|
||||
</div>
|
||||
`;
|
||||
$(inputElement).after(dialogHtml);
|
||||
}
|
||||
|
||||
function eliminarDialogoMenor(inputElement) {
|
||||
$(inputElement).next('.custom-dialog').remove();
|
||||
}
|
||||
|
||||
|
||||
function eliminarDialogoExcede(inputElement) {
|
||||
$(inputElement).next('.custom-dialog-excede').remove();
|
||||
}
|
||||
|
||||
function calcular(saldo, input) {
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var pago = parseFloat(parseFloat(input.value).toFixed(2));
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
var saldo_insoluto = parseFloat(parseFloat(saldo).toFixed(2));
|
||||
|
||||
console.log('Saldo', saldo);
|
||||
// console.log('saldo', saldo_insoluto)
|
||||
if (pago > saldo_insoluto && pago != 'NaN') {
|
||||
dialogoExcede(input);
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (pago == saldo_insoluto || pago < saldo_insoluto || pago == 'NaN') {
|
||||
eliminarDialogoExcede(input);
|
||||
}
|
||||
|
||||
recalcularTotales(input);
|
||||
}
|
||||
|
||||
|
||||
function recalcularTotales(input) {
|
||||
var deposito = parseFloat(document.getElementById('deposito').value) || 0;
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
|
||||
var textoError = document.getElementById('p-error');
|
||||
if (deposito == '') {
|
||||
textoError.style.display = 'none';
|
||||
}
|
||||
|
||||
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
|
||||
var sumaTotal = 0;
|
||||
|
||||
|
||||
var insoluto_t = 0;
|
||||
|
||||
var bandera = 0;
|
||||
|
||||
/*$('#facturasPagar tbody tr').each(function () {
|
||||
pagoTemp = $(this).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(this).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto;
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
|
||||
});*/
|
||||
|
||||
//----------------------------------------------------------------
|
||||
//Modificacion LASI para obtener todos los datos de la tabla Facturas a pagar
|
||||
//para que se haga el calculo aun cuando no estan visisbles.
|
||||
|
||||
var total = table.column(3).data() // Obtiene todos los datos, no solo los visibles
|
||||
.reduce(function(a, b,index) {
|
||||
|
||||
var pagoTemp = $(table.row(index).node()).find('td').eq(3).find('input').val();
|
||||
pagoTemp = parseFloat(pagoTemp).toFixed(2);
|
||||
|
||||
if (!isNaN(pagoTemp)) {
|
||||
sumaTotal = (parseFloat(sumaTotal) + parseFloat(pagoTemp)).toFixed(2);
|
||||
var insoluto = parseFloat($(table.row(index).node()).find('td').eq(2).text()) || 0;
|
||||
insoluto_t += insoluto.toFixed(2);
|
||||
} else {
|
||||
bandera = 1;
|
||||
}
|
||||
|
||||
return sumaTotal;
|
||||
|
||||
}, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------
|
||||
|
||||
|
||||
document.getElementById('saldo_suma').value = sumaTotal;
|
||||
|
||||
// console.log('DT', datos)
|
||||
console.log('suma total: '+sumaTotal);
|
||||
console.log('deposito: '+deposito);
|
||||
if (sumaTotal > deposito || sumaTotal < deposito) {
|
||||
console.log('no es igual');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (sumaTotal == deposito && bandera == 0) {
|
||||
console.log('es igual');
|
||||
textoError.style.display = 'none';
|
||||
guardarPagosBtn.removeAttribute('disabled');
|
||||
console.log('removido');
|
||||
}
|
||||
|
||||
|
||||
if (deposito > insoluto_t) {
|
||||
// console.log('Deposito', deposito);
|
||||
console.log('insoluto: '+insoluto_t);
|
||||
console.log('Deposito: '+ deposito);
|
||||
console.log('Excede el limite');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
} else if (deposito == '' || deposito == '0' || deposito == '0.00') {
|
||||
console.log('Excede el limite 2');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function generarSolicitud() {
|
||||
var datos = [];
|
||||
var acum = 0;
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
var allData = table.rows().data().toArray();
|
||||
/*$('#facturasPagar tbody tr').each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});*/
|
||||
//modificacion LASI para obtener todos los datos de la tabla, aun esten ocultos por paginacion
|
||||
var allRows = table.rows({ search: 'applied' }).nodes(); // Incluye filas ocultas
|
||||
|
||||
$(allRows).each(function () {
|
||||
var id = allData[acum].factura_id;
|
||||
acum = acum + 1;
|
||||
var fila = {};
|
||||
|
||||
fila['uuid'] = $(this).find('td').eq(0).text();
|
||||
fila['parcialidad'] = $(this).find('td').eq(1).text();
|
||||
fila['saldo_insoluto'] = $(this).find('td').eq(2).text();
|
||||
fila['pago'] = $(this).find('td').eq(3).find('input').val();
|
||||
fila['id_factura'] = id;
|
||||
datos.push(fila);
|
||||
});
|
||||
console.log(datos);
|
||||
var fechaInput = document.getElementById('fecha');
|
||||
var fechaSeleccionada = fechaInput.value;
|
||||
if (fechaSeleccionada == '') {
|
||||
alertify.error('Selecciona una fecha');
|
||||
return
|
||||
}
|
||||
// if (cadenaB64 == '') {
|
||||
// alertify.error('Selecciona un archivo');
|
||||
// return
|
||||
// }
|
||||
|
||||
var email = document.getElementById('email').value.replace(/\s+$/, '');
|
||||
if (email == '') {
|
||||
alertify.error('Llene un correo');
|
||||
return;
|
||||
}
|
||||
|
||||
var folio = document.getElementById('folioP').value;
|
||||
var email = document.getElementById('email').value;
|
||||
var deposito = document.getElementById('deposito').value;
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
var formaPago = $('#formaPago option:selected').val();
|
||||
|
||||
|
||||
if (formaPago == '' || formaPago == 'Forma de pago') {
|
||||
alertify.error('Seleccione una forma de pago');
|
||||
return;
|
||||
}
|
||||
|
||||
if (deposito === '' || deposito === '0') {
|
||||
alertify.error('Monto no debe ir vacio');
|
||||
return;
|
||||
}
|
||||
|
||||
var pagos = {
|
||||
folio: folio,
|
||||
archivo: cadenaB64,
|
||||
fecha_ppd: fechaSeleccionada,
|
||||
cliente: clienteTemp,
|
||||
email: email,
|
||||
monto: deposito,
|
||||
filas: datos,
|
||||
forma_pago: formaPago
|
||||
};
|
||||
|
||||
// console.log(pagos);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/inserta_solicitud.php',
|
||||
data: pagos,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
// console.log(data)
|
||||
if (data.code == '201') {
|
||||
alertify.success('Registrado con exito!');
|
||||
dataTable = dtTemp;
|
||||
inicializarDataTable(clienteTemp, dtTemp)
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
document.getElementById('deposito').value = '';
|
||||
$('#modalPagar').modal('hide');
|
||||
document.getElementById('saldo_suma').value = '';
|
||||
} else {
|
||||
p.innerText = data.messsage
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
obtenerFolio();
|
||||
var table = $('#facturasPagar').DataTable();
|
||||
table.clear().draw();
|
||||
}, error: function (error) {
|
||||
console.log('Error', error)
|
||||
p.innerText = 'Error al cargar los datos, consulte a soporte'
|
||||
$('#errores').modal('show')
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function apagaBoton() {
|
||||
// console.log('Btn')
|
||||
var guardarPagosBtn = document.getElementById('guardarPagos');
|
||||
guardarPagosBtn.setAttribute('disabled', 'disabled');
|
||||
}
|
||||
|
||||
function traerDeudores(dataTable) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
data: { opcion: '6' },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
lista_clientes = data;
|
||||
showResults('');
|
||||
console.log('deudores');
|
||||
console.log(lista_clientes);
|
||||
|
||||
}, error: function (error) {
|
||||
console.log('Error ajax', error)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showResults(searchText) {
|
||||
const searchResults = document.getElementById('searchResults');
|
||||
searchResults.innerHTML = '';
|
||||
lista_clientes.forEach(option => {
|
||||
if (option.CLIENTE.toLowerCase().includes(searchText.toLowerCase())) {
|
||||
const li = document.createElement('li');
|
||||
|
||||
li.textContent = option.CLIENTE;
|
||||
li.className = 'list-group-item';
|
||||
li.setAttribute('onclick', 'seleccionado(' + JSON.stringify(option) + ')');
|
||||
searchResults.appendChild(li);
|
||||
}
|
||||
});
|
||||
|
||||
if (searchText === '' || searchResults.children.length === 0) {
|
||||
searchResults.style.display = 'none';
|
||||
} else {
|
||||
searchResults.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function seleccionado(cliente) {
|
||||
var clienteInput = $("#searchInput");
|
||||
clienteInput.val(cliente.CLIENTE).attr('data-custom-value', cliente.ID_CLIENTE);
|
||||
textoCliente = cliente.CLIENTE;
|
||||
clienteTemp = cliente.ID_CLIENTE;
|
||||
searchResults.style.display = 'none';
|
||||
inicializarDataTable(cliente.ID_CLIENTE, dtTemp)
|
||||
}
|
||||
|
||||
|
||||
|
||||
213
js/pagos/timbrar (31.12.2024 05.47.04 p. m.).js
Normal file
213
js/pagos/timbrar (31.12.2024 05.47.04 p. m.).js
Normal file
@@ -0,0 +1,213 @@
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
construyeDT();
|
||||
inicializarDataTable(dataTable)
|
||||
});
|
||||
|
||||
|
||||
function construyeDT() {
|
||||
|
||||
var columns = [
|
||||
{ data: 'folio', title: 'Folio' },
|
||||
{ data: 'fecha_ppd', title: 'Fecha pago' },
|
||||
{ data: 'fecha_creacion', title: 'Fecha solicitud' },
|
||||
{ data: 'unidad', title: 'Unidad Venta' },
|
||||
{ data: 'cliente', title: 'Cliente' },
|
||||
{ data: 'monto', title: 'Monto pagado' },
|
||||
{ data: 'email', title: 'Correo' },
|
||||
{ data: 'forma_pago', visible: false},
|
||||
{ data: 'descripcion_pago', title: 'Forma Pago' },
|
||||
{
|
||||
data: 'id',
|
||||
title: 'Accion',
|
||||
render: function (data, type, row) {
|
||||
if (row.estatus == '2') {
|
||||
return '<button class="badge badge-info" onclick=\'timbra(' + JSON.stringify(row) + ')\'>Timbrar</button>';
|
||||
} else if (row.estatus == '4') {
|
||||
return '<span class="badge badge-success">Timbrado</span>';
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'UUID', title : 'UUID'}
|
||||
|
||||
];
|
||||
|
||||
// Destruye la DataTable si ya existe
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
}
|
||||
|
||||
// Construye la DataTable
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100, 500, 1000],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Blfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-success'
|
||||
}],
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
// Agrega un mensaje si no hay datos en la DataTable
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>');
|
||||
|
||||
// Agrega el botón #getSelectedRows al contenedor de botones
|
||||
}
|
||||
|
||||
function timbra(data) {
|
||||
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
title: 'Mensaje',
|
||||
text: '¿Desea timbrar este pago?',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Aceptar',
|
||||
cancelButtonText: 'Cancelar'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
|
||||
toggleLoader4()
|
||||
|
||||
var centro = data.id_unidad;
|
||||
var fecha_pago = data.fecha_ppd;
|
||||
var monto = data.monto;
|
||||
var email = data.email;
|
||||
var id_solicitud = data.id;
|
||||
var id_cliente = data.id_cliente;
|
||||
var folio = data.folio;
|
||||
var formaPago = data.forma_pago;
|
||||
|
||||
var solicitud = {
|
||||
unidad_negocio: centro,
|
||||
fecha_pago: fecha_pago,
|
||||
pagado: monto,
|
||||
email: email,
|
||||
solicitud: id_solicitud,
|
||||
folioP: folio,
|
||||
id_cliente: id_cliente,
|
||||
formaPago : formaPago
|
||||
};
|
||||
var titulo = document.getElementById('titulo_modal');
|
||||
var mensaje = document.getElementById('p_errores');
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: 'php/Timbrado/pagos_api.php',
|
||||
type: 'POST',
|
||||
data: solicitud,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
//--------Si es nula la respuesta
|
||||
console.log('Respuesta', data)
|
||||
if(data===null)
|
||||
{
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = 'No se puede timbrar. Error en datos';
|
||||
$('#mensajes').modal('show')
|
||||
toggleLoader4()
|
||||
|
||||
}
|
||||
else{
|
||||
if (data.code == "200") {
|
||||
titulo.innerText = '¡Timbrado!';
|
||||
mensaje.innerHTML = data.message + '<br>UUID: ' + data.uuid;
|
||||
inicializarDataTable(dataTable);
|
||||
|
||||
} else {
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = data.message;
|
||||
}
|
||||
$('#mensajes').modal('show')
|
||||
toggleLoader4()
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.log(error)
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = 'No es posible realizar timbrado, consulte a soporte';
|
||||
$('#mensajes').modal('show')
|
||||
toggleLoader4()
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function inicializarDataTable(dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: { opcion: '8' },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
// console.log(data)
|
||||
if (data.length > 0) {
|
||||
console.log('Agregar filas')
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.error('Error en la llamada AJAX', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function toggleLoader4() {
|
||||
console.log('ENTRA')
|
||||
var loaderWrapper = document.getElementById("loaderWrapper4");
|
||||
if (loaderWrapper.classList.contains("hidden")) {
|
||||
loaderWrapper.classList.remove("hidden");
|
||||
$('#overlay').removeClass('hidden');
|
||||
} else {
|
||||
loaderWrapper.classList.add("hidden");
|
||||
$('#overlay').addClass('hidden');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function recargarPag()
|
||||
{
|
||||
location.reload();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
606
js/pagos/timbrar.js
Normal file
606
js/pagos/timbrar.js
Normal file
@@ -0,0 +1,606 @@
|
||||
var dtTemp;
|
||||
var clienteTemp;
|
||||
var lista_clientes;
|
||||
var fileInput;
|
||||
var file;
|
||||
var cadenaB64 = '';
|
||||
var textoCliente = '';
|
||||
var dataTable;
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
construyeDT();
|
||||
inicializarDataTable(dataTable);
|
||||
//agregar la funcion de recuperar CFDI
|
||||
document.getElementById("btnCerrar").addEventListener("click", function () {
|
||||
var formulario = document.getElementById("miFormulario");
|
||||
formulario.style.display = "none";
|
||||
$("#overlay").addClass("hidden");
|
||||
});
|
||||
document.getElementById("btnEnviar").addEventListener("click", function () {
|
||||
var folio = document.getElementsByName("folioFactura")[0].value; // UUID
|
||||
var correo = document.getElementById("correo").value; // CORREO
|
||||
console.log(folio);
|
||||
const enviarFolio = async () => {
|
||||
const datosXML = {
|
||||
uuid: folio,
|
||||
correo1: correo,
|
||||
};
|
||||
console.log("datos a enviar " + JSON.stringify(datosXML));
|
||||
try {
|
||||
const response = await fetch("php/recuperarPDF.php", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(datosXML),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Error en la petición");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("Respuesta de la API:", data);
|
||||
var formulario = document.getElementById("miFormulario");
|
||||
formulario.style.display = "none";
|
||||
$("#overlay").addClass("hidden");
|
||||
alertify.success("La factura se ha enviado al correo especificado!");
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
};
|
||||
|
||||
enviarFolio();
|
||||
|
||||
// Realizar la petición AJAX
|
||||
// Formar la URL del archivo XML basado en el folio
|
||||
//var xmlFile = "xml/" + folio + ".xml"; // Ruta del archivo XML
|
||||
/*
|
||||
// Realizar una solicitud HEAD para verificar la existencia del archivo
|
||||
fetch(xmlFile, { method: 'HEAD' })
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Archivo no encontrado');
|
||||
}
|
||||
// Si la solicitud es exitosa, el archivo existe
|
||||
return true;
|
||||
})
|
||||
.then(fileExists => {
|
||||
if (fileExists) {
|
||||
// Si el archivo existe, muestra el contenido
|
||||
fetch(xmlFile)
|
||||
.then(response => response.text())
|
||||
.then(xmlContent => {
|
||||
// Convertir contenido a base64
|
||||
var xmlBase64 = btoa(xmlContent);
|
||||
enviarXML(folio, xmlBase64, correo);
|
||||
});
|
||||
} else {
|
||||
// Si el archivo no existe, muestra un mensaje de error
|
||||
alertify.error('Folio no encontrado!');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
// Si ocurre un error, muestra un mensaje de error
|
||||
alertify.error('Folio no encontrado!');
|
||||
});
|
||||
*/
|
||||
});
|
||||
$("#motivoSAT").change(function () {
|
||||
// Obtener el valor de la opción seleccionada
|
||||
var valorSeleccionado = $(this).val();
|
||||
|
||||
// Verificar si la opción seleccionada es la que deseas
|
||||
if (valorSeleccionado === "01") {
|
||||
// Agregar la parte de HTML
|
||||
$("#motivo_relacionado").append(
|
||||
'<label class="form-label mt-3" for="uuid_relacionado">UUID Relacionado</label><input type="text" class="form-control" name="uuid_relacionado" id="uuid_relacionado">'
|
||||
);
|
||||
} else {
|
||||
$("#motivo_relacionado").empty();
|
||||
}
|
||||
});
|
||||
//Agregar la funcion de cancelar CFDI
|
||||
$("#enviarFormulario").click(function () {
|
||||
var id = document.getElementById("idFolioSis").value;
|
||||
var UUID = document.getElementById("uuidInput").value;
|
||||
var folio = document.getElementById("folioSis").value;
|
||||
var monto = document.getElementById("montoSis").value;
|
||||
var motivo = document.getElementById("motivoInput").value;
|
||||
var motivoSAT = document.getElementById("motivoSAT").value;
|
||||
var uuid_relacionado = document.getElementById("uuid_relacionado");
|
||||
if (uuid_relacionado) {
|
||||
uuid_relacionado = document.getElementById("uuid_relacionado").value;
|
||||
} else {
|
||||
uuid_relacionado = "";
|
||||
}
|
||||
var user_id = document.getElementById("UsuarioSolicita").value;
|
||||
UNIDAD_NEGOCIO = document.getElementById("centroInput").value;
|
||||
var rfcReceptor = document.getElementById("rfcReceptor").value;
|
||||
|
||||
$.ajax({
|
||||
data: {
|
||||
idFactura: id,
|
||||
user_id: user_id,
|
||||
STATUS: 7,
|
||||
UNIDAD_NEGOCIO: UNIDAD_NEGOCIO,
|
||||
url: "url",
|
||||
FOLIO: folio,
|
||||
UUID: UUID,
|
||||
TOTAL: monto,
|
||||
RFC: rfcReceptor,
|
||||
portal: 0,
|
||||
motivo: motivo,
|
||||
motivoSAT: motivoSAT,
|
||||
uuid_relacionado: uuid_relacionado,
|
||||
}, //datos que se envian a traves de ajax
|
||||
url: "php/cancelacionAdministradoresCP.php", //archivo que recibe la peticion
|
||||
type: "post", //método de envio
|
||||
beforeSend: function () {},
|
||||
})
|
||||
.done(function (response) {
|
||||
console.log(response);
|
||||
if (response != 1) {
|
||||
console.log(response);
|
||||
err = JSON.parse(response);
|
||||
alertify.error(err.message);
|
||||
if (typeof err.code !== "undefined" && err.code !== null) {
|
||||
alertify.error(err.message);
|
||||
} else {
|
||||
console.log("Error al cancelar la factura");
|
||||
}
|
||||
/* setTimeout(function(){
|
||||
location.reload(true);
|
||||
}, 3000); */
|
||||
} else {
|
||||
alertify.success("Factura cancelada");
|
||||
setTimeout(function () {
|
||||
location.reload(true);
|
||||
}, 3000);
|
||||
}
|
||||
})
|
||||
.fail(function (error) {
|
||||
//EN CASO DE FALLO, SE PINTA UN ERROR EN CONSOLA
|
||||
console.log(error);
|
||||
err = JSON.parse(error);
|
||||
alertify.error(err.message);
|
||||
/* setTimeout(function(){
|
||||
location.reload(true);
|
||||
}, 3000); */
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function cancelarAdmin(data) {
|
||||
var string = "OK";
|
||||
alertify.confirm(
|
||||
"Confirmacion de cancelación",
|
||||
"¿Estas seguro que deseas cancelar la factura? No se podrán modificar los cambios posteriormente.",
|
||||
function () {
|
||||
limpiarForm();
|
||||
$("#modalCancel").modal("show");
|
||||
console.log(data);
|
||||
var input = document.getElementById("uuidInput");
|
||||
input.value = data.UUID;
|
||||
var folio = document.getElementById("folioSis");
|
||||
folio.value = data.folio;
|
||||
var monto = document.getElementById("montoSis");
|
||||
monto.value = data.monto;
|
||||
var id = document.getElementById("idFolioSis");
|
||||
id.value = data.id;
|
||||
},
|
||||
function () {
|
||||
alertify.error("Factura no cancelada");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function limpiarForm() {
|
||||
document.getElementById("SolCancelacion").reset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function construyeDT() {
|
||||
|
||||
var columns = [
|
||||
{ data: 'folio', title: 'Folio' },
|
||||
{ data: 'fecha_ppd', title: 'Fecha pago' },
|
||||
{ data: 'fecha_creacion', title: 'Fecha solicitud' },
|
||||
{ data: 'unidad', title: 'Unidad Venta' },
|
||||
{ data: 'cliente', title: 'Cliente' },
|
||||
{ data: 'monto', title: 'Monto pagado' },
|
||||
{ data: 'email', title: 'Correo' },
|
||||
{ data: 'forma_pago', visible: false},
|
||||
{ data: 'descripcion_pago', title: 'Forma Pago' },
|
||||
{
|
||||
data: 'id',
|
||||
title: 'Accion',
|
||||
render: function (data, type, row) {
|
||||
if (row.estatus == '2') {
|
||||
return '<button class="badge badge-info" onclick=\'timbra(' + JSON.stringify(row) + ')\'>Timbrar</button>';
|
||||
} else if (row.estatus == '4') {
|
||||
//return '<span class="badge badge-success">Timbrado</span>';
|
||||
return (
|
||||
'<span class="badge badge-success">Timbrado</span><button class="badge badge-warning" onclick=\'recuperarCFDI(' +
|
||||
JSON.stringify(row) +
|
||||
")'><small>Recuperar CFDI</small></button><button class=\"badge badge-danger\" onclick='cancelarAdmin(" +
|
||||
JSON.stringify(row) +
|
||||
")'><small>Cancelar CFDI</small></button>"
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
{ data: 'UUID', title : 'UUID'}
|
||||
|
||||
];
|
||||
|
||||
// Destruye la DataTable si ya existe
|
||||
if ($.fn.DataTable.isDataTable('#pagosDT')) {
|
||||
$('#pagosDT').DataTable().destroy();
|
||||
}
|
||||
|
||||
// Construye la DataTable
|
||||
dataTable = $('#pagosDT').DataTable({
|
||||
destroy: true,
|
||||
lengthMenu: [10, 25, 50, 100, 500, 1000],
|
||||
pageLength: 10,
|
||||
searching: true,
|
||||
paging: true,
|
||||
ordering: true,
|
||||
info: true,
|
||||
responsive: true,
|
||||
dom: 'Blfrtip',
|
||||
buttons: [{
|
||||
extend: 'pdfHtml5',
|
||||
text: 'PDF',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-danger'
|
||||
}, {
|
||||
extend: 'excelHtml5',
|
||||
text: 'Excel',
|
||||
exportOptions: { modifier: { page: 'current' } },
|
||||
className: 'btn-success'
|
||||
}],
|
||||
initComplete: function () {
|
||||
// Agregar un input de texto al lado de los botones
|
||||
/*$(".dt-buttons").append('<br><label>Selecciona un mes</label><select name="meses" id="meses"><option selected>Selecciona un Mes de consulta</option><option value="1">Enero</option><option value="2">Febrero</option><option value="3">Marzo</option><option value="4">Abril</option><option value="5">Mayo</option><option value="6">Junio</option><option value="7">Julio</option><option value="8">Agosto</option><option value="9">Septiembre</option><option value="10">Octubre</option><option value="11">Noviembre</option><option value="12">Diciembre</option></select>');
|
||||
$(".dt-buttons").append('<label> Selecciona una Unidad de Negocio</label><select name="unidadNeg" id="unidadNeg"></select>');
|
||||
$(".dt-buttons").append(' <button type="button" id="filtrarPPD" class="btn btn-info">Filtrar</button>');
|
||||
*/
|
||||
$(".dt-buttons").append(`
|
||||
<div style="display: flex; align-items: center; gap: 10px;">
|
||||
<label for="meses">Selecciona un mes:</label>
|
||||
<select name="meses" id="meses" style="height: 35px;">
|
||||
<option value="0" selected>Selecciona un Mes de consulta</option>
|
||||
<option value="1">Enero</option>
|
||||
<option value="2">Febrero</option>
|
||||
<option value="3">Marzo</option>
|
||||
<option value="4">Abril</option>
|
||||
<option value="5">Mayo</option>
|
||||
<option value="6">Junio</option>
|
||||
<option value="7">Julio</option>
|
||||
<option value="8">Agosto</option>
|
||||
<option value="9">Septiembre</option>
|
||||
<option value="10">Octubre</option>
|
||||
<option value="11">Noviembre</option>
|
||||
<option value="12">Diciembre</option>
|
||||
</select>
|
||||
|
||||
<label for="unidadNeg">Selecciona una Unidad de Negocio:</label>
|
||||
<select name="unidadNeg" id="unidadNeg" style="height: 35px;"> <option selected>Seleccione una unidad de negocio</option></select>
|
||||
|
||||
<button type="button" onclick="filtrarPPD()" class="btn btn-info">Filtrar</button>
|
||||
</div>
|
||||
`);
|
||||
fetch("php/unidad_negocio.php")
|
||||
.then((response) => {
|
||||
// Verificar que la respuesta sea correcta
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error en la solicitud: ${response.status}`);
|
||||
}
|
||||
return response.json(); // Convertir la respuesta a JSON
|
||||
})
|
||||
.then((data) => {
|
||||
console.log("Datos obtenidos:", data); // Usar los datos obtenidos
|
||||
const selectElement = document.getElementById("unidadNeg");
|
||||
selectElement.innerHTML = "";
|
||||
|
||||
// Recorrer los datos y agregarlos como opciones
|
||||
data.forEach((item) => {
|
||||
const option = document.createElement("option");
|
||||
option.value = item.codigo_unidad;
|
||||
option.textContent = item.descripcion;
|
||||
selectElement.appendChild(option);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error:", error); // Manejar errores
|
||||
});
|
||||
},
|
||||
columns: columns,
|
||||
data: []
|
||||
});
|
||||
|
||||
// Agrega un mensaje si no hay datos en la DataTable
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">Sin facturas</td></tr>');
|
||||
|
||||
// Agrega el botón #getSelectedRows al contenedor de botones
|
||||
}
|
||||
|
||||
function timbra(data) {
|
||||
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
title: 'Mensaje',
|
||||
text: '¿Desea timbrar este pago?',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Aceptar',
|
||||
cancelButtonText: 'Cancelar'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
|
||||
toggleLoader4()
|
||||
|
||||
var centro = data.id_unidad;
|
||||
var fecha_pago = data.fecha_ppd;
|
||||
var monto = data.monto;
|
||||
var email = data.email;
|
||||
var id_solicitud = data.id;
|
||||
var id_cliente = data.id_cliente;
|
||||
var folio = data.folio;
|
||||
var formaPago = data.forma_pago;
|
||||
|
||||
var solicitud = {
|
||||
unidad_negocio: centro,
|
||||
fecha_pago: fecha_pago,
|
||||
pagado: monto,
|
||||
email: email,
|
||||
solicitud: id_solicitud,
|
||||
folioP: folio,
|
||||
id_cliente: id_cliente,
|
||||
formaPago : formaPago
|
||||
};
|
||||
var titulo = document.getElementById('titulo_modal');
|
||||
var mensaje = document.getElementById('p_errores');
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: 'php/Timbrado/pagos_api.php',
|
||||
type: 'POST',
|
||||
data: solicitud,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
//--------Si es nula la respuesta
|
||||
console.log('Respuesta', data)
|
||||
if(data===null)
|
||||
{
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = 'No se puede timbrar. Error en datos';
|
||||
$('#mensajes').modal('show')
|
||||
toggleLoader4()
|
||||
|
||||
}
|
||||
else{
|
||||
if (data.code == "200") {
|
||||
titulo.innerText = '¡Timbrado!';
|
||||
mensaje.innerHTML = data.message + '<br>UUID: ' + data.uuid;
|
||||
inicializarDataTable(dataTable);
|
||||
|
||||
} else {
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = data.message;
|
||||
}
|
||||
$('#mensajes').modal('show')
|
||||
toggleLoader4()
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.log(error)
|
||||
titulo.innerText = '¡Mensaje, intento de timbrado!';
|
||||
mensaje.innerText = 'No es posible realizar timbrado, consulte a soporte';
|
||||
$('#mensajes').modal('show')
|
||||
toggleLoader4()
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function inicializarDataTable(dataTable) {
|
||||
$.ajax({
|
||||
url: 'php/ConsultasTablas/ManipulacionConsultas.php',
|
||||
type: 'POST',
|
||||
data: { opcion: '8' },
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
// console.log(data)
|
||||
if (data.length > 0) {
|
||||
console.log('Agregar filas')
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
|
||||
} else {
|
||||
$('#pagosDT tbody').html('<tr class="odd"><td valign="top" colspan="' + columns.length + '" class="dataTables_empty">No hay facturas PPD</td></tr>');
|
||||
}
|
||||
|
||||
},
|
||||
error: function (error) {
|
||||
console.error('Error en la llamada AJAX', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function toggleLoader4() {
|
||||
console.log('ENTRA')
|
||||
var loaderWrapper = document.getElementById("loaderWrapper4");
|
||||
if (loaderWrapper.classList.contains("hidden")) {
|
||||
loaderWrapper.classList.remove("hidden");
|
||||
$('#overlay').removeClass('hidden');
|
||||
} else {
|
||||
loaderWrapper.classList.add("hidden");
|
||||
$('#overlay').addClass('hidden');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function recargarPag()
|
||||
{
|
||||
location.reload();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function filtrarPPD() {
|
||||
var mes = document.getElementById("meses").value;
|
||||
var unidadNeg = document.getElementById("unidadNeg").value;
|
||||
|
||||
console.log("mes" + mes + " unidadNeg" + unidadNeg);
|
||||
construyeDT();
|
||||
$.ajax({
|
||||
url: "php/ConsultasTablas/ManipulacionConsultas.php",
|
||||
type: "POST",
|
||||
data: { opcion: "11", mes: mes, unidadNeg: unidadNeg },
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
// console.log(data)
|
||||
if (data.length > 0) {
|
||||
console.log("Agregar filas");
|
||||
dataTable.clear().rows.add(data).draw();
|
||||
} else {
|
||||
$("#pagosDT tbody").html(
|
||||
'<tr class="odd"><td valign="top" colspan="' +
|
||||
columns.length +
|
||||
'" class="dataTables_empty">No hay facturas PPD</td></tr>'
|
||||
);
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
console.error("Error en la llamada AJAX", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function recuperarCFDI(data) {
|
||||
console.log(data.UUID);
|
||||
var formulario = document.getElementById("miFormulario");
|
||||
formulario.style.display = "block";
|
||||
$("#overlay").removeClass("hidden");
|
||||
|
||||
var inputFolio = formulario.querySelector('input[name="folioFactura"]'); // Ajusta el selector según el atributo del input
|
||||
if (inputFolio) {
|
||||
inputFolio.value = data.UUID;
|
||||
console.log("Folio actualizado:", inputFolio.value);
|
||||
} else {
|
||||
console.error("El input con name='folio' no se encontró en el formulario.");
|
||||
}
|
||||
}
|
||||
|
||||
function enviarXML(uuid, xml, correo) {
|
||||
console.log(uuid);
|
||||
console.log(xml);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "php/Timbrado/recuperarCFDI1.php",
|
||||
data: {
|
||||
uuid: uuid,
|
||||
correo: correo,
|
||||
xml: xml,
|
||||
},
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
console.log(response);
|
||||
if (response.respuesta === "OK") {
|
||||
alertify.success("Se ha enviado el correo!");
|
||||
var folio = document.getElementById("folio"); // UUID
|
||||
var correo = document.getElementById("correo"); // CORREO
|
||||
var formulario = document.getElementById("miFormulario");
|
||||
formulario.style.display = "none";
|
||||
$("#overlay").addClass("hidden");
|
||||
|
||||
folio.value = "";
|
||||
correo.value = "";
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
console.error("Error en la segunda llamada AJAX", error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function timbra(data) {
|
||||
Swal.fire({
|
||||
icon: "info",
|
||||
title: "Mensaje",
|
||||
text: "¿Desea timbrar este pago?",
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Aceptar",
|
||||
cancelButtonText: "Cancelar",
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
toggleLoader4();
|
||||
|
||||
var centro = data.id_unidad;
|
||||
var fecha_pago = data.fecha_ppd;
|
||||
var monto = data.monto;
|
||||
var email = data.email;
|
||||
var id_solicitud = data.id;
|
||||
var id_cliente = data.id_cliente;
|
||||
var folio = data.folio;
|
||||
var formaPago = data.forma_pago;
|
||||
|
||||
var solicitud = {
|
||||
unidad_negocio: centro,
|
||||
fecha_pago: fecha_pago,
|
||||
pagado: monto,
|
||||
email: email,
|
||||
solicitud: id_solicitud,
|
||||
folioP: folio,
|
||||
id_cliente: id_cliente,
|
||||
formaPago: formaPago,
|
||||
};
|
||||
var titulo = document.getElementById("titulo_modal");
|
||||
var mensaje = document.getElementById("p_errores");
|
||||
|
||||
$.ajax({
|
||||
url: "php/Timbrado/pagos_api.php",
|
||||
type: "POST",
|
||||
data: solicitud,
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
console.log("Respuesta", data);
|
||||
if (data.code == "200") {
|
||||
titulo.innerText = "¡Timbrado!";
|
||||
mensaje.innerHTML = data.message + "<br>UUID: " + data.uuid;
|
||||
inicializarDataTable(dataTable);
|
||||
} else {
|
||||
titulo.innerText = "¡Mensaje, intento de timbrado!";
|
||||
mensaje.innerText = data.message;
|
||||
}
|
||||
$("#mensajes").modal("show");
|
||||
toggleLoader4();
|
||||
},
|
||||
error: function (error) {
|
||||
console.log(error);
|
||||
titulo.innerText = "¡Mensaje, intento de timbrado!";
|
||||
mensaje.innerText =
|
||||
"No es posible realizar timbrado, consulte a soporte";
|
||||
$("#mensajes").modal("show");
|
||||
toggleLoader4();
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user