mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-24 09:40:21 +00:00
trabajando en la tabla de transferencias
This commit is contained in:
@ -76,11 +76,20 @@ $(() => {
|
||||
$(document).on('click', '.btn-refund-payment', function () {
|
||||
const dsOrderId = $(this).data('dsorderid');
|
||||
const transactionId = $(this).data('transactionid');
|
||||
const maxAmountCents = $(this).data('amount');
|
||||
// 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):',
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
title: window.languageBundle['pagos.refund.title'],
|
||||
text: window.languageBundle['pagos.refund.text'],
|
||||
input: 'number',
|
||||
confirmButtonText: window.languageBundle['app.aceptar'] || 'Seleccionar',
|
||||
cancelButtonText: window.languageBundle['app.cancelar'] || 'Cancelar',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary me-2',
|
||||
cancelButton: 'btn btn-light',
|
||||
},
|
||||
inputAttributes: {
|
||||
min: 0,
|
||||
}
|
||||
@ -88,7 +97,15 @@ $(() => {
|
||||
if (result.isConfirmed) {
|
||||
const amountToRefund = parseFloat(result.value);
|
||||
if (isNaN(amountToRefund) || amountToRefund <= 0) {
|
||||
Swal.fire('Error', 'Cantidad inválida para la devolución.', 'error');
|
||||
showSwal('Error', window.languageBundle['pagos.refund.error.invalid-number'], 'error');
|
||||
return;
|
||||
}
|
||||
if (amountToRefund*100 > maxAmountCents) {
|
||||
showSwal('Error', window.languageBundle['pagos.refund.error.invalid-number'], 'error');
|
||||
return;
|
||||
}
|
||||
if (amountToRefund*100 > maxAmountCents) {
|
||||
showSwal('Error', window.languageBundle['pagos.refund.error.invalid-number'], 'error');
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
@ -98,14 +115,91 @@ $(() => {
|
||||
amountCents: amountToRefund*100
|
||||
}
|
||||
}).then((response) => {
|
||||
response = typeof response === 'string' ? JSON.parse(response) : response;
|
||||
if (response.success) {
|
||||
Swal.fire('Éxito', 'Pago devuelto con éxito.', 'success');
|
||||
table.draw();
|
||||
showSwal('Éxito', window.languageBundle['pagos.refund.success'], 'success');
|
||||
$('#pagos-redsys-datatable').DataTable().draw();
|
||||
} else {
|
||||
Swal.fire('Error', 'No se pudo procesar la devolución.', 'error');
|
||||
showSwal('Error', window.languageBundle['pagos.refund.error.general'], 'error');
|
||||
$('#pagos-redsys-datatable').DataTable().draw();
|
||||
|
||||
}
|
||||
});
|
||||
}).fail(() => {
|
||||
showSwal('Error', window.languageBundle['pagos.refund.error.general'], 'error');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
const tableT = new DataTable('#pagos-transferencias-datatable', {
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
orderCellsTop: true,
|
||||
pageLength: 50,
|
||||
lengthMenu: [10, 25, 50, 100, 500],
|
||||
language: { url: '/assets/libs/datatables/i18n/' + language + '.json' },
|
||||
responsive: true,
|
||||
dom: 'lBrtip',
|
||||
buttons: {
|
||||
dom: {
|
||||
button: {
|
||||
className: 'btn btn-sm btn-outline-primary me-1'
|
||||
},
|
||||
buttons: [
|
||||
{ extend: 'copy' },
|
||||
{ extend: 'csv' },
|
||||
{ extend: 'excel' },
|
||||
{ extend: 'pdf' },
|
||||
{ extend: 'print' },
|
||||
{ extend: 'colvis' }
|
||||
],
|
||||
}
|
||||
},
|
||||
ajax: {
|
||||
url: '/pagos/datatable/transferencias',
|
||||
method: 'GET',
|
||||
},
|
||||
order: [[7, 'desc']], // Ordena por fecha por defecto
|
||||
columns: [
|
||||
{ data: 'client', name: 'client', orderable: true },
|
||||
{ data: 'transfer_id', name: 'transfer_id', orderable: true },
|
||||
{ data: 'status', name: 'status', orderable: true },
|
||||
{ data: 'order_id', 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: 'processed_at', name: 'processedAt', 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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function showSwal(title, text, icon) {
|
||||
Swal.fire({
|
||||
title: title,
|
||||
text: text,
|
||||
icon: icon,
|
||||
buttonsStyling: false,
|
||||
confirmButtonText: window.languageBundle['app.aceptar'] || 'Aceptar',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary',
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user