Conflicts:
	src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java
multitenant
František Přibyl 10 years ago
commit 5421486189

@ -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);
} }

@ -18,6 +18,7 @@ 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;
import info.bukova.isspst.data.Workgroup;
public class OrderServiceImpl extends AbstractOwnedService<Order> implements public class OrderServiceImpl extends AbstractOwnedService<Order> implements
OrderService { OrderService {
@ -45,6 +46,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); checkEnable();
if (!canAdd(entity)) { if (!canAdd(entity)) {
throw new AddRequirementException(); throw new AddRequirementException();
} }
this.addWorkflow(entity);
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,13 +40,17 @@
</template> </template>
</hbox> </hbox>
</groupbox> </groupbox>
<hbox vflex="1" hflex="1">
<groupbox <groupbox
vflex="1" vflex="1"
hflex="1"
mold="3d"> mold="3d">
<caption <caption
image="/img/commission-small.png" image="/img/commission-small.png"
label="${labels.WorkgroupMembership}" /> label="${labels.WorkgroupMembership}" />
<hbox children="@load(vm.workgroups)"> <vbox
sclass="addScrollbar"
children="@load(vm.workgroups)">
<template name="children"> <template name="children">
<listbox model="@load(vm.groupRoles[each])"> <listbox model="@load(vm.groupRoles[each])">
<listhead> <listhead>
@ -61,8 +65,37 @@
</template> </template>
</listbox> </listbox>
</template> </template>
</hbox> </vbox>
</groupbox> </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="${labels.Limit}"/>
<listcell label="@load(each.limit) @converter(vm.standardBigDecimalConverter)"/>
</listitem>
<listitem>
<listcell label="${labels.Spent}"/>
<listcell label="@load(vm.workgroupSpent[each]) @converter(vm.standardBigDecimalConverter)"/>
</listitem>
</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