BrightSide Workbench Full Report + Source Code
TimeControlComposer.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.erp.time;
20 
21 import java.io.File;
22 import java.io.FileNotFoundException;
23 import java.util.Date;
24 import java.util.List;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.amic.util.date.CheckDate;
28 import org.turro.elephant.context.Application;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.impl.util.FileUtil;
31 import org.turro.erp.db.ErpPU;
32 import org.turro.erp.entity.HumanResource;
33 import org.turro.erp.entity.TimeControl;
34 import org.turro.erp.task.Workload;
35 import org.turro.jpa.Dao;
36 import org.zkoss.text.DateFormats;
37 import org.zkoss.zk.ui.Component;
38 import org.zkoss.zk.ui.event.Event;
39 import org.zkoss.zk.ui.select.SelectorComposer;
40 import org.zkoss.zk.ui.select.annotation.Listen;
41 import org.zkoss.zk.ui.select.annotation.Wire;
42 import org.zkoss.zul.Filedownload;
43 import org.zkoss.zul.Hlayout;
44 import org.zkoss.zul.Label;
45 import org.zkoss.zul.Tab;
46 
51 public class TimeControlComposer extends SelectorComposer<Component> {
52 
53  @Wire private Tab tabHr;
54  @Wire private Tab tabTask;
55  @Wire private Tab tabReport;
56  @Wire private Hlayout info;
57 
58  @Wire private TaskSelector taskList;
59  @Wire private TimeList timeList;
60 
61  @Wire private Label currDay;
62 
63  private HumanResource selected;
64  private Date currDate = new Date();
65 
66  @Listen("onChange = #hrList")
67  public void onHumanResourceSelect(Event evt) {
68  selected = (HumanResource) evt.getData();
69  if(selected != null) {
70  taskList.setHumanResource(selected);
71  info.getChildren().clear();
72  info.appendChild(new Label(selected.getName()));
73  tabTask.setSelected(true);
74  }
75  }
76 
77  @Listen("onChange = #taskList")
78  public void onChange(Event evt) {
79  Object obj = evt.getData();
80  if(obj instanceof TimeControl) {
81  TimeControl tc = (TimeControl) obj;
82  TimeControlUtil tcu = new TimeControlUtil();
83  tcu.end(tc);
84  tabHr.setSelected(true);
85  } else if(obj instanceof Workload) {
86  Workload wl = (Workload) obj;
87  TimeControlUtil tcu = new TimeControlUtil();
88  tcu.setHumanResource(selected);
89  tcu.setTask(wl.getTask());
90  tcu.start();
91  tabHr.setSelected(true);
92  }
93  }
94 
95  @Listen("onUser = #taskList")
96  public void onStart() {
97  if(selected != null) {
98  TimeControlUtil tcu = new TimeControlUtil();
99  tcu.setHumanResource(selected);
100  tcu.start();
101  tabHr.setSelected(true);
102  }
103  }
104 
105  @Listen("onCancel = #taskList")
106  public void onCancelSelect() {
107  tabHr.setSelected(true);
108  }
109 
110  @Listen("onClick = #export")
111  public void onExport() {
112  Dao dao = new ErpPU();
113  List<HumanResource> list = dao.getResultList(
114  "select hr from HumanResource as hr where hr.active = true order by hr.name");
117  xhrs.clear();
118  for(HumanResource hr : list) {
120  xhr.setId(hr.getId());
121  xhr.setName(hr.getName());
122  xhrs.add(xhr);
123  }
125  FileUtil.getFolderFile(file).mkdirs();
126  xhrs.saveCollection();
127  try {
128  Filedownload.save(file, "text/xml");
129  } catch (FileNotFoundException ex) {
130  Logger.getLogger(TimeControlComposer.class.getName()).log(Level.SEVERE, null, ex);
131  }
132  }
133 
134  @Listen("onClick = #report")
135  public void onReport() {
136  tabReport.setSelected(true);
137  currDay.setValue(DateFormats.format(currDate, true));
138  timeList.setDate(currDate);
139  }
140 
141  @Listen("onClick = #prevDay")
142  public void onPrevious() {
143  currDate = new CheckDate(currDate).addDays(-1).getDate();
144  currDay.setValue(DateFormats.format(currDate, true));
145  timeList.setDate(currDate);
146  }
147 
148  @Listen("onClick = #nextDay")
149  public void onNext() {
150  currDate = new CheckDate(currDate).addDays(1).getDate();
151  currDay.setValue(DateFormats.format(currDate, true));
152  timeList.setDate(currDate);
153  }
154 
155  @Listen("onClick = #back")
156  public void onBack() {
157  tabHr.setSelected(true);
158  }
159 
160 }
static File getFolderFile(File file)
Definition: FileUtil.java:290
void setHumanResource(HumanResource humanResource)
TimeControl end(TimeControl tc)
void setDate(Date date)
Definition: TimeList.java:39