merge changes from dev/presu_cliente_v2

This commit is contained in:
amazuecos
2024-10-19 07:33:41 +00:00
20 changed files with 23811 additions and 525 deletions

View File

@ -212,7 +212,7 @@ class DatosGenerales {
// Get the selected options
const value = $("#paginasColor").val();
if (value.length >= 0 && Number.isInteger(parseInt(value)) && parseInt(value) >= 0) {
if (parseInt(value) % 2 != 0) {
return {
valid: false,
@ -227,14 +227,14 @@ class DatosGenerales {
}
},
paginasNegro: {
validators: {
callback: {
validators: {
callback: {
message: window.translations["validation"].integer_greatherThan_0,
callback: function (input) {
// Get the selected options
const value = $("#paginasNegro").val();
if (value.length >= 0 && Number.isInteger(parseInt(value)) && parseInt(value) >= 0) {
if (parseInt(value) % 2 != 0) {
return {
valid: false,
@ -338,6 +338,70 @@ class DatosGenerales {
});
}
cargarDatos(datos) {
this.titulo.val(datos.titulo);
this.autor.val(datos.autor);
this.isbn.val(datos.isbn);
this.coleccion.val(datos.coleccion);
this.referenciaCliente.val(datos.referenciaCliente);
this.tirada1.val(parseInt(datos.tirada));
if (datos.tirada2)
this.tirada2.val(parseInt(datos.tirada2));
if (datos.tirada3)
this.tirada3.val(parseInt(datos.tirada3));
if (datos.tirada4)
this.tirada4.val(parseInt(datos.tirada4));
if (datos.checkFormatoPersonalizado) {
this.checkFormatoPersonalizado.prop(':checked', datos.checkFormatoPersonalizado);
this.checkFormatoPersonalizado.trigger('change');
this.papel_formato_alto.val(datos.papelFormatoAlto);
this.papel_formato_ancho.val(datos.papelFormatoAncho);
}
else {
this.formatoLibro.setOption(datos.papelFormatoId, datos.papelFormatoNombre);
this.formatoLibro.setVal(datos.papelFormatoId);
}
this.cliente.setOption(datos.clienteId, datos.clienteNombre);
this.cliente.setVal(datos.clienteId);
$(this.cliente).trigger('change');
this.paginas.val(parseInt(datos.paginas));
this.paginasNegro.val(parseInt(datos.paginasNegro));
this.paginasColor.val(parseInt(datos.paginasColor));
this.paginasColor.trigger('change');
this.posPaginasColor.val(datos.posPaginasColor);
/*
this.papelFormatoId = this.domItem.find("#papelFormatoId");
this.checkFormatoPersonalizado = this.domItem.find("#papelFormatoPersonalizado");
this.formatoPersonalizado = this.domItem.find("#formatoPersonalizado");
this.anchoPersonalizado = this.domItem.find("#papelFormatoAncho");
this.altoPersonalizado = this.domItem.find("#papelFormatoAlto");
this.fresado = $(this.domItem.find("#fresado")[0]);
this.cosido = $(this.domItem.find("#cosido")[0]);
this.tiposLibro = this.domItem.find(".tipo-libro");
this.paginasCuadernillo = this.domItem.find("#paginasCuadernillo");
this.pagColorConsecutivas = this.domItem.find("#pagColorConsecutivas");
this.divPapelDiferente = this.domItem.find("#divPapelDiferente");
this.papelDiferente = this.domItem.find("#papelDiferente");
this.divPosPaginasColor = this.domItem.find("#divPosPaginasColor");
this.posPaginasColor = this.domItem.find("#posPaginasColor");
this.ivaReducido = this.domItem.find("#ivaReducido");
this.excluirRotativa = this.domItem.find("#excluirRotativa");
this.prototipo = this.domItem.find("#prototipo");*/
}
getDimensionLibro() {
let ancho = 0;
@ -376,9 +440,9 @@ class DatosGenerales {
return tiradas;
}
getIsColor() {
if(this.paginasColor.val() > 0) {
if (this.paginasColor.val() > 0) {
return true;
}
return false;
@ -417,11 +481,11 @@ class DatosGenerales {
if (this.fresado.hasClass('selected') || this.cosido.hasClass('selected')) {
$('#tapaDuraLomoRedondo').removeClass('d-none');
if(this.cosido.hasClass('selected')){
if (this.cosido.hasClass('selected')) {
$('#tapaDuraLomoRedondo').addClass('selected');
this.divPaginasCuaderillo.removeClass('d-none');
}
else{
else {
this.divPaginasCuaderillo.addClass('d-none');
}
}
@ -511,7 +575,7 @@ class DatosGenerales {
$(".papel-interior").removeClass('selected');
$(".interior-color").removeClass('d-none');
this.#handleInteriorLayout('mixto');
}
else {
$(".interior-color").addClass('d-none');

View File

@ -212,12 +212,12 @@ class Direcciones {
if (unidades == null || unidades <= 0 || unidades == undefined)
return;
$('#loader').show();
$('#loader').modal('show');
let peticion = new Ajax('/misdirecciones/get/' + id, {}, {},
(response) => {
if (this.direcciones.length == 0) {
$('#loader').hide();
$('#loader').modal('hide');
if (entregaPalets) {
this.calcularPresupuesto = true;
}
@ -237,13 +237,13 @@ class Direcciones {
},
() => {
console.error('Error getting address');
$('#loader').hide();
$('#loader').modal('hide');
});
peticion.get();
} catch (e) {
console.error(e);
$('#loader').hide();
$('#loader').modal('hide');
}
}

View File

@ -39,7 +39,7 @@ class PresupuestoCliente {
this.ajax_calcular = new Ajax('/presupuestocliente/calcular',
{}, this.datos,
this.#procesarPresupuesto.bind(this),
() => { $('#loader').hide(); });
() => { $('#loader').modal('hide'); });
this.actualizarTiradasEnvio = false;
}
@ -66,18 +66,21 @@ class PresupuestoCliente {
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);
this.RELLENAR_PRESUPUESTO(true);
if(window.location.href.includes("edit")){
//load
if (window.location.href.includes("edit")) {
$(".calcular-presupuesto").on('change', ()=>{});
this.#cargarPresupuesto();
const successMessage = sessionStorage.getItem('message');
if(successMessage){
if (successMessage) {
popSuccessAlert(successMessage);
sessionStorage.removeItem('message');
}
}
else{
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
}
}
@ -86,7 +89,7 @@ class PresupuestoCliente {
if (event.target.id === 'divDirecciones') {
if (!this.direcciones.calcularPresupuesto) {
this.actualizarTiradasEnvio = false;
$('#loader').hide();
$('#loader').modal('hide');
return;
}
@ -107,7 +110,7 @@ class PresupuestoCliente {
if (Object.values(datos_to_check).every(this.#isValidDataForm)) {
try {
$('#loader').show();
$('#loader').modal('show');
// Si se está ejecutando la petición, abortar la petición anterior
this.ajax_calcular.abort();
@ -118,7 +121,7 @@ class PresupuestoCliente {
}
catch (e) {
console.log(e);
$('#loader').hide();
$('#loader').modal('hide');
}
}
@ -224,40 +227,49 @@ class PresupuestoCliente {
this.#getDatos(true);
try {
$('#loader').show();
$('#loader').modal('show');
if(window.location.href.includes("edit")){
if (window.location.href.includes("edit")) {
this.datos["id"] = window.location.href.split("/").pop();
}
new Ajax('/presupuestocliente/guardar',
this.datos,
{},
(response) => {
$('#loader').hide();
$('#loader').modal('hide');
console.log(response);
if(this.datos["confirmar"] || window.location.href.includes("add")){
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);
else {
popSuccessAlert(response.message);
}
},
() => { $('#loader').hide(); }
() => { $('#loader').modal('hide'); }
).post();
}
catch (e) {
console.log(e);
$('#loader').hide();
$('#loader').modal('hide');
}
}
#procesarPresupuesto(response) {
$('#loader').hide();
// checj if response.tiradas exists and is not empty
$('#loader').modal('hide');
if (Object.values(response.errors).some((value) => value !== "")) {
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);
return;
}
else{
popAlert2Hide();
}
if (response.tiradas && response.tiradas.length) {
this.divTiradasPrecios.empty();
@ -326,8 +338,11 @@ class PresupuestoCliente {
tirada: this.datosGenerales.getTiradas(),
paginas: this.datosGenerales.paginas.val(),
paginasColor: this.datosGenerales.paginasColor.val(),
paginasCuadernillo: this.datosGenerales.paginasCuadernillo.val(),
posPaginasColor: this.datosGenerales.posPaginasColor.val(),
paginasColorConsecutivas: this.datosGenerales.paginasColorConsecutivas.is(':checked') ? 1 : 0,
papelInteriorDiferente: this.datosGenerales.papelDiferente.is(':checked') ? 1 : 0,
$prototipo: this.datosGenerales.prototipo.is(':checked') ? 1 : 0,
paginasCuadernillo: this.datosGenerales.paginasCuadernillo.val(),
tipo: this.datosGenerales.tiposLibro.filter('.selected').attr('id'),
@ -397,6 +412,32 @@ class PresupuestoCliente {
}
#cargarPresupuesto() {
$('#loader').modal('show');
let id = window.location.href.split("/").pop()
new Ajax('/presupuestocliente/cargar/' + id,
{},
{},
(response) => {
if (response.status === 1) {
this.datosGenerales.cargarDatos(response.data.datosGenerales);
/*this.disenioInterior.cargarDatos(response);
this.disenioCubierta.cargarDatos(response);
this.direcciones.cargarDatos(response);
*/
}
console.log(response);
$('#loader').modal('hide');
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
},
() => {
$('#loader').modal('hide');
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
}
).get();
}
#isValidDataForm(value) {
if (value === null || value === undefined || value === '') {