moonorongo
3/16/2015 - 3:49 PM

Jasper 5.5.0 Reporte simple, listado solamente

Jasper 5.5.0 Reporte simple, listado solamente

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4c538e5d-4322-4f9f-a5b2-0777010f73f6">
	<property name="ireport.zoom" value="1.5"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="0"/>
	<style name="table">
		<box>
			<pen lineWidth="1.0" lineColor="#000000"/>
		</box>
	</style>
	<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
		<box>
			<pen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
		<box>
			<pen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
		<box>
			<pen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 1">
		<box>
			<pen lineWidth="1.0" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
		<box>
			<topPen lineWidth="0.5" lineColor="#000000"/>
			<bottomPen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
		<box>
			<topPen lineWidth="0.5" lineColor="#000000"/>
			<bottomPen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
		<box>
			<topPen lineWidth="0.5" lineColor="#000000"/>
			<bottomPen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 2">
		<box>
			<pen lineWidth="1.0" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 2_TH" mode="Opaque" backcolor="#F0F8FF">
		<box>
			<pen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 2_CH" mode="Opaque" backcolor="#BFE1FF">
		<box>
			<pen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="table 2_TD" mode="Opaque" backcolor="#FFFFFF">
		<box>
			<pen lineWidth="0.5" lineColor="#000000"/>
		</box>
		<conditionalStyle>
			<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
			<style backcolor="#EFF7FF"/>
		</conditionalStyle>
	</style>
	<subDataset name="New Dataset 2" uuid="64e17ba3-a5f0-4412-8ea6-b3498080fe0d">
		<parameter name="codigoAuditoria" class="java.lang.Integer">
			<defaultValueExpression><![CDATA[]]></defaultValueExpression>
		</parameter>
		<queryString>
			<![CDATA[SELECT * FROM CRONOAUDITORIAS WHERE CODAUDITORIA = 0]]>
		</queryString>
		<field name="CODIGO" class="java.lang.Integer"/>
		<field name="CODAUDITORIA" class="java.lang.Integer"/>
		<field name="HORA" class="java.sql.Time"/>
		<field name="DESCRIPCION" class="java.lang.String"/>
		<field name="LUGAR" class="java.lang.String"/>
		<field name="AUDITOR" class="java.lang.String"/>
	</subDataset>
	<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA["C:\\Documents and Settings\\Usuario\\Mis documentos\\isoWeb\\java\\libs\\"]]></defaultValueExpression>
	</parameter>
	<parameter name="fechaDesde" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA["1900-01-01"]]></defaultValueExpression>
	</parameter>
	<parameter name="fechaHasta" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA["2099-12-31"]]></defaultValueExpression>
	</parameter>
	<parameter name="logo" class="java.lang.Object" isForPrompting="false"/>
	<parameter name="DESCRIPCION" class="java.lang.String" isForPrompting="false"/>
	<parameter name="NOMBREFORMULARIO" class="java.lang.String" isForPrompting="false"/>
	<parameter name="FORMULARIO" class="java.lang.String" isForPrompting="false"/>
	<parameter name="REVISION" class="java.lang.String" isForPrompting="false"/>
	<parameter name="fechaDesdeFormatted" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA[$P{fechaDesde}.split("-")[2] +"/"+ $P{fechaDesde}.split("-")[1] +"/"+ $P{fechaDesde}.split("-")[0] ]]></defaultValueExpression>
	</parameter>
	<parameter name="fechaHastaFormatted" class="java.lang.String" isForPrompting="false">
		<defaultValueExpression><![CDATA[$P{fechaHasta}.split("-")[2] +"/"+ $P{fechaHasta}.split("-")[1] +"/"+ $P{fechaHasta}.split("-")[0] ]]></defaultValueExpression>
	</parameter>
	<queryString>
		<![CDATA[SELECT * FROM AUDITORIAS
WHERE ( (FECHAREAL >= $P{fechaDesde}) AND (FECHAREAL <= $P{fechaHasta}) )
ORDER BY FECHAREAL]]>
	</queryString>
	<field name="CODIGO" class="java.lang.Integer"/>
	<field name="NUMERO" class="java.lang.Integer"/>
	<field name="ANIO" class="java.lang.Integer"/>
	<field name="FECHAPROGR" class="java.sql.Date"/>
	<field name="OBJETIVO" class="java.lang.String"/>
	<field name="ALCANCE" class="java.lang.String"/>
	<field name="AUDITORES" class="java.lang.String"/>
	<field name="AUDITADOS" class="java.lang.String"/>
	<field name="LUGAR" class="java.lang.String"/>
	<field name="FECHAREAL" class="java.sql.Date"/>
	<field name="CANTNCONFORM" class="java.lang.Integer"/>
	<field name="CANTOPMEJORA" class="java.lang.Integer"/>
	<field name="CANTOBSERV" class="java.lang.Integer"/>
	<field name="TIPO" class="java.lang.Integer"/>
	<title>
		<band height="69">
			<image scaleImage="RetainShape" vAlign="Middle">
				<reportElement x="426" y="0" width="129" height="62" uuid="a07952d1-e753-4e5f-b880-9d916a51c573"/>
				<imageExpression><![CDATA[$P{logo}]]></imageExpression>
			</image>
			<textField>
				<reportElement x="0" y="0" width="426" height="62" uuid="3262e88f-f669-4a2c-84a9-9bddaa4e424f"/>
				<textElement verticalAlignment="Middle">
					<font size="14" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$P{DESCRIPCION}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement positionType="Float" x="0" y="67" width="555" height="1" forecolor="#000000" uuid="11ccf38d-3880-468a-a8eb-b7e807b8ca7a"/>
			</line>
		</band>
	</title>
	<pageHeader>
		<band height="20">
			<textField>
				<reportElement x="0" y="0" width="555" height="20" uuid="5354eb83-550e-4fb5-a09f-5c970ae2d4b5"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[new String("Periodo: "+ $P{fechaDesdeFormatted} +" a "+ $P{fechaHastaFormatted})]]></textFieldExpression>
			</textField>
		</band>
	</pageHeader>
	<columnHeader>
		<band height="20">
			<staticText>
				<reportElement mode="Opaque" x="0" y="0" width="51" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="35502411-edcb-4cca-bfa9-cb8c16516f3e"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font size="10" isBold="true"/>
					<paragraph rightIndent="4"/>
				</textElement>
				<text><![CDATA[Número]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="100" y="0" width="35" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="b70f8b27-f237-4856-93e8-53e7432bfac5"/>
				<textElement verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[Año]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="135" y="0" width="60" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="9c9bc2cb-1b61-44b8-bb8f-2b4aa3d05ad4"/>
				<textElement verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[Fecha Prog.]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="195" y="0" width="60" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="9f2f3f89-6675-457a-9c62-083ff8b0d668"/>
				<textElement verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[Fecha Real]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="255" y="0" width="99" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="6ff09ad1-b577-48fa-9b29-03dcd221d0ad"/>
				<textElement verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[Objetivo]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="355" y="0" width="100" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="a57db5b2-c5fc-49eb-b13f-3cbca2174457"/>
				<textElement verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[Alcance]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="517" y="0" width="35" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="cd46811f-e47d-4b98-bd71-00bec2f4af33"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[# Obs.]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="484" y="0" width="30" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="b7ab6688-90c9-4680-83e1-625f414c737e"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[# OM]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="454" y="0" width="30" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="370dd646-6308-40d8-aa6b-1a1d889bc8be"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[# NC]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="51" y="0" width="46" height="20" forecolor="#000000" backcolor="#FFFFFF" uuid="827f865e-4d14-46e6-afbe-bbfe51879644"/>
				<textElement verticalAlignment="Middle">
					<font size="10" isBold="true"/>
				</textElement>
				<text><![CDATA[Tipo]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="20" splitType="Stretch">
			<rectangle>
				<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="555" height="20" backcolor="#EBEBEB" uuid="715a7f70-5dca-4575-baaf-372a07a733c7">
					<printWhenExpression><![CDATA[new Boolean( $V{PAGE_COUNT}.intValue() % 2 ==0 )]]></printWhenExpression>
				</reportElement>
				<graphicElement>
					<pen lineWidth="0.0"/>
				</graphicElement>
			</rectangle>
			<textField isBlankWhenNull="true">
				<reportElement x="0" y="0" width="51" height="20" uuid="f617f97e-6a42-4b20-ae2f-150a3d4bc596"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<paragraph rightIndent="4"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{NUMERO}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement x="100" y="0" width="35" height="20" uuid="f18d36f1-8376-45e8-88a0-a4465622657b"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{ANIO}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement x="135" y="0" width="60" height="20" uuid="d81a0c69-a04e-41fe-8045-53d381c18fde"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy").format($F{FECHAPROGR})]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement x="195" y="0" width="60" height="20" uuid="0a2c9b9f-b233-4ce8-be0e-53f453f2a2ea"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[new SimpleDateFormat("dd/MM/yyyy").format($F{FECHAREAL})]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement x="255" y="0" width="99" height="20" uuid="5edbe73f-dfcc-4d0a-8d4f-8231f5993246"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{OBJETIVO}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement x="355" y="0" width="100" height="20" uuid="d485460d-0d2b-4b8f-aac2-013eec826520"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{ALCANCE}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement x="454" y="0" width="30" height="20" uuid="e0de5b30-41da-4d01-b432-9e76706b6828"/>
				<textElement textAlignment="Right" verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{CANTNCONFORM}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement x="485" y="0" width="30" height="20" uuid="78da290f-a043-455b-8398-deb82f271702"/>
				<textElement textAlignment="Right" verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{CANTOPMEJORA}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement x="517" y="0" width="35" height="20" uuid="e38aefce-57f2-416b-9562-6a4694315a15"/>
				<textElement textAlignment="Right" verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[$F{CANTOBSERV}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement x="53" y="0" width="44" height="20" uuid="0bc4efc8-a6ea-4267-99e2-d0879443cdbc"/>
				<textElement verticalAlignment="Middle"/>
				<textFieldExpression><![CDATA[($F{TIPO} == 1)? "Interna" : "Externa"]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<pageFooter>
		<band height="22">
			<textField>
				<reportElement x="443" y="2" width="112" height="20" uuid="b04a3206-e791-4340-952d-beebd4bf70e6"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font fontName="SansSerif" isBold="false"/>
					<paragraph rightIndent="5"/>
				</textElement>
				<textFieldExpression><![CDATA["Página: "+ $V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="2" width="443" height="20" uuid="a30c3096-9266-4682-ae8f-7de510b6d184"/>
				<textElement verticalAlignment="Middle">
					<font fontName="SansSerif" isBold="false"/>
					<paragraph firstLineIndent="5" rightIndent="5"/>
				</textElement>
				<textFieldExpression><![CDATA[$P{NOMBREFORMULARIO} +" - Form: "+ $P{FORMULARIO} +" - Rev: "+ $P{REVISION}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement positionType="Float" x="0" y="0" width="555" height="1" forecolor="#000000" uuid="53090cb4-c592-4dc7-bce0-d04a14bbfd56"/>
			</line>
		</band>
	</pageFooter>
</jasperReport>
	public ModelAndView exportHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getSession(true);
		
		Calendar cal = Calendar.getInstance();
		
		ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
		Firebird db = (Firebird) context.getBean("db");
		
		Configuracion configuracion = (Configuracion) context.getBean("configuracion");
		ConfiguracionData cData = configuracion.get();
		
		Reportes reportes = (Reportes) context.getBean("reportes");
		
		
		db.connect();
		
		Integer CODIGO = Integer.parseInt(request.getParameter("CODIGO"));
		Integer tipoReporte = Integer.parseInt(request.getParameter("tipoReporte"));
		String FECHADESDE = (request.getParameter("FECHADESDE").equalsIgnoreCase("-1"))? "1900-01-01" : request.getParameter("FECHADESDE");
		String FECHAHASTA = (request.getParameter("FECHAHASTA").equalsIgnoreCase("-1"))? "2099-12-31" : request.getParameter("FECHAHASTA");
		String porFecha = (request.getParameter("FECHADESDE").equalsIgnoreCase("-1") && request.getParameter("FECHAHASTA").equalsIgnoreCase("-1"))? "N" : "S";  
		String deployPath = Utils.getDeployPath();
		String jasperTemplatePath = deployPath + "static\\jasper\\auditorias\\";
		
		File logoFile = new File(deployPath + "static\\img\\logos\\"+ cData.getLOGO());
		
		String[] jasperTemplate = new String[2];
		jasperTemplate[0] = "planilla_auditorias.jasper";
		jasperTemplate[1] = "listado.jasper";

		response.setContentType("application/pdf");
		response.setHeader("Content-Disposition", "attachment; filename=reporte_auditoria_"+ cal.get(Calendar.YEAR) 
				+"_"+ (cal.get(Calendar.MONTH) + 1) 
				+"_"+ cal.get(Calendar.DAY_OF_MONTH) +".pdf");
		
		ReportesData rData = reportes.get(tipoReporte + 1);
		
		try {
			db.getConection().setAutoCommit(false);
			
			try {
				Map<String, Object> parameters = new HashMap<String, Object>();
				parameters.put("codigo", CODIGO);
				parameters.put("fechaDesde", FECHADESDE);
				parameters.put("fechaHasta", FECHAHASTA);
				parameters.put("porFecha", porFecha);
				parameters.put("reportDirPath", jasperTemplatePath);

				BufferedImage image = ImageIO.read(logoFile);
				parameters.put("logo", image );				
				parameters.put("DESCRIPCION", rData.getDESCRIPCION());
				parameters.put("NOMBREFORMULARIO", rData.getNOMBREFORMULARIO());
				parameters.put("FORMULARIO", rData.getFORMULARIO());
				parameters.put("REVISION", rData.getREVISION());
				
				
				JasperPrint print = JasperFillManager.fillReport(jasperTemplatePath + jasperTemplate[tipoReporte], parameters, db.getConection());
				JasperExportManager.exportReportToPdfStream(print, response.getOutputStream());		
				
				//JasperFillManager.fillReport(sourceFileName, params, dataSource)
				
			} catch (JRException e) {
				e.printStackTrace();
			}
			
			db.getConection().rollback();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
		db.close();
		return null;
	}