mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
764 lines
30 KiB
JavaScript
764 lines
30 KiB
JavaScript
import { getToken } from '../../common/common.js';
|
|
import Ajax from '../../components/ajax.js';
|
|
|
|
import DatosGenerales from './sections/datosGenerales.js';
|
|
import DatosLibro from './sections/datosLibro.js';
|
|
import Comparador from './sections/comparador.js';
|
|
import LineasPresupuesto from './sections/lineasPresupuesto.js';
|
|
import PreviewFormasAdmin from './sections/previewFormasAdmin.js';
|
|
import Servicios from './sections/servicios.js';
|
|
import Envios from './sections/envios.js';
|
|
import TiradasAlernativas from './sections/tiradasAlternativas.js';
|
|
import Resumen from './sections/resumen.js';
|
|
import FileUploadDropzone from '../../components/forms/fileUploadDropzone.js';
|
|
|
|
class PresupuestoAdminEdit {
|
|
|
|
constructor() {
|
|
|
|
this.domItem = $('#presupuestoForm');
|
|
|
|
this.csrf_token = getToken();
|
|
this.csrf_hash = $('#presupuestoForm').find('input[name="' + this.csrf_token + '"]').val();
|
|
|
|
this.lc = $("#lomo_cubierta");
|
|
this.lsc = $("#lomo_sobrecubierta");
|
|
this.cosido = $("#isCosido");
|
|
this.tipo_impresion = $("#tipo_impresion_id");
|
|
this.POD = $("#POD");
|
|
|
|
this.tipoTapa = $('.card-title').text().toLowerCase().includes('dura') ? 'dura' : 'blanda';
|
|
|
|
this.cargandoPresupuesto = false;
|
|
|
|
this.datosGenerales = new DatosGenerales(this.domItem.find('#accordionDatosPresupuestoTip'));
|
|
this.datosLibro = new DatosLibro(this.domItem.find('#accordionDatosLibroTip'),
|
|
() => { return this.cargandoPresupuesto },
|
|
{
|
|
checkPaginasPresupuesto: this.checkPaginasPresupuesto,
|
|
getDimensionLibro: this.getDimensionLibro,
|
|
calcularSolapas: this.calcularSolapas.bind(this),
|
|
});
|
|
this.comparador = new Comparador(this.domItem.find('#accordionDatosPresupuestoClienteTip'),
|
|
() => { return this.cargandoPresupuesto },
|
|
{
|
|
getDimensionLibro: this.getDimensionLibro,
|
|
});
|
|
this.lineasPresupuesto = new LineasPresupuesto(this.domItem.find('#accordionLineasPresupuestoTip'),
|
|
{
|
|
getDimensionLibro: this.getDimensionLibro,
|
|
calcular_mermas: this.datosLibro.calcular_mermas,
|
|
});
|
|
|
|
this.previewFormasAdmin = null;
|
|
this.servicios = new Servicios();
|
|
this.envios = new Envios();
|
|
this.tiradasAlternativas = new TiradasAlernativas({
|
|
getDimensionLibro: this.getDimensionLibro,
|
|
});
|
|
this.resumen = new Resumen();
|
|
|
|
this.guardar = $('#saveForm');
|
|
|
|
this.calcularPresupuesto = false;
|
|
|
|
this.configUploadDropzone = {
|
|
domElement: '#dropzone-presupuesto-admin-files',
|
|
nameId: "presupuesto_id",
|
|
getUri: '/presupuestos/presupuestocliente/get_files',
|
|
postUri: '/presupuestos/presupuestocliente/upload_files'
|
|
}
|
|
if ($(this.configUploadDropzone.domElement).length > 0) {
|
|
this.fileUploadDropzone = new FileUploadDropzone(this.configUploadDropzone)
|
|
}
|
|
}
|
|
|
|
init() {
|
|
|
|
// Fuerza el foco en el campo de búsqueda de select2
|
|
$(document).on('select2:open', () => {
|
|
document.querySelector('.select2-search__field').focus();
|
|
});
|
|
|
|
// Autonumeric
|
|
AutoNumeric.multiple('.autonumeric-currency', { decimalPlaces: 2, currencySymbol: '€', currencySymbolPlacement: 's', digitGroupSeparator: '.', decimalCharacter: ',' });
|
|
|
|
const impresion_id = $('#tipo_impresion_id').val();
|
|
let tipoLibro = '';
|
|
if (impresion_id == 1 || impresion_id == 2) {
|
|
tipoLibro = 'fresado';
|
|
} else if (impresion_id == 3 || impresion_id == 4) {
|
|
tipoLibro = 'cosido';
|
|
} else if (impresion_id == 5 || impresion_id == 6) {
|
|
tipoLibro = 'espiral';
|
|
} else if (impresion_id == 7 || impresion_id == 8) {
|
|
tipoLibro = 'wireo';
|
|
} else if (impresion_id == 21) {
|
|
tipoLibro = 'grapado';
|
|
}
|
|
|
|
|
|
this.datosGenerales.init();
|
|
this.datosLibro.init();
|
|
this.comparador.init();
|
|
this.lineasPresupuesto.init();
|
|
|
|
this.previewFormasAdmin = new PreviewFormasAdmin(tipoLibro, this.tipoTapa,
|
|
{
|
|
ancho: () => this.getDimensionLibro().ancho,
|
|
alto: () => this.getDimensionLibro().alto,
|
|
lomo: () => $('#lomo_cubierta').val() === '' ? parseFloat('0.0') : parseFloat($('#lomo_cubierta').val()),
|
|
lomoSobrecubierta: () => $('#lomo_sobrecubierta').val() === '' ? parseFloat('0.0') : parseFloat($('#lomo_sobrecubierta').val()),
|
|
solapas: () => $('#solapas').prop('checked') ? parseFloat($('#solapas_ancho').val()) : 0,
|
|
solapas_sobrecubierta: () => $('#solapas_sobrecubierta').prop('checked') ? parseFloat($('#solapas_ancho_sobrecubierta').val()) : 0,
|
|
lomoRedondo: () => (this.tipo_impresion == 1 || this.tipo_impresion == 3) ? parseFloat($('#compLomoRedondo').val()) : 0,
|
|
}
|
|
);
|
|
this.previewFormasAdmin.init();
|
|
this.servicios.init();
|
|
this.envios.init();
|
|
this.tiradasAlternativas.init();
|
|
this.resumen.init();
|
|
|
|
$('#btn_ajustar_revisado').on('click', function () {
|
|
|
|
this.resumen.updateTotales({ updateLP: true, updateServicios: true, updateEnvio: true }, true);
|
|
}.bind(this));
|
|
|
|
$('#total_aceptado_revisado').on('change', function () {
|
|
let totalCostes = AutoNumeric.getAutoNumericElement($('#totalCostes')[0]);
|
|
let envio_base = AutoNumeric.getAutoNumericElement($('#precioEnvios')[0]);
|
|
let autoTotalAceptado = AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]);
|
|
let totalMargenes = AutoNumeric.getAutoNumericElement($('#totalMargenes')[0]);
|
|
let total_aceptado_revisado = autoTotalAceptado.getNumber();
|
|
|
|
|
|
if (total_aceptado_revisado && total_aceptado_revisado != 0) {
|
|
const nuevoTotal = totalCostes.getNumber() + envio_base.getNumber();
|
|
|
|
if (total_aceptado_revisado < nuevoTotal) {
|
|
// Solo usá .set(), no .val() ni .html()
|
|
autoTotalAceptado.set(nuevoTotal);
|
|
total_aceptado_revisado = nuevoTotal;
|
|
}
|
|
|
|
totalMargenes.set(total_aceptado_revisado - nuevoTotal);
|
|
}
|
|
}.bind(this));
|
|
|
|
if (window.location.href.includes("edit")) {
|
|
|
|
setTimeout(() => {
|
|
this.#cargarPresupuesto();
|
|
}, 0);
|
|
|
|
const successMessage = sessionStorage.getItem('message');
|
|
if (successMessage) {
|
|
popSuccessAlert(successMessage);
|
|
sessionStorage.removeItem('message');
|
|
}
|
|
}
|
|
this.downloadPreviewImage();
|
|
|
|
$("textarea[name^='comentarios_']").on("input", function () {
|
|
let target = $("#mostrar_" + $(this).attr("name"));
|
|
if ($.trim($(this).val()) === "") {
|
|
target.addClass('d-none');
|
|
} else {
|
|
target.removeClass('d-none');
|
|
}
|
|
});
|
|
|
|
|
|
$(document).on('update-presupuesto', this.updatePresupuesto.bind(this));
|
|
|
|
this.guardar.on('click', this.guardarPresupuesto.bind(this));
|
|
|
|
$('#lomo_cubierta').on('change', this.datosLibro.changeAnchoSolapasCubierta);
|
|
$('#lomo_sobrecubierta').on('change', this.datosLibro.changeAnchoSolapasSobrecubierta);
|
|
if ($(this.configUploadDropzone.domElement).length > 0) {
|
|
this.fileUploadDropzone.init()
|
|
}
|
|
|
|
$('#reprint').on('click', this.reprintPresupuesto.bind(this));
|
|
}
|
|
|
|
|
|
async guardarPresupuesto() {
|
|
|
|
$('#loader').modal('show');
|
|
|
|
try {
|
|
|
|
const id = window.location.href.split("/").pop();
|
|
let data = this.getFormData();
|
|
|
|
await this.servicios.guardar();
|
|
await this.envios.guardarEnvios();
|
|
await this.lineasPresupuesto.guardarLineasPresupuesto();
|
|
|
|
new Ajax('/presupuestoadmin/edit/' + id, data, {},
|
|
function (response) {
|
|
sessionStorage.setItem('message', response.mensaje);
|
|
location.reload();
|
|
},
|
|
function (error) {
|
|
console.error(error);
|
|
$('#loader').modal('hide');
|
|
}
|
|
).post();
|
|
|
|
|
|
} catch (error) {
|
|
console.error(error);
|
|
$('#loader').modal('hide');
|
|
}
|
|
}
|
|
|
|
|
|
getFormData() {
|
|
|
|
let datos = {};
|
|
|
|
datos.id = window.location.href.split("/").pop();
|
|
datos.cliente_id = this.datosGenerales.cliente.getVal();
|
|
datos.tipo_impresion_id = this.tipo_impresion.val();
|
|
datos.cosido = this.cosido.val();
|
|
datos.lomo_cubierta = this.lc.val();
|
|
datos.lomo_sobrecubierta = this.lsc.val();
|
|
datos.envio_base = $('#envio_base').val();
|
|
|
|
datos = {
|
|
...datos, ...{
|
|
inc_rei: this.datosGenerales.inc_rei.select2('data')[0].id,
|
|
titulo: this.datosGenerales.titulo.val(),
|
|
autor: this.datosGenerales.autor.val(),
|
|
isbn: this.datosGenerales.isbn.val(),
|
|
pais_id: this.datosGenerales.pais.getVal(),
|
|
coleccion: this.datosGenerales.coleccion.val(),
|
|
numero_edicion: this.datosGenerales.numeroEdicion.val(),
|
|
referencia_cliente: this.datosGenerales.referenciaCliente.val(),
|
|
updated_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
|
}
|
|
}
|
|
|
|
datos = {
|
|
...datos, ...{
|
|
paginas: this.datosLibro.paginas.val(),
|
|
tirada: this.datosLibro.tirada.val(),
|
|
papel_formato_id: this.datosLibro.tamanioPersonalizado.prop('checked') ? 0 : this.datosLibro.tamanio.getVal(),
|
|
papel_formato_personalizado: this.datosLibro.tamanioPersonalizado.prop('checked') ? 1 : 0,
|
|
merma: this.datosLibro.merma.val(),
|
|
merma_cubierta: this.datosLibro.mermaCubierta.val()
|
|
}
|
|
}
|
|
if (this.datosLibro.tamanioPersonalizado.prop('checked')) {
|
|
datos.papel_formato_ancho = this.datosLibro.anchoPersonalizado.val(),
|
|
datos.papel_formato_alto = this.datosLibro.altoPersonalizado.val()
|
|
}
|
|
datos.selectedTirada = this.datosLibro.tirada.val();
|
|
datos.acabado_cubierta_id = this.datosLibro.acabadoCubierta.getVal();
|
|
datos.acabado_sobrecubierta_id = this.datosLibro.acabadoSobrecubierta.getVal();
|
|
datos.acabado_faja_id = this.datosLibro.acabadoFaja.getVal();
|
|
|
|
datos = {
|
|
...datos, ...{
|
|
'prototipo': this.datosLibro.prototipo.is(':checked') ? 1 : 0,
|
|
'ferro': this.datosLibro.ferro.is(':checked') ? 1 : 0,
|
|
'ferro_digital': this.datosLibro.ferroDigital.is(':checked') ? 1 : 0,
|
|
'marcapaginas': this.datosLibro.marcapaginas.is(':checked') ? 1 : 0,
|
|
'retractilado': this.datosLibro.retractilado.is(':checked') ? 1 : 0,
|
|
'retractilado5': this.datosLibro.retractilado5.is(':checked') ? 1 : 0,
|
|
}
|
|
};
|
|
|
|
datos.comp_tipo_impresion = this.comparador.tipo_impresion.val();
|
|
datos.comp_pos_paginas_color = this.comparador.posPagColor.val();
|
|
|
|
|
|
if (this.comparador.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) {
|
|
datos.lomoRedondo = this.comparador.lomoRedondo.select2('data')[0].id;
|
|
datos.cabezada = this.comparador.cabezada.val();
|
|
}
|
|
else {
|
|
datos.lomoRedondo = 0;
|
|
}
|
|
|
|
if ($('#tipo_impresion_id').val() != 1 && $('#tipo_impresion_id').val() != 3 &&
|
|
$('#tipo_impresion_id').val() != 5 && $('#tipo_impresion_id').val() != 7) {
|
|
datos.solapas = this.datosLibro.solapasCubierta.is(':checked') ? 1 : 0;
|
|
datos.solapas_ancho = this.datosLibro.anchoSolapasCubierta.val();
|
|
}
|
|
|
|
datos.solapas_sobrecubierta = this.datosLibro.solapasSobrecubierta.is(':checked') ? 1 : 0;
|
|
datos.solapas_ancho_sobrecubierta = this.datosLibro.anchoSolapasSobrecubierta.val();
|
|
|
|
datos.faja_color = this.datosLibro.faja.prop('checked') ? 1 : 0;
|
|
datos.solapas_ancho_faja_color = this.datosLibro.fajaSolapasAncho.val();
|
|
datos.alto_faja_color = this.datosLibro.fajaAlto.val();
|
|
|
|
datos.entrega_taller = this.envios.recogerTaller.is(':checked') ? 1 : 0;
|
|
if (parseInt(this.cosido.val())) {
|
|
|
|
let paginas_por_cuadernillo = "";
|
|
|
|
this.servicios.ServiciosEncuadernacion.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
|
var rowData = this.data();
|
|
if (rowData.paginas_por_cuadernillo != null) {
|
|
paginas_por_cuadernillo = rowData.paginas_por_cuadernillo;
|
|
}
|
|
});
|
|
|
|
datos.paginas_por_cuadernillo = paginas_por_cuadernillo;
|
|
}
|
|
|
|
datos.comentarios_cliente = $('#comentariosCliente').val();
|
|
datos.comentarios_safekat = $('#comentariosSafekat').val();
|
|
datos.comentarios_pdf = $('#comentariosPdf').val();
|
|
datos.comentarios_presupuesto = $('#comentariosPresupuesto').val();
|
|
datos.comentarios_produccion = $('#comentariosProduccion').val();
|
|
|
|
datos = { ...datos, ...this.resumen.getData() };
|
|
|
|
this.comparador.generateCompJSON();
|
|
datos.comparador_json_data = $('#comparador_json_data').val();
|
|
|
|
datos.tirada_alternativa_json_data = this.tiradasAlternativas.generate_json_tiradas();
|
|
|
|
datos.direcciones_fp_checks = JSON.stringify({
|
|
"addFP1isAddMain": $('#sameAddPrincipalFP1').prop('checked')? "1":"0",
|
|
"addFP2isAddMain": $('#sameAddPrincipalFP2').prop('checked')? "1":"0",
|
|
"addFP2isaddFP1": $('#sameAddFP1').prop('checked')? "1":"0",
|
|
});
|
|
|
|
return datos;
|
|
}
|
|
|
|
|
|
async updatePresupuesto(event, {
|
|
|
|
update_lineas = true,
|
|
update_servicios = true,
|
|
update_envios = true,
|
|
update_resumen = true,
|
|
update_tiradas_alternativas = true
|
|
}) {
|
|
|
|
const self = this;
|
|
const waitForEvent = (eventName) => {
|
|
return new Promise((resolve) => {
|
|
$(document).one(eventName, () => {
|
|
resolve();
|
|
});
|
|
});
|
|
};
|
|
|
|
if (self.cargandoPresupuesto == false) {
|
|
|
|
//self.comparador.updateComparador();
|
|
|
|
// Ejecutar los pasos de forma secuencial si están habilitados
|
|
if (update_lineas) {
|
|
$(document).trigger('update-lineas-presupuesto');
|
|
await waitForEvent('update-lineas-presupuesto-completed');
|
|
}
|
|
|
|
if (update_servicios) {
|
|
$(document).trigger('update-servicios');
|
|
await waitForEvent('update-servicios-completed');
|
|
}
|
|
|
|
if (update_envios) {
|
|
$(document).trigger('update-envios');
|
|
await waitForEvent('update-envios-completed');
|
|
}
|
|
|
|
if (update_resumen) {
|
|
$(document).trigger('update-totales');
|
|
await waitForEvent('update-totales-completed');
|
|
}
|
|
|
|
if (update_tiradas_alternativas) {
|
|
$(document).trigger('update-tiradas-alternativas');
|
|
await waitForEvent('update-tiradas-alternativas-completed');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#cargarPresupuesto() {
|
|
|
|
const self = this;
|
|
this.cargandoPresupuesto = true;
|
|
self.comparador.cargando = true;
|
|
self.datosLibro.cargando = true;
|
|
|
|
$('#loader').modal('show');
|
|
let id = window.location.href.split("/").pop()
|
|
new Ajax('/presupuestoadmin/cargar/' + id,
|
|
{},
|
|
{},
|
|
(response) => {
|
|
|
|
if (response.status === 1) {
|
|
|
|
self.lc.val(parseFloat(response.data.lc).toFixed(2));
|
|
self.lsc.val(parseFloat(response.data.lsc).toFixed(2));
|
|
self.cosido.val(response.data.cosido ? 1 : 0);
|
|
self.tipo_impresion.val(response.data.tipo_impresion);
|
|
self.POD.val(response.data.POD);
|
|
|
|
const totalAceptadoRevisado = response.data.total_aceptado_revisado != null ?
|
|
response.data.total_aceptado_revisado : response.data.resumen.total_aceptado;
|
|
if((!isNaN(totalAceptadoRevisado) && totalAceptadoRevisado !== null) || totalAceptadoRevisado === 0) {
|
|
AutoNumeric.getAutoNumericElement($('#total_aceptado_revisado')[0]).set(totalAceptadoRevisado);
|
|
}
|
|
|
|
$('#aprobado_by_at').html(response.data.aprobado_by_at);
|
|
|
|
$('#created_by').html(response.data.created_by);
|
|
$('#updated_by').html(response.data.updated_by);
|
|
$('#created_at').html(response.data.created_at);
|
|
$('#updated_at_footer').html(response.data.updated_at);
|
|
|
|
self.calcularPresupuesto = false;
|
|
|
|
self.datosGenerales.cargarDatos(response.data.datosGenerales);
|
|
self.datosLibro.cargarDatos(response.data.datosLibro);
|
|
|
|
self.lineasPresupuesto.cargarDatos(response.data.lineasPresupuesto);
|
|
|
|
self.servicios.cargar(response.data.servicios);
|
|
self.envios.cargar(response.data.direcciones, response.data.direccionesFP);
|
|
|
|
self.comparador.cargarDatos(response.data.comparador);
|
|
|
|
$('#comentariosCliente').val(response.data.comentarios_cliente);
|
|
$('#comentariosSafekat').val(response.data.comentarios_safekat);
|
|
$('#comentariosPresupuesto').val(response.data.comentarios_presupuesto);
|
|
$('#comentariosPdf').val(response.data.comentarios_pdf);
|
|
$('#comentariosProduccion').val(response.data.comentarios_produccion);
|
|
$("textarea[name^='comentarios_']").trigger("input");
|
|
|
|
self.tiradasAlternativas.cargar(response.data.tiradasAlternativas);
|
|
|
|
self.resumen.cargar(response.data.resumen);
|
|
|
|
self.datosLibro.calcular_mermas();
|
|
|
|
setTimeout(() => {
|
|
|
|
$('#loader').modal('hide');
|
|
|
|
if (response.data.state != 2) {
|
|
|
|
self.calcularPresupuesto = true;
|
|
self.cargandoPresupuesto = false;
|
|
self.datosLibro.cargando = false;
|
|
self.comparador.cargando = false;
|
|
|
|
self.comparador.updateComparador();
|
|
}
|
|
|
|
|
|
}, 0);
|
|
|
|
this.calcularSolapas();
|
|
if ($('#faja_alto').length > 0 && $('#faja_alto').attr('max') != this.getDimensionLibro().alto) {
|
|
$('#faja_alto').attr('max', this.getDimensionLibro().alto);
|
|
$('#faja_alto').trigger('change');
|
|
$('#faja_alto').closest('.mb-1').find('.form-text').text('Entre 50 y ' + this.getDimensionLibro().alto + ' mm');
|
|
}
|
|
|
|
// Funciones para detectar cambios en el formulario
|
|
setTimeout(() => {
|
|
this.#checkChangesPresupuesto();
|
|
}, 500);
|
|
$('#bc-save').on("click", function () {
|
|
showBreadCrumbSaveButton(false);
|
|
$('#saveForm').trigger('click');
|
|
});
|
|
}
|
|
},
|
|
() => {
|
|
$('#loader').modal('hide');
|
|
this.calcularPresupuesto = true;
|
|
self.cargandoPresupuesto = false;
|
|
self.datosLibro.cargando = false;
|
|
self.comparador.cargando = false;
|
|
}
|
|
).get();
|
|
}
|
|
|
|
|
|
checkPaginasPresupuesto() {
|
|
|
|
let cantidad_total = 0;
|
|
|
|
$('#tableLineasPresupuesto').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
|
|
var rowData = this.data();
|
|
if (rowData.row_id != 'lp_cubierta' && rowData.row_id != 'lp_sobrecubierta' && rowData.row_id != 'lp_guardas')
|
|
cantidad_total += parseInt(rowData.paginas)
|
|
})
|
|
let htmlString = ''
|
|
|
|
if (cantidad_total != parseInt($('#paginas').val())) {
|
|
htmlString = `
|
|
<div class="alert alert-warning d-flex align-items-baseline" role="alert">
|
|
<span class="alert-icon alert-icon-lg text-primary me-2">
|
|
<i class="ti ti-bell ti-sm"></i>
|
|
</span>
|
|
<div class="d-flex flex-column ps-1">
|
|
<h5 class="alert-heading mb-2">` +
|
|
window.language.Presupuestos.errores.paginasLP +
|
|
`</h5>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
$('#divAlarmasLineasPresupuesto').html(htmlString)
|
|
}
|
|
|
|
|
|
getPaginasColor() {
|
|
|
|
let paginasColor = 0;
|
|
this.lineasPresupuesto.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
|
var rowData = this.data();
|
|
if (rowData.row_id === 'lp_color' || rowData.row_id === 'lp_colorhq') {
|
|
return parseInt(rowData.paginas);
|
|
}
|
|
if (rowData.row_id === 'lp_rot_color') {
|
|
return parseInt(rowData.numPagColor);
|
|
}
|
|
});
|
|
return paginasColor;
|
|
}
|
|
|
|
calcularSolapas() {
|
|
|
|
let anchoTotal = 2 * this.getDimensionLibro().ancho;
|
|
let maxSolapas = 120;
|
|
|
|
let mano = 0;
|
|
this.lineasPresupuesto.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
|
var rowData = this.data();
|
|
if (rowData.row_id != 'lp_cubierta' || rowData.row_id === 'lp_sobrecubierta'
|
|
|| rowData.row_id === 'lp_guardas' || rowData.row_id === 'lp_faja'
|
|
) {
|
|
mano += parseInt(rowData.mano);
|
|
}
|
|
});
|
|
|
|
if (mano > 0) {
|
|
anchoTotal += 6 + 5; // dobleces + sangre
|
|
maxSolapas = Math.min(Math.floor((865 - anchoTotal) / 2), 0.95 * this.getDimensionLibro().ancho);
|
|
}
|
|
else {
|
|
maxSolapas = 0.95 * this.getDimensionLibro().ancho;
|
|
}
|
|
maxSolapas = Math.floor(maxSolapas, 0);
|
|
if ($('#solapas_ancho').length > 0 && $('#solapas_ancho').attr('max') != maxSolapas) {
|
|
$('#solapas_ancho').attr('max', maxSolapas);
|
|
$('#solapas_ancho').trigger('change');
|
|
$('#solapas_ancho').closest('.mb-1').find('.form-text').text('Entre 60 y ' + maxSolapas + ' mm');
|
|
}
|
|
if ($('#solapas_ancho_sobrecubierta').length > 0 && $('#solapas_ancho_sobrecubierta').attr('max') != maxSolapas) {
|
|
$('#solapas_ancho_sobrecubierta').attr('max', maxSolapas);
|
|
$('#solapas_ancho_sobrecubierta').trigger('change');
|
|
$('#solapas_ancho_sobrecubierta').closest('.mb-1').find('.form-text').text('Entre 60 y ' + maxSolapas + ' mm');
|
|
}
|
|
if ($('#faja_solapas_ancho').length > 0 && $('#faja_solapas_ancho').attr('max') != maxSolapas) {
|
|
$('#faja_solapas_ancho').attr('max', maxSolapas);
|
|
$('#faja_solapas_ancho').trigger('change');
|
|
$('#faja_solapas_ancho').closest('.mb-1').find('.form-text').text('Entre 60 y ' + maxSolapas + ' mm');
|
|
}
|
|
}
|
|
|
|
getDimensionLibro() {
|
|
|
|
var ancho = 0;
|
|
var alto = 0;
|
|
|
|
|
|
if ($('#papelFormatoPersonalizado').is(':checked')) {
|
|
ancho = parseFloat($('#papelFormatoAncho').val());
|
|
alto = parseFloat($('#papelFormatoAlto').val());
|
|
}
|
|
else {
|
|
const selectedText = $('#papelFormatoId').find('option:selected').text();
|
|
if (selectedText.length > 0) {
|
|
ancho = parseFloat(selectedText.trim().split(" x ")[0]);
|
|
alto = parseFloat(selectedText.trim().split(" x ")[1]);
|
|
}
|
|
}
|
|
|
|
return {
|
|
ancho: ancho,
|
|
alto: alto
|
|
}
|
|
}
|
|
|
|
|
|
#checkChangesPresupuesto() {
|
|
|
|
const self = this;
|
|
// Detectar cambios en inputs de texto
|
|
$('input[type="text"]').on('change', function () {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
// Detectar cambios en inputs de texto
|
|
$('input[type="number"]').on('change', function () {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
// Detectar cambios en select
|
|
$('select').on('change', function () {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
$('.select2bs').on('change', function (e) {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
// Detectar cambios en checkboxes
|
|
$('input[type="checkbox"]').change(function () {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
// Detectar cambios en textareas
|
|
$('textarea').on('input', function () {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
// Detectar cambios en otros tipos de input
|
|
$('input[type="radio"]').change(function () {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
|
|
// Detectar cambios en otros tipos de input
|
|
$('input:not([type])').on('input', function () {
|
|
if (!self.cargandoPresupuesto)
|
|
showBreadCrumbSaveButton(true);
|
|
});
|
|
}
|
|
|
|
|
|
downloadPreviewImage() {
|
|
$(document).on("click", ".download-shape", (event) => {
|
|
let parentDiv = $(event.currentTarget).parent().parent();
|
|
let shapeSvgElQuery = $(parentDiv).find("svg");
|
|
let shapeSvgEl = shapeSvgElQuery[0];
|
|
const filename = shapeSvgElQuery.parent().attr("id") ?? "image"
|
|
const serializer = new XMLSerializer();
|
|
const svgData = serializer.serializeToString(shapeSvgEl);
|
|
const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
|
|
const svgUrl = URL.createObjectURL(svgBlob);
|
|
const img = new Image(shapeSvgEl.getBoundingClientRect().width, shapeSvgEl.getBoundingClientRect().height);
|
|
img.onload = () => {
|
|
const scaleFactor = 3; // Increase resolution (e.g., 2x, 3x)
|
|
const canvas = document.createElement('canvas');
|
|
// Scale canvas for high resolution
|
|
const width = img.naturalWidth || img.width;
|
|
const height = img.naturalHeight || img.height;
|
|
canvas.width = width * scaleFactor;
|
|
canvas.height = height * scaleFactor;
|
|
const ctx = canvas.getContext('2d');
|
|
ctx.scale(scaleFactor, scaleFactor);
|
|
ctx.drawImage(img, 0, 0, width, height);
|
|
const pngUrl = canvas.toDataURL('image/png');
|
|
const downloadLink = document.createElement('a');
|
|
downloadLink.href = pngUrl;
|
|
downloadLink.download = filename ?? '.png';
|
|
document.body.appendChild(downloadLink);
|
|
downloadLink.click();
|
|
URL.revokeObjectURL(svgUrl);
|
|
};
|
|
|
|
img.src = svgUrl;
|
|
})
|
|
}
|
|
|
|
reprintPresupuesto() {
|
|
|
|
const id = window.location.href.split("/").pop();
|
|
|
|
Swal.fire({
|
|
title: 'Reimpresion',
|
|
text: "¿Quiere usar los mismos ficheros para la reimpresión?\n(Si no usa los mismos, deberá subir unos nuevos)",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonText: 'Usar los MISMOS',
|
|
cancelButtonText: 'Cancelar',
|
|
denyButtonText: "Usar OTROS",
|
|
customClass: {
|
|
confirmButton: 'btn btn-primary me-1',
|
|
denyButton: 'btn btn-primary me-1',
|
|
cancelButton: 'btn btn-secondary'
|
|
},
|
|
buttonsStyling: false
|
|
}).then((result) => {
|
|
if (result.isDenied || result.isConfirmed) {
|
|
new Ajax('/presupuestoadmin/reprint',
|
|
{ id: id, duplicateFiles: result.isConfirmed ? 1 : 0 }, {},
|
|
function (response) {
|
|
if (response.success === true) {
|
|
Swal.fire({
|
|
text: response.message,
|
|
icon: 'success',
|
|
confirmButtonColor: '#3085d6',
|
|
confirmButtonText: 'Ok',
|
|
customClass: {
|
|
confirmButton: 'btn btn-primary me-1',
|
|
},
|
|
buttonsStyling: false
|
|
})
|
|
window.open('/presupuestoadmin/edit/' + response.id, '_blank');
|
|
} else {
|
|
popErrorAlert(response.mensaje);
|
|
}
|
|
},
|
|
function (error) {
|
|
popErrorAlert(error);
|
|
}
|
|
).post();
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
const dropdown = document.querySelector(".dropdown-language");
|
|
const activeItem = dropdown.querySelector(".dropdown-menu .dropdown-item");
|
|
let locale = 'es';
|
|
if (activeItem) {
|
|
locale = activeItem.getAttribute("data-language");
|
|
}
|
|
|
|
$(document).on("keydown", "textarea", function (event) {
|
|
if (event.key === "Enter" && !event.shiftKey) {
|
|
event.preventDefault(); // Evita que el formulario se envíe
|
|
$(this).val($(this).val() + "\n"); // Agrega un salto de línea
|
|
}
|
|
});
|
|
|
|
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Presupuestos', 'PresupuestosDirecciones'] }, {},
|
|
function (translations) {
|
|
window.language = JSON.parse(translations);
|
|
new PresupuestoAdminEdit().init();
|
|
},
|
|
function (error) {
|
|
console.log("Error getting translations:", error);
|
|
}
|
|
).post();
|
|
|
|
}); |