19 package org.turro.financials.operating;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.TreeSet;
25 import org.amic.util.date.CheckDate;
26 import org.turro.elephant.db.WhereClause;
27 import org.turro.financials.db.FinancialsPU;
28 import org.turro.financials.entity.Account;
29 import org.turro.jpa.Dao;
30 import org.turro.util.CompareUtil;
38 private Date start, end;
42 if(ci !=
null && ci.
getId() ==
id) {
52 if(CompareUtil.compare(
this.start, start) != 0 || CompareUtil.compare(
this.end, end) != 0) {
56 processData(loadData());
60 private List<Object[]> loadData() {
62 return dao.getResultList(getCriteria());
65 private WhereClause getCriteria() {
66 WhereClause wc =
new WhereClause();
67 wc.addClause(
"select r.id, r.registerDate, re.account, re.debit, re.credit");
68 wc.addClause(
"from Register as r");
69 wc.addClause(
"join r.registerEntries re");
70 wc.addClause(
"where r.registerDate >= :start");
71 wc.addNamedValue(
"start", start);
72 wc.addClause(
"and r.registerDate <= :end");
73 wc.addNamedValue(
"end", end);
74 wc.addClause(
"and (re.account like '6%'");
75 wc.addClause(
"or re.account like '7%'");
76 wc.addClause(
"or re.account like '400%'");
77 wc.addClause(
"or re.account like '410%'");
78 wc.addClause(
"or re.account like '430%'");
79 wc.addClause(
"or re.account like '440%')");
83 private long currentId = 0;
84 private List<RegisterItem>
register;
86 private void processData(List<Object[]> data) {
88 for(Object[] o : data) {
94 private void processLines(Object[] data) {
95 long regId = (long) data[0];
96 if(regId != currentId) {
98 register =
new ArrayList<>();
101 RegisterItem ri =
new RegisterItem();
103 ri.date =
new CheckDate((Date) data[1]);
104 ri.account = (Account) data[2];
105 ri.debit = (double) data[3];
106 ri.credit = (double) data[4];
110 private RegisterItem participant;
111 private final List<RegisterItem> stores =
new ArrayList<>();
113 private void processList() {
116 if(
register !=
null && !
register.isEmpty()) {
119 if(!stores.isEmpty() && participant !=
null) {
120 for(RegisterItem store : stores) {
121 ContractItem ci =
getContract(store.getContractId());
122 if(ci.getName() ==
null) {
125 MonthItem mi = ci.getMonths().getMonth(store.getYear(), store.getMonth());
126 ValueItem vi = mi.getMovements().getValues().getItem(store.account.getId().substring(0, 5));
127 if(vi.getName() ==
null) {
128 vi.setName(store.account.getParent().getDescription());
130 vi.setValue(vi.getValue() + store.getValue());
132 String major = participant.account.getId();
133 if(major.charAt(3) ==
'9') {
134 major = major.substring(0, 3) +
"0" + major.substring(4);
136 vi = mi.getMovements().getParticipants().getItem(major);
137 if(vi.getName() ==
null) {
138 vi.setName(participant.account.getDescription());
140 vi.setValue(vi.getValue() + store.getValue());
146 private void findPrimaryStore() {
147 for(RegisterItem ri :
register) {
148 if(ri.account.getId().matches(
"6.*") && ri.debit != 0.0) {
150 }
if(ri.account.getId().matches(
"7.*") && ri.credit != 0.0) {
156 private void findParticipant() {
158 for(RegisterItem ri :
register) {
159 if(ri.account.getId().matches(
"4[34]0.*") && ri.debit != 0.0) {
160 if(max < Math.abs(ri.debit)) {
162 max = Math.abs(ri.debit);
164 }
if(ri.account.getId().matches(
"4[01]0.*") && ri.credit != 0.0) {
165 if(max < Math.abs(ri.credit)) {
167 max = Math.abs(ri.credit);
void loadPeriod(Date start, Date end)
ContractItem getContract(long id)