BrightSide Workbench Full Report + Source Code
EntityPortfolioList.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.entities.portfolio;
20 
21 import java.util.List;
22 import java.util.TreeSet;
23 import org.turro.financials.entity.Document;
24 import org.turro.financials.model.document.contract.DocumentPortfolio;
25 
30 public class EntityPortfolioList extends TreeSet<DocumentPortfolio> {
31 
32  private double finalBalance = 0.0, finalInvoice = 0.0,
33  finalPortfolio = 0.0, finalSettlement = 0.0;
34  private int finalCount = 0;
35 
36  public EntityPortfolioList(DocumentByEntityList documents, List<String> entityPaths) {
37  fillPortfolio(documents, entityPaths);
38  }
39 
40  public double getFinalBalance() {
41  return finalBalance;
42  }
43 
44  public double getFinalInvoice() {
45  return finalInvoice;
46  }
47 
48  public double getFinalPortfolio() {
49  return finalPortfolio;
50  }
51 
52  public double getFinalSettlement() {
53  return finalSettlement;
54  }
55 
56  public int getFinalCount() {
57  return finalCount;
58  }
59 
60  private void fillPortfolio(DocumentByEntityList documents, List<String> entityPaths) {
61 
62  documents.fillList(entityPaths);
63 
64  finalBalance = 0.0;
65  finalInvoice = 0.0;
66  finalPortfolio = 0.0;
67  finalSettlement = 0.0;
68  finalCount = documents.size();
69 
70  for(final Document doc : documents) {
71 
72  if(doc.getDocumentDefinition().getId() != 1 &&
73  doc.getDocumentDefinition().getId() != 67 &&
74  doc.getDocumentDefinition().getId() != 2 &&
75  doc.getDocumentDefinition().getId() != 43 &&
76  doc.getDocumentDefinition().getId() != 44 &&
77  doc.getDocumentDefinition().getId() != 6 &&
78  doc.getDocumentDefinition().getId() != 7) {
79  continue;
80  }
81 
82  DocumentPortfolio dp = new DocumentPortfolio();
83 
84  dp.setDocument(doc);
85  dp.setDate(doc.getDocumentDate());
86  dp.setConcept(doc.getDocumentDefinition().getName() + " " + doc.getDocumentNumber());
87 
88  double amount = doc.getTotalAmount();
89 
90  switch ((int) doc.getDocumentDefinition().getId()) {
91  case 1:
92  case 6:
93  case 44:
94  case 67:
95  break;
96  case 2:
97  case 7:
98  case 43:
99  amount = -amount;
100  break;
101  default:
102  break;
103  }
104 
105  switch ((int) doc.getDocumentDefinition().getId()) {
106  case 1:
107  case 67:
108  case 2:
109  finalBalance += amount;
110  finalInvoice += amount;
111  dp.setInvoice(amount);
112  dp.setPortfolio(null);
113  dp.setSettlement(null);
114  dp.setBalance(finalBalance);
115  break;
116  case 43:
117  case 44:
118  finalPortfolio += amount;
119  dp.setInvoice(null);
120  dp.setPortfolio(amount);
121  dp.setSettlement(null);
122  dp.setBalance(finalBalance);
123  break;
124  case 6:
125  case 7:
126  finalBalance -= amount;
127  finalSettlement += amount;
128  dp.setInvoice(null);
129  dp.setPortfolio(null);
130  dp.setSettlement(amount);
131  dp.setBalance(finalBalance);
132  break;
133  default:
134  break;
135  }
136 
137  add(dp);
138 
139  }
140 
141  }
142 
143 }
144 
EntityPortfolioList(DocumentByEntityList documents, List< String > entityPaths)