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