BrightSide Workbench Full Report + Source Code
HumanResourceGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.erp.humanres;
19 
20 import java.util.Collection;
21 import org.amic.util.date.CheckDate;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.util.DecimalFormats;
24 import org.turro.erp.db.ErpPU;
25 import org.turro.erp.menu.ErpMenu;
26 import org.turro.erp.entity.HumanResource;
27 import org.turro.erp.entity.AptitudeDegree;
28 import org.turro.erp.entity.OwnedAptitude;
29 import org.turro.zkoss.grid.PagingGrid;
30 import org.turro.zkoss.label.LabelTypes;
31 import org.turro.elephant.zkoss.ElLabel;
32 import org.zkoss.zk.ui.event.Event;
33 import org.zkoss.zk.ui.event.EventListener;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zk.ui.ext.AfterCompose;
36 import org.zkoss.zul.A;
37 import org.zkoss.zul.Column;
38 import org.zkoss.zul.Columns;
39 import org.zkoss.zul.Hlayout;
40 import org.zkoss.zul.Image;
41 import org.zkoss.zul.Label;
42 import org.zkoss.zul.Row;
43 import org.zkoss.zul.Rows;
44 import org.zkoss.zul.Vlayout;
45 
50 public class HumanResourceGrid extends PagingGrid implements AfterCompose {
51 
52  public void newHumanResource() {
54  }
55 
56  @Override
57  public void afterCompose() {
58  addColumns();
59  addRows();
60  }
61 
62  private void addRows() {
64 
65  Collection<HumanResource> list = new ErpPU().getResultList(
66  "select hr from HumanResource hr " +
67  "order by hr.name");
68 
69  Rows rows = new Rows();
70  appendChild(rows);
71 
72  for(final HumanResource hr : list) {
73  Row row = new Row();
74  rows.appendChild(row);
75  if(!hr.isActive()) {
76  row.setSclass("draft");
77  }
78  row.appendChild(new Label(hr.getId() + ""));
79  Vlayout vbox = new Vlayout();
80  row.appendChild(vbox);
81  A b = new A(hr.getName());
82  if(app.isInRole("erp-config:edit")) {
83  b.addEventListener(Events.ON_CLICK, new EventListener() {
84  @Override
85  public void onEvent(Event event) throws Exception {
86  ErpMenu.showHumanResource(hr.getId());
87  }
88  });
89  }
90  vbox.appendChild(b);
91 
92  if(!hr.getOwnedAptitudes().isEmpty()) {
93  Hlayout hbox = new Hlayout();
94  vbox.appendChild(hbox);
95  hbox.appendChild(new Image("/_zul/images/aptitude.png"));
96  for(OwnedAptitude a : hr.getOwnedAptitudes()) {
97  AptitudeDegree o = a.getAptitudeDegree();
98  Label l = LabelTypes.getSoftLabel(
99  o.getFullName() + " (" +
100  DecimalFormats.format(o.getCost()) + " / " +
101  DecimalFormats.format(o.getPrice()) + ")"
102  );
103  if(new CheckDate().isDateActive(a.getInitialDate(), a.getFinalDate())) {
104  hbox.appendChild(l);
105  } else {
106  l.setStyle("font-style:oblique");
107  hbox.appendChild(l);
108  }
109  }
110  }
111 
112  row.appendChild(new Label(DecimalFormats.format(hr.getCostHour())));
113  row.appendChild(new Label(DecimalFormats.format(hr.getPriceHour())));
114  }
115 
116  setRowCount(list.size());
117  }
118 
119  private void addColumns() {
120  Columns cols = new Columns();
121  appendChild(cols);
122 
123  Column col = new Column("#", null, "50px");
124  cols.appendChild(col);
125 
126  col = new Column(Application.getString("lName"));
127  cols.appendChild(col);
128 
129  col = new Column(Application.getString("lCost"), null, "120px");
130  col.setAlign("right");
131  cols.appendChild(col);
132 
133  col = new Column(Application.getString("lPrice"), null, "120px");
134  col.setAlign("right");
135  cols.appendChild(col);
136  }
137 
138 }
139 
static void showHumanResource(Long id)
Definition: ErpMenu.java:178