@@ -0,0 +1,24 @@
|
||||
package info.bukova.isspst.services.requirement;
|
||||
|
||||
import info.bukova.isspst.services.IsspstException;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class ApproveException extends IsspstException {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3794779381621324848L;
|
||||
|
||||
public ApproveException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ApproveException(String message) {
|
||||
super(message);
|
||||
this.setReason(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import info.bukova.isspst.data.RequirementBase;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -21,6 +22,7 @@ public interface RequirementBaseService<T extends RequirementBase> extends Servi
|
||||
public void loadType(T data);
|
||||
public void loadWorkflow(T data);
|
||||
public void approve(T entity);
|
||||
public void approve(T entity, Date approveDate);
|
||||
public boolean canApprove(T entity);
|
||||
public List<User> getNextApprover(T entity);
|
||||
|
||||
|
||||
+40
-21
@@ -18,11 +18,6 @@ import info.bukova.isspst.services.LazyLoader;
|
||||
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,6 +25,10 @@ import org.springframework.security.access.prepost.PostFilter;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
@@ -211,37 +210,45 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
}
|
||||
}
|
||||
|
||||
protected void approve(T entity, User user) {
|
||||
protected void approve(T entity, User user, Date approveDate) {
|
||||
T e = (T) dao.getById(entity.getId());
|
||||
|
||||
|
||||
if (e.getReqDate().getTime() > approveDate.getTime()) {
|
||||
throw new ApproveException("ErrApproveBeforeRequirement");
|
||||
}
|
||||
|
||||
if (e.getLastApproveDate() != null && e.getLastApproveDate().getTime() > approveDate.getTime()) {
|
||||
throw new ApproveException("ErrAppreveBeforeLastApprove");
|
||||
}
|
||||
|
||||
Workflow wf = getNextWorkflow(e);
|
||||
if (wf == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Role role = wf.getRole();
|
||||
AuthItem auth = new AuthItem();
|
||||
auth.setApprover(user);
|
||||
auth.setRole(role);
|
||||
auth.setAuthDate(new Date());
|
||||
|
||||
auth.setAuthDate(approveDate);
|
||||
|
||||
e.getAuthorization().add(auth);
|
||||
|
||||
|
||||
if (getNextWorkflow(e) == null) {
|
||||
e.setState(RequirementState.APPROVED);
|
||||
} else {
|
||||
e.setState(RequirementState.PARTIALLY);
|
||||
}
|
||||
|
||||
|
||||
super.update(e);
|
||||
|
||||
if (!autoApprove(e)) {
|
||||
|
||||
if (!autoApprove(e, approveDate)) {
|
||||
this.sendToApprovers(e);
|
||||
|
||||
|
||||
SettingsData settings = settingsService.getSettings();
|
||||
MailMessage message = null;
|
||||
|
||||
if (e.getOwnedBy().getEmail() != null
|
||||
|
||||
if (e.getOwnedBy().getEmail() != null
|
||||
&& !e.getOwnedBy().getEmail().isEmpty()
|
||||
&& e.getOwnedBy().isNotify()) {
|
||||
if (e.getState() == RequirementState.APPROVED && settings.getConfReqTemplate() != null) {
|
||||
@@ -249,17 +256,21 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
} else if (settings.getAuthReqTemplate() != null) {
|
||||
message = messageBuilder.buildMessage(settings.getAuthReqTemplate(), e);
|
||||
}
|
||||
|
||||
|
||||
if (message != null) {
|
||||
message.setFrom(getLoggedInUser().getEmail());
|
||||
message.setTo(e.getOwnedBy().getEmail());
|
||||
mailer.send(message);
|
||||
mailer.send(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
postApprove(e);
|
||||
}
|
||||
|
||||
protected void approve(T entity, User user) {
|
||||
approve(entity, user, new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -268,13 +279,21 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
|
||||
approve(entity, getLoggedInUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("this.canApprove(#entity)")
|
||||
public void approve(T entity, Date approveDate) {
|
||||
approve(entity, getLoggedInUser(), approveDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Volá se z metody approve pro automatické schválení dalším schvalovatelem v pořadí. Metoda z báze nedělá nic.
|
||||
*
|
||||
* @param entity Požadavek
|
||||
* @param approveDate
|
||||
* @return true pokud se provedlo automatické schválení.
|
||||
*/
|
||||
protected boolean autoApprove(T entity) {
|
||||
protected boolean autoApprove(T entity, Date approveDate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,15 @@ import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workflow;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
import info.bukova.isspst.services.invoicing.InvoicingService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
* @author Franta Přibyl
|
||||
@@ -48,7 +47,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean autoApprove(Requirement entity)
|
||||
protected boolean autoApprove(Requirement entity, Date approveDate)
|
||||
{
|
||||
List<User> approvers = this.getNextApprover(entity);
|
||||
Workflow nextWf = this.getNextWorkflow(entity);
|
||||
@@ -61,7 +60,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
|
||||
if ((entity.getSumTotal() != null)
|
||||
&& (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1))
|
||||
{
|
||||
approve(entity, approvers.get(0));
|
||||
approve(entity, approvers.get(0), approveDate);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package info.bukova.isspst.ui.main;
|
||||
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.RequirementBase;
|
||||
import info.bukova.isspst.services.requirement.ApproveException;
|
||||
import info.bukova.isspst.services.requirement.RequirementBaseService;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ExecutionArgParam;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Pepa Rokos
|
||||
*/
|
||||
public class ApproveDialogVM {
|
||||
|
||||
private RequirementBaseService service;
|
||||
private RequirementBase requirement;
|
||||
private ListViewModel grid;
|
||||
private Date approveDate;
|
||||
|
||||
public Date getApproveDate() {
|
||||
return approveDate;
|
||||
}
|
||||
|
||||
public void setApproveDate(Date approveDate) {
|
||||
this.approveDate = approveDate;
|
||||
}
|
||||
|
||||
@Init
|
||||
public void init(@ExecutionArgParam("service") RequirementBaseService service,
|
||||
@ExecutionArgParam("requirement") RequirementBase requirement,
|
||||
@ExecutionArgParam("grid") ListViewModel grid) {
|
||||
this.service = service;
|
||||
this.requirement = requirement;
|
||||
this.grid = grid;
|
||||
this.approveDate = new Date();
|
||||
}
|
||||
|
||||
@Command
|
||||
public void approve(@BindingParam("window") Window window) {
|
||||
try {
|
||||
service.approve(requirement, approveDate);
|
||||
BindUtils.postNotifyChange(null, null, grid, "dataBean");
|
||||
BindUtils.postNotifyChange(null, null, grid, "canApprove");
|
||||
BindUtils.postGlobalCommand(null, null, "reload", null);
|
||||
window.detach();
|
||||
} catch (ApproveException ex) {
|
||||
Messagebox.show(StringUtils.localize(ex.getReason()), StringUtils.localize("Error"), Messagebox.OK,
|
||||
Messagebox.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,14 +7,17 @@ import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.ui.BigDecimalConverter;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
import info.bukova.isspst.ui.renderers.RequirementsItemRenderer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.bind.BindUtils;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RequirementSubpage<T extends RequirementBase> extends ListViewModel<T> {
|
||||
|
||||
@@ -55,8 +58,12 @@ public class RequirementSubpage<T extends RequirementBase> extends ListViewModel
|
||||
@Command
|
||||
@NotifyChange({"dataBean", "canApprove"})
|
||||
public void approve() {
|
||||
this.getReqService().approve(getDataBean());
|
||||
BindUtils.postGlobalCommand(null, null, "reload", null);
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("service", getReqService());
|
||||
params.put("requirement", getDataBean());
|
||||
params.put("grid", this);
|
||||
Window window = (Window) Executions.createComponents("/main/approveDialog.zul", null, params);
|
||||
window.doModal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,6 +42,13 @@ RequirementItemDescription=Poznámka
|
||||
|
||||
RequirementInvoicedAmount=Fakturovaná částka:
|
||||
|
||||
RequirementApprove=Schválit
|
||||
RequirementApproveDialog=Schválení
|
||||
RequirementApproveDate=Datum schválení:
|
||||
RequirementApproveStatus=Stav schválení:
|
||||
|
||||
ErrAppreveBeforeLastApprove=Datum schválení musí být pozdější než datum posledního schválení!
|
||||
ErrApproveBeforeRequirement=Datum schválení musí být pozdější než datum požadavku!
|
||||
|
||||
AgendaMyOrders=Aktuální
|
||||
AgendaOrdersHistory=Ukončené
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,29 @@
|
||||
<?page title="${labels.RequirementApproveDialog}" contentType="text/html;charset=UTF-8"?>
|
||||
|
||||
<zk xmlns="http://www.zkoss.org/2005/zul"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
|
||||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
|
||||
|
||||
<window id="approveWin" border="normal" apply="org.zkoss.bind.BindComposer"
|
||||
viewModel="@id('vm') @init('info.bukova.isspst.ui.main.ApproveDialogVM')" width="300px" closable="true">
|
||||
<caption
|
||||
image="/img/approve-032.png"
|
||||
zclass="form-caption"
|
||||
label="${labels.RequirementApproveDialog}" />
|
||||
|
||||
<vbox hflex="1">
|
||||
<hbox>
|
||||
<label value="${labels.RequirementApproveDate}"/>
|
||||
<datebox value="@bind(vm.approveDate)"/>
|
||||
</hbox>
|
||||
<separator bar="true" hflex="1"/>
|
||||
<hbox>
|
||||
<button image="/img/approve-016.png" label="${labels.Confirm}" onClick="@command('approve', window=approveWin)" sclass="nicebutton"/>
|
||||
<button image="~./zul/img/misc/drag-disallow.png" label="${labels.ButtonStorno}" onClick="approveWin.detach()" sclass="nicebutton"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
||||
</window>
|
||||
|
||||
</zk>
|
||||
@@ -1,8 +1,10 @@
|
||||
<?page title="approve status" contentType="text/html;charset=UTF-8"?>
|
||||
<zk>
|
||||
<zk xmlns="http://www.zkoss.org/2005/zul"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
|
||||
|
||||
<label value="Stav schválení: "/>
|
||||
<button label="Schválit"
|
||||
<label value="${labels.RequirementApproveStatus}"/>
|
||||
<button label="${labels.RequirementApprove}"
|
||||
image="/img/approve-016.png"
|
||||
onClick="@command('approve')"
|
||||
disabled="@load(not vm.canApprove)"
|
||||
|
||||
Reference in New Issue
Block a user