Files
safekat/httpdocs/assets/js/safekat/pages/presupuestoAdmin/sections/comparador.js

1896 lines
80 KiB
JavaScript

import ClassSelect from '../../../components/select2.js';
import { getToken } from '../../../common/common.js';
import Ajax from '../../../components/ajax.js';
class Comparador {
constructor(domItem, cargando, functions = {}) {
this.domItem = domItem;
this.cargando = cargando;
this.getDimensionLibro = functions.getDimensionLibro;
this.tipo_impresion_id = parseInt($('#tipo_impresion_id').val());
this.csrf_token = getToken();
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
this.comparador_json = this.domItem.find("#comparador_json_data");
this.tipo_impresion = $("#tipoImpresion");
this.paginasNegro = $('#compPaginasNegro');
this.papelNegro = new ClassSelect($('#compPapelNegro'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'negro',
});
this.gramajeNegro = new ClassSelect($('#compGramajeNegro'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelNegro.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'negro',
});
this.paginasColor = $('#compPaginasColor');
this.papelColor = new ClassSelect($('#compPapelColor'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'color',
});
this.gramajeColor = new ClassSelect($('#compGramajeColor'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelColor.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'color',
});
this.paginasNegrohq = $('#compPaginasNegrohq');
this.papelNegrohq = new ClassSelect($('#compPapelNegrohq'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'negrohq',
});
this.gramajeNegrohq = new ClassSelect($('#compGramajeNegrohq'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelNegrohq.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'negrohq',
});
this.paginasColorhq = $('#compPaginasColorhq');
this.papelColorhq = new ClassSelect($('#compPapelColorhq'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'colorhq',
});
this.gramajeColorhq = new ClassSelect($('#compGramajeColorhq'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelColorhq.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'colorhq',
});
this.paginasCubierta = $('#compCarasCubierta');
this.papelCubierta = new ClassSelect($('#compPapelCubierta'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: () => $('#solapas').prop('checked') ? $('#solapas_ancho').val() : 0,
lomo: () => $('#lomo_cubierta').val(),
tipo: 'colorhq',
uso: 'cubierta',
});
this.gramajeCubierta = new ClassSelect($('#compGramajeCubierta'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelCubierta.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: () => $('#solapas').prop('checked') ? $('#solapas_ancho').val() : 0,
lomo: () => $('#lomo_cubierta').val(),
tipo: 'colorhq',
uso: 'cubierta',
});
if (this.tipo_impresion_id != 5 && this.tipo_impresion_id != 6 && this.tipo_impresion_id != 7 && this.tipo_impresion_id != 8 && this.tipo_impresion_id != 21) {
this.sobrecubierta = $('#compSobrecubierta');
this.papelSobrecubierta = new ClassSelect($('#compPapelSobrecubierta'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: () => $('#solapas').prop('checked') ? $('#solapas_ancho').val() : 0,
lomo: () => $('#lomo_sobrecubierta').val(),
tipo: 'colorhq',
uso: 'sobrecubierta',
});
this.gramajeSobrecubierta = new ClassSelect($('#compGramajeSobrecubierta'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelSobrecubierta.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: () => $('#solapas').prop('checked') ? $('#solapas_ancho').val() : 0,
lomo: () => $('#lomo_sobrecubierta').val(),
tipo: 'colorhq',
uso: 'sobrecubierta',
});
}
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
this.papelGuardas = new ClassSelect($('#compPapelGuardas'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'colorhq',
uso: 'guardas',
});
this.gramajeGuardas = new ClassSelect($('#compGramajeGuardas'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelCubierta.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => this.getDimensionLibro().alto,
sopalas: 0,
lomo: 0,
tipo: 'colorhq',
uso: 'guardas',
});
this.carasGuardas = $('#compCarasGuardas');
this.btnInsertarGuardas = $('#insertarGuardasBtn');
}
this.faja = $('#compFaja');
this.papelFaja = new ClassSelect($('#compPapelFaja'),
'/presupuestoadmin/papelgenerico', 'Seleccione papel', false,
{
[this.csrf_token]: this.csrf_hash,
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => $('faja_alto').val(),
sopalas: () => $('#faja_solapas_ancho').val(),
lomo: () => $('#lomo_sobrecubierta').val(),
tipo: 'colorhq',
uso: 'sobrecubierta',
});
this.gramajeFaja = new ClassSelect($('#compGramajeFaja'),
'/presupuestoadmin/papelgramaje', 'Seleccione gramaje', false,
{
[this.csrf_token]: this.csrf_hash,
papel_generico: () => this.papelFaja.getVal(),
tipo_impresion: this.tipo_impresion_id,
tirada: () => $('#tirada').val(),
ancho: () => this.getDimensionLibro().ancho,
alto: () => $('faja_alto').val(),
sopalas: () => $('#faja_solapas_ancho').val(),
lomo: () => $('#lomo_sobrecubierta').val(),
tipo: 'colorhq',
uso: 'sobrecubierta',
});
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
this.lomoRedondo = $('#compLomoRedondo');
this.cabezada = $('#cabezada');
}
this.posPagColor = $('#compPosPaginasColor');
this.calculatedColorPages = $('#compCalPaginasColor');
this.tableCompCubierta = null;
this.tableCompGuardas = null;
this.tableCompIntPlana = null;
this.tableCompIntRotativa = null;
this.tableCompFaja = null;
this.btnInsertarPlana = $('#insertarPlanaBtn');
this.btnInsertarRotativa = $('#insertarRotativaBtn');
this.btnInsertarCubierta = $('#insertarCubiertaBtn');
this.btnInsertarFaja = $('#insertarFajaBtn');
this.comparadorPlanaRunning = false;
}
init() {
autosize($('#compCalPaginasColor'));
this.generateTables();
this.initSelect2();
this.initEvents();
}
initSelect2() {
const self = this;
this.paginasCubierta.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
if ($('#tipo_impresion_id').val() == 1 || $('#tipo_impresion_id').val() == 3 ||
$('#tipo_impresion_id').val() == 5 || $('#tipo_impresion_id').val() == 7) {
this.papelGuardas.init();
this.carasGuardas.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
}
this.papelNegro.init();
this.gramajeNegro.init();
this.papelColor.init();
this.gramajeColor.init();
this.papelNegrohq.init();
this.gramajeNegrohq.init();
this.papelColorhq.init();
this.gramajeColorhq.init();
this.papelCubierta.init();
this.gramajeCubierta.init();
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
this.lomoRedondo.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
this.cabezada.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
}
this.faja.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
this.papelFaja.init();
this.gramajeFaja.init();
this.papelFaja.onChange(() => self.gramajeFaja.empty());
if (this.tipo_impresion_id != 5 && this.tipo_impresion_id != 6 && this.tipo_impresion_id != 7 && this.tipo_impresion_id != 8 && this.tipo_impresion_id != 21) {
this.sobrecubierta.select2({
allowClear: false,
minimumResultsForSearch: Infinity,
});
this.papelSobrecubierta.init();
this.gramajeSobrecubierta.init();
this.papelSobrecubierta.onChange(() => self.gramajeSobrecubierta.empty());
this.sobrecubierta.on('change', () => {
if (this.sobrecubierta.select2('data')[0].id == 1) {
if ($('#solapas_sobrecubierta').prop('checked') == false) {
this.sobrecubierta.val(0);
popErrorAlert(window.language.Presupuestos.errores.error_sobrecubierta_sin_solapas, 'divAlarmasComparador')
}
$('#solapas_sobrecubierta').prop('checked', true);
$('#div_solapas_ancho_sobrecubierta').removeClass('d-none');
$('#solapas_ancho_sobrecubierta').val(60);
$('#compPapelSobrecubierta').prop('disabled', false);
$('#compGramajeSobrecubierta').prop('disabled', false);
}
else {
this.papelSobrecubierta.setVal(0);
this.gramajeSobrecubierta.setVal(0);
$('#compPapelSobrecubierta').prop('disabled', true);
$('#compGramajeSobrecubierta').prop('disabled', true);
}
});
}
this.faja.on('change', () => {
if (this.faja.select2('data')[0].id == 1) {
if ($('#faja').prop('checked') == false) {
this.faja.val(0);
popErrorAlert(window.language.Presupuestos.errores.error_faja_sin_solapas, 'divAlarmasComparador');
}
$('#faja').prop('checked', true);
$('.faja-div').removeClass('d-none');
$('#compPapelFaja').prop('disabled', false);
$('#compGramajeFaja').prop('disabled', false);
}
else {
this.papelFaja.setVal(0);
this.gramajeFaja.setVal(0);
$('#compPapelFaja').prop('disabled', true);
$('#compGramajeFaja').prop('disabled', true);
}
});
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
this.papelGuardas.init();
this.gramajeGuardas.init();
this.papelGuardas.onChange(() => self.gramajeGuardas.empty());
}
this.papelNegro.onChange(() => self.gramajeNegro.empty());
this.papelNegrohq.onChange(() => self.gramajeNegrohq.empty());
this.papelColor.onChange(() => self.gramajeColor.empty());
this.papelColorhq.onChange(() => self.gramajeColorhq.empty());
this.papelCubierta.onChange(() => self.gramajeCubierta.empty());
this.tipo_impresion.select2({
allowClear: false,
});
this.posPagColor.on('keyup', () => this.#computarPaginasColor(this.posPagColor.val()));
}
initEvents() {
this.tipo_impresion.on("change", this.#handleTipoImpresion.bind(this));
$('.accordion-button').on('click', function (e) {
if (e.target.id.includes("plana")) {
$("#tableCompIntPlana").DataTable().columns.adjust();
}
else if (e.target.id.includes("rotativa")) {
$("#tableCompIntRotativa").DataTable().columns.adjust();
}
else if (e.target.id.includes("cubierta")) {
$("#tableCompCubierta").DataTable().columns.adjust();
}
else if (e.target.id.includes("guardas")) {
$("#tableCompGuardas").DataTable().columns.adjust();
}
else if (e.target.id.includes("faja")) {
$("#tableCompFaja").DataTable().columns.adjust();
}
else if (e.target.id.includes("LineasPresupuesto")) {
$("#tableLineasPresupuesto").DataTable().columns.adjust();
}
});
$('.comp_negro_items').on('change', this.obtenerComparadorInterior.bind(this));
$('.comp_negrohq_items').on('change', this.obtenerComparadorInterior.bind(this));
$('.comp_color_items').on('change', this.obtenerComparadorInterior.bind(this));
$('.comp_colorhq_items').on('change', this.obtenerComparadorInterior.bind(this));
$('.comp_cubierta_items').on('change', this.obtenerComparadorExteriores.bind(this));
if (this.tipo_impresion_id != 5 && this.tipo_impresion_id != 6 && this.tipo_impresion_id != 7 && this.tipo_impresion_id != 8 && this.tipo_impresion_id != 21) {
$('.comp_sobrecubierta_items').on('change', this.obtenerComparadorExteriores.bind(this));
}
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
$('.comp_guardas_items').on('change', this.obtenerComparadorGuardas.bind(this));
}
$('.comp_faja_items').on('change', this.obtenerComparadorFaja.bind(this));
}
#changePaginasComparador(element) {
const paginas = parseInt($('#paginas').val());
const newPaginas = parseInt($('#' + element).val());
if (paginas < newPaginas) {
$('#' + element).val(paginas)
}
if (element == this.paginasNegro.attr('id')) {
if (!$('.comp-color-selected').hasClass('d-none')) {
this.paginasColor.val((paginas - newPaginas) > 0 ? paginas - newPaginas : 0);
}
}
else if (element == this.paginasNegrohq.attr('id')) {
if (!$('.comp-colorhq-selected').hasClass('d-none')) {
this.paginasColorhq.val((paginas - newPaginas) > 0 ? paginas - newPaginas : 0);
}
}
else if (element == this.paginasColor.attr('id')) {
this.paginasNegro.val((paginas - newPaginas) > 0 ? paginas - newPaginas : 0);
}
else if (element == this.paginasColorhq.attr('id')) {
this.paginasNegrohq.val((paginas - newPaginas) > 0 ? paginas - newPaginas : 0);
}
}
cargarDatos(datos) {
this.tipo_impresion.val(datos.tipo_impresion).trigger('change');
this.updateOpcionesComparador();
if (datos.json_data != null) {
this.comparador_json.val(JSON.stringify(datos.json_data));
if (datos.json_data.bn) {
this.paginasNegro.val(datos.json_data.bn.paginas);
this.papelNegro.setOption(datos.json_data.bn.papel_id, datos.json_data.bn.papel_nombre);
this.gramajeNegro.setOption(datos.json_data.bn.gramaje, datos.json_data.bn.gramaje);
}
else {
this.paginasNegro.val(0);
}
if (datos.json_data.bnhq) {
this.paginasNegrohq.val(datos.json_data.bnhq.paginas);
this.papelNegrohq.setOption(datos.json_data.bnhq.papel_id, datos.json_data.bnhq.papel_nombre);
this.gramajeNegrohq.setOption(datos.json_data.bnhq.gramaje, datos.json_data.bnhq.gramaje);
}
else {
this.paginasNegrohq.val(0);
}
if (datos.json_data.color) {
this.paginasColor.val(datos.json_data.color.paginas);
this.papelColor.setOption(datos.json_data.color.papel_id, datos.json_data.color.papel_nombre);
this.gramajeColor.setOption(datos.json_data.color.gramaje, datos.json_data.color.gramaje);
}
else {
this.paginasColor.val(0);
}
if (datos.json_data.colorhq) {
this.paginasColorhq.val(datos.json_data.colorhq.paginas);
this.papelColorhq.setOption(datos.json_data.colorhq.papel_id, datos.json_data.colorhq.papel_nombre);
this.gramajeColorhq.setOption(datos.json_data.colorhq.gramaje, datos.json_data.colorhq.gramaje);
}
else {
this.paginasColorhq.val(0);
}
if (datos.json_data.cubierta) {
this.paginasCubierta.val(datos.json_data.cubierta.paginas);
this.papelCubierta.setOption(datos.json_data.cubierta.papel_id, datos.json_data.cubierta.papel_nombre);
this.gramajeCubierta.setOption(datos.json_data.cubierta.gramaje, datos.json_data.cubierta.gramaje);
}
if (datos.json_data.sobrecubierta) {
this.sobrecubierta.val(datos.json_data.sobrecubierta.imprimir).trigger('change');
this.papelSobrecubierta.setOption(datos.json_data.sobrecubierta.papel_id, datos.json_data.sobrecubierta.papel_nombre);
this.gramajeSobrecubierta.setOption(datos.json_data.sobrecubierta.gramaje, datos.json_data.sobrecubierta.gramaje);
}
if (datos.json_data.guardas) {
this.carasGuardas.val(datos.json_data.guardas.paginas).trigger('change');
this.papelGuardas.setOption(datos.json_data.guardas.papel_id, datos.json_data.guardas.papel_nombre);
this.gramajeGuardas.setOption(datos.json_data.guardas.gramaje, datos.json_data.guardas.gramaje);
}
if (datos.json_data.faja) {
this.faja.val(1).trigger('change');
this.papelFaja.setOption(datos.json_data.faja.papel_id, datos.json_data.faja.papel_nombre);
this.gramajeFaja.setOption(datos.json_data.faja.gramaje, datos.json_data.faja.gramaje);
}
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
this.lomoRedondo.val(datos.lomoRedondo ? 1 : 0).trigger('change');
this.cabezada.val(datos.cabezada).trigger('change');
}
if (datos.posPagColor != null && datos.posPagColor.length > 0) {
this.posPagColor.val(datos.posPagColor);
this.#computarPaginasColor(datos.posPagColor);
}
}
}
updateComparador(){
if (this.paginasColor.val() > 0) {
this.paginasColor.trigger('change');
}
else if (this.paginasColorhq.val() > 0) {
this.paginasColorhq.trigger('change');
}
else if (this.paginasNegro.val() > 0) {
this.paginasNegro.trigger('change');
}
else if (this.paginasNegrohq.val() > 0) {
this.paginasNegrohq.trigger('change');
}
this.paginasCubierta.trigger('change');
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
this.carasGuardas.trigger('change');
}
this.faja.trigger('change');
}
generateTables() {
this.tableCompIntPlana = new DataTable('#tableCompIntPlana', {
scrollX: true,
searching: false,
paging: false,
info: false,
ordering: false,
responsive: true,
select: false,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: [
{
'data': 'tipo',
'render': function (data, type, row, meta) {
if (data == 'bn')
return window.language.Presupuestos.bn;
else if (data == 'bnhq')
return window.language.Presupuestos.bnhq;
else if (data == 'color')
return window.language.Presupuestos.color;
else if (data == 'colorhq')
return window.language.Presupuestos.colorhq;
}
},
{ 'data': 'paginas' },
{ 'data': 'papel' },
{ 'data': 'gramaje' },
{ 'data': 'marca' },
{ 'data': 'maquina' },
{ 'data': 'numeroPliegos' },
{ 'data': 'pliegosPedido' },
{ 'data': 'precioPliego' },
{ 'data': 'libro' },
{ 'data': 'totalPapelPedido' },
{ 'data': 'lomo' },
{ 'data': 'peso' },
{ 'data': 'horasMaquina' },
{ 'data': 'precioImpresion' },
{ 'data': 'total' },
{ 'data': 'maquinaId' },
{ 'data': 'maquinaVelocidad' },
{ 'data': 'tiempoMaquina' },
{ 'data': 'papelGenericoId' },
{ 'data': 'papelImpresionId' },
{ 'data': 'tarifa_impresion_id' }
],
columnDefs: [
{
target: [16, 17, 18, 19, 20, 21],
visible: false,
searchable: false
},
]
});
this.tableCompIntRotativa = new DataTable('#tableCompIntRotativa', {
scrollX: true,
searching: false,
paging: false,
info: false,
ordering: false,
responsive: true,
select: false,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: [
{
'data': 'tipo',
'render': function (data, type, row, meta) {
if (data == 'rotativa')
return window.language.Presupuestos.rotativa;
}
},
{ 'data': 'paginas' },
{ 'data': 'papel' },
{ 'data': 'gramaje' },
{ 'data': 'marca' },
{
'data': 'aFavorFibra',
'render': function (data, type, row, meta) {
if (data == 'si')
return window.language.Presupuestos.si;
else if (data == 'no')
return window.language.Presupuestos.no;
}
},
{ 'data': 'maquina' },
{ 'data': 'numeroPliegos' },
{ 'data': 'pliegosPedido' },
{ 'data': 'precioPliego' },
{ 'data': 'libro' },
{ 'data': 'totalPapelPedido' },
{ 'data': 'lomo' },
{ 'data': 'peso' },
{ 'data': 'horasMaquina' },
{ 'data': 'precioImpresion' },
{ 'data': 'precioPagNegro' },
{ 'data': 'precioPagColor' },
{ 'data': 'totalTinta' },
{ 'data': 'totalCorte' },
{ 'data': 'total' },
{ 'data': 'maquinaId' },
{ 'data': 'maquinaVelocidad' },
{ 'data': 'tiempoMaquina' },
{ 'data': 'papelGenericoId' },
{ 'data': 'papelImpresionId' },
{ 'data': 'paginasColor' },
{ 'data': 'tarifa_impresion_id' }
],
columnDefs: [
{
target: [21, 22, 23, 24, 25, 26, 27],
visible: false,
searchable: false
},
]
});
this.tableCompCubierta = new DataTable('#tableCompCubierta', {
scrollX: true,
searching: false,
paging: false,
info: false,
ordering: true,
responsive: true,
select: false,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: [
{
'data': 'tipo',
'render': function (data, type, row, meta) {
if (data == 'cubierta')
return window.language.Presupuestos.cubierta;
else if (data == 'sobrecubierta')
return window.language.Presupuestos.sobrecubierta;
}
},
{ 'data': 'paginas' },
{ 'data': 'papel' },
{ 'data': 'gramaje' },
{ 'data': 'marca' },
{ 'data': 'maquina' },
{ 'data': 'numeroPliegos' },
{ 'data': 'pliegosPedido' },
{ 'data': 'precioPliego' },
{ 'data': 'libro' },
{ 'data': 'totalPapelPedido' },
{ 'data': 'lomo' },
{ 'data': 'peso' },
{ 'data': 'horasMaquina' },
{ 'data': 'precioImpresion' },
{ 'data': 'total' },
{ 'data': 'maquinaId' },
{ 'data': 'maquinaVelocidad' },
{ 'data': 'tiempoMaquina' },
{ 'data': 'papelGenericoId' },
{ 'data': 'papelImpresionId' },
{ 'data': 'tarifa_impresion_id' }
],
columnDefs: [
{
target: [16, 17, 18, 19, 20, 21],
visible: false,
searchable: false
},
],
"order": [[0, 'asc'], [15, 'asc']]
});
this.tableCompFaja = new DataTable('#tableCompFaja', {
scrollX: true,
searching: false,
paging: false,
info: false,
ordering: true,
responsive: true,
select: false,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: [
{
'data': 'tipo',
'render': function (data, type, row, meta) {
if (data == 'faja')
return window.language.Presupuestos.faja;
}
},
{ 'data': 'paginas' },
{ 'data': 'papel' },
{ 'data': 'gramaje' },
{ 'data': 'marca' },
{ 'data': 'maquina' },
{ 'data': 'numeroPliegos' },
{ 'data': 'pliegosPedido' },
{ 'data': 'precioPliego' },
{ 'data': 'libro' },
{ 'data': 'totalPapelPedido' },
{ 'data': 'lomo' },
{ 'data': 'peso' },
{ 'data': 'horasMaquina' },
{ 'data': 'precioImpresion' },
{ 'data': 'total' },
{ 'data': 'maquinaId' },
{ 'data': 'maquinaVelocidad' },
{ 'data': 'tiempoMaquina' },
{ 'data': 'papelGenericoId' },
{ 'data': 'papelImpresionId' },
{ 'data': 'tarifa_impresion_id' }
],
columnDefs: [
{
target: [16, 17, 18, 19, 20, 21],
visible: false,
searchable: false
},
],
"order": [[15, 'asc']]
});
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3 || this.tipo_impresion_id == 5 || this.tipo_impresion_id == 7) {
this.tableCompGuardas = new DataTable('#tableCompGuardas', {
scrollX: true,
searching: false,
paging: false,
info: false,
ordering: false,
responsive: true,
select: false,
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columns: [
{
'data': 'tipo',
'render': function (data, type, row, meta) {
return window.language.Presupuestos.Guardas;
}
},
{ 'data': 'paginas' },
{ 'data': 'papel' },
{ 'data': 'gramaje' },
{ 'data': 'marca' },
{ 'data': 'maquina' },
{ 'data': 'numeroPliegos' },
{ 'data': 'pliegosPedido' },
{ 'data': 'precioPliego' },
{ 'data': 'libro' },
{ 'data': 'totalPapelPedido' },
{ 'data': 'lomo' },
{ 'data': 'peso' },
{ 'data': 'horasMaquina' },
{ 'data': 'precioImpresion' },
{ 'data': 'total' },
{ 'data': 'maquinaId' },
{ 'data': 'maquinaVelocidad' },
{ 'data': 'tiempoMaquina' },
{ 'data': 'papelGenericoId' },
{ 'data': 'papelImpresionId' },
{ 'data': 'tarifa_impresion_id' },
{ 'data': 'paginas_impresion' },
],
columnDefs: [
{
target: [16, 17, 18, 19, 20, 21, 22],
visible: false,
searchable: false
},
]
});
}
}
updateOpcionesComparador() {
$('.comp_negro_items').off('change');
$('.comp_negrohq_items').off('change');
$('.comp_color_items').off('change');
$('.comp_colorhq_items').off('change');
this.tableCompIntPlana.clear().draw();
this.tableCompIntRotativa.clear().draw();
const selValue = this.tipo_impresion.val();
const elements_negro = $('.comp-negro-selected');
const elements_negrohq = $('.comp-negrohq-selected');
const elements_color = $('.comp-color-selected');
const elements_colorhq = $('.comp-colorhq-selected');
if (selValue.includes("hq")) {
Array.from(elements_negro).forEach(element => {
$(element).addClass('d-none');
});
Array.from(elements_color).forEach(element => {
$(element).addClass('d-none');
});
if (selValue.includes('color')) {
Array.from(elements_colorhq).forEach(element => {
$(element).removeClass('d-none');
});
}
else {
Array.from(elements_colorhq).forEach(element => {
$(element).addClass('d-none');
});
}
Array.from(elements_negrohq).forEach(element => {
$(element).removeClass('d-none');
});
}
else {
Array.from(elements_negrohq).forEach(element => {
$(element).addClass('d-none');
});
Array.from(elements_colorhq).forEach(element => {
$(element).addClass('d-none');
});
if (selValue.includes('color')) {
Array.from(elements_color).forEach(element => {
$(element).removeClass('d-none');
});
}
else {
Array.from(elements_color).forEach(element => {
$(element).addClass('d-none');
});
}
Array.from(elements_negro).forEach(element => {
$(element).removeClass('d-none');
});
}
$('.comp_negro_items').on('change', this.obtenerComparadorInterior.bind(this));
$('.comp_negrohq_items').on('change', this.obtenerComparadorInterior.bind(this));
$('.comp_color_items').on('change', this.obtenerComparadorInterior.bind(this));
$('.comp_colorhq_items').on('change', this.obtenerComparadorInterior.bind(this));
if (selValue.includes('color')) {
$('.pos-paginas-color').removeClass('d-none');
}
else {
$('.pos-paginas-color').addClass('d-none');
}
}
#computarPaginasColor(string) {
var numbers = [];
for (const [, beginStr, endStr] of string.matchAll(/(\d+)(?:-(\d+))?/g)) {
const [begin, end] = [beginStr, endStr].map(Number);
numbers.push(begin);
if (endStr !== undefined) {
for (let num = begin + 1; num <= end; num++) {
numbers.push(num);
}
}
}
var numbers2 = [];
numbers.forEach(function (value, i) {
// Si es impar y no está el siguiente par hay que añadirlo
if (value % 2 != 0 && numbers[i + 1] != value + 1) {
numbers2.push(value + 1);
}
});
numbers = numbers.concat(numbers2);
numbers.sort(function (a, b) {
return a - b;
});
this.calculatedColorPages.val(numbers);
autosize.update(this.calculatedColorPages);
}
#handleTipoImpresion() {
this.updateOpcionesComparador();
$('#title_int_rot').html(window.language.Presupuestos.compInteriorRotativa);
$('#title_int_plana').html(window.language.Presupuestos.compInteriorPlana);
if (($('#tipoImpresion').select2('data')[0].id == 'negro' ||
$('#tipoImpresion').select2('data')[0].id == 'color')) {
$('#tableCompIntRotativa').DataTable().clear().draw();
$('#total_comp_rot').html("0.00");
$('#compPaginasColor').val('0')
$('#compPaginasColorhq').val('0')
$('#compPaginasNegrohq').val('0');
$('#compPaginasNegro').val($('#paginas').val())
if ($('#tipoImpresion').select2('data')[0].id == 'negro') {
$('#compGramajeColor').val('').trigger('change')
$('#compPapelColor').val(0).trigger('change')
}
if ($('#tableCompIntPlana').DataTable().rows().count() > 0 &&
$('#tableCompIntPlana').DataTable().cell(0, 0).data().includes('hq')) {
$('#tableCompIntPlana').DataTable().clear().draw();
$('#total_comp_plana').html("0.00");
}
}
else if (($('#tipoImpresion').select2('data')[0].id == 'negrohq' ||
$('#tipoImpresion').select2('data')[0].id == 'colorhq')) {
$('#tableCompIntRotativa').DataTable().clear().draw();
$('#total_comp_rot').html("0.00");
$('#compPaginasColorhq').val('0')
$('#compPaginasColor').val('0')
$('#compPaginasNegro').val('0')
$('#compPaginasNegrohq').val($('#paginas').val())
if ($('#tipoImpresion').select2('data')[0].id == 'negrohq') {
$('#compGramajeColorhq').val('').trigger('change')
$('#compPapelColorhq').val(0).trigger('change')
}
if ($('#tableCompIntPlana').DataTable().rows().count() > 0 &&
!$('#tableCompIntPlana').DataTable().cell(0, 0).data().includes('hq')) {
$('#tableCompIntPlana').DataTable().clear().draw();
$('#total_comp_plana').html("0.00");
}
}
if (!this.cargando)
$('#paginas').trigger('change');
}
getDataForComp(uso = 'interior') {
if(this.cargando)
return { error: true, data: {} };
let ancho = 0;
let alto = 0;
let papel_generico = {};
let gramaje = {};
let paginasColor = 0;
let paginas = parseInt($('#paginas').val());
if (!$('#papelFormatoPersonalizado').prop('checked')) {
const selectedFormat = $('#papelFormatoId').select2('data')[0].text;
ancho = Math.round(parseFloat(selectedFormat.trim().split(" x ")[0]), 2);
alto = Math.round(parseFloat(selectedFormat.trim().split(" x ")[1]), 2);
}
else {
ancho = Math.round(parseFloat($('#papelFormatoAncho').val()), 2);
alto = Math.round(parseFloat($('#papelFormatoAlto').val()), 2);
}
if (parseInt($('#paginas').val()) <= 0) {
popErrorAlert(window.language.Presupuestos.errores.paginas, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (parseInt($('#tirada').val()) <= 0) {
popErrorAlert(window.language.Presupuestos.errores.tiradas, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (ancho && alto) {
if (alto < 60 || ancho < 60 || isNaN(alto) || isNaN(ancho)) {
popErrorAlert(window.language.Presupuestos.errores.dimension, 'divAlarmasComparador');
return { error: true, data: {} };
}
}
else {
popErrorAlert(window.language.Presupuestos.errores.dimension, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (uso == 'interior') {
let papeles = [];
let gramajes = [];
if (this.tipo_impresion.val().includes('hq')) {
if (this.tipo_impresion.val().includes('color')) {
papeles.push(this.papelColorhq);
gramajes.push(this.gramajeColorhq);
}
papeles.push(this.papelNegrohq);
gramajes.push(this.gramajeNegrohq);
}
else {
if (this.tipo_impresion.val().includes('color')) {
papeles.push(this.papelColor);
gramajes.push(this.gramajeColor);
}
papeles.push(this.papelNegro);
gramajes.push(this.gramajeNegro);
}
for (let element of papeles) {
if (element.getVal() == 0 || element.getVal() == null) {
const tipo = element.item.attr('id').split('Papel')[1];
if ($('#compPaginas' + tipo).val() > 0) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
}
}
};
for (let element of gramajes) {
if (element.getVal() == 0 || element.getVal() == null) {
const tipo = element.item.attr('id').split('Gramaje')[1];
if ($('#compPaginas' + tipo).val() > 0) {
popErrorAlert(window.language.Presupuestos.errores.seleccioneGramaje, 'divAlarmasComparador');
return { error: true, data: {} };
}
}
};
if (this.tipo_impresion.val().includes('color')) {
if (this.tipo_impresion.val().includes('hq')) {
papel_generico.color = { id: this.papelColorhq.getVal(), nombre: this.papelColorhq.getText() };
gramaje.color = this.gramajeColorhq.getVal();
paginasColor = this.paginasColorhq.val();
}
else {
papel_generico.color = { id: this.papelColor.getVal(), nombre: this.papelColor.getText() };
gramaje.color = this.gramajeColor.getVal();
paginasColor = this.paginasColor.val();
}
}
if (this.tipo_impresion.val().includes('hq')) {
papel_generico.negro = { id: this.papelNegrohq.getVal(), nombre: this.papelNegrohq.getText() };
gramaje.negro = this.gramajeNegrohq.getVal();
}
else {
papel_generico.negro = { id: this.papelNegro.getVal(), nombre: this.papelNegro.getText() };
gramaje.negro = this.gramajeNegro.getVal();
}
}
else if (uso == 'cubierta') {
if (this.papelCubierta.getVal() == 0 || this.papelCubierta.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (this.gramajeCubierta.getVal() == 0 || this.gramajeCubierta.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccioneGramaje, 'divAlarmasComparador');
return { error: true, data: {} };
}
papel_generico = { id: this.papelCubierta.getVal(), nombre: this.papelCubierta.getText() };
gramaje = this.gramajeCubierta.getVal();
paginas = this.paginasCubierta.select2('data')[0].id
}
else if (uso == 'sobrecubierta') {
if (this.papelSobrecubierta.getVal() == 0 || this.papelSobrecubierta.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (this.gramajeSobrecubierta.getVal() == 0 || this.gramajeSobrecubierta.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccioneGramaje, 'divAlarmasComparador');
return { error: true, data: {} };
}
papel_generico = { id: this.papelSobrecubierta.getVal(), nombre: this.papelSobrecubierta.getText() };
gramaje = this.gramajeSobrecubierta.getVal();
paginas = 4;
}
else if (uso == 'faja') {
if (this.papelFaja.getVal() == 0 || this.papelFaja.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (this.gramajeFaja.getVal() == 0 || this.gramajeFaja.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccioneGramaje, 'divAlarmasComparador');
return { error: true, data: {} };
}
papel_generico = { id: this.papelFaja.getVal(), nombre: this.papelFaja.getText() };
gramaje = this.gramajeFaja.getVal();
paginas = 4;
alto = $('#faja_alto').val();
}
else if (uso == 'guardas') {
if (this.papelGuardas.getVal() == 0 || this.papelGuardas.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccionePapel, 'divAlarmasComparador');
return { error: true, data: {} };
}
if (this.gramajeGuardas.getVal() == 0 || this.gramajeGuardas.getVal() == null) {
popErrorAlert(window.language.Presupuestos.errores.seleccioneGramaje, 'divAlarmasComparador');
return { error: true, data: {} };
}
papel_generico = { id: this.papelGuardas.getVal(), nombre: this.papelGuardas.getText() };
gramaje = this.gramajeGuardas.getVal();
paginas = 8;
}
const datosPedido = {
paginas: paginas,
tirada: $('#tirada').val(),
merma: $('#merma').val(),
ancho: ancho,
alto: alto,
isCosido: $('#isCosido').val(),
a_favor_fibra: 1,
};
if ($('#clienteId').select2('data').length == 0 || $('#clienteId').select2('data').id < 1) {
popErrorAlert(window.language.Presupuestos.errores.seleccioneCliente, 'divAlarmasComparador');
return { error: true, data: {} };
}
let datos = {
datosPedido: datosPedido,
uso: uso == 'faja' ? 'sobrecubierta' : uso,
tipo_impresion_id: this.tipo_impresion_id,
cliente_id: $('#clienteId').select2('data')[0].id,
papel_generico: papel_generico,
gramaje: gramaje,
isColor: this.tipo_impresion.val().includes('color') ? 1 : 0,
isHq: this.tipo_impresion.val().includes('hq') ? 1 : 0,
paginas_color: paginasColor
}
if (uso == 'cubierta') {
datos.datosPedido.lomo = $("#lomo_cubierta").val();
datos.datosPedido.solapas = $('#solapas').prop('checked') ? 1 : 0;
datos.datosPedido.solapas_ancho = $('#solapas').prop('checked') ? parseInt($('#solapas_ancho').val()) : 0;
if (this.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
datos.lomoRedondo = this.lomoRedondo.val();
}
}
else if (uso == 'sobrecubierta') {
datos.datosPedido.lomo = $("#lomo_sobrecubierta").val();
datos.datosPedido.solapas = $('#solapas_sobrecubierta').prop('checked') ? 1 : 0;
datos.datosPedido.solapas_ancho = $('#solapas_sobrecubierta').prop('checked') ? parseInt($('#solapas_ancho_sobrecubierta').val()) : 0;
}
else if (uso == 'faja') {
datos.datosPedido.lomo = $("#lomo_sobrecubierta").val();
datos.datosPedido.solapas = 1;
datos.datosPedido.solapas_ancho = parseInt($('#faja_solapas_ancho').val());
}
else if (uso == 'guardas') {
datos.datosPedido.isCosido = 1;
datos.datosPedido.isHq = 1;
datos.paginas_color = datos.datosPedido.paginas;
datos.paginas_impresion = this.carasGuardas.val();
}
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.tipo != 'lp_sobrecubierta')
lomoTotal += parseFloat(rowData.lomo);
}
})
}
catch (error) {
lomoTotal = 0;
}
$('#lomo_cubierta').val(lomoTotal);
return lomoTotal;
}
obtenerComparadorInterior(event, actualizarLineaPlana = false, actualizarLineaRot = false) {
try {
const self = this;
if (this.cargando || this.comparadorPlanaRunning) {
return
}
this.comparadorPlanaRunning = true;
if (event.currentTarget.id.includes('Paginas')) {
this.#changePaginasComparador(event.currentTarget.id);
}
this.tableCompIntPlana.clear().draw();
this.tableCompIntRotativa.clear().draw();
this.btnInsertarPlana.addClass('d-none');
this.btnInsertarRotativa.addClass('d-none');
$('#title_int_rot').html(window.language.Presupuestos.compInteriorRotativa);
$('#title_int_plana').html(window.language.Presupuestos.compInteriorPlana);
const datosComp = this.getDataForComp('interior');
if (datosComp.error) {
this.comparadorPlanaRunning = false;
return;
}
else {
const isHq = this.tipo_impresion.val().includes('hq') ? 1 : 0;
const isColor = this.tipo_impresion.val().includes('color') ? 1 : 0;
datosComp.data['tipo_maquina'] = 'plana';
datosComp.data[this.csrf_token] = this.csrf_hash;
new Ajax('/presupuestoadmin/comparadorinterior',
datosComp.data,
{},
(response) => {
if (response.data.negro && response.data.negro.length > 0) {
let sorted = response.data.negro.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) {
if (typeof linea.error == "undefined")
self.tableCompIntPlana.row
.add(self.getRowFromLinea(isHq ? 'bnhq' : 'bn', linea))
.draw()
});
}
if (response.data.color && response.data.color.length > 0) {
let sorted = response.data.color.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) {
if (typeof linea.error == "undefined")
self.tableCompIntPlana.row
.add(self.getRowFromLinea(isHq ? 'colorhq' : 'color', linea))
.draw()
});
}
self.selectLineas('plana');
if ($('#tableCompIntPlana').DataTable().rows().count() > 0) {
$('#title_int_plana').html(window.language.Presupuestos.compInteriorPlana + ' (' + self.tableCompIntPlana.rows().count() + ')');
$('#insertarPlanaBtn').removeClass('d-none');
}
else {
$('#title_int_plana').html(window.language.Presupuestos.compInteriorPlana);
$('#insertarPlanaBtn').addClass('d-none');
}
// Rotativa
if (!isHq) {
if (!isColor ||
(isColor && datosComp.data.papel_generico.negro.id == datosComp.data.papel_generico.color.id &&
datosComp.data.gramaje.negro == datosComp.data.gramaje.color) ||
(isColor && datosComp.data.datosPedido.paginas == parseInt(datosComp.data.paginas_color))) {
datosComp.data['tipo_maquina'] = 'rotativa';
if (isColor && datosComp.data.datosPedido.paginas == parseInt(datosComp.data.paginas_color)) {
datosComp.data.papel_generico.id = datosComp.data.papel_generico.color.id;
datosComp.data.papel_generico.nombre = datosComp.data.papel_generico.color.nombre;
datosComp.data.gramaje = datosComp.data.gramaje.color;
}
else {
datosComp.data.papel_generico.id = datosComp.data.papel_generico.negro.id;
datosComp.data.papel_generico.nombre = datosComp.data.papel_generico.negro.nombre;
datosComp.data.gramaje = datosComp.data.gramaje.negro;
}
new Ajax('/presupuestoadmin/comparadorinterior',
datosComp.data,
{},
(response) => {
if (response.data.rotativa && response.data.rotativa.length > 0) {
let sorted = response.data.rotativa.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) {
if (typeof linea.error == "undefined")
self.tableCompIntRotativa.row
.add(self.getRowFromLineaRot(linea))
.draw()
});
}
self.selectLineas('rotativa');
if (self.tableCompIntRotativa.rows().count() > 0) {
self.btnInsertarRotativa.removeClass('d-none');
$('#title_int_rot').html(window.language.Presupuestos.compInteriorRotativa + ' (' + self.tableCompIntRotativa.rows().count() + ')');
}
else {
$('#title_int_rot').html(window.language.Presupuestos.compInteriorRotativa);
}
self.comparadorPlanaRunning = false;
},
(error) => {
console.log(error);
self.comparadorPlanaRunning = false;
}
).post();
}
else {
self.comparadorPlanaRunning = false;
}
}
else {
self.comparadorPlanaRunning = false;
}
},
(error) => {
console.log(error);
self.comparadorPlanaRunning = false;
}
).post();
}
} catch (e) {
console.log(e);
this.comparadorPlanaRunning = false;
}
}
obtenerComparadorExteriores(event, actualizarLineaPlana = false, actualizarLineaRot = false) {
try {
const self = this;
if (this.cargando) {
return
}
this.tableCompCubierta.clear().draw();
this.btnInsertarCubierta.addClass('d-none');
$('#title_cubierta').html(window.language.Presupuestos.compCubiertaSobrecubierta);
let datosComp = {};
datosComp.cubierta = this.getDataForComp('cubierta');
if (datosComp.cubierta.error) {
return;
}
if (this.tipo_impresion_id != 5 && this.tipo_impresion_id != 6 && this.tipo_impresion_id != 7 && this.tipo_impresion_id != 8 && this.tipo_impresion_id != 21) {
if (this.sobrecubierta.val() == 1) {
datosComp.sobrecubierta = this.getDataForComp('sobrecubierta');
if (datosComp.sobrecubierta.error) {
return;
}
}
else {
datosComp.sobrecubierta = {};
}
}
else {
datosComp.sobrecubierta = {};
}
datosComp.cubierta.data[this.csrf_token] = this.csrf_hash;
if (Object.keys(datosComp.sobrecubierta).length > 0) {
datosComp.sobrecubierta.data[this.csrf_token] = this.csrf_hash;
}
new Ajax('/presupuestoadmin/comparadorexteriores',
{
cubierta: datosComp.cubierta.data,
sobrecubierta: datosComp.sobrecubierta.data
},
{},
(response) => {
this.tableCompCubierta.clear().draw();
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[0].forEach(function (linea) {
if (typeof linea.error == "undefined")
self.tableCompCubierta.row
.add(self.getRowFromLinea('cubierta', linea))
.draw();
});
}
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[0].forEach(function (linea) {
if (typeof linea.error == "undefined")
self.tableCompCubierta.row
.add(self.getRowFromLinea('sobrecubierta', linea))
.draw()
});
}
self.selectLineas('cubierta');
if (self.tableCompCubierta.rows().count() > 0) {
$('#title_cubierta').html(window.language.Presupuestos.compCubiertaSobrecubierta +
(' (' + self.tableCompCubierta.rows().count() + ')'));
self.btnInsertarCubierta.removeClass('d-none');
}
else {
$('#title_cubierta').html(window.language.Presupuestos.compCubiertaSobrecubierta);
self.btnInsertarCubierta.addClass('d-none');
}
},
(error) => {
console.log(error);
}
).post();
} catch (e) {
console.log(e)
}
}
obtenerComparadorFaja(event, actualizarLineaPlana = false, actualizarLineaRot = false) {
try {
const self = this;
if (this.cargando) {
return
}
this.tableCompFaja.clear().draw();
this.btnInsertarFaja.addClass('d-none');
$('#title_faja').html(window.language.Presupuestos.faja);
let datosComp = {};
datosComp.sobrecubierta = this.getDataForComp('faja');
if(datosComp.sobrecubierta.error){
return;
}
datosComp.sobrecubierta.data['faja'] = 1; // se indica que es faja para el calculo de formas
datosComp.sobrecubierta.data[this.csrf_token] = this.csrf_hash;
new Ajax('/presupuestoadmin/comparadorexteriores',
{
sobrecubierta: datosComp.sobrecubierta.data
},
{},
(response) => {
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[0].forEach(function (linea) {
if (typeof linea.error == "undefined")
self.tableCompFaja.row
.add(self.getRowFromLinea('faja', linea))
.draw()
});
}
self.selectLineas('faja');
if (self.tableCompFaja.rows().count() > 0) {
$('#title_faja').html(window.language.Presupuestos.faja +
(' (' + self.tableCompFaja.rows().count() + ')'));
self.btnInsertarFaja.removeClass('d-none');
}
else {
$('#title_faja').html(window.language.Presupuestos.faja);
self.btnInsertarFaja.addClass('d-none');
}
},
(error) => {
console.log(error);
}
).post();
} catch (e) {
console.log(e)
}
}
obtenerComparadorGuardas(event, actualizarLineaPlana = false, actualizarLineaRot = false) {
try {
const self = this;
if (this.cargando) {
return
}
this.tableCompGuardas.clear().draw();
this.btnInsertarGuardas.addClass('d-none');
$('#title_guardas').html(window.language.Presupuestos.Guardas);
let datosComp = {};
datosComp = this.getDataForComp('guardas');
if (datosComp.error) {
return;
}
datosComp.data[this.csrf_token] = this.csrf_hash;
new Ajax('/presupuestoadmin/comparadorguardas',
datosComp.data,
{},
(response) => {
if (response.data && Object.keys(response.data).length > 0) {
let sorted = Object.values(response.data).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[0].forEach(function (linea) {
if (typeof linea.error == "undefined")
self.tableCompGuardas.row
.add(self.getRowFromLinea('guardas', linea))
.draw();
});
}
self.selectLineas('guardas');
if (self.tableCompGuardas.rows().count() > 0) {
$('#title_guardas').html(window.language.Presupuestos.Guardas +
(' (' + self.tableCompGuardas.rows().count() + ')'));
self.btnInsertarGuardas.removeClass('d-none');
}
else {
$('#title_guardas').html(window.language.Presupuestos.Guardas);
self.btnInsertarGuardas.addClass('d-none');
}
},
(error) => {
console.log(error);
}
).post();
} catch (e) {
console.log(e)
}
}
selectLineas(tabla) {
let table = this.tableCompIntPlana;
let select1 = false;
let select2 = false;
let tipo1 = 'bn';
let tipo2 = 'color';
let total_label = '#total_comp_plana'
switch (tabla) {
case 'guardas':
table = this.tableCompGuardas;
tipo1 = 'guardas';
total_label = '#total_comp_guardas';
break;
case 'cubierta':
table = this.tableCompCubierta;
tipo1 = 'cubierta';
tipo2 = 'sobrecubierta';
total_label = '#total_comp_cubierta';
break;
case 'faja':
table = this.tableCompFaja;
tipo1 = 'faja';
total_label = '#total_comp_faja';
break;
case 'rotativa':
table = this.tableCompIntRotativa;
tipo1 = 'rotativa';
total_label = '#total_comp_rot';
break;
default:
break;
}
table.rows('.selected').deselect();
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
if (!select1 && table.cell(rowIdx, 0).data().includes(tipo1)) {
table.row(rowIdx).nodes().to$().toggleClass('selected');
select1 = true;
}
if (tabla == 'plana' || tabla == 'cubierta')
if (!select2 && table.cell(rowIdx, 0).data().includes(tipo2)) {
table.row(rowIdx).nodes().to$().toggleClass('selected');
select2 = true;
}
});
var rows = table.rows('.selected').indexes();
var data = table.rows(rows).data();
var value_total = 0.00;
for (let i = 0; i < data.length; i++) {
value_total += parseFloat(data[i]['total'])
}
$(total_label).html(value_total.toFixed(2));
}
getRowFromLinea(tipo, linea) {
const precio_impresion = isNaN(parseFloat(linea.fields.precio_impresion_horas + linea.fields.margen_impresion_horas + linea.fields.precio_click_pedido)) ? "" :
parseFloat(linea.fields.precio_impresion_horas + linea.fields.margen_impresion_horas + linea.fields.precio_click_pedido).toFixed(2);
let data = {
'tipo': tipo,
'paginas': linea.fields.paginas,
'papel': linea.fields.papel_generico,
'gramaje': linea.fields.gramaje,
'marca': linea.fields.papel_impresion,
'maquina': linea.fields.maquina,
'numeroPliegos': isNaN(parseFloat(linea.fields.pliegos_libro)) ? "" : parseFloat(linea.fields.pliegos_libro).toFixed(2),
'pliegosPedido': isNaN(parseFloat(linea.fields.pliegos_pedido)) ? "" : parseFloat(linea.fields.pliegos_pedido).toFixed(2),
'precioPliego': isNaN(parseFloat(linea.fields.precios_pliegos)) ? "" : parseFloat(linea.fields.precios_pliegos).toFixed(6),
'libro': isNaN(parseFloat(linea.fields.precio_libro)) ? "" : parseFloat(linea.fields.precio_libro).toFixed(2),
'totalPapelPedido': isNaN(parseFloat(linea.fields.precio_pedido)) ? "" : parseFloat(linea.fields.precio_pedido).toFixed(2),
'lomo': isNaN(parseFloat(linea.fields.mano)) ? "" : parseFloat(linea.fields.mano).toFixed(2),
'peso': isNaN(parseFloat(linea.fields.peso)) ? "" : parseFloat(linea.fields.peso).toFixed(2),
'horasMaquina': isNaN(parseFloat(linea.fields.horas_maquina)) ? "" : parseFloat(linea.fields.horas_maquina).toFixed(2),
'precioImpresion': precio_impresion,
'total': isNaN(parseFloat(linea.fields.total_impresion).toFixed(2)) ? "" : parseFloat(linea.fields.total_impresion).toFixed(2),
'maquinaId': linea.fields.maquina_id,
'maquinaVelocidad': linea.fields.maquina_velocidad,
'tiempoMaquina': linea.fields.tiempo_maquina,
'papelGenericoId': linea.fields.papel_generico_id,
'papelImpresionId': linea.fields.papel_impresion_id,
'tarifa_impresion_id': linea.fields.tarifa_impresion_id,
}
if (data['tipo'] == 'guardas')
data['paginas_impresion'] = linea.fields.paginas_impresion;
return data;
}
getRowFromLineaRot(linea) {
const precio_impresion = isNaN(parseFloat(linea.fields.precio_impresion_horas + linea.fields.precio_click_pedido)) ? "" :
parseFloat(linea.fields.precio_impresion_horas + linea.fields.precio_click_pedido).toFixed(2);
return {
'tipo': 'rotativa',
'paginas': linea.fields.paginas,
'papel': linea.fields.papel_generico,
'gramaje': linea.fields.gramaje,
'marca': linea.fields.papel_impresion,
'aFavorFibra': linea.fields.a_favor_fibra == 1 ? 'si' : 'no',
'maquina': linea.fields.maquina,
'numeroPliegos': isNaN(parseFloat(linea.fields.pliegos_libro)) ? "" : parseFloat(linea.fields.pliegos_libro).toFixed(2),
'pliegosPedido': isNaN(parseFloat(linea.fields.pliegos_pedido)) ? "" : parseFloat(linea.fields.pliegos_pedido).toFixed(2),
'precioPliego': isNaN(parseFloat(linea.fields.precios_pliegos)) ? "" : parseFloat(linea.fields.precios_pliegos).toFixed(6),
'libro': isNaN(parseFloat(linea.fields.precio_libro)) ? "" : parseFloat(linea.fields.precio_libro).toFixed(2),
'totalPapelPedido': isNaN(parseFloat(linea.fields.precio_pedido)) ? "" : parseFloat(linea.fields.precio_pedido).toFixed(2),
'lomo': isNaN(parseFloat(linea.fields.mano)) ? "" : parseFloat(linea.fields.mano).toFixed(2),
'peso': isNaN(parseFloat(linea.fields.peso)) ? "" : parseFloat(linea.fields.peso).toFixed(2),
'horasMaquina': isNaN(parseFloat(linea.fields.horas_maquina)) ? "" : parseFloat(linea.fields.horas_maquina).toFixed(2),
'precioImpresion': precio_impresion,
'precioPagNegro': isNaN(parseFloat(linea.fields.precio_pagina_negro)) ? "" : parseFloat(linea.fields.precio_pagina_negro).toFixed(6),
'precioPagColor': isNaN(parseFloat(linea.fields.precio_pagina_color)) ? "" : parseFloat(linea.fields.precio_pagina_color).toFixed(6),
'totalTinta': isNaN(parseFloat(linea.fields.precio_tinta)) ? "" : parseFloat(linea.fields.precio_tinta).toFixed(2),
'totalCorte': isNaN(parseFloat(linea.fields.total_corte)) ? "" : parseFloat(linea.fields.total_corte).toFixed(2),
'total': isNaN(parseFloat(linea.fields.total_impresion)) ? "" : (parseFloat(linea.fields.total_impresion)).toFixed(2),
'maquinaId': linea.fields.maquina_id,
'maquinaVelocidad': linea.fields.maquina_velocidad,
'tiempoMaquina': linea.fields.tiempo_maquina,
'papelGenericoId': linea.fields.papel_generico_id,
'papelImpresionId': linea.fields.papel_impresion_id,
'paginasColor': linea.fields.paginas_color,
'tarifa_impresion_id': linea.fields.tarifa_impresion_id,
}
}
generateCompJSON() {
let data = {}
if ($('#tipoImpresion').select2('data')[0].id == 'negro' || $('#tipoImpresion').select2('data')[0].id == 'color') {
let bn_obj = {};
try {
bn_obj = {
"bn": {
'paginas': $('#compPaginasNegro').val(),
'papel_id': $('#compPapelNegro').select2('data')[0].id,
'gramaje': $('#compGramajeNegro').select2('data')[0].text.trim(),
}
}
}
catch (e) {
}
$.extend(data, bn_obj);
}
if ($('#tipoImpresion').select2('data')[0].id == 'negrohq' || $('#tipoImpresion').select2('data')[0].id == 'colorhq') {
let bnhq_obj = {};
try {
bnhq_obj = {
"bnhq": {
'paginas': $('#compPaginasNegrohq').val(),
'papel_id': $('#compPapelNegrohq').select2('data')[0].id,
'gramaje': $('#compGramajeNegrohq').select2('data')[0].text.trim(),
}
}
}
catch (e) {
}
$.extend(data, bnhq_obj);
}
if ($('#tipoImpresion').select2('data')[0].id == 'color') {
let color_obj = {};
try {
color_obj = {
"color": {
'paginas': $('#compPaginasColor').val(),
'papel_id': $('#compPapelColor').select2('data')[0].id,
'gramaje': $('#compGramajeColor').select2('data')[0].text.trim(),
},
}
}
catch (e) {
}
$.extend(data, color_obj);
}
if ($('#tipoImpresion').select2('data')[0].id == 'colorhq') {
let colorhq_obj = {};
try {
colorhq_obj = {
"colorhq": {
'paginas': $('#compPaginasColorhq').val(),
'papel_id': $('#compPapelColorhq').select2('data')[0].id,
'gramaje': $('#compGramajeColorhq').select2('data')[0].text.trim(),
},
}
}
catch (e) {
}
$.extend(data, colorhq_obj);
}
let cubierta_obj = {};
try {
cubierta_obj = {
"cubierta": {
'paginas': $('#compCarasCubierta option:selected').val(),
'papel_id': $('#compPapelCubierta').select2('data')[0].id,
'gramaje': $('#compGramajeCubierta').select2('data')[0].text.trim(),
},
}
}
catch (e) {
}
$.extend(data, cubierta_obj);
let sobrecubierta_obj = {};
try {
sobrecubierta_obj = {
"sobrecubierta": {
'imprimir': $('#compSobrecubierta option:selected').val(),
'papel_id': $('#compPapelSobrecubierta').select2('data')[0].id,
'gramaje': $('#compGramajeSobrecubierta').select2('data')[0].text.trim(),
},
}
}
catch (e) {
}
$.extend(data, sobrecubierta_obj);
if ($('#compCarasGuardas').length > 0) {
let guardas_obj = {};
try {
guardas_obj = {
"guardas": {
'paginas_impresion': $('#compCarasGuardas option:selected').val(),
'papel_id': $('#compPapelGuardas').select2('data')[0].id,
'gramaje': $('#compGramajeGuardas').select2('data')[0].text.trim(),
},
}
}
catch (e) {
}
$.extend(data, guardas_obj);
}
if (parseInt($('#compFaja').val()) == 1) {
let faja_obj = {};
try {
faja_obj = {
"faja": {
'papel_id': $('#compPapelFaja').select2('data')[0].id,
'gramaje': $('#compGramajeFaja').select2('data')[0].text.trim(),
},
}
}
catch (e) {
}
$.extend(data, faja_obj);
}
const data_str = JSON.stringify(data)
$('#comparador_json_data').val(data_str)
}
}
export default Comparador;