From d7e02f4ccca3b6893d587b0b1ac1736a2d37379c Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Thu, 2 Oct 2014 16:00:14 +0200 Subject: [PATCH] =?UTF-8?q?Implementov=C3=A1no=20hl=C3=ADd=C3=A1n=C3=AD=20?= =?UTF-8?q?limit=C5=AF=20pro=20komise.=20Po=C5=BEadavek,=20kter=C3=BD=20by?= =?UTF-8?q?=20p=C5=99ekro=C4=8D=C3=ADl=20limit=20komise=20nelze=20ulo?= =?UTF-8?q?=C5=BEit.=20V=20glob=C3=A1ln=C3=ADm=20nastaven=C3=AD=20byl=20ro?= =?UTF-8?q?zchozen=20checkbox=20"Povolit=20zad=C3=A1v=C3=A1n=C3=AD=20po?= =?UTF-8?q?=C5=BEadavk=C5=AF".=20closes=20#137?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/approved/OrderService.java | 3 + .../services/approved/OrderServiceImpl.java | 10 +++ .../RequirementBaseServiceImpl.java | 11 ++- .../requirement/RequirementServiceImpl.java | 29 +++++++ .../isspst/ui/dashboard/DashBoardVM.java | 16 +++- .../WEB-INF/locales/zk-label.properties | 4 + src/main/webapp/app/info.zul | 75 +++++++++++++----- src/main/webapp/img/money-small.png | Bin 0 -> 1428 bytes src/main/webapp/img/money.png | Bin 0 -> 3152 bytes 9 files changed, 124 insertions(+), 24 deletions(-) create mode 100644 src/main/webapp/img/money-small.png create mode 100644 src/main/webapp/img/money.png 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 1e7decc7..dbe02066 100644 --- a/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; +import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -12,6 +13,7 @@ import info.bukova.isspst.data.AddressEmb; import info.bukova.isspst.data.JoinedItem; import info.bukova.isspst.data.Order; import info.bukova.isspst.data.OrderItem; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.settings.GlobalSettingsService; @@ -42,6 +44,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..77b8891a 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(); } + 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/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 4546bc7f..2b9009ec 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..8d5bb0bb 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 0000000000000000000000000000000000000000..4ac391cfdd92522a6d1a9ec8aa14cc44a7b3edc6 GIT binary patch literal 1428 zcmV;F1#9|=P)P000>X1^@s6#OZ}&00006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-U=5?EPG4`e1_6IM~~H znvv!=-~6vLf(FOGrp^rf`|9l9ZQngIG50Aeo7wct^Y0}a(Q1usdU@(KDt6|nrk?td zdgKZpFHTaZZ0I-ctJt-h>WxMqi^b)`G1>HRwYLHYOx++`EcEyNc2xDXb#t))_DfyS zj^F)t?A0`I=|;V{*`Zap${uqMh4R|>Ca#>jXhc+aCCI1^V?z|3BBf%HTsF)6`~ua@ z5dG04daq<<-z+oVPl;V2CA&n-icz$SFJ%18(^Xkj>)yJ^`+2f%maLma3W-z_U;3cI z;?g2>&X*{um^-l@vdvvFD@MMO|EZ^WPj{Fd;33L>nYFn!#6CeaS7m8>ndq%iI{MlP zf&kwSs1*W~RE@>Nt-HoldFu6~xs^By#rX?gaQgEzJiPCRNPNy*n8lh?Bp;2Vd_}!t zR4tCKQZRYIeSsdRXkP=OpPJN+{lXGx3T}rDC4aA4&+_6g zpWQjTlv3h}cb<^R{YgCKvEr$qc`I{3ZL|?~d-= zR)+hAzdY4*YIu2SIb)Y>gdzSXq}PBdP&5xjICN|;Atcc*Qyo8W><`xicI;j6&Q6Xb zN+Tz4nZ9#EI~Pg^xj=qnyV$bE5Q5f_$(?;eSZe`IaZOB=KRmf>;Ga4DOtUM4iytq2 zkSr88NG)IGp@YZ%nJ-K)`Fn%=E9c8dP0)I%nYa;RAksyT+0On0om?*0@Ev#e6dqq4 zk7W0+B<-W?)H`wrq4;#^i{nDu@{wi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