From 5b380386bd58e2c8aac4d6088445e5cda8ac4720 Mon Sep 17 00:00:00 2001 From: Franta Pribyl Date: Wed, 15 Oct 2014 16:49:39 +0200 Subject: [PATCH] =?UTF-8?q?Objedn=C3=A1vku=20lze=20nyn=C3=AD=20ozna=C4=8Di?= =?UTF-8?q?t=20jako=20objednanou.=20Na=20schv=C3=A1len=C3=A9=20polo=C5=BEk?= =?UTF-8?q?y=20se=20prop=C3=AD=C5=A1=20=C4=8D=C3=ADslo=20objedn=C3=A1vky.?= =?UTF-8?q?=20V=C5=A1echny=20objedn=C3=A1vky,=20kter=C3=A9=20schv=C3=A1len?= =?UTF-8?q?=C3=A9=20a=20objednan=C3=A9=20polo=C5=BEky=20obsahuj=C3=AD=20ji?= =?UTF-8?q?=C5=BE=20nen=C3=AD=20mo=C5=BEno=20znovu=20objednat.=20Objedn?= =?UTF-8?q?=C3=A1vky=20mazat=20nelze,=20tak=C5=BEe=20maz=C3=A1n=C3=AD=20do?= =?UTF-8?q?klad=C5=AF=20ne=C5=99e=C5=A1=C3=ADme.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #153 --- .../java/info/bukova/isspst/StringUtils.java | 16 ++++----- .../bukova/isspst/dao/RequirementItemDao.java | 8 +++++ .../isspst/dao/jpa/RequirementItemDaoJPA.java | 8 +++++ .../java/info/bukova/isspst/data/Order.java | 26 +++++++++++++- .../bukova/isspst/data/RequirementItem.java | 13 +++++++ .../bukova/isspst/filters/OrderFilter.java | 4 ++- .../approved/ApprovedServiceImpl.java | 2 +- .../services/approved/OrderService.java | 1 + .../services/approved/OrderServiceImpl.java | 27 +++++++++++++- .../bukova/isspst/ui/DocumentViewModel.java | 13 +++++++ .../ui/main/orders/created/OrderForm.java | 35 +++++++++++++++++++ .../WEB-INF/locales/zk-label.properties | 1 + .../webapp/WEB-INF/spring/root-context.xml | 4 +++ src/main/webapp/main/orders/created/grid.zul | 27 ++++++++++++-- .../webapp/main/orders/created/orderForm.zul | 17 ++++++++- 15 files changed, 187 insertions(+), 15 deletions(-) create mode 100644 src/main/java/info/bukova/isspst/dao/RequirementItemDao.java create mode 100644 src/main/java/info/bukova/isspst/dao/jpa/RequirementItemDaoJPA.java diff --git a/src/main/java/info/bukova/isspst/StringUtils.java b/src/main/java/info/bukova/isspst/StringUtils.java index e7402ed2..07e8cbdf 100644 --- a/src/main/java/info/bukova/isspst/StringUtils.java +++ b/src/main/java/info/bukova/isspst/StringUtils.java @@ -7,12 +7,12 @@ import org.zkoss.util.resource.Labels; public class StringUtils { - private static String nullStr(String str) + public static String nullToEmptyString(String str) { return str == null ? "" : str; } - private static String not0ToStr(long i) + private static String zeroToEmptyString(long i) { return i == 0 ? "" : String.valueOf(i); } @@ -60,8 +60,8 @@ public class StringUtils public static boolean isEqualForFilter(String value, String search) { - value = StringUtils.nullStr(value).toLowerCase(); - search = StringUtils.nullStr(search).toLowerCase(); + value = StringUtils.nullToEmptyString(value).toLowerCase(); + search = StringUtils.nullToEmptyString(search).toLowerCase(); if (search.isEmpty()) { @@ -73,8 +73,8 @@ public class StringUtils public static boolean isIcEqualForFilter(long value, long search) { - String compareValue = StringUtils.not0ToStr(value); - String searchValue = StringUtils.not0ToStr(search); + String compareValue = StringUtils.zeroToEmptyString(value); + String searchValue = StringUtils.zeroToEmptyString(search); return compareValue.startsWith(searchValue); } @@ -124,7 +124,7 @@ public class StringUtils for (int i = 0; i < list.size(); i++) { - String item = StringUtils.nullStr(list.get(i)); + String item = StringUtils.nullToEmptyString(list.get(i)); result = StringUtils.addSeparator(result, separator); result += item; } @@ -138,7 +138,7 @@ public class StringUtils for (int i = 0; i < list.size(); i++) { - String item = StringUtils.nullStr(list.get(i)); + String item = StringUtils.nullToEmptyString(list.get(i)); if (!item.isEmpty()) { diff --git a/src/main/java/info/bukova/isspst/dao/RequirementItemDao.java b/src/main/java/info/bukova/isspst/dao/RequirementItemDao.java new file mode 100644 index 00000000..126d3e26 --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/RequirementItemDao.java @@ -0,0 +1,8 @@ +package info.bukova.isspst.dao; + +import info.bukova.isspst.data.RequirementItem; + +public interface RequirementItemDao extends BaseDao +{ + +} \ No newline at end of file diff --git a/src/main/java/info/bukova/isspst/dao/jpa/RequirementItemDaoJPA.java b/src/main/java/info/bukova/isspst/dao/jpa/RequirementItemDaoJPA.java new file mode 100644 index 00000000..612b8e70 --- /dev/null +++ b/src/main/java/info/bukova/isspst/dao/jpa/RequirementItemDaoJPA.java @@ -0,0 +1,8 @@ +package info.bukova.isspst.dao.jpa; + +import info.bukova.isspst.dao.RequirementItemDao; +import info.bukova.isspst.data.RequirementItem; + +public class RequirementItemDaoJPA extends BaseDaoJPA implements RequirementItemDao +{ +} diff --git a/src/main/java/info/bukova/isspst/data/Order.java b/src/main/java/info/bukova/isspst/data/Order.java index d8862f46..c56e3c48 100644 --- a/src/main/java/info/bukova/isspst/data/Order.java +++ b/src/main/java/info/bukova/isspst/data/Order.java @@ -19,7 +19,7 @@ import org.hibernate.annotations.LazyCollectionOption; @Entity @Table(name = "ORDERS") -public class Order extends BaseData +public class Order extends BaseData implements Cloneable { @Column(name = "NUMSER") @@ -292,4 +292,28 @@ public class Order extends BaseData this.invoiceTotal = invoiceTotal; } + public boolean isIcludedRequirementItemFromAnotherOrder() + { + for (OrderItem oItem : this.getItems()) + { + RequirementItem rItem = oItem.getReqItem(); + + if (rItem != null) + { + String orderNum = rItem.getOrderNum(); + boolean isIncluded = !((orderNum == null) || (orderNum.isEmpty())); + return isIncluded; + } + } + + return false; + } + + @Override + public Object clone() throws CloneNotSupportedException + { + Order cloned = (Order) super.clone(); + cloned.setTotal(new BigDecimal(this.getTotal().toString())); + return cloned; + } } diff --git a/src/main/java/info/bukova/isspst/data/RequirementItem.java b/src/main/java/info/bukova/isspst/data/RequirementItem.java index 3e2198a3..b3d22d45 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementItem.java +++ b/src/main/java/info/bukova/isspst/data/RequirementItem.java @@ -56,6 +56,9 @@ public class RequirementItem @Column(name = "DELIVERED") private Boolean delivered; + @Column(name = "ORDERNUM") + private String orderNum; + public int getId() { return id; @@ -187,4 +190,14 @@ public class RequirementItem public void setDelivered(Boolean delivered) { this.delivered = delivered; } + + public String getOrderNum() + { + return orderNum; + } + + public void setOrderNum(String orderNum) + { + this.orderNum = orderNum; + } } diff --git a/src/main/java/info/bukova/isspst/filters/OrderFilter.java b/src/main/java/info/bukova/isspst/filters/OrderFilter.java index 376cea1e..a23b62f0 100644 --- a/src/main/java/info/bukova/isspst/filters/OrderFilter.java +++ b/src/main/java/info/bukova/isspst/filters/OrderFilter.java @@ -42,6 +42,7 @@ public class OrderFilter implements Filter @Override public boolean matchesSafely(Order item) { + boolean foundOrdered = (item.isOrdered() == condition.isOrdered()); boolean foundNumSer = StringUtils.isEqualForFilter(item.getNumser(), condition.getNumser()); boolean foundOrderDate = DateTimeUtils.isEqualByDateForFilter(item.getOrderDate(), condition.getOrderDate()); boolean foundTotal = true;// BigDecimalUtils.isEqualByDecimalForFilter(item.getTotal(), @@ -56,7 +57,8 @@ public class OrderFilter implements Filter boolean foundInvoiceAddr = AddressEmb.isEqualByAddressEmbForFilter(item.getAddress(), condition.getAddress()); boolean foundOwnedBy = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy()); boolean foundDescription = StringUtils.isEqualForFilter(item.getDescription(), condition.getDescription()); - return (foundNumSer + return (foundOrdered + && foundNumSer && foundOrderDate && foundTotal && foundDeliveryDate diff --git a/src/main/java/info/bukova/isspst/services/approved/ApprovedServiceImpl.java b/src/main/java/info/bukova/isspst/services/approved/ApprovedServiceImpl.java index f17d69be..8234267d 100644 --- a/src/main/java/info/bukova/isspst/services/approved/ApprovedServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/approved/ApprovedServiceImpl.java @@ -35,7 +35,7 @@ public class ApprovedServiceImpl extends AbstractService implements { List wgList = workgroupService.getUserCentres(userService.getCurrent()); Query q = queryDao -.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)"); + .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) and (item.orderNum Is Null or item.orderNum = '')"); q.setParameterList("wgList", wgList); q.setParameter("state", RequirementState.APPROVED); List items = new ArrayList(); diff --git a/src/main/java/info/bukova/isspst/services/approved/OrderService.java b/src/main/java/info/bukova/isspst/services/approved/OrderService.java index d1cc5636..0966403c 100644 --- a/src/main/java/info/bukova/isspst/services/approved/OrderService.java +++ b/src/main/java/info/bukova/isspst/services/approved/OrderService.java @@ -22,4 +22,5 @@ public interface OrderService extends Service { public BigDecimal calcSumTotalFromItems(List items); + public void updateApprovedItems(Order order, boolean orderedChanged); } diff --git a/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java b/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java index 0c55466a..808e358f 100644 --- a/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java @@ -1,9 +1,11 @@ package info.bukova.isspst.services.approved; +import info.bukova.isspst.dao.RequirementItemDao; 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.RequirementItem; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; import info.bukova.isspst.services.LazyLoader; @@ -23,7 +25,10 @@ public class OrderServiceImpl extends AbstractOwnedService implements @Autowired private GlobalSettingsService globalSettings; - + + @Autowired + private RequirementItemDao requirementItemDao; + @Override @PreAuthorize("hasPermission(this, 'PERM_ADD')") public Order createOrder(List items) { @@ -171,4 +176,24 @@ public class OrderServiceImpl extends AbstractOwnedService implements return sumTotal; } + + @Transactional + public void updateApprovedItems(Order order, boolean orderedChanged) + { + if (orderedChanged) + { + for (OrderItem item : order.getItems()) + { + RequirementItem rItem = item.getReqItem(); + + if (rItem != null) + { + rItem.setOrderNum(order.isOrdered() ? order.getNumser() : null); + requirementItemDao.modify(rItem); + } + } + } + + super.update(order); + } } diff --git a/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java b/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java index 678e88b3..793fb02c 100644 --- a/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java @@ -17,6 +17,8 @@ public class DocumentViewModel { protected BigDecimalConverter standardBigDecimalConverter; + protected BoolConverter standardBoolConverter; + public BigDecimalConverter getStandardBigDecimalConverter() { return standardBigDecimalConverter; @@ -27,10 +29,21 @@ public class DocumentViewModel this.standardBigDecimalConverter = standardBigDecimalConverter; } + public BoolConverter getStandardBoolConverter() + { + return standardBoolConverter; + } + + public void setStandardBoolConverter(BoolConverter standardBoolConverter) + { + this.standardBoolConverter = standardBoolConverter; + } + @Init public void initDocumentViewModel() { this.standardBigDecimalConverter = new BigDecimalConverter(); + this.standardBoolConverter = new BoolConverter(); } @Command diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java index 3905a8aa..7177ed89 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderForm.java @@ -51,6 +51,11 @@ public class OrderForm extends FormViewModel protected List syncOrderItems; + /** + * Obsah záznamu před editací + */ + protected Order recordBeforeEdit; + @Init(superclass = true) public void initOrderForm() { @@ -78,6 +83,16 @@ public class OrderForm extends FormViewModel } this.syncOrderItems = this.getDataBean().getItems(); + + try + { + this.recordBeforeEdit = (Order) this.getDataBean().clone(); + } + catch (CloneNotSupportedException e) + { + log.error("Nelze provést hlubokou kopii objednávky!"); + e.printStackTrace(); + } } public OrderFormValidator getOrderFormValidator() @@ -165,6 +180,16 @@ public class OrderForm extends FormViewModel this.syncOrderItems = syncOrderItems; } + public Order getRecordBeforeEdit() + { + return recordBeforeEdit; + } + + public void setRecordBeforeEdit(Order recordBeforeEdit) + { + this.recordBeforeEdit = recordBeforeEdit; + } + @Command @NotifyChange("dataBean") public void doFillSuppAddress() @@ -252,4 +277,14 @@ public class OrderForm extends FormViewModel // Calculate total price at form this.calcAndUpdateFormTotalPrice(form); } + + @Override + protected void doSave() + { + // Zjisti, zda se změnil příznak objednávky (objednáno/neobjednáno) + boolean orderedChanged = (this.recordBeforeEdit.isOrdered() != this.getDataBean().isOrdered()); + // Aktualizovat příznak schválených položek, aby se nemohli vložit do + // jiných objednávek + orderService.updateApprovedItems(this.getDataBean(), orderedChanged); + } } diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 13246e59..a1fae789 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -279,6 +279,7 @@ false=Ne Information=Informace Order=Objednávka Orders=Objednávky +OrderAbr=Obj. MaterialRequirement=Požadavek na materiál MaterialRequirements=Požadavky na materiál diff --git a/src/main/webapp/WEB-INF/spring/root-context.xml b/src/main/webapp/WEB-INF/spring/root-context.xml index 9a4e0675..dc990d89 100644 --- a/src/main/webapp/WEB-INF/spring/root-context.xml +++ b/src/main/webapp/WEB-INF/spring/root-context.xml @@ -219,6 +219,10 @@ + + + + diff --git a/src/main/webapp/main/orders/created/grid.zul b/src/main/webapp/main/orders/created/grid.zul index c23dde74..cc048a46 100644 --- a/src/main/webapp/main/orders/created/grid.zul +++ b/src/main/webapp/main/orders/created/grid.zul @@ -27,9 +27,13 @@ model="@load(vm.dataList)"> + + label="${labels.number}" /> + +
+
+ +
+
+ +
+
+
@@ -251,6 +268,7 @@