BrightSide Workbench Full Report + Source Code
MajorAccount.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.financials.entity;
19 
20 import java.util.Collections;
21 import java.util.List;
22 import javax.persistence.*;
23 import org.turro.financials.db.FinancialsPU;
24 
29 @Entity
30 public class MajorAccount implements java.io.Serializable {
31 
32  @Id
33  @GeneratedValue(strategy=GenerationType.IDENTITY)
34  @Column(name="IDENTIFIER")
35  private long id;
36 
37  private String account;
38 
39  private String description;
40 
41  private MajorAccountType type;
42 
43  @ManyToOne
44  private BookDefinition bookDefinition;
45 
46  public String getAccount() {
47  return account;
48  }
49 
50  public void setAccount(String account) {
51  this.account = account;
52  }
53 
55  return bookDefinition;
56  }
57 
58  public void setBookDefinition(BookDefinition bookDefinition) {
59  this.bookDefinition = bookDefinition;
60  }
61 
62  public List<MajorAccount> getDescendants() {
63  if(account != null) {
64  return new FinancialsPU().getResultList(
65  "select m from MajorAccount as m " +
66  "where m.account like '" + account + "_' " +
67  "and exists ( " +
68  " select re from RegisterEntry as re " +
69  " where re.account.id like concat(m.account, '%') " +
70  ") " +
71  "order by m.account");
72  //account.substring(0, account.length() - 1)+ "?'"));
73  }
74  return Collections.EMPTY_LIST;
75  }
76 
77  public String getDescription() {
78  return description;
79  }
80 
81  public void setDescription(String description) {
82  this.description = description;
83  }
84 
85  public long getId() {
86  return id;
87  }
88 
89  public void setId(long id) {
90  this.id = id;
91  }
92 
94  return type;
95  }
96 
97  public void setType(MajorAccountType type) {
98  this.type = type;
99  }
100 
102  if(account != null && account.length() > 1) {
103  List l = new FinancialsPU().getResultList(
104  "select m from MajorAccount as m where m.account = '" +
105  account.substring(0, account.length() - 1)+ "' " +
106  "order by m.account");
107  if(!l.isEmpty()) {
108  return (MajorAccount) l.get(0);
109  }
110  }
111  return null;
112  }
113 
114  public List<Account> getAccounts() {
115  if(account != null) {
116  return new FinancialsPU().getResultList(
117  "select a from Account as a " +
118  "where exists ( " +
119  " select ma from MajorAccount as ma " +
120  " where ma.account = '" + account + "' " +
121  " and a.id like concat(ma.account, '_%') " +
122  " and not exists ( " +
123  " select ma2 from MajorAccount as ma2 " +
124  " where ma2.account like concat(ma.account, '0%') " +
125  " ) " +
126  ") " +
127  "order by a.id");
128  }
129  return Collections.EMPTY_LIST;
130  }
131 
132  public static MajorAccount getMajor(String account) {
133  if(account != null && account.length() > 1) {
135  "select m from MajorAccount as m where m.account = '" +
136  account + "'");
137  }
138  return null;
139  }
140 
141 }
void setBookDefinition(BookDefinition bookDefinition)
static MajorAccount getMajor(String account)
void setDescription(String description)
void setType(MajorAccountType type)
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380