@@ -0,0 +1,24 @@
|
||||
package info.bukova.isspst;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class BigDecimalUtils
|
||||
{
|
||||
public static boolean isEqualByDecimalForFilter(BigDecimal value, BigDecimal search)
|
||||
{
|
||||
if (search == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (value != null)
|
||||
{
|
||||
String valueS = value.toPlainString();
|
||||
String searchS = search.toPlainString();
|
||||
return valueS.startsWith(searchS);
|
||||
// return (value.compareTo(search) == 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import info.bukova.isspst.data.Role;
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.reporting.ReportMapping;
|
||||
import info.bukova.isspst.services.addressbook.AdbService;
|
||||
import info.bukova.isspst.services.approved.ApprovedService;
|
||||
import info.bukova.isspst.services.buildings.BuildingService;
|
||||
import info.bukova.isspst.services.munits.MUnitService;
|
||||
import info.bukova.isspst.services.reqsubjects.MaterialService;
|
||||
@@ -67,20 +68,21 @@ public class Constants {
|
||||
public final static String MOD_TRIPREQUIREMENTS = "TRIPREQUIREMENTS";
|
||||
public final static String MOD_WORKFLOW = "WORKFLOW";
|
||||
public final static String MOD_TRIPBILL = "TRIPBILL";
|
||||
public final static String MOD_APPROVED = "APPROVED";
|
||||
public final static Module MODULES[] = {
|
||||
new Module(MOD_USERS, "Uživatelé", UserService.class),
|
||||
new Module(MOD_PERMISSIONS, "Práva", RoleService.class),
|
||||
new Module(MOD_ADDRESSBOOK, "Dodavatelé", AdbService.class),
|
||||
new Module(MOD_BUILDINGS, "Budovy", BuildingService.class),
|
||||
new Module(MOD_MUNITS, "Měrné jednotky", MUnitService.class),
|
||||
new Module(MOD_MATERIAL, "Materiál", MaterialService.class),
|
||||
new Module(MOD_SERVICES, "Služby", ServiceItemService.class),
|
||||
new Module(MOD_WORKGROUPS, "Pracovní skupiny", WorkgroupService.class),
|
||||
new Module(MOD_REQUIREMENTS, "Požadavky na nákupy", RequirementService.class),
|
||||
new Module(MOD_TRIPREQUIREMENTS, "Pžadavky na služební cesty", TripRequirementService.class),
|
||||
new Module(MOD_WORKFLOW, "Procesy schválení", RequirementTypeService.class),
|
||||
new Module(MOD_TRIPBILL, "Cestovní příkazy", TripBillService.class)
|
||||
};
|
||||
new Module(MOD_USERS, "Uživatelé", UserService.class),
|
||||
new Module(MOD_PERMISSIONS, "Práva", RoleService.class),
|
||||
new Module(MOD_ADDRESSBOOK, "Dodavatelé", AdbService.class),
|
||||
new Module(MOD_BUILDINGS, "Budovy", BuildingService.class),
|
||||
new Module(MOD_MUNITS, "Měrné jednotky", MUnitService.class),
|
||||
new Module(MOD_MATERIAL, "Materiál", MaterialService.class),
|
||||
new Module(MOD_SERVICES, "Služby", ServiceItemService.class),
|
||||
new Module(MOD_WORKGROUPS, "Pracovní skupiny", WorkgroupService.class),
|
||||
new Module(MOD_REQUIREMENTS, "Požadavky na nákupy", RequirementService.class),
|
||||
new Module(MOD_TRIPREQUIREMENTS, "Požadavky na služební cesty", TripRequirementService.class),
|
||||
new Module(MOD_WORKFLOW, "Procesy schválení", RequirementTypeService.class),
|
||||
new Module(MOD_TRIPBILL, "Cestovní příkazy", TripBillService.class),
|
||||
new Module(MOD_APPROVED, "Schválené položky příkazů", ApprovedService.class) };
|
||||
|
||||
public final static String PERM_APPROVE = "PERM_APPROVE";
|
||||
public final static String PERM_SHOW_WORKGROUP_REQ = "PERM_SHOW_WORKGROUP_REQ";
|
||||
|
||||
@@ -1,34 +1,201 @@
|
||||
package info.bukova.isspst.data;
|
||||
|
||||
public class JoinedItem implements FilterableRequirement {
|
||||
|
||||
private RequirementItem item;
|
||||
private Workgroup workgroup;
|
||||
private Workgroup centre;
|
||||
private User ownedBy;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
public JoinedItem(RequirementItem item, Workgroup workgroup,
|
||||
Workgroup centre, User owner) {
|
||||
super();
|
||||
/**
|
||||
* Položka schválených požadavků na materiál nebo službu
|
||||
*/
|
||||
public class JoinedItem implements DataModel, FilterableRequirement
|
||||
{
|
||||
// Konstruktoři
|
||||
|
||||
protected void CopyItem(RequirementItem item)
|
||||
{
|
||||
this.item = item;
|
||||
|
||||
this.id = item.getId();
|
||||
this.reqSubject = item.getReqSubject();
|
||||
this.requirement = item.getRequirement();
|
||||
this.code = item.getCode();
|
||||
this.name = item.getName();
|
||||
this.textItem = item.getTextItem();
|
||||
this.quantity = item.getQuantity();
|
||||
this.munit = item.getMunit();
|
||||
this.unitPrice = item.getUnitPrice();
|
||||
this.total = item.getTotal();
|
||||
this.description = item.getDescription();
|
||||
}
|
||||
|
||||
// Default konstruktor kvůli volání newInstance()
|
||||
public JoinedItem()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public JoinedItem(RequirementItem item)
|
||||
{
|
||||
super();
|
||||
|
||||
this.CopyItem(item);
|
||||
}
|
||||
|
||||
public JoinedItem(RequirementItem item, Workgroup workgroup, Workgroup centre, User owner)
|
||||
{
|
||||
super();
|
||||
|
||||
this.CopyItem(item);
|
||||
|
||||
this.workgroup = workgroup;
|
||||
this.centre = centre;
|
||||
this.ownedBy = owner;
|
||||
}
|
||||
|
||||
public JoinedItem(RequirementItem item) {
|
||||
super();
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public RequirementItem getItem() {
|
||||
// Kdyby se přistupovalo k datům přes další strukturu, byl by to problém pro
|
||||
// tisk, řazení a Bůh ví co ještě
|
||||
|
||||
private RequirementItem item;
|
||||
|
||||
public RequirementItem getItem()
|
||||
{
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(RequirementItem item) {
|
||||
public void setItem(RequirementItem item)
|
||||
{
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
// Členové RequirementItem
|
||||
|
||||
private int id;
|
||||
private RequirementSubject reqSubject;
|
||||
private Requirement requirement;
|
||||
private String code;
|
||||
private String name;
|
||||
private String textItem;
|
||||
private BigDecimal quantity;
|
||||
private MUnitEmb munit;
|
||||
private BigDecimal unitPrice;
|
||||
private BigDecimal total;
|
||||
private String description;
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public RequirementSubject getReqSubject()
|
||||
{
|
||||
return reqSubject;
|
||||
}
|
||||
|
||||
public void setReqSubject(RequirementSubject reqSubject)
|
||||
{
|
||||
this.reqSubject = reqSubject;
|
||||
}
|
||||
|
||||
public Requirement getRequirement()
|
||||
{
|
||||
return requirement;
|
||||
}
|
||||
|
||||
public void setRequirement(Requirement requirement)
|
||||
{
|
||||
this.requirement = requirement;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code)
|
||||
{
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTextItem()
|
||||
{
|
||||
return textItem;
|
||||
}
|
||||
|
||||
public void setTextItem(String textItem)
|
||||
{
|
||||
this.textItem = textItem;
|
||||
}
|
||||
|
||||
public BigDecimal getQuantity()
|
||||
{
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(BigDecimal quantity)
|
||||
{
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public MUnitEmb getMunit()
|
||||
{
|
||||
return munit;
|
||||
}
|
||||
|
||||
public void setMunit(MUnitEmb munit)
|
||||
{
|
||||
this.munit = munit;
|
||||
}
|
||||
|
||||
public BigDecimal getUnitPrice()
|
||||
{
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitPrice(BigDecimal unitPrice)
|
||||
{
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
public BigDecimal getTotal()
|
||||
{
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(BigDecimal total)
|
||||
{
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
// Hodnoty z Requirement
|
||||
private Workgroup workgroup;
|
||||
private Workgroup centre;
|
||||
private User ownedBy;
|
||||
|
||||
public Workgroup getWorkgroup() {
|
||||
return workgroup;
|
||||
}
|
||||
@@ -53,4 +220,61 @@ public class JoinedItem implements FilterableRequirement {
|
||||
this.ownedBy = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
if (obj instanceof JoinedItem)
|
||||
{
|
||||
JoinedItem item = (JoinedItem) obj;
|
||||
|
||||
return (this.getId() == item.getId());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Zbytenčné metody nutné kvůli přetížení z předka DataModel - chybka v
|
||||
// návrhu no...
|
||||
|
||||
@Override
|
||||
public void setCreated(Date created)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreated()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModified(Date modified)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getModified()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValid(boolean valid)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,20 @@ public class MUnitEmb
|
||||
this.description = StringUtils.encodeSpecialChars(description);
|
||||
}
|
||||
|
||||
public static boolean isEqualMUnitEmbForFilter(MUnitEmb value, MUnitEmb search)
|
||||
{
|
||||
if (search == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (value != null)
|
||||
{
|
||||
return StringUtils.isEqualForFilter(value.getName(), search.getName());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean eqWith(MUnit munit)
|
||||
{
|
||||
if (munit == null)
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package info.bukova.isspst.filters;
|
||||
|
||||
import info.bukova.isspst.BigDecimalUtils;
|
||||
import info.bukova.isspst.StringUtils;
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.MUnitEmb;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Factory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
public class JoinedItemFilter implements Filter<JoinedItem>
|
||||
{
|
||||
private JoinedItem condition;
|
||||
|
||||
public JoinedItemFilter(JoinedItem cond)
|
||||
{
|
||||
this.condition = cond;
|
||||
}
|
||||
|
||||
private static class JoinedItemMatcher extends TypeSafeMatcher<JoinedItem>
|
||||
{
|
||||
private JoinedItem condition;
|
||||
|
||||
public JoinedItemMatcher(JoinedItem cond)
|
||||
{
|
||||
this.condition = cond;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description desc)
|
||||
{
|
||||
desc.appendText("JoinedItem matches");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesSafely(JoinedItem item)
|
||||
{
|
||||
boolean foundCode = StringUtils.isEqualForFilter(item.getCode(), condition.getCode());
|
||||
boolean foundName = StringUtils.isEqualForFilter(item.getName(), condition.getName());
|
||||
boolean foundTextItem = StringUtils.isEqualForFilter(item.getTextItem(), condition.getTextItem());
|
||||
boolean foundQuantity = BigDecimalUtils.isEqualByDecimalForFilter(item.getQuantity(), condition.getQuantity());
|
||||
boolean foundUnitPrice = BigDecimalUtils.isEqualByDecimalForFilter(item.getUnitPrice(), condition.getUnitPrice());
|
||||
boolean foundMUnit = MUnitEmb.isEqualMUnitEmbForFilter(item.getMunit(), condition.getMunit());
|
||||
boolean foundTotal = BigDecimalUtils.isEqualByDecimalForFilter(item.getTotal(), condition.getTotal());
|
||||
boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription());
|
||||
return (foundCode && foundName && foundTextItem && foundDescription && foundQuantity && foundUnitPrice && foundMUnit && foundTotal && foundDescription);
|
||||
}
|
||||
|
||||
@Factory
|
||||
public static Matcher<JoinedItem> matchBuilding(JoinedItem item)
|
||||
{
|
||||
return new JoinedItemMatcher(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JoinedItemMatcher matcher()
|
||||
{
|
||||
return new JoinedItemMatcher(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String queryString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package info.bukova.isspst.services.approved;
|
||||
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.services.Service;
|
||||
|
||||
public interface ApprovedService extends Service<JoinedItem>
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package info.bukova.isspst.services.approved;
|
||||
|
||||
import info.bukova.isspst.dao.BaseDao;
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.services.AbstractService;
|
||||
import info.bukova.isspst.services.users.UserService;
|
||||
import info.bukova.isspst.services.workgroups.WorkgroupService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PostFilter;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class ApprovedServiceImpl extends AbstractService<JoinedItem> implements ApprovedService
|
||||
{
|
||||
@Autowired
|
||||
WorkgroupService workgroupService;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
// V bázi je BaseDao<T>, což nelze použít, protože třída JoinedItem nemá
|
||||
// ekvivalent v databázi
|
||||
// Bylo by dobré tuto funčnost vložit do báze...
|
||||
BaseDao<?> dao4Query;
|
||||
|
||||
public BaseDao<?> getDao4Query()
|
||||
{
|
||||
return dao4Query;
|
||||
}
|
||||
|
||||
public void setDao4Query(BaseDao<?> dao4Query)
|
||||
{
|
||||
this.dao4Query = dao4Query;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_SHOW_CENTRE_REQ')")
|
||||
@PostFilter("hasPermission(filterObject, 'PERM_SHOW_CENTRE_REQ')")
|
||||
public List<JoinedItem> getAll()
|
||||
{
|
||||
List<Workgroup> wgList = workgroupService.getUserCentres(userService.getCurrent());
|
||||
Query q = dao4Query.getQuery("select item from RequirementItem item left join item.requirement rq join rq.centre c where rq.kind is not null and rq.state = :state and c in (:wgList)");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
List<JoinedItem> items = new ArrayList<JoinedItem>();
|
||||
|
||||
for (RequirementItem it : (List<RequirementItem>)q.list()) {
|
||||
items.add(new JoinedItem(it, it.getRequirement().getWorkgroup(), it.getRequirement().getCentre(), it.getRequirement().getOwnedBy()));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
package info.bukova.isspst.services.requirement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
|
||||
public interface RequirementService extends RequirementBaseService<Requirement>
|
||||
{
|
||||
public void loadGroups(Requirement req);
|
||||
public List<JoinedItem> getItemsForOrder();
|
||||
}
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
package info.bukova.isspst.services.requirement;
|
||||
|
||||
import info.bukova.isspst.Constants;
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.data.Requirement;
|
||||
import info.bukova.isspst.data.RequirementItem;
|
||||
import info.bukova.isspst.data.RequirementState;
|
||||
import info.bukova.isspst.data.RequirementSubject;
|
||||
import info.bukova.isspst.data.User;
|
||||
import info.bukova.isspst.data.Workflow;
|
||||
import info.bukova.isspst.data.Workgroup;
|
||||
import info.bukova.isspst.services.LazyLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.PostFilter;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
public class RequirementServiceImpl extends
|
||||
@@ -56,25 +50,6 @@ public class RequirementServiceImpl extends
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Transactional
|
||||
@PreAuthorize("hasPermission(this, 'PERM_SHOW_CENTRE_REQ')")
|
||||
@PostFilter("hasPermission(filterObject, 'PERM_SHOW_CENTRE_REQ')")
|
||||
public List<JoinedItem> getItemsForOrder() {
|
||||
List<Workgroup> wgList = workgroupService.getUserCentres(getLoggedInUser());
|
||||
Query q = dao.getQuery("select item from RequirementItem item left join item.requirement rq join rq.centre c where rq.kind is not null and rq.state = :state and c in (:wgList)");
|
||||
q.setParameterList("wgList", wgList);
|
||||
q.setParameter("state", RequirementState.APPROVED);
|
||||
List<JoinedItem> items = new ArrayList<JoinedItem>();
|
||||
|
||||
for (RequirementItem it : (List<RequirementItem>)q.list()) {
|
||||
items.add(new JoinedItem(it, it.getRequirement().getWorkgroup(), it.getRequirement().getCentre(), it.getRequirement().getOwnedBy()));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package info.bukova.isspst.ui.main.approved;
|
||||
|
||||
import info.bukova.isspst.data.JoinedItem;
|
||||
import info.bukova.isspst.filters.JoinedItemFilter;
|
||||
import info.bukova.isspst.services.approved.ApprovedService;
|
||||
import info.bukova.isspst.ui.BigDecimalConverter;
|
||||
import info.bukova.isspst.ui.ListViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
|
||||
public class ApprovedList extends ListViewModel<JoinedItem>
|
||||
{
|
||||
@WireVariable
|
||||
protected ApprovedService approvedService;
|
||||
|
||||
private BigDecimalConverter bigDecimalConverter;
|
||||
|
||||
@Init
|
||||
public void initApprovedList()
|
||||
{
|
||||
service = approvedService;
|
||||
dataClass = JoinedItem.class;
|
||||
// formZul = "form.zul";
|
||||
dataFilter = new JoinedItemFilter(getFilterTemplate());
|
||||
bigDecimalConverter = new BigDecimalConverter();
|
||||
}
|
||||
|
||||
public BigDecimalConverter getBigDecimalConverter()
|
||||
{
|
||||
return bigDecimalConverter;
|
||||
}
|
||||
|
||||
public List<JoinedItem> getItems()
|
||||
{
|
||||
return approvedService.getAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user