Implementováno hlídání limitů pro komise. Požadavek, který by překročíl

limit komise nelze uložit. 
V globálním nastavení byl rozchozen checkbox "Povolit zadávání
požadavků".
closes #137
multitenant
Josef Rokos 10 years ago
parent 81ff039da8
commit d7e02f4ccc

@ -1,13 +1,16 @@
package info.bukova.isspst.services.approved; package info.bukova.isspst.services.approved;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import info.bukova.isspst.data.JoinedItem; import info.bukova.isspst.data.JoinedItem;
import info.bukova.isspst.data.Order; import info.bukova.isspst.data.Order;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.Service; import info.bukova.isspst.services.Service;
public interface OrderService extends Service<Order> { public interface OrderService extends Service<Order> {
public Order createOrder(List<JoinedItem> items); public Order createOrder(List<JoinedItem> items);
public BigDecimal totalOrderedForWorkgroup(Workgroup workgroup);
} }

@ -4,6 +4,7 @@ import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.hibernate.Query;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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;
@ -12,6 +13,7 @@ import info.bukova.isspst.data.AddressEmb;
import info.bukova.isspst.data.JoinedItem; import info.bukova.isspst.data.JoinedItem;
import info.bukova.isspst.data.Order; import info.bukova.isspst.data.Order;
import info.bukova.isspst.data.OrderItem; import info.bukova.isspst.data.OrderItem;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.AbstractOwnedService;
import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.settings.GlobalSettingsService;
@ -42,6 +44,14 @@ public class OrderServiceImpl extends AbstractOwnedService<Order> implements
return order; 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 @Override
@Transactional @Transactional
@PreAuthorize("hasPermission(this, 'PERM_ADD')") @PreAuthorize("hasPermission(this, 'PERM_ADD')")

@ -56,18 +56,27 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> exte
} }
entity.setWorkgroup(reqWorkgroup); entity.setWorkgroup(reqWorkgroup);
entity.setNumser(this.getNumberSerie());
this.addWorkflow(entity); this.addWorkflow(entity);
checkEnable();
if (!canAdd(entity)) { if (!canAdd(entity)) {
throw new AddRequirementException(); throw new AddRequirementException();
} }
entity.setNumser(this.getNumberSerie());
super.add(entity); super.add(entity);
this.sendToApprovers(entity); this.sendToApprovers(entity);
} }
private void checkEnable() {
if (!settingsService.getSettings().isEnableRequirements()) {
throw new AddRequirementException("RequirementsDisabled");
}
}
protected boolean canAdd(T entity) { protected boolean canAdd(T entity) {
return true; return true;
} }

@ -8,7 +8,9 @@ import info.bukova.isspst.data.RequirementSubject;
import info.bukova.isspst.data.User; 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.approved.OrderService;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -21,6 +23,8 @@ public class RequirementServiceImpl extends
@Autowired @Autowired
private RequirementTypeService reqTypeService; private RequirementTypeService reqTypeService;
@Autowired
private OrderService orderService;
@Override @Override
protected Requirement createEntity() { protected Requirement createEntity() {
@ -50,6 +54,31 @@ public class RequirementServiceImpl extends
return false; 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. * Lazy load pro načtení seznamu skupin materiálu nebo služeb do comba.
* Ošetřuje se zde případné neexistující vazby na ID smazaných skupin * Ošetřuje se zde případné neexistující vazby na ID smazaných skupin

@ -3,9 +3,12 @@ package info.bukova.isspst.ui.dashboard;
import info.bukova.isspst.data.Role; import info.bukova.isspst.data.Role;
import info.bukova.isspst.data.User; import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workgroup; 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.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.DocumentViewModel;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -14,20 +17,24 @@ import java.util.Map;
import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.Init;
import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.select.annotation.WireVariable;
public class DashBoardVM { public class DashBoardVM extends DocumentViewModel {
@WireVariable @WireVariable
private WorkgroupService workgroupService; private WorkgroupService workgroupService;
@WireVariable @WireVariable
private UserService userService; private UserService userService;
@WireVariable
private OrderService orderService;
private User user; private User user;
private Map<Workgroup, List<Role>> groupRoles; private Map<Workgroup, List<Role>> groupRoles;
private Map<Workgroup, BigDecimal> workgroupSpent;
@Init @Init(superclass = true)
public void init() { public void init() {
user = userService.getCurrent(); user = userService.getCurrent();
groupRoles = new HashMap<Workgroup, List<Role>>(); groupRoles = new HashMap<Workgroup, List<Role>>();
workgroupSpent = new HashMap<Workgroup, BigDecimal>();
List<Workgroup> wg = new ArrayList<Workgroup>(); List<Workgroup> wg = new ArrayList<Workgroup>();
if (workgroupService.getUserCentres(user) != null) { if (workgroupService.getUserCentres(user) != null) {
@ -40,6 +47,7 @@ public class DashBoardVM {
for (Workgroup w : wg) { for (Workgroup w : wg) {
List<Role> r = workgroupService.getUserWorkgroupRoles(w, user); List<Role> r = workgroupService.getUserWorkgroupRoles(w, user);
groupRoles.put(w, r); groupRoles.put(w, r);
workgroupSpent.put(w, orderService.totalOrderedForWorkgroup(w));
} }
} }
@ -59,4 +67,8 @@ public class DashBoardVM {
return groupRoles; return groupRoles;
} }
public Map<Workgroup, BigDecimal> getWorkgroupSpent() {
return workgroupSpent;
}
} }

@ -142,6 +142,10 @@ Centres=Střediska
OfferSelectedOnly=Nabízet pouze vybraná střediska OfferSelectedOnly=Nabízet pouze vybraná střediska
Select=Vybrat Select=Vybrat
OfferedCentres=Nabízená střediska 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: Number=Číslo:
Prefix=Prefix: Prefix=Prefix:

@ -40,29 +40,62 @@
</template> </template>
</hbox> </hbox>
</groupbox> </groupbox>
<groupbox <hbox vflex="1">
vflex="1" <groupbox
mold="3d"> vflex="1"
<caption hflex="1"
image="/img/commission-small.png" mold="3d">
label="${labels.WorkgroupMembership}" /> <caption
<hbox children="@load(vm.workgroups)"> image="/img/commission-small.png"
<template name="children"> label="${labels.WorkgroupMembership}" />
<listbox model="@load(vm.groupRoles[each])"> <vbox
<listhead> sclass="addScrollbar"
<listheader label="@load(each.fullName)" /> children="@load(vm.workgroups)">
</listhead> <template name="children">
<template <listbox model="@load(vm.groupRoles[each])">
name="model" <listhead>
var="role"> <listheader label="@load(each.fullName)" />
</listhead>
<template
name="model"
var="role">
<listitem>
<listcell label="@load(role.description)" />
</listitem>
</template>
</listbox>
</template>
</vbox>
</groupbox>
<groupbox
vflex="1"
hflex="1"
mold="3d">
<caption
image="/img/money-small.png"
label="${labels.WorkgroupLimits}" />
<vbox
sclass="addScrollbar"
children="@load(vm.workgroups)">
<template name="children">
<listbox>
<listhead>
<listheader label="@load(each.fullName)"/>
<listheader/>
</listhead>
<listitem> <listitem>
<listcell label="@load(role.description)" /> <listcell label="${labels.Limit}"/>
<listcell label="@load(each.limit) @converter(vm.standardBigDecimalConverter)"/>
</listitem> </listitem>
</template> <listitem>
</listbox> <listcell label="${labels.Spent}"/>
</template> <listcell label="@load(vm.workgroupSpent[each]) @converter(vm.standardBigDecimalConverter)"/>
</hbox> </listitem>
</groupbox> </listbox>
</template>
</vbox>
</groupbox>
</hbox>
</vbox> </vbox>
</window> </window>
</zk> </zk>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Loading…
Cancel
Save