terminado

This commit is contained in:
2025-05-04 18:35:08 +02:00
parent 39639d9ff8
commit 7b645539e3
9 changed files with 589 additions and 74 deletions

View File

@ -16,7 +16,9 @@ class EtiquetaEdit {
{ data: "id" },
{ data: "pesoUnidad" },
{ data: "unidadesRaw" },
{ data: "action" }
{ data: "action" },
{ data: "numero_caja_raw" }
];
this.table = null;
@ -25,6 +27,9 @@ class EtiquetaEdit {
this.addLineas = $('#btnAddLinea');
this.btnEliminarLineas = $('#btnEliminarLineas');
this.btbnGuardarComentarios = $('#guardarComentarios');
this.btnSelectAll = $('#btnSelectAll');
this.btnRenumber = $('#btnRenumber');
this.btnImprimirEtiquetas = $('#btnImprimirEtiquetas');
this.buscador = new ClassSelect($('#buscadorPedidos'), '/etiquetasTitulos/findOts', '', true, { 'id': $('#id').val() });
}
@ -41,10 +46,88 @@ class EtiquetaEdit {
$(document).on('change', '.input-lineas', this._updateLinea.bind(this));
this.btnEliminarLineas.on('click', this._deleteLinea.bind(this));
this.btbnGuardarComentarios.on('click', this._guardarComentarios.bind(this));
this.btnSelectAll.on('click', this._selectAll.bind(this));
this.btnRenumber.on('click', this._renumber.bind(this));
this.btnImprimirEtiquetas.on('click', this._imprimirEtiquetas.bind(this));
}
_imprimirEtiquetas() {
const self = this;
const ids = [];
this.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
const node = this.node(); // DOM del tr
const checkbox = $(node).find('.checkbox-linea-envio');
if (checkbox.is(':checked')) {
const data = this.data();
ids.push(data.id);
}
});
$.post(
'/etiquetasTitulos/imprimirEtiquetas',
{
etiqueta_id: $('#id').val(),
ids: ids,
impresora_id: $('#impresoraEtiquetas').val()
},
function (response) {
if (response.status) {
popSuccessAlert(response.message);
if(response.data) {
// show xml in new tab
const blob = new Blob([response.data], { type: 'application/xml' });
const url = URL.createObjectURL(blob);
const newTab = window.open(url, '_blank');
if (newTab) {
newTab.onload = function () {
// Revoke the object URL after the new tab has loaded
URL.revokeObjectURL(url);
};
} else {
popErrorAlert('Error abriendo la pestaña');
}
}
} else {
popErrorAlert('Error imprimiendo las etiquetas');
}
}
).fail(function (xhr, status, error) {
popErrorAlert(error);
});
}
_renumber() {
const self = this;
$.post(
'/etiquetasTitulos/renumber',
{
id: $('#id').val()
},
function (response) {
if (response.status) {
self.table.ajax.reload();
popSuccessAlert(response.message);
} else {
popErrorAlert('Error renumerando las lineas');
}
}
).fail(function (xhr, status, error) {
popErrorAlert(error);
});
}
_selectAll() {
const checkboxes = this.table.$('input[type="checkbox"]');
const allChecked = checkboxes.length === checkboxes.filter(':checked').length;
checkboxes.prop('checked', !allChecked);
}
_initDatatable() {
const self = this;
this.table = $('#tableLineasEtiqueta').DataTable({
processing: true,
serverSide: true,
@ -52,54 +135,137 @@ class EtiquetaEdit {
responsive: true,
scrollX: true,
orderCellsTop: true,
orderable: false,
order: [[7, 'asc']],
lengthMenu: [5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500],
rowId: 'id',
order: [[10, 'asc']],
rowGroup: {
dataSrc: 'numero_caja_raw',
startRender: function (rows, group) {
let totalUnidades = 0;
let totalPeso = 0;
rows.data().each(function (row) {
const unidades = parseFloat(row.unidadesRaw) || 0;
const pesoUnidad = parseFloat(row.pesoUnidad) || 0;
totalUnidades += unidades;
totalPeso += unidades * pesoUnidad;
});
const groupId = 'grupo-caja-' + group;
return $('<tr/>')
.attr('data-group', groupId)
.addClass('group-header bg-light fw-bold')
.css('cursor', 'pointer')
.append(
`<td colspan="11">
📦 CAJA ${group} UNIDADES: ${totalUnidades} PESO: ${totalPeso.toFixed(2)} kg
</td>`
);
}
},
rowReorder: {
dataSrc: 'numero_caja_raw',
update: false,
selector: 'td:not(.dt-no-reorder)' // evita inputs
},
lengthMenu: [5, 10, 25, 50, 100],
pageLength: 50,
"dom": 'lrtip',
"ajax": {
"url": "/etiquetasTitulos/datatableLineas/" + $('#id').val(),
"data": function (d) {
ajax: {
url: "/etiquetasTitulos/datatableLineas/" + $('#id').val(),
data: function (d) {
d.direccion = $('#direccion').val();
d.id = $('#id').val();
},
},
"columns": this.tableCols,
"language": {
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": [
columnDefs: [
{
"targets": [0, 9],
"className": "text-center",
"orderable": false,
"searchable": false,
targets: [0, 9],
className: "text-center dt-no-reorder",
orderable: false,
searchable: false
},
{
"targets": [1, 2, 4, 5, 6],
"className": "text-center",
targets: [3, 4],
className: "text-center dt-no-reorder"
},
{
targets: [6, 7, 8],
targets: [1, 2, 4, 5, 6],
className: "text-center"
},
{
targets: [6, 7, 8, 10],
visible: false
}
]
});
$('#tableLineasEtiqueta tbody').on('click', 'tr.group-header', function () {
const group = $(this).data('group');
const table = $('#tableLineasEtiqueta').DataTable();
const icon = $(this).find('.group-toggle-icon');
let visible = true;
table.rows().every(function () {
const row = this.node();
const data = this.data();
if ('numero_caja' in data && ('grupo-caja-' + data.numero_caja) === group) {
if (!$(row).hasClass('group-header')) {
$(row).toggle();
visible = !$(row).is(':visible');
}
}
});
// Cambiar el icono
icon.text(visible ? '▼' : '►');
});
this.table.on('row-reorder', function (e, diff, edit) {
if (!diff.length || !edit.triggerRow) return;
const table = self.table;
const movedRowData = table.row(edit.triggerRow).data();
if (!movedRowData?.id) return;
const movedItem = diff.find(d => {
const rowData = table.row(d.node).data();
return rowData?.id === movedRowData.id;
});
if (!movedItem) return;
const payload = {
id: movedRowData.id,
numero_caja: movedItem.newData
};
$.ajax({
url: '/etiquetasTitulos/updateOrdenCajas',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ orden: [payload] }),
success: function (response) {
if (response.status) {
setTimeout(() => {
self.table.ajax.reload(null, false);
}, 100);
} else {
popErrorAlert('Error actualizando el orden');
}
},
error: function () {
popErrorAlert('Error en la solicitud AJAX');
}
});
});
}
_addLineas() {
@ -185,7 +351,7 @@ class EtiquetaEdit {
}
});
}
else{
else {
ids.push($(e.currentTarget).attr('data-id'));
}
Swal.fire({
@ -241,13 +407,16 @@ class EtiquetaEdit {
if (!response.status) {
popErrorAlert('Error actualizando la linea');
}
else {
self.table.ajax.reload();
}
}
).fail(function (xhr, status, error) {
popErrorAlert(error);
});
}
_guardarComentarios(){
_guardarComentarios() {
const self = this;
const id = $('#id').val();
const comentarios = $('#comentarios').val();
@ -263,7 +432,7 @@ class EtiquetaEdit {
if (!response.status) {
popErrorAlert('Error actualizando comentarios');
}
else{
else {
popSuccessAlert(response.message);
}
}