trabajando en devoluciones

This commit is contained in:
2025-11-05 15:09:26 +01:00
parent ed32f773a4
commit a4443763d8
13 changed files with 330 additions and 124 deletions

View File

@ -23,9 +23,10 @@ $(() => {
serverSide: true,
orderCellsTop: true,
pageLength: 50,
lengthMenu: [10, 25, 50, 100, 500],
language: { url: '/assets/libs/datatables/i18n/' + language + '.json' },
responsive: true,
dom: 'lrBtip',
dom: 'lBrtip',
buttons: {
dom: {
button: {
@ -45,16 +46,66 @@ $(() => {
url: '/pagos/datatable/redsys',
method: 'GET',
},
order: [[4, 'asc']], // Ordena por fecha por defecto
order: [[5, 'desc']], // Ordena por fecha por defecto
columns: [
{ data: 'client', name: 'user.fullName', orderable: true },
{ data: 'gateway_order_id', name: 'payments.gateway_order_id', orderable: true },
{ data: 'orderId', name: 'order.id', orderable: true },
{ data: 'amount_cents', name: 'amount_cents', orderable: true },
{ data: 'created_at', name: 'created_at', orderable: true },
{ data: 'actions', name: 'actions' }
{ data: 'client', name: 'client', orderable: true },
{ data: 'gateway_order_id', name: 'payment.gatewayOrderId', orderable: true },
{ data: 'orderId', name: 'payment.orderId', orderable: true },
{ data: 'amount_cents', name: 'amountCents', orderable: true },
{ data: 'amount_cents_refund', name: 'amountCentsRefund', orderable: true },
{ data: 'created_at', name: 'createdAt', orderable: true },
{ data: 'actions', name: 'actions', orderable: false, searchable: false }
],
columnDefs: [{ targets: -1, orderable: false, searchable: false }]
});
})
// Fila de filtros = segunda fila del thead (index 1)
$('#pagos-redsys-datatable thead tr:eq(1) th').each(function (colIdx) {
const input = $(this).find('input');
if (input.length === 0) return; // columnas sin filtro
input.on('keyup change', function () {
const value = this.value;
if (table.column(colIdx).search() !== value) {
table.column(colIdx).search(value).draw();
}
});
});
$(document).on('click', '.btn-refund-payment', function () {
const dsOrderId = $(this).data('dsorderid');
const transactionId = $(this).data('transactionid');
// show swal confirmation with input for amount to refund
Swal.fire({
title: '¿Estás seguro de que deseas devolver este pago?',
text: 'Introduce la cantidad a devolver (en euros):',
input: 'number',
inputAttributes: {
min: 0,
}
}).then((result) => {
if (result.isConfirmed) {
const amountToRefund = parseFloat(result.value);
if (isNaN(amountToRefund) || amountToRefund <= 0) {
Swal.fire('Error', 'Cantidad inválida para la devolución.', 'error');
return;
}
$.ajax({
url: '/pagos/redsys/refund/' + transactionId,
method: 'POST',
data: {
amountCents: amountToRefund*100
}
}).then((response) => {
if (response.success) {
Swal.fire('Éxito', 'Pago devuelto con éxito.', 'success');
table.draw();
} else {
Swal.fire('Error', 'No se pudo procesar la devolución.', 'error');
}
});
}
});
});
});