18 package org.turro.financials.report;
20 import org.turro.elephant.util.DecimalFormats;
21 import org.turro.i18n.I_;
22 import org.turro.math.Zero;
23 import org.turro.zkoss.grid.PagingGrid;
24 import org.turro.zkoss.label.LabelTypes;
25 import org.zkoss.zk.ui.Component;
26 import org.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.*;
51 getRows().getChildren().clear();
62 private void addColumns() {
65 Column col =
new Column(
I_.
get(
"Item"));
66 col.setWidth(
"200px");
67 cols.appendChild(col);
70 col =
new Column(period.getYear() +
"-" + period.getMonth());
71 col.setAlign(
"right");
72 col.setWidth(
"120px");
74 cols.appendChild(col);
79 private void addRows() {
81 for(AccountReportItem item : report.
getChildren()) {
87 for(AccountReportFormula formula : report.
getFormulas()) {
88 addFormula(formula, rows);
92 private void addItem(AccountReportItem root, Rows rows) {
94 for(Component col :
getColumns().getChildren()) {
95 if(((Column)col).getValue() ==
null) {
96 row.appendChild(getLabelFor(root));
98 row.appendChild(getComponentFor(root.getPeriodFor((AccountReportPeriod) ((Column)col).getValue())));
101 rows.appendChild(row);
102 for(AccountReportItem item : root.getChildren()) {
105 if(root.isShowTotal()) {
106 addItem(root.getTotalItem(), rows);
110 private void addFormula(AccountReportFormula formula, Rows rows) {
112 for(Component col :
getColumns().getChildren()) {
113 if(((Column)col).getValue() ==
null) {
114 row.appendChild(LabelTypes.getCaptionLabel(I_.get(formula.getLabel())));
116 row.appendChild(LabelTypes.getCaptionLabel(DecimalFormats.format(formula.getValue((AccountReportPeriod) ((Column)col).getValue()))));
119 rows.appendChild(row);
122 private Component getComponentFor(AccountReportPeriod period) {
123 if(period ==
null || Zero.near(period.getValue(), 0)) {
124 return new Label(
"");
125 }
else if(period.getItem().isTotalItem() || period.getItem().isShowTotal()) {
126 return LabelTypes.getCaptionLabel(DecimalFormats.format(period.getValue()));
128 return new Label(DecimalFormats.format(period.getValue()));
132 private Component getLabelFor(AccountReportItem item) {
133 Hbox hbox =
new Hbox();
134 hbox.setWidth(
"100%");
135 hbox.setWidths(
"98%, 2%");
137 if(item.isTotalItem() || item.isShowTotal() || item.isTitleItem()) {
138 l = LabelTypes.getCaptionLabel(
139 (item.isTotalItem() ?
"Total " :
"") +
140 I_.get(item.getLabel()));
142 l =
new Label(I_.get(item.getLabel()));
144 l.setStyle(
"padding-left:" + (getLevel(item) * 3) +
"px");
146 if(item.getMode() !=
null) {
147 hbox.appendChild(LabelTypes.getTinyLabel(I_.get(item.getMode().getLabel())));
152 private int getLevel(AccountReportItem item) {
154 while(item.getParent() !=
null) {
156 item = item.getParent();
AccountReport getReport()
void setReport(AccountReport report)
void incrementPeriod(int amount)
AccountReportItem getTotalItem()
List< AccountReportItem > getChildren()
List< AccountReportFormula > getFormulas()
PeriodSet getExistingPeriods()
PeriodSet getCurrentPeriod(int count)
void incrementPeriod(int amount)
static String get(String msg)
Columns getColumns(boolean create)
Rows getRows(boolean create)