<%-- Document : xml_get_declaracion_pdf Created on : 06/08/2013, 01:14:56 PM Author : Martha --%> <%@page import="extras.formatFecha"%> <%@page import="clases.comun"%> <%@page import = "java.sql.*" import = "conexion.*" import = "java.util.*" import = "java.util.Map" import = "java.util.HashMap" import = "java.util.Date" import = "java.text.SimpleDateFormat" import = "java.io.*" import = "java.lang.*" import = "general.Config" import = "general.Permisos" import = "net.sf.jasperreports.engine.*" import = "net.sf.jasperreports.engine.JasperExportManager" import = "net.sf.jasperreports.engine.JasperFillManager" import = "net.sf.jasperreports.engine.JasperPrint" import = "net.sf.jasperreports.engine.JasperReport" import = "net.sf.jasperreports.engine.util.JRLoader" import = "net.sf.jasperreports.engine.data.JRBeanCollectionDataSource" import = "net.sf.jasperreports.engine.design.JasperDesign" import = "net.sf.jasperreports.engine.design.JRDesignQuery" import = "net.sf.jasperreports.engine.xml.JRXmlLoader" import = "net.sf.jasperreports.engine.util.JRLoader" %> Reportes de Declaraciones <% out.println(""); String nompag[] = request.getRequestURI().split("/"); /********************** tomo el formato de la fecha *************************/ SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat formato1 = new SimpleDateFormat("dd-MMMM-yyyy"); SimpleDateFormat formato2 = new SimpleDateFormat("yyyy"); Date hoy = new Date(); String fecha_hoy = formato.format(hoy); %> <% Conexion c = null; Connection lc_connection = null; ResultSet lrs_res = null; Statement lst_stm = null; /*Segunda Conexión*/ ConexionDeclaranet cd = null; Connection lcd_connection = null; Statement lstg_conecta=null; /*FIN. SEGUNDA CONEXIÓN*/ boolean lb_connection = true; Connection lcnt_con = null; String debug = new String("si"); String emergent_error = new String(""); //String nompag[] = request.getRequestURI().split("/"); String ruta = new String(""); String ruta_archivos = new String(""); String ruta_imagen = new String(""); String ruta_imagen1 = new String(""); boolean correcto = false; String Wquery = new String(""); String ls_query = ""; String nombre_jrxml = new String(""); String tittle_reporte = new String(" DECLARACIONES"); String ruta_archivos_exportar = new String(""); String nombre_archivo = new String(""); String descripcion = ""; String descripcion0 = ""; String descripcion1 = ""; String fecha = ""; String fecha1 = ""; String dividir[] = {"0", "0", "0"}; /*Periodo de la declaracion Anual*/ String fecha_hoy1 = formato2.format(hoy); //String mes = comun.obtenerMes(); int year = Integer.parseInt(fecha_hoy1); //fecha_hoy1 = (year-1)+"-"+(Integer.parseInt(mes)+3)+"-01"; //int dia = comun.obtenerUltimoDiaMes(year, (Integer.parseInt(mes))); String fecha_final = "31 DE DICIEMBRE DE "+(year-1); /**/ /********* INICIO. Conexión a la base de datos 2 ********/ try { cd = new ConexionDeclaranet(); lcd_connection = cd.getConnection(); lstg_conecta = lcd_connection.createStatement(); lb_connection = true; }catch (Exception e) { emergent_error = "Error al conectarse a la base de datos 2 "; if (debug.equals("si")) { emergent_error += e; } lb_connection = false; } /********* FIN. Conexión a la base de datos ********/ if (lb_connection) { try { // Creando ruta de archivos fisica try { java.net.URL url_clase = Conexion.class.getResource(""); ruta = url_clase.getPath().substring(0, url_clase.getPath().indexOf("WEB-INF")); int hli_vacio = 0; String ls_path = ""; // Eliminar los espacios en la ruta (%20) hli_vacio = ruta.indexOf("%20"); if (hli_vacio > 0) { ls_path = ruta.substring(0, hli_vacio); while (hli_vacio < ruta.length() && hli_vacio > 0) { ls_path = ls_path + " " + ruta.substring(hli_vacio + 3, ruta.length()); hli_vacio = ruta.indexOf("%20", hli_vacio + 1); if (hli_vacio == -1) { ruta = ls_path; break; } ls_path = ls_path.substring(0, hli_vacio - 2); } } } catch (Exception e) { emergent_error += " Error al obtener la ruta física para almacenar el achivo: "; if (debug.equals("si")) { emergent_error += e; } throw new Exception(e.toString()); } int total_imbuebles_adquisiciones = 0; int total_imbuebles_remodelacion = 0; int total_imbuebles_ventas = 0; int total_muebles_adquisiciones = 0; int total_muebles_ventas = 0; int total_cuentas_bancarias = 0; int total_inversiones = 0; int total_inversiones_e = 0; int total_adeudos = 0; int total_pago_adeudos = 0; ls_query="select count(*) as total from real_estates re " + "where re.estate_custom_type_id=1 AND re.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { total_imbuebles_adquisiciones =lrs_res.getInt("total"); } ls_query="select count(*) as total from real_estates re " + "where re.estate_custom_type_id=2 AND re.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { total_imbuebles_remodelacion =lrs_res.getInt("total"); } ls_query="select count(*) as total from real_estates re " + "where re.estate_custom_type_id=3 AND re.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { total_imbuebles_ventas =lrs_res.getInt("total"); } ls_query="select COUNT(*) AS total from personal_belongings pb " + "where pb.is_sale_id=1 and id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { total_muebles_adquisiciones =lrs_res.getInt("total"); } ls_query="select COUNT(*) AS total from personal_belongings pb " + "where pb.is_sale_id=0 and id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { total_muebles_ventas =lrs_res.getInt("total"); } ls_query="select COUNT(*) AS total from bank_accounts b " + "where b.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { total_cuentas_bancarias =lrs_res.getInt("total"); } ls_query="select COUNT(*) AS total from investments i " + "where i.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { total_inversiones =lrs_res.getInt("total"); } ls_query="select COUNT(*) AS total from establishment_investments i " + "where i.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); if (lrs_res.next()) { total_inversiones_e =lrs_res.getInt("total"); } ls_query="select COUNT(*) AS total from debits d " + "where is_payment_id=0 and d.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); if (lrs_res.next()) { total_adeudos =lrs_res.getInt("total"); } ls_query="select COUNT(*) AS total from debits d " + "where is_payment_id=1 and d.id_declaracion="+request.getParameter("id_declaracion")+";"; lrs_res = lstg_conecta.executeQuery(ls_query); if (lrs_res.next()) { total_pago_adeudos =lrs_res.getInt("total"); } ls_query="select a.id_altabaja, a.id_funcionario, a.id_puesto_funcionario, " + "d.id_declaracion, td.descripcion, d.id_tipodeclaracion, d.id_altabajafi, " + "d.fecha_declaracion, d.period_at, d.permiso, d.id_historial " + "from declaration d " + "left join altabaja a ON a.id_altabaja=d.id_altabaja " + "left join tipodeclaracion td ON td.id_tipodeclaracion=d.id_tipodeclaracion " + "where d.id_declaracion="+request.getParameter("id_declaracion")+";"; ////////termina la creacion de la ruta fisica ruta_imagen = ruta + "medios/imagenes/"; ruta_imagen1 = ruta + "medios/tema/"; ruta_archivos = ruta + "declaranet/declaraciones/"; ruta_archivos_exportar = ruta + "declaranet/declaraciones/pdf/"; nombre_archivo = "declaracion"; String ruta_jasper = ruta_archivos + "jaspers/"; String archivo = ruta_archivos + "pdf/"; nombre_jrxml = ruta_archivos + "jaspers/00.jrxml"; String permiso = ""; //out.println(ls_query); Map params = new HashMap(); params.put("escudo", ruta_imagen1 + "/banner.png"); //params.put("mich", ruta_imagen + "/michoacan.png"); params.put("escudomich", ruta_imagen + "/esc.jpg"); params.put("id_declaracion", Integer.parseInt(request.getParameter("id_declaracion"))); params.put("SUBREPORT_DIR", ruta_jasper); params.put("total_imbuebles_adquisiciones", total_imbuebles_adquisiciones); params.put("total_imbuebles_remodelacion", total_imbuebles_remodelacion); params.put("total_imbuebles_ventas", total_imbuebles_ventas); params.put("total_muebles_adquisiciones", total_muebles_adquisiciones); params.put("total_muebles_ventas", total_muebles_ventas); params.put("total_cuentas_bancarias", total_cuentas_bancarias); params.put("total_inversiones", total_inversiones); params.put("total_inversiones_e", total_inversiones_e); params.put("total_adeudos", total_adeudos); params.put("total_pago_adeudos", total_pago_adeudos); try { lrs_res = lstg_conecta.executeQuery(ls_query); //out.println(lst_stm); if (lrs_res.next()) { //out.println("Entro"); if(lrs_res.getString("permiso").equals("0")){ permiso= "NO"; }else if(lrs_res.getString("permiso").equals("1")){ permiso= "SI"; } nombre_archivo += ".pdf"; if(lrs_res.getInt("id_tipodeclaracion")==2){ descripcion="DECLARACIÓN ANUAL DE MODIFICACIONES PATRIMONIALES"; descripcion0="BAJO PROTESTA DE DECIR VERDAD Y EN CUMPLIMIENTO A LO DISPUESTO EN LOS ARTÍCULOS 8, FRACCIÓN XXIV, 48, 49 Y 52, DE LA LEY DE RESPONSABILIDADES Y REGISTRO PATRIMONIAL DE LOS SERVIDORES PÚBLICOS DEL ESTADO DE MICHOACÁN Y SUS MUNICIPIOS, 1, 4 Y 12 DE LOS LINEAMIENTOS PARA LA RECEPCIÓN, REGISTRO, CONTROL, RESGUARDO Y SEGUIMIENTO DE LAS DECLARATACIONES DE SITUACIÓN PATRIMONIAL, PRESENTO A USTED LAS MODIFICACIONES A MI SITUACIÓN PATRIMONIAL POR EL PERIODO:"; descripcion1=""; dividir=formato1.format(lrs_res.getDate("period_at")).split("-"); fecha="DEL "+dividir[0]+" DE "+dividir[1].toUpperCase()+" DEL "+dividir[2]+" AL "; //dividir=formato1.format(lrs_res.getDate("fecha_declaracion")).split("-"); //fecha+="31 DE DICIEMBRE DEL 2014"; fecha+=fecha_final; }else{ descripcion="DECLARACIÓN DE SITUACIÓN PATRIMONIAL INICIAL/FINAL"; descripcion0="BAJO PROTESTA DE DECIR VERDAD Y EN CUMPLIMIENT A LOS DISPUESTO EN LOS ARTÍCULOS 8, FRACCIÓN XXIV, 48, 49 Y 52, DE LA LEY DE RESPONSABILIDADES Y REGISTRO PATRIMONIAL DE LOS SERVIDORES PÚBLICOS DEL ESTADO DE MICHOACÁN Y SUS MUNICIPIOS; 1, 4 Y 12 DE LOS LINEAMIENTOS PARA LA RECEPCIÓN, REGISTRO, CONTROL, RESGUARDO Y SERGUIMIENTO DE LAS DECLARACIONES DE SITUACIÓN PATRIMONIAL, PRESENTO A USTED LA DECLARACIÓN DE MI SITUACIÓN PATRIMONIAL."; descripcion1="DECLARACIÓN DE SITUACIÓN PATRIMONIAL"; dividir=formato1.format(lrs_res.getDate("fecha_declaracion")).split("-"); fecha=dividir[0]+" DE "+dividir[1].toUpperCase()+" DEL "+dividir[2]; } params.put("descripcion", descripcion); params.put("descripcion0", descripcion0); params.put("descripcion1", descripcion1); params.put("fecha", fecha); params.put("permisos", permiso); params.put("id_altabajafi", lrs_res.getString("id_altabajafi")); %>
Generando reporte, espere por favor...


Cargando
<% JasperDesign jasperDesign = JRXmlLoader.load(nombre_jrxml); JRDesignQuery query = new JRDesignQuery(); query.setText(ls_query); jasperDesign.setQuery(query); JasperReport reporte = JasperCompileManager.compileReport(jasperDesign); JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, params, lcd_connection); JasperExportManager.exportReportToPdfFile(jasperPrint, ruta_archivos_exportar + nombre_archivo); out.println(" "); %> <% } else { %>

Lo sentimos pero no se generó el PDF. Verifique la información.
<% } } catch (Exception e) { %>
<%="Error al crear reporte de Acuse de la Declaración. Error: " + e%>
<% } finally { lst_stm.close(); lcnt_con.close(); lstg_conecta.close(); lcd_connection.close(); } }catch (Exception e) { } } %>