trabajando en la tabla de las lineas

This commit is contained in:
2025-05-03 18:27:52 +02:00
parent 71e70bf551
commit 3f90665c39
9 changed files with 682 additions and 8 deletions

View File

@ -0,0 +1,112 @@
import ClassSelect from '../../components/select2.js';
import Ajax from '../../components/ajax.js';
import AlbaranComponent from '../../components/albaranComponent.js';
class EtiquetaEdit {
constructor() {
this.tableCols = [
{ data: "rowSelected" },
{ data: "ot" },
{ data: "titulo" },
{ data: "numero_caja" },
{ data: "unidades" },
{ data: "unidadesTotal" },
{ data: "id" },
{ data: "pesoUnidad" },
{ data: "unidadesRaw" }
];
this.table = null;
this.direccion = $('#direccion');
}
init() {
this.initDatatable();
}
initDatatable() {
this.table = $('#tableLineasEtiqueta').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
orderCellsTop: true,
orderable: false,
order: [[7, 'asc']],
lengthMenu: [5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500],
pageLength: 50,
"dom": 'lrtip',
"ajax": {
"url": "/etiquetasTitulos/datatableLineas/" + $('#id').val(),
"data": function (d) {
d.direccion = $('#direccion').val();
d.id = $('#id').val();
},
},
"columns": this.tableCols,
"language": {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
footerCallback: function (row, data, start, end, display) {
let totalUnidades = 0;
let totalPeso = 0;
data.forEach(row => {
const unidades = parseFloat(row.unidadesEnvioRaw) || 0;
const pesoUnidad = parseFloat(row.pesoUnidad) || 0;
totalUnidades += unidades;
totalPeso += unidades * pesoUnidad;
});
// Mostrar en spans personalizados del <tfoot>
$('#footer-unidades-envio').text(totalUnidades);
$('#footer-peso').text(totalPeso.toFixed(2));
},
"columnDefs": [
{
"targets": [0],
"className": "text-center",
"orderable": false,
"searchable": false,
},
{
"targets": [1, 2, 4, 5, 6],
"className": "text-center",
},
{
targets: [6, 7, 8],
visible: false
}
]
});
}
}
document.addEventListener('DOMContentLoaded', function () {
/*const dropdown = document.querySelector(".dropdown-language");
const activeItem = dropdown.querySelector(".dropdown-menu .dropdown-item");
let locale = 'es';
if (activeItem) {
locale = activeItem.getAttribute("data-language");
}
new Ajax('/translate/getTranslation', { locale: locale, translationFile: [] }, {},
function (translations) {
window.language = JSON.parse(translations);
new EtiquetaEdit().init();
},
function (error) {
console.log("Error getting translations:", error);
}
).post();
*/
new EtiquetaEdit().init();
});
export default EtiquetaEdit;

View File

@ -2,6 +2,8 @@ import ClassSelect from '../../components/select2.js';
$(() => {
let otsFilter = '';
const selectOts = new ClassSelect($('#buscadorPedidos'), '/etiquetasTitulos/otList', "", true);
selectOts.init();
@ -26,7 +28,7 @@ $(() => {
selectDirecciones.item.on('change', () => {
$('.add-etiqueta').removeClass('d-none');
})
$('#btnAddEtiqueta').on('click', () => {
Swal.fire({
@ -59,7 +61,9 @@ $(() => {
data,
function (response) {
if (response.status) {
// OK
tableEtiquetas.ajax.reload();
// open the new etiqueta in a new tab
window.open(`${window.location.origin}/etiquetasTitulos/edit/${response.etiqueta}`, '_blank');
} else {
popErrorAlert('Error en la respuesta');
}
@ -70,4 +74,104 @@ $(() => {
}
});
})
const tableEtiquetas = $('#tableOfEquiquetas').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
orderCellsTop: true,
lengthMenu: [5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500],
pageLength: 50,
"dom": 'lBrtip',
"ajax": {
"url": "/etiquetasTitulos/datatable",
"data": function (d) {
d.otsFilter = otsFilter;
}
},
"columns": [
{ "data": "id" },
{ "data": "lista_ots" },
{ "data": "cajas" },
{ "data": "att" },
{ "data": "direccion" },
{ "data": "action" }
],
"language": {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
"columnDefs": [
{
orderable: false,
searchable: false,
targets: [5]
},
],
"order": [[0, "desc"]],
});
$(document).on('click', '.btn-edit', function (e) {
window.location.href = '/etiquetasTitulos/edit/' + $(this).attr('data-id');
});
$(document).on('click', '.btn-delete', function (e) {
Swal.fire({
title: '¿Está seguro de eliminar la etiqueta?',
text: "No podrá revertir esta acción",
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Sí',
cancelButtonText: 'Cancelar',
customClass: {
confirmButton: 'btn btn-danger me-1',
cancelButton: 'btn btn-secondary'
},
buttonsStyling: false
}).then((result) => {
if (result.isConfirmed) {
$.post(
'/etiquetasTitulos/delete',
{
id: $(this).attr('data-id')
},
function (response) {
if (response.status) {
tableEtiquetas.ajax.reload();
popSuccessAlert(response.message);
} else {
popErrorAlert('Error borrando la etiqueta');
}
}
).fail(function (xhr, status, error) {
popErrorAlert(error);
});
}
})
});
$(document).on("keyup", ".envio-filter", (event) => {
let columnName = $(event.currentTarget).attr("name");
let columnIndex = $('#tableOfEquiquetas').DataTable().columns().eq(0).filter(function (index) {
return $('#tableOfEquiquetas').DataTable().column(index).dataSrc() === columnName;
})[0];
$('#tableOfEquiquetas').DataTable().column(columnIndex).search($(event.currentTarget).val()).draw()
})
$(document).on("keyup", ".envio-filter-ots", (event) => {
otsFilter = $(event.currentTarget).val();
$('#tableOfEquiquetas').DataTable().ajax.reload();
})
$(document).on("change", ".envio-filter-select", (event) => {
let columnName = $(event.currentTarget).attr("name");
let columnIndex = $('#tableOfEquiquetas').DataTable().columns().eq(0).filter(function (index) {
return $('#tableOfEquiquetas').DataTable().column(index).dataSrc() === columnName;
})[0];
$('#tableOfEquiquetas').DataTable().column(columnIndex).search($(event.currentTarget).val()).draw();
});
})