diff --git a/src/main/java/info/bukova/isspst/services/requirement/ApproveException.java b/src/main/java/info/bukova/isspst/services/requirement/ApproveException.java new file mode 100644 index 00000000..df93361c --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/requirement/ApproveException.java @@ -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); + } + +} diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java index 02d320d5..27407beb 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseService.java @@ -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 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 getNextApprover(T entity); diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java index bc44a3f5..afef01a3 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -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 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 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 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; } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java index a97f078d..1e33ee45 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -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 approvers = this.getNextApprover(entity); Workflow nextWf = this.getNextWorkflow(entity); @@ -61,7 +60,7 @@ public class RequirementServiceImpl extends RequirementBaseServiceImpl extends ListViewModel { @@ -55,8 +58,12 @@ public class RequirementSubpage extends ListViewModel @Command @NotifyChange({"dataBean", "canApprove"}) public void approve() { - this.getReqService().approve(getDataBean()); - BindUtils.postGlobalCommand(null, null, "reload", null); + Map params = new HashMap(); + 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 diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index d8dea6f6..cd200e25 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -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é diff --git a/src/main/webapp/img/approve-032.png b/src/main/webapp/img/approve-032.png new file mode 100644 index 00000000..b629aab1 Binary files /dev/null and b/src/main/webapp/img/approve-032.png differ diff --git a/src/main/webapp/main/approveDialog.zul b/src/main/webapp/main/approveDialog.zul new file mode 100644 index 00000000..4fa1a7f2 --- /dev/null +++ b/src/main/webapp/main/approveDialog.zul @@ -0,0 +1,29 @@ + + + + + + + + + + + + + +