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
This commit is contained in:
@@ -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<Order> {
|
||||
|
||||
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.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<Order> 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')")
|
||||
|
||||
+10
-1
@@ -56,18 +56,27 @@ public abstract class RequirementBaseServiceImpl<T extends RequirementBase> 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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<Workgroup, List<Role>> groupRoles;
|
||||
private Map<Workgroup, BigDecimal> workgroupSpent;
|
||||
|
||||
@Init
|
||||
@Init(superclass = true)
|
||||
public void init() {
|
||||
user = userService.getCurrent();
|
||||
|
||||
groupRoles = new HashMap<Workgroup, List<Role>>();
|
||||
workgroupSpent = new HashMap<Workgroup, BigDecimal>();
|
||||
|
||||
List<Workgroup> wg = new ArrayList<Workgroup>();
|
||||
if (workgroupService.getUserCentres(user) != null) {
|
||||
@@ -40,6 +47,7 @@ public class DashBoardVM {
|
||||
for (Workgroup w : wg) {
|
||||
List<Role> 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<Workgroup, BigDecimal> getWorkgroupSpent() {
|
||||
return workgroupSpent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -40,29 +40,62 @@
|
||||
</template>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
<groupbox
|
||||
vflex="1"
|
||||
mold="3d">
|
||||
<caption
|
||||
image="/img/commission-small.png"
|
||||
label="${labels.WorkgroupMembership}" />
|
||||
<hbox children="@load(vm.workgroups)">
|
||||
<template name="children">
|
||||
<listbox model="@load(vm.groupRoles[each])">
|
||||
<listhead>
|
||||
<listheader label="@load(each.fullName)" />
|
||||
</listhead>
|
||||
<template
|
||||
name="model"
|
||||
var="role">
|
||||
<hbox vflex="1">
|
||||
<groupbox
|
||||
vflex="1"
|
||||
hflex="1"
|
||||
mold="3d">
|
||||
<caption
|
||||
image="/img/commission-small.png"
|
||||
label="${labels.WorkgroupMembership}" />
|
||||
<vbox
|
||||
sclass="addScrollbar"
|
||||
children="@load(vm.workgroups)">
|
||||
<template name="children">
|
||||
<listbox model="@load(vm.groupRoles[each])">
|
||||
<listhead>
|
||||
<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>
|
||||
<listcell label="@load(role.description)" />
|
||||
<listcell label="${labels.Limit}"/>
|
||||
<listcell label="@load(each.limit) @converter(vm.standardBigDecimalConverter)"/>
|
||||
</listitem>
|
||||
</template>
|
||||
</listbox>
|
||||
</template>
|
||||
</hbox>
|
||||
</groupbox>
|
||||
<listitem>
|
||||
<listcell label="${labels.Spent}"/>
|
||||
<listcell label="@load(vm.workgroupSpent[each]) @converter(vm.standardBigDecimalConverter)"/>
|
||||
</listitem>
|
||||
</listbox>
|
||||
</template>
|
||||
</vbox>
|
||||
</groupbox>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
||||
</zk>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Reference in New Issue
Block a user