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 = [
|
this.tableCols = [
|
||||||
{ data: "rowSelected" },
|
{ data: "rowSelected" },
|
||||||
{ data: "cajas", defaultContent: ""},
|
{ data: "cajas", defaultContent: "" },
|
||||||
{ data: "pedido" },
|
{ data: "pedido" },
|
||||||
{ data: "presupuesto" },
|
{ data: "presupuesto" },
|
||||||
{ data: "titulo" },
|
{ data: "titulo" },
|
||||||
@ -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": [
|
||||||
@ -84,9 +92,28 @@ class EnvioEdit {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"order": [[1, "asc"]],
|
"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', () => {
|
$('#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) => {
|
||||||
@ -126,7 +189,7 @@ class EnvioEdit {
|
|||||||
const id = $(e.currentTarget).data('id');
|
const id = $(e.currentTarget).data('id');
|
||||||
const row = table.row($(e.currentTarget).closest('tr'));
|
const row = table.row($(e.currentTarget).closest('tr'));
|
||||||
const rowData = row.data();
|
const rowData = row.data();
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: 'Editar unidades a enviar',
|
title: 'Editar unidades a enviar',
|
||||||
input: 'number',
|
input: 'number',
|
||||||
@ -151,7 +214,7 @@ class EnvioEdit {
|
|||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
if (result.isConfirmed) {
|
if (result.isConfirmed) {
|
||||||
const nuevasUnidades = parseInt(result.value);
|
const nuevasUnidades = parseInt(result.value);
|
||||||
|
|
||||||
$.post('/logistica/updateUnidadesEnvio', {
|
$.post('/logistica/updateUnidadesEnvio', {
|
||||||
id: rowData.id,
|
id: rowData.id,
|
||||||
unidades_envio: nuevasUnidades
|
unidades_envio: nuevasUnidades
|
||||||
@ -188,7 +251,7 @@ class EnvioEdit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.buscarPedidos.init();
|
this.buscarPedidos.init();
|
||||||
|
|
||||||
@ -196,7 +259,7 @@ class EnvioEdit {
|
|||||||
this.btnAddCaja.on('click', this._addCaja.bind(this));
|
this.btnAddCaja.on('click', this._addCaja.bind(this));
|
||||||
this.btnDeleteLinea.on('click', this._deleteLineas.bind(this));
|
this.btnDeleteLinea.on('click', this._deleteLineas.bind(this));
|
||||||
this.btnGuardarComentarios.on('click', () => {
|
this.btnGuardarComentarios.on('click', () => {
|
||||||
|
|
||||||
$.post('/logistica/updateComentariosEnvio', {
|
$.post('/logistica/updateComentariosEnvio', {
|
||||||
id: $('#id').val(),
|
id: $('#id').val(),
|
||||||
comentarios: $('#comentarios').val()
|
comentarios: $('#comentarios').val()
|
||||||
@ -443,7 +506,7 @@ class EnvioEdit {
|
|||||||
|
|
||||||
_addEnvioLinea() {
|
_addEnvioLinea() {
|
||||||
|
|
||||||
if(!this.buscarPedidos.getVal()) {
|
if (!this.buscarPedidos.getVal()) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: 'Atención!',
|
title: 'Atención!',
|
||||||
text: 'Debe seleccionar un pedido antes de añadir una línea de envío.',
|
text: 'Debe seleccionar un pedido antes de añadir una línea de envío.',
|
||||||
|
|||||||
Reference in New Issue
Block a user