BrightSide Workbench Full Report + Source Code
workorder/ReceiptsGrid.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.workorder;
20 
21 import java.util.Date;
22 import org.turro.command.CommandUtil;
23 import org.turro.command.ControlAdapter;
24 import org.turro.elephant.context.Application;
25 import org.turro.elephant.util.DateFormats;
26 import org.turro.elephant.util.DecimalFormats;
27 import org.turro.elephant.util.Images;
28 import org.turro.erp.entity.*;
29 import org.turro.zkoss.grid.PagingGrid;
30 import org.turro.zkoss.label.LabelAdapter;
31 import org.turro.zkoss.label.PercentLabel;
32 import org.zkoss.zk.ui.Component;
33 import org.zkoss.zk.ui.ext.AfterCompose;
34 import org.zkoss.zul.*;
35 
40 public class ReceiptsGrid extends PagingGrid implements AfterCompose {
41 
42  private WorkOrder workOrder;
43  private boolean humanResource = true, resource = true, product = true;
44 
45  public void setWorkOrder(WorkOrder workOrder) {
46  this.workOrder = workOrder;
47  }
48 
49  public void setHumanResource(boolean humanResource) {
50  this.humanResource = humanResource;
51  checkRows();
52  }
53 
54  public void setResource(boolean resource) {
55  this.resource = resource;
56  checkRows();
57  }
58 
59  public void setProduct(boolean product) {
60  this.product = product;
61  checkRows();
62  }
63 
64  @Override
65  public void afterCompose() {
66  addColumns();
67  addRows();
68  }
69 
70  private void addRows() {
71  ReceiptSet rs = new ReceiptSet(workOrder);
72 
73  Rows rows = new Rows();
74  appendChild(rows);
75 
76  for(final ReceiptItem ri : rs) {
77  Row row = new Row();
78  rows.appendChild(row);
79  row.setValue(ri);
80  Vlayout vbox = new Vlayout();
81  row.appendChild(vbox);
82  RequiredUsage requiredUsage = ri.getOrderItem().getOwnerRequiredUsage();
83  Task task = requiredUsage.getTask();
84  OrderReference orderReference = task.getOrderReference();
85  vbox.appendChild(CommandUtil.getLabel(orderReference));
86  vbox.appendChild(new ControlAdapter(CommandUtil.getLabel(task)).setSclass("softLabel"));
87  vbox = new Vlayout();
88  row.appendChild(vbox);
89  vbox.appendChild(new Label(DateFormats.formatNull(ri.getWorkDate(), !"product".equals(ri.getType()))));
90  if(task.getDelivery() != null) {
91  Label l = new Label(DateFormats.format(task.getDelivery(), true));
92  if(task.getDelivery().after(new Date())) {
93  l.setStyle("color:green;font-size:11px;");
94  } else {
95  l.setStyle("color:red;font-size:11px;");
96  }
97  vbox.appendChild(l);
98  }
99  row.appendChild(new Image(Images.getImage(ri.getType())));
100  row.appendChild(new Label(ri.getName()));
101  row.appendChild(new Label(ri.getDescription()));
102  vbox = new Vlayout();
103  row.appendChild(vbox);
104  vbox.appendChild(new Label(DecimalFormats.format(ri.getUnits())));
105  if(ri.getHumanResource() != null) {
106  vbox.appendChild(new LabelAdapter(new PercentLabel(ri.getDedication())).setSclass("softLabel"));
107  }
108  row.appendChild(new Label(DecimalFormats.format(ri.getAmount())));
109  }
110 
111  setRowCount(rs.size());
112  }
113 
114  private void addColumns() {
115  Columns cols = new Columns();
116  appendChild(cols);
117 
118  Column col = new Column(Application.getString("lReference"));
119  cols.appendChild(col);
120 
121  col = new Column(Application.getString("lDate"), null, "120px");
122  cols.appendChild(col);
123 
124  col = new Column(null, null, "30px");
125  cols.appendChild(col);
126 
127  col = new Column(Application.getString("lResource") + " / " + Application.getString("lProduct"));
128  cols.appendChild(col);
129 
130  col = new Column(Application.getString("lConcept"));
131  cols.appendChild(col);
132 
133  col = new Column(Application.getString("lHours") + " / " + Application.getString("lQuantity"), null, "120px");
134  col.setAlign("right");
135  cols.appendChild(col);
136 
137  col = new Column(Application.getString("lAmount"), null, "120px");
138  col.setAlign("right");
139  cols.appendChild(col);
140 
141  }
142 
143  private void checkRows() {
144  for(Component row : getRows().getChildren()) {
145  ReceiptItem ri = (ReceiptItem) ((Row) row).getValue();
146  row.setVisible(
147  (ri.getHumanResource() != null && humanResource) ||
148  (ri.getResource() != null && resource) ||
149  ("product".equals(ri.getType()) && product));
150  }
151  }
152 
153 }
static HtmlBasedComponent getLabel(Object entity)
HtmlBasedComponent setSclass(String sclass)
static final String format(Date d, boolean dateOnly)
static String formatNull(Date d, boolean dateOnly)
static String format(Number value, String pattern)
void setHumanResource(boolean humanResource)
Rows getRows(boolean create)