bug para presupuesto cliente (en direcciones)

This commit is contained in:
2024-11-06 17:15:41 +01:00
parent 55b225ab49
commit 0b614d4d58
7 changed files with 276 additions and 65 deletions

View File

@ -64,9 +64,8 @@ class DatosGenerales {
// Selects
this.formatoLibro.init();
if (!$(this.excluirRotativa).prop('hidden')){
this.cliente.init();
}
this.cliente.init();
// Inicializa el tipo de impresion
this.#handlePaginas();
@ -386,11 +385,9 @@ class DatosGenerales {
this.coleccion.val(datos.coleccion);
this.referenciaCliente.val(datos.referenciaCliente);
if (!$(this.excluirRotativa).prop('hidden')){
this.cliente.setOption(datos.clienteId, datos.clienteNombre);
this.cliente.setVal(datos.clienteId);
$(this.cliente).trigger('change');
}
this.cliente.setOption(datos.clienteId, datos.clienteNombre);
this.cliente.setVal(datos.clienteId);
$(this.cliente).trigger('change');
if (datos.excluirRotativa) {
this.excluirRotativa.prop('checked', true);
@ -440,7 +437,7 @@ class DatosGenerales {
this.ivaReducido.val(datos.ivaReducido ? 1 : 0).trigger('change');
}
getCliente(){
getCliente() {
if ($(this.excluirRotativa).prop('hidden'))
return $('#clienteId').val();
return this.cliente.getVal();

View File

@ -61,8 +61,15 @@ class PresupuestoCliente {
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){
if (this.datosGenerales.excluirRotativa.length == 0) {
this.direcciones.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").val() })
}
@ -71,6 +78,7 @@ class PresupuestoCliente {
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.btnConfirm.on('click', this.#confirmPresupuesto.bind(this));
this.titulosMenu.on('click', this.#handleTitulosMenu.bind(this));
@ -88,7 +96,6 @@ class PresupuestoCliente {
}
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
}
@ -362,10 +369,27 @@ class PresupuestoCliente {
}
#confirmPresupuesto() {
this.#solicitudGuardarPresupuesto(true);
}
#savePresupuesto() {
this.#solicitudGuardarPresupuesto(false);
}
#solicitudGuardarPresupuesto(confirmar = false) {
this.#getDatos(true);
if (confirmar) {
this.datos["confirmar"] = 1;
}
try {
$('#loader').modal('show');
@ -599,17 +623,28 @@ class PresupuestoCliente {
this.calcularPresupuesto = false;
this.datosGenerales.cargarDatos(response.data.datosGenerales);
if (!$(this.datosGenerales.excluirRotativa).prop("hidden")) {
this.direcciones.handleChangeCliente();
}
this.direcciones.handleChangeCliente();
this.disenioInterior.cargarDatos(response.data.interior, response.data.datosGenerales.papelInteriorDiferente);
this.disenioCubierta.cargarDatos(response.data.cubierta, response.data.guardas, response.data.sobrecubierta);
this.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales);
setTimeout(() => {
$('#loader').modal('hide');
this.calcularPresupuesto = true;
this.checkForm({ target: { id: 'tirada' } });
if (response.data.state != 2) {
this.calcularPresupuesto = true;
this.checkForm({ target: { id: 'tirada' } });
}
else {
$('#menu_resumen_button').trigger('click');
setTimeout(() => {
this.resumen.init_dropzone();
this.resumen.generate_total(response.data.resumen.base, response.data.resumen.precio_unidad);
}, 0);
}
}, 0);
}
},

View File

@ -53,13 +53,133 @@ class Resumen {
this.divPreview = $(this.domItem.find("#pv_ec_shape"));
this.btnPreviewCubierta = $(this.domItem.find("#btnPreviewCubierta"));
this.init();
this.submitFiles = $(this.domItem.find("#submit-all-files"));
this.dropzone = null;
this.presupuesto_id = -1;
}
init() {
init(presupuesto_id = -1) {
this.btnPreviewCubierta.on('click', this.#btnPreview.bind(this));
this.submitFiles.on('click', this.#btnUploadFiles.bind(this));
if (presupuesto_id != -1) {
this.presupuesto_id = presupuesto_id;
}
}
init_dropzone(presupuesto_id) {
Dropzone.autoDiscover = false;
const previewTemplate = `<div class="dz-preview dz-file-preview">
<div class="dz-details">
<div class="dz-thumbnail">
<!---<img data-dz-thumbnail>
<span class="dz-nopreview">No preview</span> --->
<div class="dz-success-mark"></div>
<div class="dz-error-mark"></div>
<div class="dz-error-message"><span data-dz-errormessage></span></div>
<div class="progress">
<div class="progress-bar progress-bar-primary" role="progressbar" aria-valuemin="0" aria-valuemax="100" data-dz-uploadprogress></div>
</div>
</div>
<div class="dz-filename" data-dz-name></div>
<div class="dz-size" data-dz-size></div>
</div>
</div>`;
this.dropzone = new Dropzone('#dropzone-multi', {
url: "/presupuestos/presupuestocliente/upload_files",
addRemoveLinks: true,
previewTemplate: previewTemplate,
paramName: "file",
uploadMultiple: true,
parallelUploads: 4, // Ajusta este número al máximo número de archivos que esperas subir a la vez
maxFiles: 5, // Ajusta este número al máximo número de archivos que esperas subir a la vez
autoProcessQueue: true,
dictRemoveFile: "Eliminar",
acceptedFiles: 'image/*, application/pdf',
maxFilesize: 5e+7, // Bytes
init: function () {
let thisDropzone = this;
$('#loader').show();
$.ajax({
url: "/presupuestos/presupuestocliente/get_files",
type: 'POST',
data: { presupuesto_id: presupuesto_id },
}).done(function (response) {
if (response == null || response == "") {
return;
}
let values = JSON.parse(response);
for (var i = 0; i < values.length; i++) {
var mockFile = { name: values[i].name, size: values[i].size, hash: values[i].hash };
thisDropzone.files.push(mockFile); // add to files array
thisDropzone.emit("addedfile", mockFile);
thisDropzone.emit("thumbnail", mockFile, window.location.host + "/sistema/intranet/presupuestos/" + values[i].hash);
thisDropzone.emit("complete", mockFile);
thisDropzone.options.success.call(thisDropzone, mockFile);
};
}).always(function () {
$('#loader').hide();
});
this.on("addedfile", function (file) {
if (file.hash) {
var viewButton = Dropzone.createElement("<span class='dz-remove'>Ver</span>");
file.previewElement.appendChild(viewButton);
// Listen to the view button click event
viewButton.addEventListener("click", function (e) {
window.open(window.location.protocol + "//" + window.location.host + "/sistema/intranet/presupuestos/" + file.hash, '_blank');
});
}
});
}
});
}
#btnUploadFiles() {
var files = this.dropzone.files;
$('#loader').show();
var formData = new FormData();
var oldFiles = [];
var counter = 0;
for (var i = 0; i < files.length; i++) {
if (files[i].upload) {
var file = files[i];
formData.append('file[' + counter + ']', file);
counter += 1;
}
else {
oldFiles.push(files[i].name);
}
}
formData.append('oldFiles', JSON.stringify(oldFiles));
formData.append('presupuesto_id', this.presupuesto_id);
$.ajax({
url: "/presupuestos/presupuestocliente/upload_files",
type: 'POST',
data: formData,
processData: false, // Indicar a jQuery que no procese los datos
contentType: false // Indicar a jQuery que no establezca el tipo de contenido
}).done(function (response) {
}).always(function () {
$('#loader').hide();
});
}
@ -178,15 +298,15 @@ class Resumen {
const tarjetaPrecio = $('.tarjeta-tiradas-precios').filter(function () {
return parseInt($(this).find('.tarjeta-tiradas-precios-tirada').attr('data')) == unidades;
});
let precio_u_text = tarjetaPrecio.find('.tarjeta-tiradas-precios-precio-unidad').text();
let precio_u_text = tarjetaPrecio.find('.tarjeta-tiradas-precios-precio-unidad').text();
precio_u_text = precio_u_text.replace('€/u', '');
precio_u_text = this.#changeDecimalFormat(precio_u_text);
const base = tarjetaPrecio.find('.tarjeta-tiradas-precios-precio').attr('data');
let base_text = this.#changeDecimalFormat(base);
const iva_porcentaje = this.datosGenerales.ivaReducido.find('option:selected').val() == 1 ? 0.21 : 0.04;
const iva = (parseFloat(base) * iva_porcentaje).toFixed(2);
let iva_text = this.#changeDecimalFormat(iva);
@ -202,6 +322,28 @@ class Resumen {
}
generate_total(base, precio_u) {
let precio_u_text = String(precio_u);
precio_u_text = precio_u_text.replace('€/u', '');
precio_u_text = this.#changeDecimalFormat(precio_u_text);
let base_text = this.#changeDecimalFormat(String(base));
const iva_porcentaje = this.datosGenerales.ivaReducido.find('option:selected').val() == 1 ? 0.21 : 0.04;
const iva = (parseFloat(base) * iva_porcentaje).toFixed(2);
let iva_text = this.#changeDecimalFormat(iva);
const total = (parseFloat(base) + parseFloat(iva)).toFixed(2);
let total_text = this.#changeDecimalFormat(total);
this.precio_unidad.text(precio_u_text);
this.total_base.text(base_text);
this.iva_porcentaje.text(this.datosGenerales.ivaReducido.find('option:selected').val() == 1 ? '21' : '4');
this.iva.text(iva_text);
this.total.text(total_text);
}
#capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
@ -209,7 +351,7 @@ class Resumen {
#changeDecimalFormat(number) {
let cleanedNumber = String(number).replace(/[^\d.]/g, '');
let partes = cleanedNumber.split('.');
partes[0] = partes[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');