comparador cubierta y sobrecubierta terminado

This commit is contained in:
2024-12-19 11:12:40 +01:00
parent 57c34b768d
commit 77db3104d3
6 changed files with 96 additions and 112 deletions

View File

@ -240,6 +240,7 @@ class Comparador {
this.papelColor.onChange(() => this.gramajeColor.setVal(0))
this.papelColorhq.onChange(() => this.gramajeColorhq.setVal(0))
this.papelCubierta.onChange(() => this.gramajeCubierta.setVal(0))
this.papelCubierta.onChange(() => this.gramajeSobrecubierta.setVal(0))
this.tipo_impresion.select2({
@ -841,7 +842,7 @@ class Comparador {
}
}
else if (uso = 'cubierta') {
else if (uso == 'cubierta') {
if (this.papelCubierta.getVal() == 0 || this.papelCubierta.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
@ -857,7 +858,7 @@ class Comparador {
paginas = this.paginasCubierta.select2('data')[0].id
}
else if (uso = 'sobrecubierta') {
else if (uso == 'sobrecubierta') {
if (this.papelSobrecubierta.getVal() == 0 || this.papelSobrecubierta.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
@ -900,15 +901,47 @@ class Comparador {
isHq: this.tipo_impresion.val().includes('hq'),
paginas_color: paginasColor
}
// TO-DO
if(uso == 'cubierta'){
if (uso == 'cubierta') {
datos.datosPedido.lomo = this.getLomoLineasPresupuesto('interior');
datos.datosPedido.solapas = $('#solapas').prop('checked') ? 1 : 0;
datos.datosPedido.solapas_ancho = $('#solapas').prop('checked') ? parseInt($('#solapas_ancho').val()) : 0;
// TO-DO
datos.lomoRedondo = false;
}
else if (uso == 'sobrecubierta') {
datos.datosPedido.lomo = this.getLomoLineasPresupuesto() + this.getLomoLineasPresupuesto('cubierta');
datos.datosPedido.solapas = $('#solapas_sobrecubierta').prop('checked') ? 1 : 0;
datos.datosPedido.solapas_ancho = $('#solapas_sobrecubierta').prop('checked') ? parseInt($('#solapas_ancho_sobrecubierta').val()) : 0;
}
return { error: false, data: datos };
}
getLomoLineasPresupuesto(tipo_lomo='interior') {
let lomoTotal = 0
try {
$('#tableLineasPresupuesto').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
var rowData = this.data();
if (tipo_lomo = 'interior') {
if (rowData.row_id != 'lp_cubierta' && rowData.tipo != 'lp_sobrecubierta')
lomoTotal += parseFloat(rowData.lomo);
}
else if (tipo_lomo == 'cubierta') {
if (rowData.row_id == 'lp_cubierta')
lomoTotal += parseFloat(rowData.lomo);
}
})
}
catch (error) {
lomoTotal = 0;
}
$('#lomo_cubierta').val(lomoTotal);
return lomoTotal;
}
obtenerComparadorInterior(event, actualizarLineaPlana = false, actualizarLineaRot = false) {
try {
@ -1067,15 +1100,15 @@ class Comparador {
return;
}
}
else{
else {
datosComp.sobrecubierta = {};
}
}
else{
else {
datosComp.sobrecubierta = {};
}
datosComp.cubierta.data[this.csrf_token] = this.csrf_hash;
if(Object.keys(datosComp.sobrecubierta).length > 0){
if (Object.keys(datosComp.sobrecubierta).length > 0) {
datosComp.sobrecubierta.data[this.csrf_token] = this.csrf_hash;
}
new Ajax('/presupuestoadmin/comparadorexteriores',
@ -1085,22 +1118,23 @@ class Comparador {
},
{},
(response) => {
if (response.data.cubierta.length > 0) {
let sorted = response.data.cubierta.sort(
if (response.data.cubierta && Object.keys(response.data.cubierta).length > 0) {
let sorted = Object.values(response.data.cubierta).sort(
(p1, p2) => ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) < (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ?
-1 : ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) > (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ? 1 : 0);
sorted.forEach(function (linea) {
sorted[0].forEach(function (linea) {
if (typeof linea.error == "undefined")
self.tableCompCubierta.row
add(self.getRowFromLinea('cubierta', linea))
.draw()
.add(self.getRowFromLinea('cubierta', linea))
.draw();
});
}
if (response.data.sobrecubierta) {
let sorted = response.data.sobrecubierta.sort(
if (response.data.sobrecubierta && Object.keys(response.data.sobrecubierta).length > 0) {
let sorted = Object.values(response.data.sobrecubierta).sort(
(p1, p2) => ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) < (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ?
-1 : ((p1.fields.precio_pedido + p1.fields.precio_click_pedido) > (p2.fields.precio_pedido + p2.fields.precio_click_pedido)) ? 1 : 0);
sorted.forEach(function (linea) {
sorted[0].forEach(function (linea) {
if (typeof linea.error == "undefined")
self.tableCompCubierta.row
.add(self.getRowFromLinea('sobrecubierta', linea))
@ -1141,8 +1175,8 @@ class Comparador {
switch (tabla) {
case 'cubierta':
table = this.tableCompCubierta;
tipo1 = 'lp_cubierta';
tipo2 = 'lp_sobrecubierta';
tipo1 = 'cubierta';
tipo2 = 'sobrecubierta';
total_label = '#total_comp_cubierta';
break;