guardar terminado

This commit is contained in:
2024-10-17 22:22:43 +02:00
parent a0128d8f1e
commit 7c9b8a0b6d
19 changed files with 22569 additions and 349 deletions

View File

@ -23,6 +23,10 @@ class PresupuestoCliente {
this.btnSave = $('#btnSave');
this.btnConfirm = $('#btnConfirm');
this.c = $("#c");
this.lc = $("#lc");
this.lsc = $("#lsc");
this.datosGenerales = new DatosGenerales($("#datos-generales"), this.clientePresupuestoWizard, this.validationStepper);
this.disenioInterior = new DisenioInterior($("#interior-libro"), this.clientePresupuestoWizard, this.validationStepper);
this.disenioCubierta = new DisenioCubierta($("#cubierta-libro"), this.clientePresupuestoWizard, this.validationStepper);
@ -43,10 +47,7 @@ class PresupuestoCliente {
init() {
this.btnNext.on('click', this.#nextStep.bind(this));
this.btnPrev.on('click', this.#prevtStep.bind(this));
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
this.RELLENAR_PRESUPUESTO(false);
// Fuerza el foco en el campo de búsqueda de select2
$(document).on('select2:open', () => {
@ -60,18 +61,35 @@ class PresupuestoCliente {
this.disenioCubierta.init();
this.direcciones.init();
//this.RELLENAR_PRESUPUESTO();
this.btnNext.on('click', this.#nextStep.bind(this));
this.btnPrev.on('click', this.#prevtStep.bind(this));
this.btnSave.on('click', this.#savePresupuesto.bind(this));
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
this.RELLENAR_PRESUPUESTO(true);
if(window.location.href.includes("edit")){
//load
const successMessage = sessionStorage.getItem('message');
if(successMessage){
popSuccessAlert(successMessage);
sessionStorage.removeItem('message');
}
}
}
checkForm(event) {
if (event.target.id === 'divDirecciones') {
this.actualizarTiradasEnvio = false;
if(this.direcciones.direcciones.length == 1 && this.direcciones.direcciones[0].getEntregaPalets() == false) {
if (!this.direcciones.calcularPresupuesto) {
this.actualizarTiradasEnvio = false;
$('#loader').hide();
return;
}
}
else {
this.actualizarTiradasEnvio = true;
@ -82,10 +100,10 @@ class PresupuestoCliente {
this.divTiradasPrecios.empty();
let datos_to_check = this.datos;
let datos_to_check = { ...this.datos };
if (datos_to_check.direcciones) {
delete datos_to_check.direcciones;
}
delete datos_to_check.direcciones;
}
if (Object.values(datos_to_check).every(this.#isValidDataForm)) {
try {
@ -96,6 +114,7 @@ class PresupuestoCliente {
this.ajax_calcular.setData(this.datos);
this.ajax_calcular.post();
this.direcciones.calcularPresupuesto = false;
}
catch (e) {
console.log(e);
@ -106,59 +125,66 @@ class PresupuestoCliente {
}
RELLENAR_PRESUPUESTO() {
RELLENAR_PRESUPUESTO(finalizar) {
$("#titulo").val("Titulo del libro");
$("#titulo").trigger('change');
if (finalizar) {
const clienteId = $("#clienteId");
const newOption = new Option("Cliente Potencial", "1817", true, true);
clienteId.append(newOption).trigger('change');
$("#titulo").val("Titulo del libro");
$("#titulo").trigger('change');
const papelFormatoId = $("#papelFormatoId");
const newOption2 = new Option("148 x 210", "1", true, true);
papelFormatoId.append(newOption2).trigger('change');
const clienteId = $("#clienteId");
const newOption = new Option("Cliente Potencial", "1817", true, true);
clienteId.append(newOption).trigger('change');
const papelFormatoId = $("#papelFormatoId");
const newOption2 = new Option("148 x 210", "1", true, true);
papelFormatoId.append(newOption2).trigger('change');
$("#paginasColor").val("6");
$("#paginasColor").trigger('change');
$("#paginasColor").val("6");
$("#paginasColor").trigger('change');
$("#fresado").trigger("click");
$("#fresado").trigger("click");
$("#colorPremium").trigger("click");
$("#offsetBlanco").trigger("click");
$("#colorPremium").trigger("click");
$("#offsetBlanco").trigger("click");
setTimeout(function () {
$("#gramaje90").trigger("click");
}, 0);
setTimeout(function () {
$("#gramaje90").trigger("click");
}, 0);
setTimeout(function () {
$("#tapaDura").trigger("click");
}, 0);
setTimeout(function () {
$("#tapaDura").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#unidadesEnvio").val("50");
}, 0);
setTimeout(function () {
$("#unidadesEnvio").val("50");
}, 0);
}
else {
$("#titulo").trigger('change');
}
}
stepperHandler() {
const element = $('.fv-plugins-bootstrap5.fv-plugins-framework.active');
switch (element.attr('id')) {
case 'datos-generales':
this.btnPrev.addClass('d-none');
@ -193,6 +219,41 @@ class PresupuestoCliente {
}
#savePresupuesto() {
this.#getDatos(true);
try {
$('#loader').show();
if(window.location.href.includes("edit")){
this.datos["id"] = window.location.href.split("/").pop();
}
new Ajax('/presupuestocliente/guardar',
this.datos,
{},
(response) => {
$('#loader').hide();
console.log(response);
if(this.datos["confirmar"] || window.location.href.includes("add")){
sessionStorage.setItem('message', response.message);
window.location.href = response.url + '/' + response.status;
}
else{
popSuccessAlert(response.message);
}
},
() => { $('#loader').hide(); }
).post();
}
catch (e) {
console.log(e);
$('#loader').hide();
}
}
#procesarPresupuesto(response) {
$('#loader').hide();
@ -213,6 +274,8 @@ class PresupuestoCliente {
if (this.actualizarTiradasEnvio)
this.direcciones.insertTirada(response.tiradas[i]);
this.lc.val(parseFloat(response.info.lomo_cubierta).toFixed(2));
this.lsc.val(parseFloat(response.info.lomo_sobrecubierta).toFixed(2));
}
}
// DEBUG
@ -247,13 +310,13 @@ class PresupuestoCliente {
#prevtStep() {
if (this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4){
if (this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4) {
this.validationStepper.previous();
}
}
#getDatos() {
#getDatos(save = false) {
this.datos = {
@ -314,8 +377,23 @@ class PresupuestoCliente {
}
if (this.direcciones.direcciones.length > 0) {
this.datos.direcciones = this.direcciones.direcciones;
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();
}
}