mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
975 lines
33 KiB
JavaScript
975 lines
33 KiB
JavaScript
import DatosGenerales from './datosGenerales.js';
|
|
import DisenioInterior from './disenioInterior.js';
|
|
import DisenioCubierta from './disenioCubierta.js';
|
|
import Direcciones from './direcciones.js';
|
|
import Resumen from './resumen.js';
|
|
import Ajax from '../../components/ajax.js';
|
|
import { alertWarningMessage } from '../../components/alerts/sweetAlert.js';
|
|
|
|
|
|
import tarjetaTiradasPrecio from './tarjetaTiradasPrecio.js';
|
|
|
|
class PresupuestoCliente {
|
|
|
|
constructor() {
|
|
|
|
this.clientePresupuestoWizard = document.querySelector('#wizard-presupuesto-cliente');
|
|
|
|
this.validationStepper = new Stepper(this.clientePresupuestoWizard, {
|
|
linear: true
|
|
});
|
|
|
|
this.btnNext = $('#btnNext');
|
|
this.btnPrev = $('#btnPrev');
|
|
this.btnPrint = $('#btnPrint');
|
|
this.btnSave = $('#btnSave');
|
|
this.btnDuplicate = $('#cloneForm');
|
|
this.btnConfirm = $('#btnConfirm');
|
|
this.btnUploadFile = $('#btnUploadFile')
|
|
|
|
this.c = $("#c");
|
|
this.lc = $("#lc");
|
|
this.lsc = $("#lsc");
|
|
|
|
this.rl_interior = $(".rl-interior");
|
|
this.rl_cubierta = $(".rl-cubierta");
|
|
this.rl_sobrecubierta = $(".rl-sobrecubierta");
|
|
|
|
this.datosGenerales = new DatosGenerales($("#datos-generales"), this.clientePresupuestoWizard, this.validationStepper);
|
|
this.disenioInterior = new DisenioInterior($("#interior-libro"), this.clientePresupuestoWizard, this.validationStepper, this);
|
|
this.disenioCubierta = new DisenioCubierta($("#cubierta-libro"), this.clientePresupuestoWizard, this.validationStepper, this);
|
|
this.direcciones = new Direcciones($("#direcciones-libro"), this.clientePresupuestoWizard, this.validationStepper);
|
|
this.resumen = new Resumen($("#resumen-libro"), this.datosGenerales, this.disenioInterior, this.disenioCubierta, this.direcciones);
|
|
|
|
this.divTiradasPrecios = $(".divTiradasPrecio");
|
|
|
|
this.titulosMenu = $(".titulos-menu");
|
|
|
|
this.datos = {};
|
|
this.ajax_calcular = new Ajax('/presupuestocliente/calcular',
|
|
this.datos,
|
|
{},
|
|
this.#procesarPresupuesto.bind(this),
|
|
() => { $('#loader').modal('hide'); });
|
|
|
|
this.actualizarTiradasEnvio = false;
|
|
this.calcularPresupuesto = false;
|
|
|
|
if (!window.location.href.includes("edit")) {
|
|
this.#processResumenLateral();
|
|
}
|
|
}
|
|
|
|
|
|
init() {
|
|
|
|
// Fuerza el foco en el campo de búsqueda de select2
|
|
$(document).on('select2:open', () => {
|
|
document.querySelector('.select2-search__field').focus();
|
|
});
|
|
|
|
this.validationStepper._element.addEventListener('shown.bs-stepper', this.stepperHandler.bind(this));
|
|
|
|
this.datosGenerales.init();
|
|
this.disenioInterior.init();
|
|
this.disenioCubierta.init();
|
|
this.direcciones.init();
|
|
|
|
if (window.location.href.includes("edit")) {
|
|
this.resumen.init(window.location.href.split("/").pop());
|
|
}
|
|
else {
|
|
this.resumen.init();
|
|
}
|
|
|
|
|
|
if (this.datosGenerales.excluirRotativa.length == 0) {
|
|
|
|
this.direcciones.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").val() })
|
|
}
|
|
|
|
|
|
this.btnNext.on('click', this.#nextStep.bind(this));
|
|
this.btnPrev.on('click', this.#prevtStep.bind(this));
|
|
this.btnSave.on('click', this.#savePresupuesto.bind(this));
|
|
this.btnDuplicate.on('click', this.#clonePresupuesto.bind(this));
|
|
this.btnConfirm.on('click', this.#confirmPresupuesto.bind(this));
|
|
this.btnPrint.on('click', this.#printPresupuesto.bind(this));
|
|
this.btnUploadFile.on('click', () => {
|
|
$('#dropzone-multi').trigger('click');
|
|
})
|
|
this.titulosMenu.on('click', this.#handleTitulosMenu.bind(this));
|
|
|
|
if (window.location.href.includes("edit")) {
|
|
|
|
setTimeout(() => {
|
|
this.#cargarPresupuesto();
|
|
}, 0);
|
|
|
|
const successMessage = sessionStorage.getItem('message');
|
|
if (successMessage) {
|
|
popSuccessAlert(successMessage);
|
|
sessionStorage.removeItem('message');
|
|
}
|
|
}
|
|
else {
|
|
this.calcularPresupuesto = true;
|
|
$('.tirada-presupuesto').trigger('change');
|
|
}
|
|
|
|
|
|
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
|
|
$(".calcular-solapas").on('change', this.calcularSolapas.bind(this));
|
|
$(".calcular-lomo").on('change', this.checkLomoInterior.bind(this));
|
|
|
|
}
|
|
|
|
|
|
#processResumenLateral() {
|
|
|
|
this.datosGenerales.processMenuLateral();
|
|
this.disenioInterior.processMenuLateral();
|
|
this.disenioCubierta.processMenuLateral();
|
|
}
|
|
|
|
|
|
calcularSolapas() {
|
|
|
|
/* Solapas Max */
|
|
this.#getDatos(false, true);
|
|
if (Object.values(this.datos).every(this.#isValidDataForm)) {
|
|
new Ajax('/presupuestocliente/calcularsolapas',
|
|
this.datos,
|
|
{},
|
|
(response) => {
|
|
if (response === null || response === undefined || response === "") {
|
|
console.error("Error en el calculo máximo de solapas.");
|
|
return;
|
|
}
|
|
this.disenioCubierta.tamanioSolapasCubierta.attr('max', response);
|
|
this.disenioCubierta.solapasSobrecubierta.attr('max', response);
|
|
this.disenioCubierta.textoSolapasCubierta.text("Entre 60 y " + response + " mm");
|
|
this.disenioCubierta.textoSolapasSobrecubierta.text("Entre 60 y " + response + " mm");
|
|
this.disenioCubierta.textoSolapasFaja.text("Entre 60 y " + response + " mm");
|
|
},
|
|
() => { }
|
|
).post();
|
|
}
|
|
}
|
|
|
|
checkLomoInterior() {
|
|
|
|
/* Limites lomo */
|
|
this.#getDatos(false, true);
|
|
if (Object.values(this.datos).every(this.#isValidDataForm)) {
|
|
new Ajax('/presupuestocliente/checklomo',
|
|
this.datos,
|
|
{},
|
|
(response) => {
|
|
if (response === null || response === undefined || response === "") {
|
|
console.log("Error en el calculo del lomo interior.");
|
|
return;
|
|
}
|
|
if (response.errors.status == 1) {
|
|
popErrorAlert('' + response.errors.value, "sk-alert-lomo", false);
|
|
}
|
|
else {
|
|
popAlert2Hide('sk-alert-lomo');
|
|
}
|
|
},
|
|
() => { }
|
|
).post();
|
|
}
|
|
}
|
|
|
|
checkForm(event) {
|
|
|
|
this.#processResumenLateral();
|
|
|
|
$(".divTiradasPrecio").empty();
|
|
|
|
if (this.calcularPresupuesto) {
|
|
|
|
const element = $('.fv-plugins-bootstrap5.fv-plugins-framework.active');
|
|
|
|
switch (element.attr('id')) {
|
|
case 'datos-generales':
|
|
if(!this.datosGenerales.validate(false)) {
|
|
return;
|
|
}
|
|
break;
|
|
|
|
case 'interior-libro':
|
|
if(!this.disenioInterior.validate(false)) {
|
|
return;
|
|
}
|
|
break;
|
|
case 'cubierta-libro':
|
|
if(!this.disenioCubierta.validate(false)) {
|
|
return;
|
|
}
|
|
break;
|
|
case 'direcciones-libro':
|
|
if(!this.direcciones.validate(false)) {
|
|
return;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (event.target.id === 'divDirecciones') {
|
|
this.actualizarTiradasEnvio = false;
|
|
|
|
if (!this.direcciones.calcularPresupuesto) {
|
|
|
|
$('#loader').modal('hide');
|
|
return;
|
|
}
|
|
|
|
}
|
|
else {
|
|
this.actualizarTiradasEnvio = true;
|
|
//this.direcciones.divTiradas.empty();
|
|
}
|
|
|
|
let datos_to_check = this.#prepareData();
|
|
|
|
if (Object.values(datos_to_check).every(this.#isValidDataForm)) {
|
|
|
|
// buscar elementos dentro de #mainContainer que tengan la clase is-invalid
|
|
const invalidElements = $('#mainContainer').find('.is-invalid');
|
|
if (invalidElements.length > 0) {
|
|
// si hay elementos inválidos, no se procede con el
|
|
return;
|
|
}
|
|
try {
|
|
|
|
setTimeout(function () {
|
|
$('#loader').modal('show');
|
|
}, 0);
|
|
|
|
// Si se está ejecutando la petición, abortar la petición anterior
|
|
this.ajax_calcular.abort();
|
|
|
|
this.ajax_calcular.setData(this.datos);
|
|
this.ajax_calcular.post();
|
|
this.direcciones.calcularPresupuesto = false;
|
|
}
|
|
catch (e) {
|
|
console.log(e);
|
|
$('#loader').modal('hide');
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#handleTitulosMenu(event) {
|
|
|
|
$('.titulos-menu').removeClass('crossed');
|
|
|
|
const nextElement = $(event.target).attr('data-target')
|
|
const currentElement = $('.dstepper-block.active').attr('id');
|
|
|
|
if (currentElement === nextElement) {
|
|
return;
|
|
}
|
|
|
|
if (nextElement === 'resumen-libro') {
|
|
$(".rl-item").addClass('d-none');
|
|
}
|
|
|
|
if (currentElement !== 'resumen-libro') {
|
|
this.#validateCurrentForm(currentElement, nextElement);
|
|
//this.#goToForm(nextElement);
|
|
}
|
|
else {
|
|
this.#goToForm(nextElement);
|
|
}
|
|
if (!nextElement.includes('resumen-libro'))
|
|
this.#processResumenLateral();
|
|
else {
|
|
$(".rl-item").addClass('d-none');
|
|
}
|
|
}
|
|
|
|
#goToForm(form) {
|
|
|
|
switch (form) {
|
|
case '#datos-generales':
|
|
this.validationStepper.to(1);
|
|
break;
|
|
|
|
case '#interior-libro':
|
|
this.validationStepper.to(2);
|
|
break;
|
|
|
|
case '#cubierta-libro':
|
|
this.validationStepper.to(3);
|
|
break;
|
|
|
|
case '#direcciones-libro':
|
|
this.validationStepper.to(4);
|
|
break;
|
|
|
|
case '#resumen-libro':
|
|
this.validationStepper.to(5);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
#validateCurrentForm(form, nextForm) {
|
|
|
|
switch (form) {
|
|
case 'datos-generales':
|
|
if (this.datosGenerales.validate(false))
|
|
this.#goToForm(nextForm);
|
|
break;
|
|
|
|
case 'interior-libro':
|
|
if (this.disenioInterior.validate(false))
|
|
this.#goToForm(nextForm);
|
|
break;
|
|
|
|
case 'cubierta-libro':
|
|
if (this.disenioCubierta.validate(false))
|
|
this.#goToForm(nextForm);
|
|
break;
|
|
|
|
case 'direcciones-libro':
|
|
if (this.direcciones.validate(false)) {
|
|
this.#goToForm(nextForm);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
stepperHandler() {
|
|
|
|
const element = $('.fv-plugins-bootstrap5.fv-plugins-framework.active');
|
|
|
|
switch (element.attr('id')) {
|
|
case 'datos-generales':
|
|
this.btnPrev.addClass('d-none');
|
|
this.btnNext.removeClass('d-none');
|
|
this.btnSave.addClass('d-none');
|
|
this.btnDuplicate.addClass('d-none');
|
|
this.btnPrint.addClass('d-none');
|
|
this.btnConfirm.addClass('d-none');
|
|
break;
|
|
|
|
case 'interior-libro':
|
|
case 'cubierta-libro':
|
|
case 'direcciones-libro':
|
|
this.btnPrev.removeClass('d-none');
|
|
this.btnNext.removeClass('d-none');
|
|
this.btnSave.removeClass('d-none');
|
|
this.btnDuplicate.addClass('d-none');
|
|
this.btnPrint.addClass('d-none');
|
|
this.btnConfirm.addClass('d-none');
|
|
break;
|
|
|
|
case 'resumen-libro':
|
|
this.btnPrev.removeClass('d-none');
|
|
this.btnNext.addClass('d-none');
|
|
this.btnDuplicate.removeClass('d-none');
|
|
this.btnSave.removeClass('d-none');
|
|
this.btnPrint.removeClass('d-none');
|
|
this.btnConfirm.removeClass('d-none');
|
|
this.resumen.generate();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
#printPresupuesto() {
|
|
|
|
window.open('/printpresupuestos/generar/' + window.location.href.split("/").pop(), '_blank');
|
|
}
|
|
|
|
#confirmPresupuesto() {
|
|
|
|
let total_unidades = 0;
|
|
if (!this.direcciones.recogidaTaller.is(':checked')) {
|
|
|
|
this.direcciones.direcciones.forEach(element => {
|
|
total_unidades += parseInt(element.getUnidades());
|
|
});
|
|
|
|
|
|
if (total_unidades != parseInt(this.direcciones.getSelectedTirada())) {
|
|
popErrorAlert("No se puede confirmar el presupuesto. La suma de las unidades enviadas no coincide con la tirada seleccionada.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
this.#solicitudGuardarPresupuesto(true);
|
|
}
|
|
|
|
#clonePresupuesto() {
|
|
|
|
const id = window.location.href.split("/").pop();
|
|
new Ajax('/presupuestoadmin/clone',
|
|
{
|
|
tipo: 'duplicar',
|
|
presupuesto_id: id
|
|
},
|
|
{},
|
|
(response) => {
|
|
// check if response object has a property named 'id'
|
|
if (response.id) {
|
|
|
|
const new_location = window.location.href.replace(id, response.id);
|
|
window.location.href = new_location;
|
|
}
|
|
else {
|
|
popErrorAlert("No se ha podido duplicar el presupuesto");
|
|
}
|
|
},
|
|
(error) => {
|
|
console.error('Error al duplicar el presupuesto:', error);
|
|
}
|
|
).post();
|
|
|
|
}
|
|
|
|
|
|
#savePresupuesto() {
|
|
|
|
this.#solicitudGuardarPresupuesto(false);
|
|
}
|
|
|
|
|
|
#solicitudGuardarPresupuesto(confirmar = false) {
|
|
|
|
try {
|
|
$('#loader').modal('show');
|
|
|
|
if (this.direcciones.tiradaSeleccionada == null || this.direcciones.tiradaSeleccionada == undefined
|
|
|| this.direcciones.tiradaSeleccionada == "" || this.direcciones.tiradaSeleccionada == 0) {
|
|
popErrorAlert("Seleccione una tirada en la pestaña direcciones para guardar el presupuesto.");
|
|
$('#loader').modal('hide');
|
|
return;
|
|
}
|
|
|
|
this.#getDatos();
|
|
|
|
let datos_to_check = this.#prepareData();
|
|
|
|
if (!Object.values(datos_to_check).every(this.#isValidDataForm)) {
|
|
popErrorAlert("Por favor, rellene todos los datos del presupuesto antes de guardar.");
|
|
$('#loader').modal('hide');
|
|
return;
|
|
}
|
|
|
|
this.#getDatos(true);
|
|
|
|
if (confirmar) {
|
|
this.datos["confirmar"] = 1;
|
|
}
|
|
|
|
if (window.location.href.includes("edit")) {
|
|
this.datos["id"] = window.location.href.split("/").pop();
|
|
}
|
|
new Ajax('/presupuestocliente/guardar',
|
|
this.datos,
|
|
{},
|
|
(response) => {
|
|
$('#loader').modal('hide');
|
|
if (this.datos["confirmar"] || window.location.href.includes("add")) {
|
|
if (response.status) {
|
|
sessionStorage.setItem('message', response.message);
|
|
window.location.href = response.url + '/' + response.status;
|
|
}
|
|
else {
|
|
popErrorAlert("Presupuesto no válido, corrija los errores antes de guardar.");
|
|
}
|
|
}
|
|
else {
|
|
if (response.error) {
|
|
popErrorAlert("Presupuesto no válido, corrija los errores antes de guardar.");
|
|
}
|
|
else {
|
|
$('.is-invalid').removeClass('is-invalid');
|
|
const skAlert = document.getElementById('sk-alert');
|
|
skAlert.innerHTML = '';
|
|
popSuccessAlert(response.message);
|
|
}
|
|
|
|
}
|
|
},
|
|
() => { $('#loader').modal('hide'); }
|
|
).post();
|
|
|
|
}
|
|
catch (e) {
|
|
console.log(e);
|
|
$('#loader').modal('hide');
|
|
}
|
|
}
|
|
|
|
|
|
#procesarPresupuesto(response) {
|
|
|
|
$('#loader').modal('hide');
|
|
|
|
if (response === null || response === undefined || response === "") {
|
|
popErrorAlert("No se ha podido calcular el presupuesto para los datos proporcionados. Por favor, póngase en contacto con el departamento comercial."
|
|
, "sk-alert-2", false);
|
|
this.divTiradasPrecios.empty();
|
|
return;
|
|
}
|
|
if (Object.values(response.errors).some((value) => value !== "")) {
|
|
if (response.errors.status == 1) {
|
|
popErrorAlert("No se ha podido calcular el presupuesto para los datos proporcionados. Por favor, póngase en contacto con el departamento comercial."
|
|
, "sk-alert-2", false);
|
|
this.divTiradasPrecios.empty();
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (response.tiradas && response.tiradas.length) {
|
|
|
|
let tiradas = { ...response.tiradas };
|
|
tiradas = Object.keys(tiradas).map((key) => tiradas[key]);
|
|
tiradas.sort((a, b) => a - b);
|
|
|
|
if (this.actualizarTiradasEnvio) {
|
|
this.direcciones.divTiradas.empty();
|
|
}
|
|
|
|
popAlert2Hide("sk-alert-2");
|
|
|
|
this.divTiradasPrecios.empty();
|
|
|
|
for (let i = 0; i < response.tiradas.length; i++) {
|
|
if (i == 0) {
|
|
$('#eb').val(response.eb[i]);
|
|
}
|
|
|
|
let precio = parseFloat((response.precio_u[i]) * parseInt(response.tiradas[i]));
|
|
|
|
|
|
new tarjetaTiradasPrecio(
|
|
this.divTiradasPrecios,
|
|
('precio-tiradas-' + response.tiradas[i]),
|
|
response.tiradas[i],
|
|
precio,
|
|
response.precio_u[i],
|
|
response.coste_envio[i]
|
|
);
|
|
|
|
if (this.actualizarTiradasEnvio) {
|
|
this.direcciones.insertTirada(response.tiradas[i]);
|
|
if (i == 0) {
|
|
$('#tiradaEnvios-' + response.tiradas[i]).trigger('click');
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
this.lc.val(parseFloat(response.info.lomo_cubierta).toFixed(2));
|
|
this.lsc.val(parseFloat(response.info.lomo_sobrecubierta).toFixed(2));
|
|
|
|
this.disenioCubierta.processMenuLateral();
|
|
|
|
$('.is-invalid').removeClass('is-invalid');
|
|
const skAlert = document.getElementById('sk-alert');
|
|
skAlert.innerHTML = '';
|
|
|
|
const acabadoCubierta = this.disenioCubierta.getAcabados();
|
|
|
|
if (acabadoCubierta && acabadoCubierta != null && acabadoCubierta > 0) {
|
|
|
|
$('#alert-cubierta-sin-acabado').addClass('d-none');
|
|
}
|
|
else {
|
|
$('#alert-cubierta-sin-acabado').removeClass('d-none');
|
|
$(window).scrollTop(0);
|
|
}
|
|
|
|
if (this.datos.cubierta && this.datos.cubierta.acabado)
|
|
setTimeout(() => {
|
|
$(`#containerTiradasEnvios .tirada-envio input[tirada="${this.direcciones.tiradaSeleccionada}"]`).trigger('click');
|
|
}, 0);
|
|
}
|
|
$('#loader').modal('hide');
|
|
// DEBUG
|
|
//console.log(response);
|
|
}
|
|
|
|
|
|
#nextStep() {
|
|
|
|
switch (this.validationStepper._currentIndex) {
|
|
case 0:
|
|
this.datosGenerales.validate();
|
|
break;
|
|
|
|
case 1:
|
|
this.disenioInterior.validate();
|
|
break;
|
|
|
|
|
|
case 2:
|
|
this.disenioCubierta.validate();
|
|
break;
|
|
|
|
case 3:
|
|
this.direcciones.validate();
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
$('html, body').animate({ scrollTop: 0 }, 'slow');
|
|
}
|
|
|
|
|
|
#prevtStep() {
|
|
switch (this.validationStepper._currentIndex) {
|
|
|
|
case 1:
|
|
if (this.disenioInterior.validate(false))
|
|
this.validationStepper.previous();
|
|
break;
|
|
|
|
|
|
case 2:
|
|
if (this.disenioCubierta.validate(false))
|
|
this.validationStepper.previous();
|
|
break;
|
|
|
|
case 3:
|
|
if (this.direcciones.formValidation.validate(false))
|
|
this.validationStepper.previous();
|
|
break;
|
|
|
|
default:
|
|
this.validationStepper.previous();
|
|
break;
|
|
}
|
|
$('html, body').animate({ scrollTop: 0 }, 'slow');
|
|
}
|
|
|
|
|
|
#prepareData(save = false) {
|
|
this.#getDatos(save);
|
|
|
|
let datos_to_check = { ...this.datos };
|
|
if (datos_to_check.direcciones) {
|
|
delete datos_to_check.direcciones;
|
|
}
|
|
if (datos_to_check.posPaginasColor == "" || datos_to_check.posPaginasColor == null) {
|
|
delete datos_to_check.posPaginasColor;
|
|
}
|
|
if (datos_to_check.cubierta.acabado == 0) {
|
|
delete datos_to_check.cubierta.acabado;
|
|
}
|
|
if (datos_to_check.sobrecubierta.acabado == 0) {
|
|
delete datos_to_check.sobrecubierta.acabado;
|
|
}
|
|
|
|
return datos_to_check;
|
|
}
|
|
|
|
|
|
#getDatos(save = false, calcularSolapas = false) {
|
|
|
|
this.datos = {
|
|
|
|
clienteId: this.datosGenerales.getCliente(),
|
|
|
|
tamanio: this.datosGenerales.getDimensionLibro(),
|
|
tirada: this.datosGenerales.getTiradas(),
|
|
paginas: this.datosGenerales.paginas.val(),
|
|
paginasColor: this.datosGenerales.paginasColor.val(),
|
|
pagColorConsecutivas: this.datosGenerales.pagColorConsecutivas.is(':checked') ? 1 : 0,
|
|
papelInteriorDiferente: this.datosGenerales.papelDiferente.is(':checked') ? 1 : 0,
|
|
paginasCuadernillo: this.datosGenerales.paginasCuadernillo.val(),
|
|
|
|
tipo: this.datosGenerales.tiposLibro.filter('.selected').attr('id'),
|
|
|
|
isColor: this.datosGenerales.getIsColor() ? 1 : 0,
|
|
isHq: this.disenioInterior.getIsHq() ? 1 : 0,
|
|
|
|
interior: {
|
|
papelInterior: this.disenioInterior.getPapel(),
|
|
gramajeInterior: this.disenioInterior.getGramaje(),
|
|
|
|
},
|
|
}
|
|
|
|
if (this.direcciones.getSelectedTirada() != null && this.direcciones.getSelectedTirada() != undefined && this.direcciones.getSelectedTirada() > 0) {
|
|
this.datos.selectedTirada = this.direcciones.getSelectedTirada();
|
|
}
|
|
|
|
this.datos.guardas = this.disenioCubierta.getGuardas();
|
|
|
|
if (calcularSolapas) {
|
|
return;
|
|
}
|
|
|
|
this.datos.posPaginasColor = this.datosGenerales.posPaginasColor.val();
|
|
|
|
this.datos.prototipo = this.datosGenerales.prototipo.is(':checked') ? 1 : 0;
|
|
this.datos.ferro = this.datosGenerales.ferro.is(':checked') ? 1 : 0;
|
|
this.datos.ferroDigital = this.datosGenerales.ferroDigital.is(':checked') ? 1 : 0;
|
|
this.datos.marcapaginas = this.datosGenerales.marcapaginas.is(':checked') ? 1 : 0;
|
|
this.datos.retractilado = this.datosGenerales.retractilado.is(':checked') ? 1 : 0;
|
|
this.datos.retractilado5 = this.datosGenerales.retractilado5.is(':checked') ? 1 : 0;
|
|
|
|
this.datos.eb = $('#eb').val();
|
|
|
|
this.datos.cubierta = {
|
|
tipoCubierta: this.disenioCubierta.disenioCubierta.filter('.selected').attr('id'),
|
|
papelCubierta: this.disenioCubierta.getPapel(),
|
|
gramajeCubierta: this.disenioCubierta.getGramaje(),
|
|
cabezada: this.disenioCubierta.getCabezada(),
|
|
acabado: this.disenioCubierta.getAcabados(),
|
|
carasImpresion: this.disenioCubierta.carasCubierta.val(),
|
|
};
|
|
|
|
|
|
this.datos.sobrecubierta = this.disenioCubierta.getSobrecubierta();
|
|
this.datos.faja = this.disenioCubierta.getFaja();
|
|
|
|
this.datos.excluirRotativa = this.datosGenerales.excluirRotativa.is(':checked') ? 1 : 0;
|
|
this.datos.ivaReducido = this.datosGenerales.ivaReducido.find('option:selected').val();
|
|
this.datos.servicios = {
|
|
//'prototipo': this.datosGenerales.prototipo.is(':checked') ? 1 : 0,
|
|
//'ferro': this.datosGenerales.ferro.is(':checked') ? 1 : 0,
|
|
//'ferroDigital': this.datosGenerales.ferroDigital.is(':checked') ? 1 : 0,
|
|
'marcapaginas': this.datosGenerales.marcapaginas.is(':checked') ? 1 : 0,
|
|
'retractilado': this.datosGenerales.retractilado.is(':checked') ? 1 : 0,
|
|
'retractilado5': this.datosGenerales.retractilado5.is(':checked') ? 1 : 0,
|
|
'serviciosExtra': this.datosGenerales.getServiciosExtra(),
|
|
};
|
|
|
|
let lomoRedondo = 0;
|
|
if (this.disenioCubierta.disenioCubierta.filter('.selected').length > 0)
|
|
lomoRedondo = this.disenioCubierta.disenioCubierta.filter('.selected').attr('id').includes('Redondo') ? 1 : 0;
|
|
this.datos.cubierta.lomoRedondo = lomoRedondo;
|
|
|
|
if (this.datos.tipo == "cosido") {
|
|
this.datos.paginasCuadernillo = this.datosGenerales.paginasCuadernillo.val();
|
|
}
|
|
let solapasCubierta = this.disenioCubierta.getSolapasCubierta();
|
|
if (solapasCubierta !== null && solapasCubierta !== undefined) {
|
|
|
|
if (solapasCubierta === false)
|
|
this.datos.cubierta.solapas = 0;
|
|
else {
|
|
this.datos.cubierta.solapas = 1;
|
|
this.datos.cubierta.tamanioSolapas = solapasCubierta;
|
|
}
|
|
}
|
|
else {
|
|
this.datos.cubierta.solapas = 0;
|
|
}
|
|
|
|
this.datos.entrega_taller = this.direcciones.recogidaTaller.is(':checked') ? 1 : 0;
|
|
|
|
if (!this.direcciones.recogidaTaller.is(':checked')) {
|
|
if (this.direcciones.direcciones.length > 0) {
|
|
this.datos.direcciones = [];
|
|
for (let i = 0; i < this.direcciones.direcciones.length; i++) {
|
|
this.datos.direcciones.push(this.direcciones.direcciones[i].getFormData());
|
|
};
|
|
}
|
|
}
|
|
if (save) {
|
|
this.datos.datosCabecera = {
|
|
titulo: this.datosGenerales.titulo.val(),
|
|
autor: this.datosGenerales.autor.val(),
|
|
isbn: this.datosGenerales.isbn.val(),
|
|
coleccion: this.datosGenerales.coleccion.val(),
|
|
referenciaCliente: this.datosGenerales.referenciaCliente.val(),
|
|
}
|
|
this.datos.selectedTirada = this.direcciones.getSelectedTirada();
|
|
}
|
|
|
|
if (window.location.href.includes("edit")) {
|
|
this.datos["id"] = window.location.href.split("/").pop();
|
|
}
|
|
}
|
|
|
|
|
|
#cargarPresupuesto() {
|
|
|
|
const self = this;
|
|
|
|
$('#loader').modal('show');
|
|
let id = window.location.href.split("/").pop()
|
|
new Ajax('/presupuestocliente/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.calcularPresupuesto = false;
|
|
|
|
self.datosGenerales.cargarDatos(response.data.datosGenerales);
|
|
self.direcciones.handleChangeCliente();
|
|
|
|
self.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales);
|
|
|
|
try {
|
|
self.disenioInterior.cargarDatos(response.data.interior, response.data.datosGenerales.papelInteriorDiferente);
|
|
}
|
|
catch (e) {
|
|
console.log("Error al cargar diseño interior: " + e);
|
|
}
|
|
try {
|
|
self.disenioCubierta.cargarDatos(response.data.cubierta, response.data.guardas, response.data.sobrecubierta, response.data.faja);
|
|
}
|
|
catch (e) {
|
|
console.log("Error al cargar diseño cubierta: " + e);
|
|
}
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
$('#loader').modal('hide');
|
|
|
|
if (response.data.state != 2) {
|
|
|
|
self.calcularPresupuesto = true;
|
|
self.checkForm({ target: { id: 'tirada' } });
|
|
}
|
|
else {
|
|
self.disenioInterior.presupuestoConfirmado = true;
|
|
if (response.data.interior.negro) {
|
|
self.disenioInterior.papelNegroForResumen = response.data.interior.negro.papel.nombre;
|
|
self.disenioInterior.gramajeNegroForResumen = response.data.interior.negro.gramaje;
|
|
}
|
|
if (response.data.interior.color) {
|
|
self.disenioInterior.papelColorForResumen = response.data.interior.color.nombre;
|
|
self.disenioInterior.gramajeColorForResumen = response.data.interior.color.gramaje;
|
|
}
|
|
|
|
self.disenioCubierta.presupuestoConfirmado = true;
|
|
self.disenioCubierta.papelForResumen = response.data.cubierta.papel.nombre;
|
|
self.disenioCubierta.gramajeForResumen = response.data.cubierta.gramaje;
|
|
|
|
$('#menu_resumen_button').trigger('click');
|
|
setTimeout(() => {
|
|
self.resumen.init_dropzone();
|
|
self.resumen.generate_total(response.data.resumen.base,
|
|
response.data.resumen.precio_unidad,
|
|
response.data.resumen.total_envio,
|
|
response.data.datosGenerales.ivaReducido);
|
|
}, 0);
|
|
}
|
|
}, 0);
|
|
}
|
|
},
|
|
() => {
|
|
$('#loader').modal('hide');
|
|
this.calcularPresupuesto = true;
|
|
}
|
|
).get();
|
|
}
|
|
|
|
|
|
#isValidDataForm(value) {
|
|
if (value === null || value === undefined || value === '') {
|
|
return false;
|
|
}
|
|
if (typeof value === 'object' && value !== null) {
|
|
const isValidData = Object.values(value).every(isValid);
|
|
return isValidData;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
function isValid(value) {
|
|
if (value === null || value === undefined || value === '') {
|
|
return false;
|
|
}
|
|
if (typeof value === 'object' && value !== null) {
|
|
return Object.values(value).every(isValid);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
function initialize(translations) {
|
|
|
|
window.translations = JSON.parse(translations);
|
|
|
|
let presupuestoCliente = new PresupuestoCliente();
|
|
presupuestoCliente.init();
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
function moveStepperHeader() {
|
|
if ($(window).width() < 768) { // Dispositivos pequeños (menos de 768px)
|
|
if (!$('.bs-stepper-header').parent().hasClass('offcanvas-body')) {
|
|
$('.bs-stepper-header').appendTo('.offcanvas-body');
|
|
}
|
|
} else { // Dispositivos medianos y grandes (768px o más)
|
|
if ($('.bs-stepper-header').parent().hasClass('offcanvas-body')) {
|
|
$('.bs-stepper-header').insertBefore('.offcanvas-body');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Ejecutar la función al cargar la página
|
|
moveStepperHeader();
|
|
|
|
// Ejecutar la función al cambiar el tamaño de la ventana
|
|
window.addEventListener('resize', function () {
|
|
moveStepperHeader();
|
|
});
|
|
|
|
function moveStepperHeader() {
|
|
if ($(window).width() < 768) { // Dispositivos pequeños (menos de 768px)
|
|
if (!$('.bs-stepper-header').parent().hasClass('offcanvas-body')) {
|
|
$('.bs-stepper-header').appendTo('.offcanvas-body');
|
|
}
|
|
} else { // Dispositivos medianos y grandes (768px o más)
|
|
if ($('.bs-stepper-header').parent().hasClass('offcanvas-body')) {
|
|
$('.bs-stepper-header').insertAfter('#menu-offcanvas');
|
|
}
|
|
}
|
|
}
|
|
|
|
const dropdown = document.querySelector(".dropdown-language");
|
|
const activeItem = dropdown.querySelector(".dropdown-menu .dropdown-item");
|
|
let locale = 'es';
|
|
if (activeItem) {
|
|
locale = activeItem.getAttribute("data-language");
|
|
}
|
|
|
|
new Ajax('/translate/getTranslation', { locale: locale, translationFile: 'Presupuestos' }, {},
|
|
initialize,
|
|
function (error) {
|
|
console.log("Error getting translations:", error);
|
|
}
|
|
).post();
|
|
|
|
});
|
|
|
|
|