mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
añadido switch a los grupos para seleccionar
This commit is contained in:
@ -8,7 +8,7 @@ class EnvioEdit {
|
||||
|
||||
this.tableCols = [
|
||||
{ data: "rowSelected" },
|
||||
{ data: "cajas", defaultContent: ""},
|
||||
{ data: "cajas", defaultContent: "" },
|
||||
{ data: "pedido" },
|
||||
{ data: "presupuesto" },
|
||||
{ data: "titulo" },
|
||||
@ -64,7 +64,15 @@ class EnvioEdit {
|
||||
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": [
|
||||
@ -84,9 +92,28 @@ class EnvioEdit {
|
||||
}
|
||||
],
|
||||
"order": [[1, "asc"]],
|
||||
"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', () => {
|
||||
const table = this.table;
|
||||
@ -119,6 +146,42 @@ class EnvioEdit {
|
||||
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) => {
|
||||
@ -443,7 +506,7 @@ class EnvioEdit {
|
||||
|
||||
_addEnvioLinea() {
|
||||
|
||||
if(!this.buscarPedidos.getVal()) {
|
||||
if (!this.buscarPedidos.getVal()) {
|
||||
Swal.fire({
|
||||
title: 'Atención!',
|
||||
text: 'Debe seleccionar un pedido antes de añadir una línea de envío.',
|
||||
|
||||
Reference in New Issue
Block a user