18 package org.turro.financials.treasury.m111;
20 import java.util.Date;
21 import java.util.List;
22 import java.util.TreeSet;
23 import org.turro.financials.db.FinancialsPU;
24 import org.turro.financials.entity.Document;
25 import org.turro.financials.entity.DocumentLine;
26 import org.turro.financials.entity.Register;
27 import org.turro.financials.entity.RegisterEntry;
28 import org.turro.jpa.Dao;
29 import org.turro.math.Round;
30 import org.turro.math.Zero;
36 public class ModelSet extends TreeSet<ModelEntry> {
38 private Date fromDate, toDate;
42 this.fromDate = fromDate;
54 private void createEntries() {
55 List<Register> l =
getDao().getResultList(
56 "select distinct r from Register r " +
57 "join r.registerEntries re " +
58 "where r.registerDate >= ? " +
59 "and r.registerDate <= ? " +
60 "and (r.exclude = FALSE and r.closing = FALSE and r.regularizeIRPF = FALSE) " +
61 "and re.account.id like '4751%' " +
62 "and re.credit <> 0 " +
73 private void addRegister(Register
register) {
74 double retention = 0.0, perCent = 0.0, taxable = 0.0;
75 long contractId = 0, documentId = 0;
76 String contractName =
"*****";
77 ModelType type =
null;
78 Document doc =
register.getDocument();
80 documentId = doc.getId();
81 contractId = doc.getContract().getId();
82 contractName = doc.getContract().getFullDescription();
83 for(DocumentLine dl : doc.getDocumentLines()) {
84 if(!Zero.near(dl.getRetention(), 0)) {
85 perCent = dl.getRetention();
86 retention += dl.getRetained();
87 taxable += dl.getTaxable();
93 boolean useRegister =
false;
94 if(retention == 0.0) {
98 for(RegisterEntry re :
register.getRegisterEntries()) {
100 type = ModelType.checkType(re.getAccount().getId());
103 retention = re.getCredit();
104 }
else if(retention != re.getCredit()) {
108 perCent = Double.valueOf(re.getAccount().getId().substring(7));
113 if(ModelType.isTaxable(re.getAccount().getId())) {
114 taxable += re.getDebit();
118 if(useRegister && perCent == 0.0 && taxable != 0.0 && retention != 0.0) {
119 perCent = (retention / taxable) * 100.0;
122 ModelEntry me = addModelEntry(type, perCent);
123 me.addValue(contractId, contractName, documentId, retention, taxable);
127 private ModelEntry addModelEntry(ModelType type,
double percent) {
128 for(ModelEntry me :
this) {
129 if(me.getType().equals(type) && me.getPerCent() ==
new Round(percent).decimals(2).value()) {
133 ModelEntry me =
new ModelEntry(
this, type, percent);
ModelSet(Date fromDate, Date toDate)