BrightSide Workbench Full Report + Source Code
AccountRI.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.register;
19 
20 import java.util.List;
21 import org.turro.financials.db.FinancialsPU;
22 import org.turro.financials.entity.Account;
23 import org.turro.financials.entity.MajorAccount;
24 
29 public class AccountRI {
30 
31  private Account account;
32  private BalanceFilter filter;
33  private Double amountsA[], amountsB[];
34  private String parentId;
35 
36  public AccountRI(Account account, BalanceFilter filter) {
37  this.account = account;
38  this.filter = filter;
39  amountsA = filter.getAmountsA(account.getId());
40  amountsB = filter.getAmountsB(account.getId());
41  parentId = account.getParent().getAccount();
42  }
43 
44  public String getId() {
45  return account.getId();
46  }
47 
48  public String getDescription() {
49  return account.getDescription();
50  }
51 
52  public Double getDebitA() {
53  return amountsA[0];
54  }
55 
56  public Double getCreditA() {
57  return amountsA[1];
58  }
59 
60  public Double getBalanceA() {
61  return getDebitA() - getCreditA();
62  }
63 
64  public Double getDebitB() {
65  return amountsB[0];
66  }
67 
68  public Double getCreditB() {
69  return amountsB[1];
70  }
71 
72  public Double getBalanceB() {
73  return getDebitB() - getCreditB();
74  }
75 
76  public Double getDebit() {
77  return amountsA[0] - amountsB[0];
78  }
79 
80  public Double getCredit() {
81  return amountsA[1] - amountsB[1];
82  }
83 
84  public Double getBalance() {
85  return getDebit() - getCredit();
86  }
87 
88  public String getParentId() {
89  return parentId;
90  }
91 
93  return this;
94  }
95 
96  public String getMajorName(String major) {
97  if(major != null && major.length() > 0) {
98  List l = new FinancialsPU().getResultList(
99  "select m from MajorAccount as m " +
100  "where m.account = '" + major + "' " +
101  "order by m.account desc");
102  if(!l.isEmpty()) {
103  return ((MajorAccount) l.get(0)).getDescription();
104  }
105  }
106  return null;
107  }
108 }
AccountRI(Account account, BalanceFilter filter)
Definition: AccountRI.java:36