Umožněna změna data schválení požadavku.

closes #209
Verze_2.0
Josef Rokos 10 years ago
parent 48d2c75d7b
commit c6ebf8959b

@ -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.data.User;
import info.bukova.isspst.services.Service; import info.bukova.isspst.services.Service;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -21,6 +22,7 @@ public interface RequirementBaseService<T extends RequirementBase> extends Servi
public void loadType(T data); public void loadType(T data);
public void loadWorkflow(T data); public void loadWorkflow(T data);
public void approve(T entity); public void approve(T entity);
public void approve(T entity, Date approveDate);
public boolean canApprove(T entity); public boolean canApprove(T entity);
public List<User> getNextApprover(T entity); public List<User> getNextApprover(T entity);

@ -18,11 +18,6 @@ import info.bukova.isspst.services.LazyLoader;
import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.settings.GlobalSettingsService;
import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService; 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.LazyInitializationException;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired; 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.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/** /**
* @author Pepa Rokos * @author Pepa Rokos
* @author Franta Přibyl * @author Franta Přibyl
@ -211,9 +210,17 @@ 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()); 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); Workflow wf = getNextWorkflow(e);
if (wf == null) { if (wf == null) {
return; return;
@ -223,7 +230,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
AuthItem auth = new AuthItem(); AuthItem auth = new AuthItem();
auth.setApprover(user); auth.setApprover(user);
auth.setRole(role); auth.setRole(role);
auth.setAuthDate(new Date()); auth.setAuthDate(approveDate);
e.getAuthorization().add(auth); e.getAuthorization().add(auth);
@ -235,7 +242,7 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
super.update(e); super.update(e);
if (!autoApprove(e)) { if (!autoApprove(e, approveDate)) {
this.sendToApprovers(e); this.sendToApprovers(e);
SettingsData settings = settingsService.getSettings(); SettingsData settings = settingsService.getSettings();
@ -261,6 +268,10 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
postApprove(e); postApprove(e);
} }
protected void approve(T entity, User user) {
approve(entity, user, new Date());
}
@Override @Override
@Transactional @Transactional
@PreAuthorize("this.canApprove(#entity)") @PreAuthorize("this.canApprove(#entity)")
@ -268,13 +279,21 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
approve(entity, getLoggedInUser()); 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. * 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 entity Požadavek
* @param approveDate
* @return true pokud se provedlo automatické schválení. * @return true pokud se provedlo automatické schválení.
*/ */
protected boolean autoApprove(T entity) { protected boolean autoApprove(T entity, Date approveDate) {
return false; return false;
} }

@ -10,16 +10,15 @@ import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workflow; import info.bukova.isspst.data.Workflow;
import info.bukova.isspst.services.LazyLoader; import info.bukova.isspst.services.LazyLoader;
import info.bukova.isspst.services.invoicing.InvoicingService; 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.Hibernate;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/** /**
* @author Pepa Rokos * @author Pepa Rokos
* @author Franta Přibyl * @author Franta Přibyl
@ -48,7 +47,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
} }
@Override @Override
protected boolean autoApprove(Requirement entity) protected boolean autoApprove(Requirement entity, Date approveDate)
{ {
List<User> approvers = this.getNextApprover(entity); List<User> approvers = this.getNextApprover(entity);
Workflow nextWf = this.getNextWorkflow(entity); Workflow nextWf = this.getNextWorkflow(entity);
@ -61,7 +60,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl<Requireme
if ((entity.getSumTotal() != null) if ((entity.getSumTotal() != null)
&& (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1)) && (entity.getSumTotal().compareTo(nextWf.getLimit()) == -1))
{ {
approve(entity, approvers.get(0)); approve(entity, approvers.get(0), approveDate);
return true; 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.BigDecimalConverter;
import info.bukova.isspst.ui.ListViewModel; import info.bukova.isspst.ui.ListViewModel;
import info.bukova.isspst.ui.renderers.RequirementsItemRenderer; import info.bukova.isspst.ui.renderers.RequirementsItemRenderer;
import java.util.List;
import org.zkoss.bind.BindUtils; import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.select.annotation.WireVariable; 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> { public class RequirementSubpage<T extends RequirementBase> extends ListViewModel<T> {
@ -55,8 +58,12 @@ public class RequirementSubpage<T extends RequirementBase> extends ListViewModel
@Command @Command
@NotifyChange({"dataBean", "canApprove"}) @NotifyChange({"dataBean", "canApprove"})
public void approve() { public void approve() {
this.getReqService().approve(getDataBean()); Map<String, Object> params = new HashMap<String, Object>();
BindUtils.postGlobalCommand(null, null, "reload", null); 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 @Override

@ -42,6 +42,13 @@ RequirementItemDescription=Poznámka
RequirementInvoicedAmount=Fakturovaná částka: 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í AgendaMyOrders=Aktuální
AgendaOrdersHistory=Ukončené 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"?> <?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í: "/> <label value="${labels.RequirementApproveStatus}"/>
<button label="Schválit" <button label="${labels.RequirementApprove}"
image="/img/approve-016.png" image="/img/approve-016.png"
onClick="@command('approve')" onClick="@command('approve')"
disabled="@load(not vm.canApprove)" disabled="@load(not vm.canApprove)"

Loading…
Cancel
Save