Files
safekat/httpdocs/assets/js/safekat/pages/presupuestoCliente/resumen.js
2024-10-19 10:38:13 +02:00

143 lines
7.7 KiB
JavaScript

class Resumen {
constructor(domItem, datosGenerales, disenioInterior, disenioCubierta, direcciones) {
this.domItem = domItem;
this.datosGenerales = datosGenerales;
this.disenioInterior = disenioInterior;
this.disenioCubierta = disenioCubierta;
this.titulo = $(this.domItem.find("#resumenTitulo"));
this.tipoLibro = $(this.domItem.find("#resumenTipoLibro"));
this.formato = $(this.domItem.find("#resumenFormato"));
this.paginas = $(this.domItem.find("#resumenPaginas"));
this.paginasColor = $(this.domItem.find("#resumenPaginasColor"));
this.paginasNegro = $(this.domItem.find("#resumenPaginasNegro"));
this.tirada = $(this.domItem.find("#resumenTirada"));
this.prototipo = $(this.domItem.find("#resumenPrototipo"));
this.impresionInterior = $(this.domItem.find("#resumenImpresion"));
this.papelInterior = $(this.domItem.find("#resumenPapelInterior"));
this.gramajeInterior = $(this.domItem.find("#resumenGramajeInterior"));
this.papelInteriorColor = $(this.domItem.find("#resumenPapelInteriorColor"));
this.gramajeInteriorColor = $(this.domItem.find("#resumenGramajeInteriorColor"));
this.papelInteriorNegro = $(this.domItem.find("#resumenPapelInteriorNegro"));
this.gramajeInteriorNegro = $(this.domItem.find("#resumenGramajeInteriorNegro"));
this.cubiertaTipo = $(this.domItem.find("#resumenCubiertaTipo"));
this.itemsCubiertaTapaBlanda = $(this.domItem.find(".cubierta-tapa-blanda"));
this.itemsCubiertaTapaDura = $(this.domItem.find(".cubierta-tapa-dura"));
this.carasCubierta = $(this.domItem.find("#resumenCarasCubierta"));
this.papelCubierta = $(this.domItem.find("#resumenPapelCubierta"));
this.gramajeCubierta = $(this.domItem.find("#resumenGramajeCubierta"));
this.solapasCubierta = $(this.domItem.find("#resumenSolapasCubierta"));
this.papelGuardas = $(this.domItem.find("#resumenPapelGuardas"));
this.guardasImpresas = $(this.domItem.find("#resumenGuardasImpresas"));
this.cabezada = $(this.domItem.find("#resumenCabezada"));
this.cubiertaAcabados = $(this.domItem.find("#resumenCubiertaAcabados"));
this.divSobrecubierta = $(this.domItem.find("#divResumenSobrecubierta"));
this.papelSobrecubierta = $(this.domItem.find("#resumenPapelSobrecubierta"));
this.gramajeSobrecubierta = $(this.domItem.find("#resumenGramajeSobrecubierta"));
this.solapasSobrecubierta = $(this.domItem.find("#resumenSolapasSobrecubierta"));
this.plastificadoSobrecubierta = $(this.domItem.find("#resumenPlastificadoSobrecubierta"));
this.precio_unidad = $(this.domItem.find("#resumenPrecioU"));
this.total_base = $(this.domItem.find("#resumenTotalBase"));
this.iva_porcentaje = $(this.domItem.find("#resumenIvaPorcentaje"));
this.iva = $(this.domItem.find("#resumenIva"));
this.total = $(this.domItem.find("#resumenTotal"));
}
init() {
}
generate() {
this.titulo.text(this.datosGenerales.titulo.val());
this.tipoLibro.text(this.#capitalizeFirstLetter(this.datosGenerales.tiposLibro.filter('.selected').attr('id')));
this.formato.text(this.datosGenerales.papelFormatoId.find('option:selected').text());
this.paginas.text(this.datosGenerales.paginas.val());
this.paginasColor.text(this.datosGenerales.paginasColor.val());
this.paginasNegro.text(this.datosGenerales.paginasNegro.val());
this.tirada.text(parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada')));
this.prototipo.text(this.datosGenerales.prototipo.is(':checked') ? 'Sí' : 'No');
const HQ = this.disenioInterior.getIsHq();
const color = this.datosGenerales.getIsColor();
const papelInterior = this.disenioInterior.getPapel(true);
const gramajeInterior = this.disenioInterior.getGramaje();
if ($(".interior-color").hasClass('d-none')) {
this.domItem.find(".mismoInterior").removeClass('d-none');
this.domItem.find(".diferenteInterior").addClass('d-none');
const impInterior = (color ? "Color " : "Blanco y Negro") + (HQ ? "Premium" : "Estándar");
this.impresionInterior.text(impInterior);
this.papelInterior.text(papelInterior);
this.gramajeInterior.text(gramajeInterior);
}
else {
this.domItem.find(".mismoInterior").addClass('d-none');
this.domItem.find(".diferenteInterior").removeClass('d-none');
const impInterior = ("Negro " + (HQ.negro ? "Premium" : "Estándar") + " / Color" + (HQ.color ? "Premium" : "Estándar"));
this.impresionInterior.text(impInterior);
this.papelInteriorNegro.text(papelInterior.negro);
this.papelInteriorColor.text(papelInterior.color);
this.gramajeInteriorNegro.text(gramajeInterior.negro);
this.gramajeInteriorColor.text(gramajeInterior.color);
}
this.cubiertaTipo.text($($('.tipo-cubierta.selected').find('.form-label')).text());
this.carasCubierta.text(this.disenioCubierta.carasCubierta.find('option:selected').text());
if (this.cubiertaTipo.text().toLowerCase().includes('blanda')) {
this.itemsCubiertaTapaBlanda.removeClass('d-none');
this.itemsCubiertaTapaDura.addClass('d-none');
const solapasCubierta = this.disenioCubierta.getSolapasCubierta();
this.solapasCubierta.text( solapasCubierta == false ? 'No' : solapasCubierta);
}
else {
this.itemsCubiertaTapaDura.removeClass('d-none');
this.itemsCubiertaTapaBlanda.addClass('d-none');
const guardas = this.disenioCubierta.getGuardas(true);
this.papelGuardas.text(guardas.papel + ' ' + guardas.gramaje);
this.guardasImpresas.text(guardas.guardasImpresas);
this.cabezada.text(this.disenioCubierta.getCabezada(true));
}
this.papelCubierta.text($($('.papel-cubierta.selected').find('.form-label')).text())
this.gramajeCubierta.text(this.disenioCubierta.getGramaje());
this.cubiertaAcabados.text(this.disenioCubierta.getAcabados(true));
if (this.disenioCubierta.getSobrecubierta()) {
this.divSobrecubierta.removeClass('d-none');
const sobrecubierta = this.disenioCubierta.getSobrecubierta(true);
this.papelSobrecubierta.text(sobrecubierta.papel);
this.gramajeSobrecubierta.text(sobrecubierta.gramaje);
this.solapasSobrecubierta.text(sobrecubierta.solapas);
this.plastificadoSobrecubierta.text(sobrecubierta.plastificado);
}
else {
this.divSobrecubierta.addClass('d-none');
}
const unidades = parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada'));
const tarjetaPrecio = $('.tarjeta-tiradas-precios').filter(function () {
return parseInt($(this).find('.tarjeta-tiradas-precios-tirada').attr('data')) == unidades;
});
this.precio_unidad.text(tarjetaPrecio.find('.tarjeta-tiradas-precios-precio-unidad').attr('data'));
const base = tarjetaPrecio.find('.tarjeta-tiradas-precios-precio').attr('data');
const iva_porcentaje = this.datosGenerales.ivaReducido.find('option:selected').val() == 1 ? 0.21 : 0.04;
const iva = (parseFloat(base) * iva_porcentaje).toFixed(2);
this.total_base.text(base);
this.iva_porcentaje.text(this.datosGenerales.ivaReducido.find('option:selected').val() == 1 ? '21' : '4');
this.iva.text(iva);
this.total.text((parseFloat(base) + parseFloat(iva)).toFixed(2));
}
#capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
}
export default Resumen;