1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package ar.com.fdvs.dj.test;
31
32
33 import java.util.Date;
34
35 import net.sf.jasperreports.view.JasperDesignViewer;
36 import net.sf.jasperreports.view.JasperViewer;
37 import ar.com.fdvs.dj.domain.DJCalculation;
38 import ar.com.fdvs.dj.domain.DynamicReport;
39 import ar.com.fdvs.dj.domain.Style;
40 import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
41 import ar.com.fdvs.dj.domain.builders.StyleBuilder;
42 import ar.com.fdvs.dj.domain.constants.Border;
43 import ar.com.fdvs.dj.domain.constants.Font;
44 import ar.com.fdvs.dj.domain.constants.GroupLayout;
45 import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
46 import ar.com.fdvs.dj.domain.entities.DJGroupVariable;
47
48 public class TotalingReportTest extends BaseDjReportTest {
49
50 public DynamicReport buildReport() throws Exception {
51
52
53
54
55
56
57
58 Style headerStyle1 = new StyleBuilder(false).setFont(Font.ARIAL_BIG).setBorderBottom(Border.THIN()).setPaddingTop(new Integer(15)) .build();
59 Style headerStyle2 = new StyleBuilder(false).setFont(Font.ARIAL_SMALL).setPaddingLeft(new Integer(20)).build();
60
61 FastReportBuilder drb = new FastReportBuilder();
62 drb.addColumn("State", "state", String.class.getName(),70, headerStyle1, headerStyle1)
63 .addColumn("Branch", "branch", String.class.getName(),70, headerStyle2, headerStyle2)
64 .addColumn("Amount", "amount", Float.class.getName(),70)
65 .addGroups(2)
66 .setTitle("November " + getYear() +" sales report")
67 .setSubtitle("This report was generated at " + new Date())
68 .setPrintBackgroundOnOddRows(false)
69 .setPrintColumnNames(false)
70 .setShowDetailBand(false)
71 .setUseFullPageWidth(true);
72
73
74 Style hstyle1 = new StyleBuilder(false).setHorizontalAlign(HorizontalAlign.RIGHT).setBorderBottom(Border.THIN()).build();
75 Style hstyle2 = new StyleBuilder(false).setHorizontalAlign(HorizontalAlign.RIGHT).setFont(Font.ARIAL_SMALL).build();
76 drb.getGroup(0).addHeaderVariable(new DJGroupVariable(drb.getColumn(2),DJCalculation.SUM,hstyle1));
77 drb.getGroup(1).addHeaderVariable(new DJGroupVariable(drb.getColumn(2),DJCalculation.SUM, hstyle2));
78
79 drb.getGroup(0).setLayout(GroupLayout.VALUE_IN_HEADER);
80
81 drb.getGroup(0).setHeaderVariablesHeight(new Integer(20));
82 drb.getGroup(1).setHeaderVariablesHeight(new Integer(15));
83
84 DynamicReport dr = drb.build();
85
86 return dr;
87 }
88
89 public static void main(String[] args) throws Exception {
90 TotalingReportTest test = new TotalingReportTest();
91 test.testReport();
92 test.exportToJRXML();
93 JasperViewer.viewReport(test.jp);
94 JasperDesignViewer.viewReportDesign(test.jr);
95 }
96
97 }