diff --git a/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js b/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js
index e1e38ea3..f9debeb4 100644
--- a/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js
+++ b/httpdocs/assets/js/safekat/pages/logistica/envioEdit.js
@@ -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: ${totalPeso.toFixed(1)} kg]`;
+ return `
+
+ `;
}
},
"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) => {
@@ -126,7 +189,7 @@ class EnvioEdit {
const id = $(e.currentTarget).data('id');
const row = table.row($(e.currentTarget).closest('tr'));
const rowData = row.data();
-
+
Swal.fire({
title: 'Editar unidades a enviar',
input: 'number',
@@ -151,7 +214,7 @@ class EnvioEdit {
}).then((result) => {
if (result.isConfirmed) {
const nuevasUnidades = parseInt(result.value);
-
+
$.post('/logistica/updateUnidadesEnvio', {
id: rowData.id,
unidades_envio: nuevasUnidades
@@ -188,7 +251,7 @@ class EnvioEdit {
});
}
});
- });
+ });
this.buscarPedidos.init();
@@ -196,7 +259,7 @@ class EnvioEdit {
this.btnAddCaja.on('click', this._addCaja.bind(this));
this.btnDeleteLinea.on('click', this._deleteLineas.bind(this));
this.btnGuardarComentarios.on('click', () => {
-
+
$.post('/logistica/updateComentariosEnvio', {
id: $('#id').val(),
comentarios: $('#comentarios').val()
@@ -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.',