diff --git a/src/main/java/info/bukova/isspst/BigDecimalUtils.java b/src/main/java/info/bukova/isspst/BigDecimalUtils.java new file mode 100644 index 00000000..e7c40aa1 --- /dev/null +++ b/src/main/java/info/bukova/isspst/BigDecimalUtils.java @@ -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; + } +} diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index e7b6107d..842eab7c 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -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"; diff --git a/src/main/java/info/bukova/isspst/data/JoinedItem.java b/src/main/java/info/bukova/isspst/data/JoinedItem.java index 48a3abb8..31632aa7 100644 --- a/src/main/java/info/bukova/isspst/data/JoinedItem.java +++ b/src/main/java/info/bukova/isspst/data/JoinedItem.java @@ -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 + } } diff --git a/src/main/java/info/bukova/isspst/data/MUnitEmb.java b/src/main/java/info/bukova/isspst/data/MUnitEmb.java index 1217f952..59a451de 100644 --- a/src/main/java/info/bukova/isspst/data/MUnitEmb.java +++ b/src/main/java/info/bukova/isspst/data/MUnitEmb.java @@ -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) diff --git a/src/main/java/info/bukova/isspst/filters/JoinedItemFilter.java b/src/main/java/info/bukova/isspst/filters/JoinedItemFilter.java new file mode 100644 index 00000000..313b065d --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/JoinedItemFilter.java @@ -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 +{ + private JoinedItem condition; + + public JoinedItemFilter(JoinedItem cond) + { + this.condition = cond; + } + + private static class JoinedItemMatcher extends TypeSafeMatcher + { + 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 matchBuilding(JoinedItem item) + { + return new JoinedItemMatcher(item); + } + } + + @Override + public JoinedItemMatcher matcher() + { + return new JoinedItemMatcher(condition); + } + + @Override + public String queryString() + { + return ""; + } +} diff --git a/src/main/java/info/bukova/isspst/services/approved/ApprovedService.java b/src/main/java/info/bukova/isspst/services/approved/ApprovedService.java new file mode 100644 index 00000000..a992b985 --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/approved/ApprovedService.java @@ -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 +{ +} diff --git a/src/main/java/info/bukova/isspst/services/approved/ApprovedServiceImpl.java b/src/main/java/info/bukova/isspst/services/approved/ApprovedServiceImpl.java new file mode 100644 index 00000000..67a78b2d --- /dev/null +++ b/src/main/java/info/bukova/isspst/services/approved/ApprovedServiceImpl.java @@ -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 implements ApprovedService +{ + @Autowired + WorkgroupService workgroupService; + + @Autowired + UserService userService; + + // V bázi je BaseDao, 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 getAll() + { + List 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 items = new ArrayList(); + + for (RequirementItem it : (List)q.list()) { + items.add(new JoinedItem(it, it.getRequirement().getWorkgroup(), it.getRequirement().getCentre(), it.getRequirement().getOwnedBy())); + } + + return items; + } +} diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java index cabbefaf..1b841c8d 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java @@ -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 { public void loadGroups(Requirement req); - public List getItemsForOrder(); } 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 6569d861..dcc9ba11 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -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 getItemsForOrder() { - List 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 items = new ArrayList(); - - for (RequirementItem it : (List)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 diff --git a/src/main/java/info/bukova/isspst/ui/main/approved/ApprovedList.java b/src/main/java/info/bukova/isspst/ui/main/approved/ApprovedList.java new file mode 100644 index 00000000..e4ad6144 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/main/approved/ApprovedList.java @@ -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 +{ + @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 getItems() + { + return approvedService.getAll(); + } +} diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index f1eac0d1..8b42b8b6 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -265,6 +265,7 @@ MaterialRequirement=Požadavek na materiál MaterialRequirements=Požadavky na materiál ServiceRequirement=Požadavek na servis ServiceRequirements=Požadavky na servis +ApprovedRequirementItems=Schválené položky požadavků CurrentRequirements=Aktuální požadavky ApprovedOrders=Schválené objednávky diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index abc4569c..19a4a874 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -301,6 +301,10 @@ + + + + diff --git a/src/main/webapp/app/mainMenu.zul b/src/main/webapp/app/mainMenu.zul index c7987158..c266e23f 100644 --- a/src/main/webapp/app/mainMenu.zul +++ b/src/main/webapp/app/mainMenu.zul @@ -22,6 +22,11 @@ label="${labels.ServiceRequirements}" href="/main/orders/services/" /> + + diff --git a/src/main/webapp/css/zk-modify.css b/src/main/webapp/css/zk-modify.css index 6364f59f..a9d4cb44 100644 --- a/src/main/webapp/css/zk-modify.css +++ b/src/main/webapp/css/zk-modify.css @@ -19,6 +19,12 @@ text-align: right; } +.find-grid-img-left { + display: table-cell; + width: 20px; + text-align: left; +} + .find-grid-divtextbox { display: table-cell; } @@ -27,6 +33,11 @@ width: 100%; } +.find-grid-textbox-right { + width: 100%; + text-align: right; +} + .grid-textbox-max { width: 100%; } diff --git a/src/main/webapp/img/hammer-016.png b/src/main/webapp/img/hammer-016.png new file mode 100644 index 00000000..11ab96d5 Binary files /dev/null and b/src/main/webapp/img/hammer-016.png differ diff --git a/src/main/webapp/img/hammer-032.png b/src/main/webapp/img/hammer-032.png new file mode 100644 index 00000000..7ede0280 Binary files /dev/null and b/src/main/webapp/img/hammer-032.png differ diff --git a/src/main/webapp/main/orders/approved/grid.zul b/src/main/webapp/main/orders/approved/grid.zul new file mode 100644 index 00000000..d7a529cf --- /dev/null +++ b/src/main/webapp/main/orders/approved/grid.zul @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/src/main/webapp/main/orders/approved/index.zul b/src/main/webapp/main/orders/approved/index.zul new file mode 100644 index 00000000..ec14e6fa --- /dev/null +++ b/src/main/webapp/main/orders/approved/index.zul @@ -0,0 +1,10 @@ + + + + + String gridZul = "grid.zul"; + + + + + \ No newline at end of file