BrightSide Workbench Full Report + Source Code
m303/Model349List.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 java.text.NumberFormat;
22 import java.util.Date;
23 import java.util.List;
24 import java.util.TreeSet;
25 import org.turro.financials.entity.Register;
26 import org.turro.financials.model.business.CompanyWrapper;
27 import org.turro.i18n.I_;
28 import org.turro.zkoss.input.CollectionListbox;
29 import org.zkoss.zul.Listhead;
30 import org.zkoss.zul.Listheader;
31 
36 public class Model349List extends CollectionListbox<Item349> {
37 
38  private TreeSet<Item349> set = new TreeSet<Item349>();
39  private NumberFormat currencyFormatter = CompanyWrapper.getCurrencyFormatter();
40 
41 
43  addHeaders();
44  fillData(eq);
45  }
46 
47  @Override
48  protected String convertToString(Item349 v) {
50  currencyFormatter.format(v.amount[0]) +
52  currencyFormatter.format(v.amount[1]);
53  }
54 
55  private void fillData(EntryQuarter eq) {
56  Date init = eq.getQuarterInitialDate(),
57  end = eq.getFinalDate();
58  String vatAcc = eq.getEntry().getType().getVatAccount(),
59  opAcc = eq.getEntry().getType().getOpAccount();
60  long book = eq.getEntry().getType().getBookId();
61  List<Register> l = eq.getDao().getResultList(
62  "select distinct r from Register r " +
63  "join r.registerEntries e " +
64  "join r.bookRegisters b with b.bookDefinition.id = ? " +
65  "where r.registerDate <= ? " +
66  "and r.registerDate >= ? " +
67  "and r.view.id = 1 " +
68  "and (r.exclude = FALSE and e.register.closing = FALSE and e.register.regularizeVAT = FALSE) " +
69  "and e.account.id like ?",
70  new Object[] { book, end, init, vatAcc });
71  for(Register r : l) {
72  Item349 i349 = getItem(Item349.getName(r));
73  if(i349 != null) {
74  i349.addAmounts(r, opAcc);
75  }
76  }
77  setCollection(set);
78  }
79 
80  private Item349 getItem(String name) {
81  if(name == null) return null;
82  for(Item349 i349 : set) {
83  if(name.equals(i349.name)) {
84  return i349;
85  }
86  }
87  Item349 i349 = new Item349(name);
88  set.add(i349);
89  return i349;
90  }
91 
92  private void addHeaders() {
93  if(getListhead() != null) return;
94  Listhead lh = new Listhead();
95  lh.setSizable(true);
96  lh.appendChild(new Listheader(I_.get("Name"), null, "50%"));
97  lh.appendChild(new Listheader(I_.get("Product"), null, "25%"));
98  lh.appendChild(new Listheader(I_.get("Service"), null, "25%"));
99  appendChild(lh);
100  }
101 
102 }
void setCollection(Collection< V > collection)