BrightSide Workbench Full Report + Source Code
bserp-www/src/main/java/org/turro/erp/humanres/logic/HumanResourceWrapper.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.logic;
19 
20 import java.util.Date;
21 import org.turro.auth.Authentication;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.turro.elephant.context.Application;
25 import org.turro.elephant.log.LogType;
26 import org.turro.elephant.util.ZkossUtils;
27 import org.turro.erp.aptitude.AptitudeDegreeCombobox;
28 import org.turro.erp.entity.AptitudeDegree;
29 import org.turro.erp.entity.HumanResource;
30 import org.turro.erp.entity.OwnedAptitude;
31 import org.turro.jpa.Dao;
32 import org.turro.jpa.entity.EntityCollectionUtil;
33 import org.turro.zkoss.dialog.InputDialog;
34 import org.turro.zkoss.dialog.InputField;
35 import org.turro.zkoss.input.DateboxShort;
36 import org.turro.zul.frame.Framework;
37 import org.zkoss.zk.ui.HtmlBasedComponent;
38 
43 public class HumanResourceWrapper extends org.turro.hr.humanres.HumanResourceWrapper {
44 
46  super(entity);
47  }
48 
49  public void delete(final boolean close) {
50  // Check if possible and notify
51  if(canDelete()) {
52  ZkossUtils.confirmDeletion(null, new Command() {
53  @Override
54  public Object execute(Context context) {
55  if(HumanResourceWrapper.super.delete()) {
56  if(close) Framework.getCurrent().closeSelected();
57  }
58  return null;
59  }
60  });
61  }
62  }
63 
64  @Override
65  public boolean canDelete() {
66  if(entity.getId() == 0) return false;
67  Dao dao = getDao();
68 // Long count = (Long) dao.getSingleResult(
69 // "select count(*) from Document " +
70 // "where contract = ?",
71 // new Object[] { contract });
72 // if(count == 0) {
73 // count = (Long) dao.getSingleResult(
74 // "select count(*) from DocumentLine " +
75 // "where store = ?",
76 // new Object[] { contract });
77 // }
78 // return count == 0;
79  return true;
80  }
81 
82  public void addAptitude() {
84  Framework.getCurrent().getPage(),
85  Application.getString("lAptitudes"),
86  new InputField[] {
87  new InputField("lFrom", null, null, 0) {
88  @Override
89  protected HtmlBasedComponent createEditor() {
90  return new DateboxShort(new Date());
91  }
92  },
93  new InputField("lTo", null, null, 0) {
94  @Override
95  protected HtmlBasedComponent createEditor() {
96  return new DateboxShort(null);
97  }
98  },
99  new InputField("lAptitude", null, null, 0) {
100  @Override
101  protected HtmlBasedComponent createEditor() {
102  return new AptitudeDegreeCombobox();
103  }
104  }
105  }, new Command() {
106 
107  @Override
108  public Object execute(Context context) {
109  InputField[] fields = (InputField[]) context.get("fields");
110  if(fields.length > 0) {
111  Date from = null, to = null;
112  AptitudeDegree o = null;
113  Integer d = 0;
114  for(InputField f : fields) {
115  if("lAptitude".equals(f.getLabel())) {
116  o = (AptitudeDegree) f.getValue();
117  } else if("lFrom".equals(f.getLabel())) {
118  from = (Date) f.getValue();
119  } else if("lTo".equals(f.getLabel())) {
120  to = (Date) f.getValue();
121  }
122  }
123  if(o != null) {
124  OwnedAptitude oo = new OwnedAptitude();
125  oo.setAptitudeDegree(o);
126  oo.setInitialDate(from);
127  oo.setFinalDate(to);
128  oo.setDefaultDegree(false);
129  oo.setHumanResource(entity);
130  entity.getOwnedAptitudes().add(oo);
131  }
132  }
133  return null;
134  }
135  });
136  }
137 
138  public void deleteAptitude(OwnedAptitude aptitude) {
139  if(aptitude != null) {
140  EntityCollectionUtil.remove(entity.getOwnedAptitudes(), aptitude);
141  }
142  }
143 
144  @Override
145  protected void logEntity(LogType logType, String path, String action, String data) {
146  Authentication.log(logType, path, action, data);
147  }
148 
149 }
static String getString(String key)
boolean equals(Object obj)
Definition: DaoEntity.java:154
static void getInput(Page page, String title, String label, Object value, String format, int scale, final Command onOk)
static Framework getCurrent()
Definition: Framework.java:203