BrightSide Workbench Full Report + Source Code
Item349.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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 
19 package org.turro.financials.treasury.m303;
20 
21 import org.turro.financials.entity.Account;
22 import org.turro.financials.entity.Register;
23 import org.turro.financials.entity.RegisterEntry;
24 import org.turro.math.Zero;
25 import org.turro.util.CompareUtil;
26 
31 public class Item349 implements Comparable<Item349> {
32 
33  public String name;
34  public double amount[] = new double[2];
35 
36  public Item349(String name) {
37  this.name = name;
38  }
39 
40  public void addAmounts(Register r, String opAcc) {
41  for(RegisterEntry re : r.getRegisterEntries()) {
42  Account acc = re.getAccount();
43  if(acc.getId().matches(opAcc.replaceAll("_", ".").replaceAll("%", ".*"))) {
44  if(acc.getId().startsWith("60") || acc.getId().startsWith("70")) {
45  amount[0] += Zero.near(re.getCredit(), 2) ? re.getDebit() : re.getCredit();
46  } else {
47  amount[1] += Zero.near(re.getCredit(), 2) ? re.getDebit() : re.getCredit();
48  }
49  }
50  }
51  }
52 
53  public static String getName(Register r) {
54  for(RegisterEntry re : r.getRegisterEntries()) {
55  Account acc = re.getAccount();
56  if(isAccountName(acc)) {
57  return acc.getDescription();
58  }
59  }
60  return null;
61  }
62 
63  private static boolean isAccountName(Account acc) {
64  if(acc.getId().startsWith("43") || acc.getId().startsWith("44") ||
65  acc.getId().startsWith("40") || acc.getId().startsWith("41")) {
66  return true;
67  }
68  return false;
69  }
70 
71  @Override
72  public int compareTo(Item349 o) {
73  return CompareUtil.compare(name, o.name);
74  }
75 
76 }
Set< RegisterEntry > getRegisterEntries()
Definition: Register.java:135
void addAmounts(Register r, String opAcc)
Definition: Item349.java:40
static String getName(Register r)
Definition: Item349.java:53
static boolean near(double value, int digits)
Definition: Zero.java:30