18 package org.turro.financials.report;
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.turro.string.Strings;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.util.PhraseBuilder;
34 private List<AccountReportItem> children =
new ArrayList<AccountReportItem>();
36 private List<String> patterns =
new ArrayList<String>();
37 private boolean showTotal;
40 private boolean totalItem =
false;
58 patterns.add(pattern);
106 this.showTotal = showTotal;
110 return patterns ==
null || patterns.isEmpty();
118 this.totalItem = totalItem;
125 if(!Strings.isBlank(label)) {
127 if(label.equals(ari.getLabel())) {
140 if(periods ==
null) {
142 if(!patterns.isEmpty()) {
143 String sqlQuery = getSQLQuery();
144 if(!sqlQuery.contains(
"in ()")) {
146 for(Object[] o : (List<Object[]>) l) {
151 existingPeriods.add(arp);
156 ari.loadData(existingPeriods);
164 if(period.getYear() == accountReportPeriod.
getYear() && period.getMonth() == accountReportPeriod.
getMonth()) {
178 double acumulated = 0;
181 if(period.getYear() == year) {
182 acumulated += period.getValue();
184 acumulated = period.getValue();
185 year = period.getYear();
187 period.setValue(acumulated);
192 tam.add(period.getValue());
198 ari.regularizeMode(existingPeriods);
219 double accumulated = p ==
null ? 0.0 : p.
getValue();
221 accumulated += item.getAccumulatedFor(period);
226 private String getSQLQuery() {
228 wc.
addClause(
"select year(re.register.registerDate), month(re.register.registerDate), sum(re.debit) - sum(re.credit)");
230 wc.
addClause(
"where re.account.id in " + getInString());
231 wc.
addClause(
"and re.register.exclude = FALSE");
232 wc.
addClause(
"group by year(re.register.registerDate), month(re.register.registerDate)");
236 private String getInString() {
237 PhraseBuilder pb =
new PhraseBuilder(
"(");
238 for(String account :
getReport().getAccounts()) {
239 for(String regexp : patterns) {
240 if(account.matches(regexp)) {
241 pb.addWord(
"'" + account +
"'");
242 pb.addPendingSeparator(
",");
247 pb.cancelSeparator();
249 return pb.toString();
void addClause(String clause)
AccountReportItem getItem(String label)
AccountReportItem(String label)
void regularizeMode(PeriodSet existingPeriods)
List< AccountReportItem > getChildren()
AccountReportItem addItem(AccountReportItem item)
void setShowTotal(boolean showTotal)
void setLabel(String label)
PeriodSet loadData(PeriodSet existingPeriods)
void addPattern(String pattern)
void setParent(AccountReportItem parent)
void setMode(ItemMode mode)
AccountReportItem getParent()
AccountReport getReport()
void setTotalItem(boolean totalItem)
void setReport(AccountReport report)
AccountReportItem addItem(String label)
AccountReportItem getTotalItem()
AccountReportPeriod getPeriodFor(AccountReportPeriod accountReportPeriod)
double getAccumulatedFor(AccountReportPeriod period)
void setItem(AccountReportItem item)
void setValue(double value)