añadido switch a los grupos para seleccionar

This commit is contained in:
2025-04-18 13:52:49 +02:00
parent 46c29f3c13
commit 65c9b34f56

View File

@ -64,7 +64,15 @@ class EnvioEdit {
totalPeso += parseFloat(row.pesoUnidad) * unidades || 0; totalPeso += parseFloat(row.pesoUnidad) * unidades || 0;
}); });
return `CAJA: ${nombreGrupo} [unidades: ${totalUnidades}, peso: <span class="peso-grupo" data-valor="${totalPeso}">${totalPeso.toFixed(1)}</span> kg]`; return `
<label class="switch switch-square">
<input type="checkbox" class="switch-input switch-grupo" data-grupo="${nombreGrupo}" id="switch-grupo-${nombreGrupo}">
<span class="switch-toggle-slider"></span>
<span class="switch-label">
CAJA: ${nombreGrupo} [unidades: ${totalUnidades}, peso: <span class="peso-grupo" data-valor="${totalPeso}">${totalPeso.toFixed(1)}</span> kg]
</span>
</label>
`;
} }
}, },
"columnDefs": [ "columnDefs": [
@ -87,6 +95,25 @@ class EnvioEdit {
"orderFixed": [[1, 'asc']], "orderFixed": [[1, 'asc']],
}); });
$('#tableLineasEnvio').on('change', '.switch-grupo', function () {
const grupo = $(this).data('grupo');
const checked = $(this).is(':checked');
const table = $('#tableLineasEnvio').DataTable();
table.rows().every(function () {
const rowData = this.data();
const node = $(this.node());
const valorCaja = (rowData.cajas === null || rowData.cajas === '' || rowData.cajas === 0 || rowData.cajas === '0')
? 'SIN ASIGNAR'
: rowData.cajas;
if (valorCaja == grupo) {
node.find('.checkbox-linea-envio').prop('checked', checked);
}
});
});
$('#tableLineasEnvio').on('draw.dt', () => { $('#tableLineasEnvio').on('draw.dt', () => {
const table = this.table; const table = this.table;
@ -119,6 +146,42 @@ class EnvioEdit {
modifyValueOnWheel: false modifyValueOnWheel: false
}); });
}); });
$('#tableLineasEnvio').on('change', '.checkbox-linea-envio', function () {
const $row = $(this).closest('tr');
const table = $('#tableLineasEnvio').DataTable();
const rowData = table.row($row).data();
const valorCaja = (rowData.cajas === null || rowData.cajas === '' || rowData.cajas === 0 || rowData.cajas === '0')
? 'SIN ASIGNAR'
: rowData.cajas;
// 1. Filtrar todas las filas del mismo grupo
let total = 0;
let seleccionadas = 0;
table.rows().every(function () {
const data = this.data();
const grupo = (data.cajas === null || data.cajas === '' || data.cajas === 0 || data.cajas === '0')
? 'SIN ASIGNAR'
: data.cajas;
if (grupo == valorCaja) {
total++;
if ($(this.node()).find('.checkbox-linea-envio').is(':checked')) {
seleccionadas++;
}
}
});
// 2. Actualizar el checkbox del grupo
const checkGrupo = $(`.switch-grupo[data-grupo="${valorCaja}"]`);
if (seleccionadas === total) {
checkGrupo.prop('checked', true);
} else {
checkGrupo.prop('checked', false);
}
});
}); });
$(document).on('click', '.btn-edit', (e) => { $(document).on('click', '.btn-edit', (e) => {