BrightSide Workbench Full Report + Source Code
OrderItemRowRenderer.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 package org.turro.erp.purchase;
19 
20 import java.util.Date;
21 import org.turro.string.Strings;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
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.ZkossUtils;
28 import org.turro.elephant.zkoss.Modal;
29 import org.turro.erp.entity.OrderItem;
30 import org.turro.erp.entity.RequiredUsage;
31 import org.turro.erp.entity.Task;
32 import org.turro.erp.entity.WorkOrder;
33 import org.turro.financials.entity.Contract;
34 import org.turro.util.PhraseBuilder;
35 import org.turro.zkoss.label.LabelAdapter;
36 import org.turro.zkoss.label.PercentLabel;
37 import org.zkoss.zk.ui.Executions;
38 import org.zkoss.zk.ui.event.Event;
39 import org.zkoss.zk.ui.event.EventListener;
40 import org.zkoss.zk.ui.event.Events;
41 import org.zkoss.zul.*;
42 
47 public class OrderItemRowRenderer implements RowRenderer {
48 
49  private OrdersGrid grid;
50 
52  this.grid = grid;
53  }
54 
55  @Override
56  public void render(final Row row, Object data, int index) throws Exception {
57  if(row instanceof Group) {
58  OrderItem oi = (OrderItem) data;
59  PhraseBuilder pb = new PhraseBuilder();
60  Contract provider = oi.getProvider();
61  if(provider != null) {
62  pb.addWord(provider.getName());
63  }
64  if(oi.getDocumentDate() != null) {
65  pb.addWord(Application.getString("lDate"));
66  pb.addWord(DateFormats.format(oi.getDocumentDate(), true));
67  }
68  if(!Strings.isBlank(oi.getDocumentNumber())) {
69  pb.addWord(Application.getString("lNumber"));
70  pb.addWord(oi.getDocumentNumber());
71  }
72  row.appendChild(new Label(pb.toString()));
73  } else if(row instanceof Groupfoot) {
75  row.appendChild(new Space());
76  row.appendChild(new Label("" + dros.items));
77  A docProps = new A(Application.getString("lDocumentProperties"), "/_zul/images/properties.png");
78  docProps.addEventListener(Events.ON_CLICK, new EventListener() {
79  @Override
80  public void onEvent(Event event) throws Exception {
81  doEdit(dros);
82  }
83  });
84  row.appendChild(docProps);
85  row.appendChild(new Space());
86  row.appendChild(new Space());
87  row.appendChild(new Label(DecimalFormats.format(dros.quatity)));
88  row.appendChild(new Label(DecimalFormats.format(dros.cost)));
89  row.appendChild(new Space());
90  } else {
91  final OrderItem oi = (OrderItem) data;
92  row.appendChild(grid.getEditBox(row, oi));
93  row.appendChild(new Label(oi.getName()));
94  Vlayout vbox = new Vlayout();
95  row.appendChild(vbox);
97  Task task = null;
98  if(oru != null) {
99  task = oru.getTask();
100  }
101  if(task != null) {
103  if(wo != null) {
104  vbox.appendChild(new Label(wo.getFullDescription()));
105  vbox.appendChild(new LabelAdapter(new Label(wo.getContract().getName())).setSclass("softLabel"));
106  }
107  vbox.appendChild(new LabelAdapter(new Label(task.getFullDescription())).setSclass("softLabel"));
108  }
109  row.appendChild(new Label(oi.getDescription()));
110  vbox = new Vlayout();
111  row.appendChild(vbox);
112  vbox.appendChild(new Label(DateFormats.formatNull(oi.getDocumentDate(), true)));
113  if(task != null && task.getDelivery() != null) {
114  Label l = new Label(DateFormats.formatNull(task.getDelivery(), true));
115  if(task.getDelivery().after(new Date())) {
116  l.setStyle("color:green;font-size:11px;");
117  } else {
118  l.setStyle("color:red;font-size:11px;");
119  }
120  vbox.appendChild(l);
121  }
122  vbox = new Vlayout();
123  row.appendChild(vbox);
124  vbox.appendChild(new Label(DecimalFormats.format(oi.getUnits())));
125  if(oi.getRequiredUsage() != null) {
126  vbox.appendChild(new LabelAdapter(new PercentLabel(oi.getDedication())).setSclass("softLabel"));
127  }
128  vbox = new Vlayout();
129  row.appendChild(vbox);
130  vbox.appendChild(new Label(DecimalFormats.format(oi.getCost())));
131  vbox.appendChild(new LabelAdapter(new Label(DecimalFormats.format(oi.getAmount()))).setSclass("softLabel"));
132 
133  OrderItem owner = oi.getOwner();
134  if(owner == null) {
135  Toolbarbutton del = new Toolbarbutton(null, "/_zul/images/edit-delete.png");
136  del.addEventListener(Events.ON_CLICK, new EventListener() {
137  @Override
138  public void onEvent(Event event) throws Exception {
139  ZkossUtils.confirmDeletion(null, new Command() {
140  @Override
141  public Object execute(Context context) {
142  grid.deleteOrder(oi);
143  return null;
144  }
145  });
146  }
147  });
148  row.appendChild(del);
149  } else {
150  row.appendChild(new Space());
151  }
152  }
153  }
154 
155  private void doEdit(OrderItemModel.OrderItemSummary dros) {
156  Window w = (Window) Executions.createComponents("/WEB-INF/_zul/erp/purchase/editOrderGroup.zul", null, null);
157  w.setMode(Window.MODAL);
158  Events.sendEvent(Events.ON_USER, w, dros);
159  Modal.doModal(w, new Command() {
160  @Override
161  public Object execute(Context context) {
162  grid.refresh();
163  return null;
164  }
165  });
166  }
167 
168 }
static String getString(String key)
static final String format(Date d, boolean dateOnly)
static String formatNull(Date d, boolean dateOnly)
static String format(Number value, String pattern)
static int doModal(String file)
Definition: Modal.java:38
RequiredUsage getOwnerRequiredUsage()
Definition: OrderItem.java:374
RequiredUsage getRequiredUsage()
Definition: OrderItem.java:249
void render(final Row row, Object data, int index)
Component getEditBox(final Row row, final OrderItem oi)
Definition: OrdersGrid.java:90