mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta ordenar por cajas
This commit is contained in:
@ -88,6 +88,9 @@ let ClassSelect = function (domItem, url, placeholder, allowClear = false, param
|
||||
this.getText = () => {
|
||||
return this.item.find(":selected").text();
|
||||
};
|
||||
this.getDesc = () => {
|
||||
return this.item.find(":selected").data("desc");
|
||||
};
|
||||
this.onChange = function (callback) {
|
||||
this.item.on('change', callback);
|
||||
};
|
||||
|
||||
@ -15,19 +15,35 @@ class EtiquetaEdit {
|
||||
{ data: "unidadesTotal" },
|
||||
{ data: "id" },
|
||||
{ data: "pesoUnidad" },
|
||||
{ data: "unidadesRaw" }
|
||||
{ data: "unidadesRaw" },
|
||||
{ data: "action" }
|
||||
];
|
||||
|
||||
this.table = null;
|
||||
|
||||
this.direccion = $('#direccion');
|
||||
this.addLineas = $('#btnAddLinea');
|
||||
this.btnEliminarLineas = $('#btnEliminarLineas');
|
||||
this.btbnGuardarComentarios = $('#guardarComentarios');
|
||||
|
||||
this.buscador = new ClassSelect($('#buscadorPedidos'), '/etiquetasTitulos/findOts', '', true, { 'id': $('#id').val() });
|
||||
}
|
||||
|
||||
init() {
|
||||
this.initDatatable();
|
||||
|
||||
const self = this;
|
||||
|
||||
this._initDatatable();
|
||||
this.buscador.init();
|
||||
|
||||
this.addLineas.on('click', this._addLineas.bind(this));
|
||||
$(document).on('click', '.btn-delete', this._deleteLinea.bind(this));
|
||||
$(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));
|
||||
}
|
||||
|
||||
initDatatable() {
|
||||
_initDatatable() {
|
||||
|
||||
this.table = $('#tableLineasEtiqueta').DataTable({
|
||||
processing: true,
|
||||
@ -69,7 +85,7 @@ class EtiquetaEdit {
|
||||
},
|
||||
"columnDefs": [
|
||||
{
|
||||
"targets": [0],
|
||||
"targets": [0, 9],
|
||||
"className": "text-center",
|
||||
"orderable": false,
|
||||
"searchable": false,
|
||||
@ -84,8 +100,178 @@ class EtiquetaEdit {
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
_addLineas() {
|
||||
if (this.buscador.item.select2('data').length > 0) {
|
||||
|
||||
let maxUnidades = 0;
|
||||
if (this.buscador.item.select2('data')[0].desc) {
|
||||
maxUnidades = parseInt(this.buscador.item.select2('data')[0].desc);
|
||||
Swal.fire({
|
||||
title: 'Unidades',
|
||||
html: `
|
||||
<div class="mb-2">
|
||||
<label for="inputUnidades">Unidades:</label>
|
||||
<input type="number" id="inputUnidades" class="swal2-input" value="${maxUnidades}">
|
||||
</div>
|
||||
<div>
|
||||
<label for="inputCajas">Cajas:</label>
|
||||
<input type="number" id="inputCajas" class="swal2-input" value="1">
|
||||
</div>
|
||||
`,
|
||||
icon: 'info',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
confirmButtonText: 'Aceptar',
|
||||
cancelButtonText: 'Cancelar',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-primary me-1',
|
||||
cancelButton: 'btn btn-secondary'
|
||||
},
|
||||
buttonsStyling: false,
|
||||
preConfirm: () => {
|
||||
const unidades = parseInt(document.getElementById('inputUnidades').value);
|
||||
const cajas = parseInt(document.getElementById('inputCajas').value);
|
||||
if (isNaN(unidades) || isNaN(cajas)) {
|
||||
Swal.showValidationMessage('Debe completar ambos campos');
|
||||
}
|
||||
return { unidades, cajas };
|
||||
}
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
const { unidades, cajas } = result.value;
|
||||
const url = '/etiquetasTitulos/addLineas';
|
||||
const data = {
|
||||
etiqueta_id: $('#id').val(),
|
||||
ot_id: this.buscador.getVal(),
|
||||
unidades: unidades,
|
||||
cajas: cajas
|
||||
};
|
||||
$.post(
|
||||
url,
|
||||
data,
|
||||
function (response) {
|
||||
if (response.status) {
|
||||
self.table.ajax.reload();
|
||||
popSuccessAlert(response.message);
|
||||
|
||||
} else {
|
||||
popErrorAlert('Error en la respuesta');
|
||||
}
|
||||
}
|
||||
).fail(function (xhr, status, error) {
|
||||
popErrorAlert(error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_deleteLinea(e) {
|
||||
e.preventDefault();
|
||||
const self = this;
|
||||
let ids = [];
|
||||
if (e.currentTarget.id == "btnEliminarLineas") {
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
else{
|
||||
ids.push($(e.currentTarget).attr('data-id'));
|
||||
}
|
||||
Swal.fire({
|
||||
title: '¿Está seguro de eliminar la linea?',
|
||||
text: "No podrá revertir esta acción",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sí',
|
||||
cancelButtonText: 'Cancelar',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-danger me-1',
|
||||
cancelButton: 'btn btn-secondary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.post(
|
||||
'/etiquetasTitulos/deleteLineas',
|
||||
{
|
||||
ids: ids
|
||||
},
|
||||
function (response) {
|
||||
if (response.status) {
|
||||
self.table.ajax.reload();
|
||||
popSuccessAlert(response.message);
|
||||
} else {
|
||||
popErrorAlert('Error borrando la etiqueta');
|
||||
}
|
||||
}
|
||||
).fail(function (xhr, status, error) {
|
||||
popErrorAlert(error);
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
_updateLinea(e) {
|
||||
e.preventDefault();
|
||||
const self = this;
|
||||
const id = $(e.currentTarget).attr('data-id');
|
||||
const name = $(e.currentTarget).attr('data-name');
|
||||
const value = $(e.currentTarget).val();
|
||||
const url = '/etiquetasTitulos/updateLineas';
|
||||
const data = {
|
||||
id: id,
|
||||
name: name,
|
||||
value: value
|
||||
};
|
||||
$.post(
|
||||
url,
|
||||
data,
|
||||
function (response) {
|
||||
if (!response.status) {
|
||||
popErrorAlert('Error actualizando la linea');
|
||||
}
|
||||
}
|
||||
).fail(function (xhr, status, error) {
|
||||
popErrorAlert(error);
|
||||
});
|
||||
}
|
||||
|
||||
_guardarComentarios(){
|
||||
const self = this;
|
||||
const id = $('#id').val();
|
||||
const comentarios = $('#comentarios').val();
|
||||
const url = '/etiquetasTitulos/updateComentarios';
|
||||
const data = {
|
||||
id: id,
|
||||
comentarios: comentarios
|
||||
};
|
||||
$.post(
|
||||
url,
|
||||
data,
|
||||
function (response) {
|
||||
if (!response.status) {
|
||||
popErrorAlert('Error actualizando comentarios');
|
||||
}
|
||||
else{
|
||||
popSuccessAlert(response.message);
|
||||
}
|
||||
}
|
||||
).fail(function (xhr, status, error) {
|
||||
popErrorAlert(error);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
Reference in New Issue
Block a user