diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js new file mode 100644 index 00000000..2ba02e94 --- /dev/null +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminAdd.js @@ -0,0 +1,75 @@ +import ClassSelect from '../../components/select2.js'; +import Ajax from '../../components/ajax.js'; + +class PresupuestoAdminAdd{ + + constructor(){ + + this.inc_rei = $('#incRei'); + this.cliente = new ClassSelect($('#clienteId'), '/clientes/cliente/getSelect2', 'Seleccione cliente'); + this.pais = new ClassSelect($('#paisId'), '/paises/menuitems2', 'Seleccione PaĆ­s'); + + $('#solapas').addClass('d-none'); + $('#solapas_sobrecubierta').addClass('d-none'); + $('#div_solapas_ancho').addClass('d-none'); + $('#div_solapas_ancho_sobrecubierta').addClass('d-none'); + + this.tamanio = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.language.Presupuestos.formatoLibro); + this.tamanioPersonalizado = $('#papelFormatoPersonalizado'); + this.anchoPersonalizado = $('#papelFormatoAncho'); + this.altoPersonalizado = $('#papelFormatoAlto'); + + this.init(); + } + + init(){ + + this.cliente.init(); + this.pais.init(); + + this.tamanio.init(); + + this.inc_rei.select2({ + allowClear: false, + }); + + this.tamanioPersonalizado.on('change', this.changeTipoTamanio.bind(this)); + } + + changeTipoTamanio() { + + if (this.tamanioPersonalizado.prop('checked')) { + $('.tamanio-personalizado').removeClass('d-none'); + $('.tamanio-estandar').addClass('d-none'); + this.tamanio.setVal(''); + $("#label_papelFormatoId").text( + window.language.Presupuestos.papelFormatoId + " (" + + window.language.Presupuestos.papelFormatoAncho + " x " + window.language.Presupuestos.papelFormatoAncho + ")*"); + } + else { + this.anchoPersonalizado.val(""); + this.altoPersonalizado.val(""); + $('.tamanio-personalizado').addClass('d-none'); + $('.tamanio-estandar').removeClass('d-none'); + $("#label_papelFormatoId").text( + window.language.Presupuestos.papelFormatoId + '*'); + } + + } + +} + +document.addEventListener('DOMContentLoaded', function () { + + const locale = document.querySelector('meta[name="locale"]').getAttribute('content'); + + new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Presupuestos', 'PresupuestosDirecciones'] }, {}, + function (translations) { + window.language = JSON.parse(translations); + new PresupuestoAdminAdd().init(); + }, + function (error) { + console.log("Error getting translations:", error); + } + ).post(); +}); \ No newline at end of file diff --git a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js index 2d363c1f..59c1d8d9 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js @@ -118,13 +118,95 @@ class PresupuestoAdminEdit { async guardarPresupuesto() { - await this.servicios.guardar(); - await this.envios.guardarEnvios(); - await this.lineasPresupuesto.guardarLineasPresupuesto(); + $('#loader').modal('show'); + + try { + + let formData = $('#presupuestoForm').serialize() + + await this.servicios.guardar(); + await this.envios.guardarEnvios(); + await this.lineasPresupuesto.guardarLineasPresupuesto(); + + } 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 = { + ...datos, ...{ + inc_rei = this.datosGenerales.inc_rei.val(); + titulo: this.datosGenerales.titulo.val(), + autor: this.datosGenerales.autor.val(), + isbn: this.datosGenerales.isbn.val(), + 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.papelFormatoId.hasClass('d-none') ? 0 : this.datosLibro.papelFormatoId.val(), + ///////////////////////////////////////////////////////// + } + } + datos.selectedTirada = this.datosLibro.tirada.val(); + + datos.servicios = { + 'prototipo': this.datosLibro.prototipo.is(':checked') ? 1 : 0, + 'ferro': this.datosLibro.ferro.is(':checked') ? 1 : 0, + 'ferroDigital': 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, + }; + + if (this.comparador.tipo_impresion_id == 1 || this.tipo_impresion_id == 3) { + datos.lomoRedondo = this.comparador.lomoRedondo.select2('data')[0].id; + } + else { + datos.lomoRedondo = 0; + } + + this.datos.entrega_taller = this.envios.entrega_taller.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_presupuesto = $('#comentariosPdf').val(); + datos.comentarios_produccion = $('#comentariosProduccion').val(); + } async updatePresupuesto(event, { + update_lineas = true, update_servicios = true, update_envios = true, @@ -244,7 +326,7 @@ class PresupuestoAdminEdit { cantidad_total += parseInt(rowData.paginas) }) htmlString = '' - + if (cantidad_total != parseInt($('#paginas').val())) { htmlString = `