BrightSide Workbench Full Report + Source Code
WorkloadGrid.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.task.usage;
20 
21 import org.turro.command.Command;
22 import org.turro.command.Context;
23 import org.turro.elephant.util.ZkossUtils;
24 import org.turro.erp.entity.HumanResource;
25 import org.turro.erp.entity.OrderItem;
26 import org.turro.erp.entity.Resource;
27 import org.turro.erp.purchase.OrderItemWrapper;
28 import org.turro.erp.task.Workload;
29 import org.turro.erp.task.WorkloadSet;
30 import org.turro.erp.task.WorksheetReport;
31 import org.turro.zkoss.grid.PagingGrid;
32 import org.zkoss.zk.ui.ext.AfterCompose;
33 import org.zkoss.zul.Column;
34 import org.zkoss.zul.Include;
35 import org.zkoss.zul.Row;
36 
41 public class WorkloadGrid extends PagingGrid implements AfterCompose {
42 
43  private WorkloadSet workloads;
44  private HumanResource humanResource;
45  private boolean assigned;
46 
47  public void setAssigned(boolean assigned) {
48  this.assigned = assigned;
49  }
50 
51  public void setHumanResource(HumanResource humanResource) {
52  if(!assigned || humanResource != null) {
53  this.humanResource = humanResource;
54  setWorkloads(new WorkloadSet(humanResource, assigned));
55  }
56  }
57 
58  public void setResource(Resource resource) {
59  if(resource != null) {
60  humanResource = null;
61  setWorkloads(new WorkloadSet(resource, assigned));
62  }
63  }
64 
65  public void setWorkloads(WorkloadSet workloads) {
66  this.workloads = workloads;
67  refresh();
68  }
69 
70  public void printWorksheet() {
71  WorksheetReport wsr = new WorksheetReport();
72  wsr.setOperator(humanResource);
73  wsr.setSendToParticipants(false);
74  wsr.setWorkloads(workloads);
75  wsr.print();
76  }
77 
78  public void sendWorksheet() {
79  WorksheetReport wsr = new WorksheetReport();
80  wsr.setOperator(humanResource);
81  wsr.setSendToParticipants(true);
82  wsr.setWorkloads(workloads);
83  wsr.print();
84  }
85 
86  @Override
87  public void afterCompose() {
88  addColumns();
89  }
90 
91  public void refresh() {
92  getRows(true).getChildren().clear();
93  addRows();
94  }
95 
96  public void createOrderItems() {
97  for(Workload wl : workloads) {
98  if(wl.getOrderUnits() != 0.0d) {
99  OrderItem oi = wl.getRequiredUsage().startOrder(wl.getOrderUnits());
100  oi.setHumanResource(humanResource);
101  if(!oi.isEmpty()) {
102  new OrderItemWrapper(oi).save();
103  }
104  }
105  }
106  }
107 
108  public void deleteOrder(final OrderItem oi, final Row row) {
109  ZkossUtils.confirmDeletion(null, new Command() {
110  @Override
111  public Object execute(Context context) {
112  if(new OrderItemWrapper(oi).delete()) {
113  row.detach();
114  }
115  return null;
116  }
117  });
118  }
119 
120  private void addRows() {
121  if(assigned) {
122  for(Workload wl : workloads) {
123  Row r = new Row();
124  getRows(true).appendChild(r);
125  Include inc = new Include("/WEB-INF/_zul/erp/task/workload_order.zul");
126  inc.setDynamicProperty("orderItem", wl.getOrderItem());
127  inc.setDynamicProperty("grid", this);
128  inc.setDynamicProperty("row", r);
129  inc.setDynamicProperty("workload", wl);
130  inc.setWidth("100%");
131  inc.setHeight("100%");
132  r.appendChild(inc);
133  }
134  } else {
135  for(Workload wl : workloads) {
136  Row r = new Row();
137  getRows(true).appendChild(r);
138  Include inc = new Include("/WEB-INF/_zul/erp/task/workload_usage.zul");
139  inc.setDynamicProperty("requiredUsage", wl.getRequiredUsage());
140  inc.setDynamicProperty("workload", wl);
141  inc.setWidth("100%");
142  inc.setHeight("100%");
143  r.appendChild(inc);
144  }
145  }
146  }
147 
148  private void addColumns() {
149  getColumns(true).appendChild(new Column());
150  getColumns().setVisible(false);
151  }
152 
153 }
RequiredUsage getRequiredUsage()
Definition: OrderItem.java:249
void setHumanResource(HumanResource humanResource)
Definition: OrderItem.java:161
void setOperator(HumanResource operator)
void setWorkloads(WorkloadSet workloads)
void setSendToParticipants(boolean sendToParticipants)
void deleteOrder(final OrderItem oi, final Row row)
void setHumanResource(HumanResource humanResource)
void setResource(Resource resource)
void setAssigned(boolean assigned)
void setWorkloads(WorkloadSet workloads)
Columns getColumns(boolean create)
Rows getRows(boolean create)