Requirement:The user has the following report data: | [toc on_off::hide=0 box::collapsed=1] |
The report requirement is to print an acknowledgement letter to each customer along with an Invoice summary in one page, followed by individual invoices for the customer on separate pages. Using the sample data above, the report layout will be as the following:
Page 1
Page 2
Page 3
Page 4
Page 5
Design Consideration
- In this sample report, we will use one single report template to display the report layout as requested.
- Report uses multiple detail bands to host different parts of the report layout. This makes report design flexible and scalable. User can simply add additional information to each segment of the original report design in the corresponding detail band without having to modify the entire report layout. It relies on JasperReports engine to adjust report field and band height at the run time to accommodate data overflow.
- Report data is sorted in customer and invoice order.
- Report main query will produce invoice page (refer to report sample page 2, 3, and 5 above) in detail band 5.
- Report uses four detail bands (1 through 4) to display customer page (sample page 1 and 4 above). Variable height band 1 contains acknowledgement letter. Fixed height band 2 contains customer information and invoice listing column headers. Variable height band 3 contains customer invoice detail information. Fixed height band 4 contains invoice tally information.
- Report sub query will produce customer invoice information (refer to the middle part of the page 1 and 4 above) and display it in a report List element in detail band 3.
- Report contains two groups.
- The outer group (customer) is used to help determine the first invoice in the group so as to trigger detail band 1 to 4 to be printed before printing invoice detail band 5.
- The outer group (customer) also helps to tally the customer invoice total amount displayed in detail band 4.
- The inner group (invoice) is used to trigger new pages for every invoice records.
- There’s a hard coded page break in detail band 4 after the invoice amount total field to separate customer page and invoice page.
Report Design
<?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.1.0.beta-v201503201603 using JasperReports Library version 6.0.4 --> <!-- 2015-03-31T20:52:17 --> <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="sample_report_4susobh" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="27f50dbe-36cc-4a65-8bd5-e0166d16d1f1"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JRSrepo"/> <subDataset name="Dataset1-customer" uuid="6adcc2f7-01c0-4e96-a01a-a5bc10691a80"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JRSrepo"/> <parameter name="customer" class="java.lang.String"> <defaultValueExpression><![CDATA["A1"]]></defaultValueExpression> </parameter> <queryString language="SQL"> <![CDATA[ select * from ( select 'A1' as Customer,'INV001' as Invoice,DATE '2010-01-01' as InvoiceDate,1000.00 as Amount union all select 'A2' as Customer,'INV002' as Invoice,DATE '2010-03-02' as InvoiceDate,2000.00 as Amount union all select 'A1' as Customer,'INV003' as Invoice,DATE '2010-03-02' as InvoiceDate,1500.00 as Amount ) as mock_up_data where Customer = $P{customer} order by 1, 2 ]]> </queryString> <field name="customer" class="java.lang.String"/> <field name="invoice" class="java.lang.String"/> <field name="invoicedate" class="java.sql.Date"/> <field name="amount" class="java.math.BigDecimal"/> </subDataset> <parameter name="Acknowledgement" class="java.lang.String"> <parameterDescription><![CDATA[]]></parameterDescription> <defaultValueExpression><![CDATA["Acknowledgement"]]></defaultValueExpression> </parameter> <queryString language="SQL"> <![CDATA[ select * from ( select 'A1' as Customer,'INV001' as Invoice,DATE '2010-01-01' as InvoiceDate,1000.00 as Amount union all select 'A2' as Customer,'INV002' as Invoice,DATE '2010-03-02' as InvoiceDate,2000.00 as Amount union all select 'A1' as Customer,'INV003' as Invoice,DATE '2010-03-02' as InvoiceDate,1500.00 as Amount ) as mock_up_data order by 1, 2 ]]> </queryString> <field name="customer" class="java.lang.String"/> <field name="invoice" class="java.lang.String"/> <field name="invoicedate" class="java.sql.Date"/> <field name="amount" class="java.math.BigDecimal"/> <variable name="sum_amount" class="java.math.BigDecimal" resetType="Group" resetGroup="customer" calculation="Sum"> <variableExpression><![CDATA[$F{amount}]]></variableExpression> </variable> <group name="customer"> <groupExpression><![CDATA[$F{customer}]]></groupExpression> </group> <group name="invoice" isStartNewPage="true"> <groupExpression><![CDATA[$F{invoice}]]></groupExpression> </group> <background> <band splitType="Stretch"/> </background> <title> <band height="30" splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <staticText> <reportElement x="0" y="0" width="570" height="30" forecolor="#DE1512" uuid="ff55e1e7-5eaa-4106-892c-5db836bd52e7"/> <textElement textAlignment="Center"> <font size="20" isBold="true"/> </textElement> <text><![CDATA[Sample Report]]></text> </staticText> </band> </title> <pageHeader> <band splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </band> </pageHeader> <columnHeader> <band splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </band> </columnHeader> <detail> <band height="40" splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <printWhenExpression><![CDATA[$V{customer_COUNT}.intValue()==1]]></printWhenExpression> <textField isStretchWithOverflow="true"> <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="570" height="30" isPrintWhenDetailOverflows="true" uuid="d9887ecf-374c-46f0-9fd6-acb85ca470d1"/> <textFieldExpression><![CDATA[$P{Acknowledgement}]]></textFieldExpression> </textField> </band> <band height="60" splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <printWhenExpression><![CDATA[$V{customer_COUNT}.intValue()==1]]></printWhenExpression> <staticText> <reportElement x="0" y="0" width="100" height="30" uuid="2a91a38a-c1c5-477c-adf0-1685bef6ede9"/> <text><![CDATA[Customer:]]></text> </staticText> <textField> <reportElement x="100" y="0" width="100" height="30" uuid="e6257d16-8070-4309-910d-c2245bb26d48"/> <textFieldExpression><![CDATA[$F{customer}]]></textFieldExpression> </textField> <staticText> <reportElement x="50" y="30" width="100" height="30" uuid="491da14f-9c2a-4101-9589-f4a03be6aab8"/> <text><![CDATA[Invoice]]></text> </staticText> <staticText> <reportElement x="200" y="30" width="100" height="30" uuid="51f2fb54-d793-4323-b4bc-bac4afd83d9e"> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> <text><![CDATA[Invoice Date]]></text> </staticText> <staticText> <reportElement x="350" y="30" width="100" height="30" uuid="55b4e951-7f0d-4756-8149-793d699ba675"> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> <text><![CDATA[Amount]]></text> </staticText> </band> <band height="30" splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <printWhenExpression><![CDATA[$V{customer_COUNT}.intValue()==1]]></printWhenExpression> <componentElement> <reportElement x="50" y="0" width="400" height="30" uuid="9385c3d8-9220-4a37-bd96-0b68f7e4e4a8"/> <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal"> <datasetRun subDataset="Dataset1-customer" uuid="401aabe3-12f3-4d14-91a4-a53dc9b83421"> <datasetParameter name="customer"> <datasetParameterExpression><![CDATA[$F{customer}]]></datasetParameterExpression> </datasetParameter> <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> </datasetRun> <jr:listContents height="30" width="400"> <textField> <reportElement x="0" y="0" width="100" height="30" uuid="fadaee53-6a7c-49dd-a61e-0c3534d9970f"> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <textFieldExpression><![CDATA[$F{invoice}]]></textFieldExpression> </textField> <textField pattern="MM/dd/yyyy"> <reportElement x="150" y="0" width="100" height="30" uuid="a5e26a7f-4562-4160-ab0d-0bce90004835"> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <textFieldExpression><![CDATA[$F{invoicedate}]]></textFieldExpression> </textField> <textField pattern="¤#,##0.00#;¤(#,##0.00#-)"> <reportElement x="300" y="0" width="100" height="30" uuid="3221d060-41ab-4f5a-bfa7-a7c3f7c1f304"> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression> </textField> </jr:listContents> </jr:list> </componentElement> </band> <band height="31" splitType="Prevent"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <printWhenExpression><![CDATA[$V{customer_COUNT}.intValue()==1]]></printWhenExpression> <textField evaluationTime="Auto" pattern="¤#,##0.00#;¤(#,##0.00#-)"> <reportElement x="350" y="0" width="100" height="30" uuid="49adbce6-7bad-4b30-b20a-6c1f1cabab3f"/> <textElement> <font size="11" isBold="true"/> </textElement> <textFieldExpression><![CDATA[$V{sum_amount}]]></textFieldExpression> </textField> <break> <reportElement x="0" y="30" width="1" height="1" uuid="8f021af5-3787-4e5c-84db-914c4b79644e"> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="local_mesure_unity" value="pixel"/> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> </break> </band> <band height="90"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <staticText> <reportElement x="0" y="0" width="100" height="30" uuid="74c64f4f-1170-421a-9304-6418ef2e0418"/> <text><![CDATA[Customer:]]></text> </staticText> <textField> <reportElement x="100" y="0" width="100" height="30" uuid="5a30c367-31e1-4701-adad-cd0a6b963507"/> <textFieldExpression><![CDATA[$F{customer}]]></textFieldExpression> </textField> <staticText> <reportElement x="50" y="30" width="100" height="30" uuid="e799bb73-9be8-422b-9980-9030a57f1692"/> <text><![CDATA[Invoice]]></text> </staticText> <staticText> <reportElement x="200" y="30" width="100" height="30" uuid="56ecfc7c-8d51-4427-bae2-843736dd87bc"> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> <text><![CDATA[Invoice Date]]></text> </staticText> <staticText> <reportElement x="350" y="30" width="100" height="30" uuid="d897c032-9bb6-487e-b7e9-b470d7a91061"> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> <text><![CDATA[Amount]]></text> </staticText> <textField> <reportElement x="50" y="60" width="100" height="30" uuid="47777510-e15f-49f0-a5da-6cf89496e8e6"/> <textFieldExpression><![CDATA[$F{invoice}]]></textFieldExpression> </textField> <textField pattern="MM/dd/yyyy"> <reportElement x="200" y="60" width="100" height="30" uuid="a8662441-a0f0-4163-9d6d-db96b99cc573"/> <textFieldExpression><![CDATA[$F{invoicedate}]]></textFieldExpression> </textField> <textField pattern="¤#,##0.00#;¤(#,##0.00#-)"> <reportElement x="350" y="60" width="100" height="30" uuid="89293b5c-071b-4bc7-8cea-bd4d8962339b"/> <textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </band> </columnFooter> <pageFooter> <band height="30" splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField> <reportElement x="0" y="0" width="570" height="30" forecolor="#09B00C" uuid="1382d3a7-c1f1-4c98-9ee8-f26c77f0f5e5"> <property name="local_mesure_unitx" value="pixel"/> <property name="com.jaspersoft.studio.unit.x" value="px"/> </reportElement> <textElement textAlignment="Center"> <font size="16" isBold="true"/> </textElement> <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}]]></textFieldExpression> </textField> </band> </pageFooter> <summary> <band height="30" splitType="Stretch"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField> <reportElement mode="Opaque" x="0" y="0" width="570" height="30" backcolor="#E6FF05" uuid="a472936c-24de-4080-9a2e-3d6de440ec48"/> <textElement> <font size="14" isBold="true"/> </textElement> <textFieldExpression> <![CDATA["Total Invoices Processed "+$V{REPORT_COUNT}]]> </textFieldExpression> </textField> </band> </summary> </jasperReport>
This report can be tested using any PostgreSQL data source. The report PDF output can be downloaded from sample_report_4susobh.pdf.
TTC-20150331
Recommended Comments
There are no comments to display.