18 package org.turro.financials.register;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.List;
24 import org.amic.util.date.CheckDate;
25 import org.turro.contacts.Contact;
26 import org.turro.financials.db.FinancialsPU;
27 import org.turro.financials.entity.*;
28 import org.turro.financials.view.ViewSets;
29 import org.turro.i18n.I_;
38 private Date fromDate, toDate;
45 private List<Long> contractListIds;
46 private int breakdown = 4;
49 fromDate =
new CheckDate().setDay(1).setMonth(1).getDate();
59 this.breakdown = breakdown;
67 return !(viewSets.
getGroupA().isEmpty()) &&
76 this.fromDate = fromDate;
92 this.viewSets = viewSets;
101 this.company = company;
110 this.contact = contact;
119 this.contract = contract;
128 this.department = department;
137 this.headquarters = headquarters;
146 this.service = service;
150 if(company !=
null) {
152 }
else if(contact !=
null) {
154 }
else if(contract !=
null) {
156 }
else if(department !=
null) {
158 }
else if(headquarters !=
null) {
159 return I_.
get(
"Headquarters") +
": " + headquarters.
getName();
160 }
else if(service !=
null) {
178 public Double[]
getAmounts(String account, String viewFilter) {
179 Object[] pars =
new Object[] {
185 "select sum(round(entry.debit, 4) + 0.0), sum(round(entry.credit, 4) + 0.0) " +
186 "from RegisterEntry as entry " +
187 "where entry.account.id like ? " +
188 getInClause(
"entry.account.id") +
189 "and entry.register.registerDate >= ? " +
190 "and entry.register.registerDate <= ? " +
191 "and entry.register.exclude = FALSE " +
194 return new Double[] {
195 (Double) (o[0] ==
null ? 0.0 : o[0]),
196 (Double) (o[1] ==
null ? 0.0 : o[1])
201 Object[] pars =
new Object[] {
209 List<MajorAccount> l =
new FinancialsPU().getResultList(
210 "select m from MajorAccount as m " +
211 "where m.account like '" + parent +
"' " +
213 " select re from RegisterEntry as re " +
214 " where re.account.id like concat(m.account, '%') " +
215 getInClause(
"re.account.id") +
216 " and re.register.registerDate >= ? " +
217 " and re.register.registerDate <= ? " +
220 "order by m.account",
226 Object[] pars =
new Object[] {
231 "select a from Account as a " +
233 " select ma from MajorAccount as ma " +
234 " where ma.account = '" + parent +
"' " +
235 " and a.id like concat(ma.account, '_%') " +
236 " and not exists ( " +
237 " select ma2 from MajorAccount as ma2 " +
238 " where ma2.account like concat(substring(a.id, 1, length(ma.account) + 1), '%') " +
242 " select re from RegisterEntry as re " +
243 " where re.account.id = a.id " +
244 getInClause(
"re.account.id") +
245 " and re.register.registerDate >= ? " +
246 " and re.register.registerDate <= ? " +
254 Object[] pars =
new Object[] {
259 "select a from Account as a " +
261 " select re from RegisterEntry as re " +
262 " where re.account.id = a.id " +
263 getInClause(
"re.account.id") +
264 " and re.register.registerDate >= ? " +
265 " and re.register.registerDate <= ? " +
272 private void clearValues() {
281 private String getInClause(String field) {
282 contractListIds =
new ArrayList<Long>();
283 boolean done =
false;
284 if(company !=
null) {
286 fillCompanyContracts(company);
287 }
else if(contact !=
null) {
289 fillContactContracts(contact);
290 }
else if(contract !=
null) {
292 contractListIds.add(contract.
getId());
293 }
else if(department !=
null) {
295 fillDepartmentContracts(department);
296 }
else if(headquarters !=
null) {
298 fillHeadquartersContracts(headquarters);
299 }
else if(service !=
null) {
301 fillServiceContracts(service);
303 StringBuilder sb =
new StringBuilder(
"");
304 if(contractListIds.size() > 0) {
305 sb.append(
" and substring(" + field +
",5,10)");
308 for(Long l : contractListIds) {
314 sb.append(
" and " + field +
" not like '477%'");
315 sb.append(
" and " + field +
" not like '472%'");
316 sb.append(
" and " + field +
" not like '475%'");
318 sb.append(
" and " + field +
" = 'zzzzzzzzzzzz'");
320 return sb.toString();
323 private void fillContactContracts(
Contact contact) {
324 for(
Contract ctc : getContactContracts(contact)) {
325 contractListIds.add(ctc.getId());
329 private void fillCompanyContracts(
Company company) {
331 fillServiceContracts(serv);
334 fillHeadquartersContracts(hq);
338 private void fillServiceContracts(
Service service) {
340 contractListIds.add(ctc.getId());
344 private void fillHeadquartersContracts(
Headquarters headquarters) {
346 fillDepartmentContracts(dept);
350 private void fillDepartmentContracts(
Department department) {
352 contractListIds.add(ctc.getId());
356 private Iterable<Contract> getContactContracts(
Contact contact) {
358 "select contract from Contract as contract " +
359 "where contract.contractor = ?",
360 new Object[] { contact.
getId() }
Set< Service > getServices()
Set< Headquarters > getHeadquarters()
String getFullDescription()
Set< Contract > getStores()
Set< Department > getDepartments()
Set< Contract > getStores()
Collection< AccountRI > getRIs(BalanceFilter filter)
void setHeadquarters(Headquarters headquarters)
void setService(Service service)
void setBreakdown(int breakdown)
String getFullFilterString()
Collection< AccountRI > getAccountRIs()
void setFromDate(Date fromDate)
void setCompany(Company company)
Double[] getAmountsA(String account)
void setContract(Contract contract)
void setViewSets(ViewSets viewSets)
List< Account > getAccounts(String parent)
Department getDepartment()
void setToDate(Date toDate)
Headquarters getHeadquarters()
Double[] getAmountsB(String account)
List< MajorAccount > getMajorAccounts(String parent)
void setDepartment(Department department)
Double[] getAmounts(String account, String viewFilter)
void setContact(Contact contact)
Set< RegisterView > getGroupA()
String getSqlWhereA(String field)
String getSqlWhereAB(String field)
Set< RegisterView > getGroupB()
String getSqlWhereB(String field)
static String get(String msg)
Object getSingleResult(WhereClause wc)