diff --git a/src/main/java/info/bukova/isspst/services/approved/OrderService.java b/src/main/java/info/bukova/isspst/services/approved/OrderService.java index 4d36ba21..c0aed201 100644 --- a/src/main/java/info/bukova/isspst/services/approved/OrderService.java +++ b/src/main/java/info/bukova/isspst/services/approved/OrderService.java @@ -1,13 +1,16 @@ package info.bukova.isspst.services.approved; +import java.math.BigDecimal; import java.util.List; import info.bukova.isspst.data.JoinedItem; import info.bukova.isspst.data.Order; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.Service; public interface OrderService extends Service { public Order createOrder(List items); + public BigDecimal totalOrderedForWorkgroup(Workgroup workgroup); } diff --git a/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java b/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java index 3783bc6d..9ddf678b 100644 --- a/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java @@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; +import info.bukova.isspst.data.Workgroup; public class OrderServiceImpl extends AbstractOwnedService implements OrderService { @@ -45,6 +46,14 @@ public class OrderServiceImpl extends AbstractOwnedService implements return order; } + @Override + @Transactional + public BigDecimal totalOrderedForWorkgroup(Workgroup workgroup) { + Query q = dao.getQuery("select sum(oi.total) from OrderItem oi join oi.reqItem ri join ri.requirement rq join rq.workgroup w where ri.delivered = true and w = :workgroup"); + q.setParameter("workgroup", workgroup); + return (BigDecimal)q.uniqueResult(); + } + @Override @Transactional @PreAuthorize("hasPermission(this, 'PERM_ADD')") 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 0b4765ed..b3adda62 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementBaseServiceImpl.java @@ -56,18 +56,27 @@ public abstract class RequirementBaseServiceImpl exte } entity.setWorkgroup(reqWorkgroup); - entity.setNumser(this.getNumberSerie()); - this.addWorkflow(entity); + + checkEnable(); if (!canAdd(entity)) { throw new AddRequirementException(); } + this.addWorkflow(entity); + entity.setNumser(this.getNumberSerie()); + super.add(entity); this.sendToApprovers(entity); } + private void checkEnable() { + if (!settingsService.getSettings().isEnableRequirements()) { + throw new AddRequirementException("RequirementsDisabled"); + } + } + protected boolean canAdd(T entity) { return true; } 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 dcc9ba11..8eef0ae1 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -8,7 +8,9 @@ import info.bukova.isspst.data.RequirementSubject; import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workflow; import info.bukova.isspst.services.LazyLoader; +import info.bukova.isspst.services.approved.OrderService; +import java.math.BigDecimal; import java.util.Date; import java.util.List; @@ -21,6 +23,8 @@ public class RequirementServiceImpl extends @Autowired private RequirementTypeService reqTypeService; + @Autowired + private OrderService orderService; @Override protected Requirement createEntity() { @@ -49,6 +53,31 @@ public class RequirementServiceImpl extends return false; } + + @Override + protected boolean canAdd(Requirement entity) { + if (entity.getWorkgroup() != null + && entity.getWorkgroup().getLimit() != null + && entity.getWorkgroup().getLimit().compareTo(BigDecimal.ZERO) != 0) { + + BigDecimal total = orderService.totalOrderedForWorkgroup(entity.getWorkgroup()); + + if (total == null) { + total = BigDecimal.ZERO; + } + + total = total.add(entity.getSumTotal()); + + if (total.compareTo(entity.getWorkgroup().getLimit()) <= 0) { + return true; + } + + } else { + return true; + } + + throw new AddRequirementException("LimitExceeded"); + } /* * Lazy load pro načtení seznamu skupin materiálu nebo služeb do comba. diff --git a/src/main/java/info/bukova/isspst/storage/StorageException.java b/src/main/java/info/bukova/isspst/storage/StorageException.java index 6538e4bf..5c0b89b9 100644 --- a/src/main/java/info/bukova/isspst/storage/StorageException.java +++ b/src/main/java/info/bukova/isspst/storage/StorageException.java @@ -1,17 +1,17 @@ -package info.bukova.isspst.storage; - -import info.bukova.isspst.services.IsspstException; - -public class StorageException extends IsspstException { - - private static final long serialVersionUID = -1303880908451845756L; - - public StorageException(String reason) { - super(reason); - } - - public StorageException(String reason, Throwable cause) { - super(reason, cause); - } - -} +package info.bukova.isspst.storage; + +import info.bukova.isspst.services.IsspstException; + +public class StorageException extends IsspstException { + + private static final long serialVersionUID = -1303880908451845756L; + + public StorageException(String reason) { + super(reason); + } + + public StorageException(String reason, Throwable cause) { + super(reason, cause); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/dashboard/DashBoardVM.java b/src/main/java/info/bukova/isspst/ui/dashboard/DashBoardVM.java index ae4784bc..7be10133 100644 --- a/src/main/java/info/bukova/isspst/ui/dashboard/DashBoardVM.java +++ b/src/main/java/info/bukova/isspst/ui/dashboard/DashBoardVM.java @@ -3,9 +3,12 @@ package info.bukova.isspst.ui.dashboard; import info.bukova.isspst.data.Role; import info.bukova.isspst.data.User; import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.approved.OrderService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.DocumentViewModel; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -14,20 +17,24 @@ import java.util.Map; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.WireVariable; -public class DashBoardVM { +public class DashBoardVM extends DocumentViewModel { @WireVariable private WorkgroupService workgroupService; @WireVariable private UserService userService; + @WireVariable + private OrderService orderService; private User user; private Map> groupRoles; + private Map workgroupSpent; - @Init + @Init(superclass = true) public void init() { user = userService.getCurrent(); groupRoles = new HashMap>(); + workgroupSpent = new HashMap(); List wg = new ArrayList(); if (workgroupService.getUserCentres(user) != null) { @@ -40,6 +47,7 @@ public class DashBoardVM { for (Workgroup w : wg) { List r = workgroupService.getUserWorkgroupRoles(w, user); groupRoles.put(w, r); + workgroupSpent.put(w, orderService.totalOrderedForWorkgroup(w)); } } @@ -59,4 +67,8 @@ public class DashBoardVM { return groupRoles; } + public Map getWorkgroupSpent() { + return workgroupSpent; + } + } diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 6f574ed0..4c81e9a6 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -142,6 +142,10 @@ Centres=Střediska OfferSelectedOnly=Nabízet pouze vybraná střediska Select=Vybrat OfferedCentres=Nabízená střediska +LimitExceeded=Požadavek nelze uložit z důvodu překročení limitu komise. +Spent=Vyčerpáno: +WorkgroupLimits=Limity komisí +RequirementsDisabled=Vkládání požadavků je administrátorem zakázáno Number=Číslo: Prefix=Prefix: diff --git a/src/main/webapp/app/info.zul b/src/main/webapp/app/info.zul index ac5216c7..a1b78138 100644 --- a/src/main/webapp/app/info.zul +++ b/src/main/webapp/app/info.zul @@ -40,29 +40,62 @@ - - - - + + + \ No newline at end of file diff --git a/src/main/webapp/img/money-small.png b/src/main/webapp/img/money-small.png new file mode 100644 index 00000000..4ac391cf Binary files /dev/null and b/src/main/webapp/img/money-small.png differ diff --git a/src/main/webapp/img/money.png b/src/main/webapp/img/money.png new file mode 100644 index 00000000..cc9e9d69 Binary files /dev/null and b/src/main/webapp/img/money.png differ