diff --git a/src/main/java/info/bukova/isspst/AddressUtils.java b/src/main/java/info/bukova/isspst/AddressUtils.java new file mode 100644 index 00000000..b118eed6 --- /dev/null +++ b/src/main/java/info/bukova/isspst/AddressUtils.java @@ -0,0 +1,41 @@ +package info.bukova.isspst; + +import info.bukova.isspst.data.Address; +import info.bukova.isspst.data.AddressEmb; + +import java.util.ArrayList; +import java.util.List; + + +public class AddressUtils +{ + public static AddressEmb convertAddressToAddressEmb(Address input) + { + if (input == null) + { + return null; + } + + AddressEmb output = new AddressEmb(input); + return output; + } + + public static List convertListAddressToListAddressEmb(List
inputList) + { + if (inputList == null) + { + return null; + } + + List outputList = new ArrayList(); + + for (int i = 0; i < inputList.size(); i++) + { + Address inputItem = inputList.get(i); + AddressEmb outputItem = new AddressEmb(inputItem); + outputList.add(outputItem); + } + + return outputList; + } +} diff --git a/src/main/java/info/bukova/isspst/data/Address.java b/src/main/java/info/bukova/isspst/data/Address.java index 5ea4cfe9..1f8e6bed 100644 --- a/src/main/java/info/bukova/isspst/data/Address.java +++ b/src/main/java/info/bukova/isspst/data/Address.java @@ -199,21 +199,39 @@ public class Address extends BaseData String str, street; List listStreet = new ArrayList(); + if (this.street != null) + { listStreet.add(this.street); + } + if (this.houseNumber != null) + { listStreet.add(this.houseNumber); + } + street = StringUtils.join(listStreet, " "); List list = new ArrayList(); + if (this.company != null) + { list.add(this.company); + } + if (street != null) + { list.add(street); + } + if (this.city != null) + { list.add(this.city); + } + list.add(Long.toString(this.ic)); str = StringUtils.join(list, ", "); + return str; } diff --git a/src/main/java/info/bukova/isspst/data/AddressEmb.java b/src/main/java/info/bukova/isspst/data/AddressEmb.java index fa00f14d..402004f9 100644 --- a/src/main/java/info/bukova/isspst/data/AddressEmb.java +++ b/src/main/java/info/bukova/isspst/data/AddressEmb.java @@ -1,10 +1,16 @@ package info.bukova.isspst.data; +import info.bukova.isspst.StringUtils; + +import java.util.ArrayList; +import java.util.List; + import javax.persistence.Embeddable; @Embeddable -public class AddressEmb { - +public class AddressEmb +{ + private int id; private String company; private String department; @@ -20,11 +26,12 @@ public class AddressEmb { private String email; private String web; private String description; - - public AddressEmb() { + + public AddressEmb() + { super(); } - + public AddressEmb(Address address) { if (address == null) @@ -33,10 +40,10 @@ public class AddressEmb { } this.id = address.getId(); - this.company = address.getCompany(); + this.company = address.getCompany(); this.department = address.getDepartment(); this.contactName = address.getContactName(); - this.street = address.getStreet(); + this.street = address.getStreet(); this.houseNumber = address.getHouseNumber(); this.zipCode = address.getZipCode(); this.city = address.getCity(); @@ -82,116 +89,200 @@ public class AddressEmb { this.id = id; } - public String getCompany() { + public String getCompany() + { return company; } - public void setCompany(String company) { + public void setCompany(String company) + { this.company = company; } - public String getDepartment() { + public String getDepartment() + { return department; } - public void setDepartment(String department) { + public void setDepartment(String department) + { this.department = department; } - public String getContactName() { + public String getContactName() + { return contactName; } - public void setContactName(String contactName) { + public void setContactName(String contactName) + { this.contactName = contactName; } - public String getStreet() { + public String getStreet() + { return street; } - public void setStreet(String street) { + public void setStreet(String street) + { this.street = street; } - public String getHouseNumber() { + public String getHouseNumber() + { return houseNumber; } - public void setHouseNumber(String houseNumber) { + public void setHouseNumber(String houseNumber) + { this.houseNumber = houseNumber; } - public String getZipCode() { + public String getZipCode() + { return zipCode; } - public void setZipCode(String zipCode) { + public void setZipCode(String zipCode) + { this.zipCode = zipCode; } - public String getCity() { + public String getCity() + { return city; } - public void setCity(String city) { + public void setCity(String city) + { this.city = city; } - public String getState() { + public String getState() + { return state; } - public void setState(String state) { + public void setState(String state) + { this.state = state; } - public long getIc() { + public long getIc() + { return ic; } - public void setIc(long ic) { + public void setIc(long ic) + { this.ic = ic; } - public String getDic() { + public String getDic() + { return dic; } - public void setDic(String dic) { + public void setDic(String dic) + { this.dic = dic; } - public String getPhone() { + public String getPhone() + { return phone; } - public void setPhone(String phone) { + public void setPhone(String phone) + { this.phone = phone; } - public String getEmail() { + public String getEmail() + { return email; } - public void setEmail(String email) { + public void setEmail(String email) + { this.email = email; } - public String getWeb() { + public String getWeb() + { return web; } - public void setWeb(String web) { + public void setWeb(String web) + { this.web = web; } - public String getDescription() { + public String getDescription() + { return description; } - public void setDescription(String description) { + public void setDescription(String description) + { this.description = description; } + public String toString() + { + String str, street; + + List listStreet = new ArrayList(); + + if (this.street != null) + { + listStreet.add(this.street); + } + + if (this.houseNumber != null) + { + listStreet.add(this.houseNumber); + } + + street = StringUtils.join(listStreet, " "); + + List list = new ArrayList(); + + if (this.company != null) + { + list.add(this.company); + } + + if (street != null) + { + list.add(street); + } + + if (this.city != null) + { + list.add(this.city); + } + + list.add(Long.toString(this.ic)); + str = StringUtils.join(list, ", "); + + return str; + } + + public static boolean isEqualByAddressEmbForFilter(AddressEmb value, AddressEmb search) + { + if ((search == null) || search.toString().isEmpty()) + { + return true; + } + else if (value != null) + { + String valueS = value.toString(); + String searchS = search.toString(); + return StringUtils.isEqualForFilter(valueS, searchS); + } + + return false; + } } diff --git a/src/main/java/info/bukova/isspst/filters/OrderFilter.java b/src/main/java/info/bukova/isspst/filters/OrderFilter.java new file mode 100644 index 00000000..77bbdb72 --- /dev/null +++ b/src/main/java/info/bukova/isspst/filters/OrderFilter.java @@ -0,0 +1,87 @@ +package info.bukova.isspst.filters; + +import info.bukova.isspst.BigDecimalUtils; +import info.bukova.isspst.DateTimeUtils; +import info.bukova.isspst.StringUtils; +import info.bukova.isspst.data.AddressEmb; +import info.bukova.isspst.data.Order; +import info.bukova.isspst.data.User; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class OrderFilter implements Filter +{ + private Order condition; + + public OrderFilter(Order cond) + { + this.condition = cond; + // this.condition.setSuplier(new AddressEmb()); + // this.condition.setDeliveryAddress(new AddressEmb()); + // this.condition.setAddress(new AddressEmb()); + // this.condition.setOwnedBy(new User()); + } + + private static class OrderMatcher extends TypeSafeMatcher + { + private Order condition; + + public OrderMatcher(Order cond) + { + this.condition = cond; + } + + @Override + public void describeTo(Description desc) + { + desc.appendText("Order matches"); + } + + @Override + public boolean matchesSafely(Order item) + { + boolean foundNumSer = StringUtils.isEqualForFilter(item.getNumser(), condition.getNumser()); + boolean foundOrderDate = DateTimeUtils.isEqualByDateForFilter(item.getOrderDate(), condition.getOrderDate()); + boolean foundTotal = BigDecimalUtils.isEqualByDecimalForFilter(item.getTotal(), condition.getTotal()); + boolean foundDeliveryDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveryDate(), condition.getDeliveryDate()); + boolean foundDeliveredDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveredDate(), condition.getDeliveredDate()); + boolean foundInvoiceNumber = StringUtils.isEqualForFilter(item.getInvoiceNumber(), condition.getInvoiceNumber()); + boolean foundSupplierAddr = AddressEmb.isEqualByAddressEmbForFilter(item.getSuplier(), condition.getSuplier()); + boolean foundDeliveryAddr = AddressEmb.isEqualByAddressEmbForFilter(item.getDeliveryAddress(), condition.getDeliveryAddress()); + 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 + && foundOrderDate + && foundTotal + && foundDeliveryDate + && foundDeliveredDate + && foundInvoiceNumber + && foundSupplierAddr + && foundDeliveryAddr + && foundInvoiceAddr + && foundOwnedBy && foundDescription); + } + + @Factory + public static Matcher matchBuilding(Order item) + { + return new OrderMatcher(item); + } + } + + @Override + public OrderMatcher matcher() + { + return new OrderMatcher(condition); + } + + @Override + public String queryString() + { + return ""; + } +} 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 1e7decc7..3783bc6d 100644 --- a/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/approved/OrderServiceImpl.java @@ -1,20 +1,23 @@ package info.bukova.isspst.services.approved; +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.services.AbstractOwnedService; +import info.bukova.isspst.services.LazyLoader; +import info.bukova.isspst.services.settings.GlobalSettingsService; + import java.math.BigDecimal; import java.util.Date; import java.util.List; +import org.hibernate.Hibernate; +import org.hibernate.Query; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -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.services.AbstractOwnedService; -import info.bukova.isspst.services.settings.GlobalSettingsService; - public class OrderServiceImpl extends AbstractOwnedService implements OrderService { @@ -50,4 +53,41 @@ public class OrderServiceImpl extends AbstractOwnedService implements super.add(order); } + @SuppressWarnings("unchecked") + @Override + @Transactional + @PreAuthorize("hasPermission(this, 'PERM_READ')") + public List getAll() + { + Query q = dao.getQuery("select o from Order o join fetch o.ownedBy"); + return q.list(); + } + + @LazyLoader("form") + @Transactional + public void lazyLoadOwnedBy(Order order) + { + if (order == null) + { + return; + } + + Order o = dao.getById(order.getId()); + Hibernate.initialize(o.getOwnedBy()); + order.setOwnedBy(o.getOwnedBy()); + } + + @LazyLoader({ "form", "grid" }) + @Transactional + public void lazyLoadItems(Order order) + { + if (order == null) + { + return; + } + + Order o = dao.getById(order.getId()); + Hibernate.initialize(o.getItems()); + order.setItems(o.getItems()); + } } diff --git a/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java b/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java index e6811dd2..70e2169b 100644 --- a/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java @@ -49,4 +49,32 @@ public class DocumentViewModel break; } } + + @Command + public void handleComboKey(@BindingParam("ctrl") Combobox cb, @BindingParam("keyEvent") KeyEvent keyEvent) + { + if (cb == null) + { + return; + } + + int keyCode = keyEvent.getKeyCode(); + boolean isShiftKey = keyEvent.isShiftKey(); + + switch (keyCode) + { + case 46: // del + + if (isShiftKey) + { + // Zrušit jakoukoli vybranou položku + cb.setSelectedIndex(-1); + // Zavřít listbox + cb.close(); + // Vyvolat událost změny + Events.postEvent("onChange", cb, null); + } + break; + } + } } diff --git a/src/main/java/info/bukova/isspst/ui/ListViewModel.java b/src/main/java/info/bukova/isspst/ui/ListViewModel.java index ba6fad15..1d517e79 100644 --- a/src/main/java/info/bukova/isspst/ui/ListViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/ListViewModel.java @@ -18,6 +18,7 @@ import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.GlobalCommand; +import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; @@ -48,6 +49,12 @@ public class ListViewModel extends DocumentViewModel protected String formZul; protected Filter dataFilter; + @Init + public void initListViewModel() + { + super.initDocumentViewModel(); + } + public List getDataList() { if (dataList == null) { dataList = new ArrayList(); 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 8d925dc3..499aaa09 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 @@ -37,22 +37,31 @@ public class OrderForm extends FormViewModel protected Address selectedDeliveryAddrItem; + protected String suppCompany; + + protected String deliveryCompany; + @Init(superclass = true) public void initOrderForm() { this.orderFormValidator = new OrderFormValidator(); - this.selectedDeliveryAddrItem = this.getDataBean().getDeliveryAddress().getAddress(); if (this.getDataBean().getSuplier() == null) { this.getDataBean().setSuplier(new AddressEmb()); } + this.selectedSuppAddrItem = this.getDataBean().getSuplier().getAddress(); + this.suppCompany = this.selectedSuppAddrItem.getCompany(); + if (this.getDataBean().getDeliveryAddress() == null) { this.getDataBean().setDeliveryAddress(new AddressEmb()); } + this.selectedDeliveryAddrItem = this.getDataBean().getDeliveryAddress().getAddress(); + this.deliveryCompany = this.selectedDeliveryAddrItem.getCompany(); + if (this.getDataBean().getAddress() == null) { this.getDataBean().setAddress(new AddressEmb()); @@ -114,31 +123,65 @@ public class OrderForm extends FormViewModel this.selectedDeliveryAddrItem = selectedDeliveryAddrItem; } + public String getSuppCompany() + { + return suppCompany; + } + + public void setSuppCompany(String suppCompany) + { + this.suppCompany = suppCompany; + } + + public String getDeliveryCompany() + { + return deliveryCompany; + } + + public void setDeliveryCompany(String deliveryCompany) + { + this.deliveryCompany = deliveryCompany; + } + @Command @NotifyChange("dataBean") public void doFillSuppAddress() { + AddressEmb addr; + if (this.selectedSuppAddrItem == null) { - return; + addr = this.getDataBean().getSuplier(); + addr.setId(0); + addr.setCompany(this.suppCompany); + } + else + { + // Naplnit pole podle vybrané adresy z comba + addr = new AddressEmb(this.selectedSuppAddrItem); } - // Naplnit pole podle vybrané adresy z comba - AddressEmb supplier = new AddressEmb(this.selectedSuppAddrItem); - this.getDataBean().setSuplier(supplier); + this.getDataBean().setSuplier(addr); } @Command @NotifyChange("dataBean") public void doFillDeliveryAddress() { + AddressEmb addr; + if (this.selectedDeliveryAddrItem == null) { - return; + addr = this.getDataBean().getDeliveryAddress(); + addr.setId(0); + addr.setCompany(this.deliveryCompany); + } + else + { + // Naplnit pole podle vybrané adresy z comba + addr = new AddressEmb(this.selectedDeliveryAddrItem); } - // Naplnit pole podle vybrané adresy z comba - AddressEmb delivery = new AddressEmb(this.selectedDeliveryAddrItem); - this.getDataBean().setDeliveryAddress(delivery); + this.getDataBean().setDeliveryAddress(addr); } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderList.java b/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderList.java new file mode 100644 index 00000000..1f1965a3 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/main/orders/created/OrderList.java @@ -0,0 +1,88 @@ +package info.bukova.isspst.ui.main.orders.created; + +import info.bukova.isspst.AddressUtils; +import info.bukova.isspst.data.Address; +import info.bukova.isspst.data.AddressEmb; +import info.bukova.isspst.data.Order; +import info.bukova.isspst.data.SettingsData; +import info.bukova.isspst.data.User; +import info.bukova.isspst.filters.OrderFilter; +import info.bukova.isspst.services.addressbook.AdbService; +import info.bukova.isspst.services.approved.OrderService; +import info.bukova.isspst.services.settings.GlobalSettingsService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.ui.ListViewModel; + +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +public class OrderList extends ListViewModel +{ + @SuppressWarnings("unused") + private final static Logger log = LoggerFactory.getLogger(OrderList.class.getName()); + + @WireVariable + protected OrderService orderService; + + @WireVariable + protected AdbService adbService; + + @WireVariable + protected GlobalSettingsService settingsService; + + @WireVariable + protected UserService userService; + + @Init(superclass = true) + public void initOrderList() + { + service = orderService; + dataClass = Order.class; + formZul = "orderForm.zul"; + dataFilter = new OrderFilter(getFilterTemplate()); + } + + public List getSuppAddresses() + { + List
list = adbService.getAll(); + List listEmb = AddressUtils.convertListAddressToListAddressEmb(list); + return listEmb; + } + + public List getDeliveryAddresses() + { + SettingsData data = settingsService.getSettings(); + + if (data == null) + { + return null; + } + + List
list = data.getAllShippingAddrs(); + List listEmb = AddressUtils.convertListAddressToListAddressEmb(list); + return listEmb; + } + + public AddressEmb getInvoiceAddress() + { + SettingsData data = settingsService.getSettings(); + + if (data == null) + { + return null; + } + + Address addr = data.getMainAddress(); + AddressEmb addrEmb = AddressUtils.convertAddressToAddressEmb(addr); + return addrEmb; + } + + public List getUsers() + { + return userService.getAll(); + } +} diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 4546bc7f..6f574ed0 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -279,7 +279,7 @@ ServiceRequirements=Požadavky na servis ApprovedRequirementItems=Schválené položky požadavků CurrentRequirements=Aktuální požadavky -ApprovedOrders=Schválené objednávky +CreatedOrders=Vytvořené objednávky BussinessTrips=Služební cesty Lists=Seznamy Settings=Nastavení @@ -317,6 +317,7 @@ OrderFormDeliveredDate=Dodáno dne OrderFormInvoiceNumber=Číslo faktury HandleComboKeyFilter=#del +HandleComboKey=$#del WorkgroupFormUserIsCenterMember=Uživatel je členem střediska, jehož je komise členem! WorkgroupFormMemberIsCenterMember=Některý ze členů přidávané komise je členem tohoto střediska! diff --git a/src/main/webapp/app/mainMenu.zul b/src/main/webapp/app/mainMenu.zul index c266e23f..9dd08de3 100644 --- a/src/main/webapp/app/mainMenu.zul +++ b/src/main/webapp/app/mainMenu.zul @@ -26,10 +26,10 @@ image="/img/hammer-016.png" label="${labels.ApprovedRequirementItems}" href="/main/orders/approved/" /> - + image="/img/autotruck-016.png" + label="${labels.CreatedOrders}" + href="/main/orders/created/" /> diff --git a/src/main/webapp/css/zk-modify.css b/src/main/webapp/css/zk-modify.css index 0a491830..7bf6088b 100644 --- a/src/main/webapp/css/zk-modify.css +++ b/src/main/webapp/css/zk-modify.css @@ -63,3 +63,7 @@ white-space: nowrap; } +.combo { + width: 100%; + min-width: 0; +} diff --git a/src/main/webapp/main/orders/created/grid.zul b/src/main/webapp/main/orders/created/grid.zul new file mode 100644 index 00000000..e9b547a6 --- /dev/null +++ b/src/main/webapp/main/orders/created/grid.zul @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ + + +
+
+ +
+
+
+ +
+
+ + + +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+ + + +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/src/main/webapp/main/orders/created/index.zul b/src/main/webapp/main/orders/created/index.zul new file mode 100644 index 00000000..fe73f6ad --- /dev/null +++ b/src/main/webapp/main/orders/created/index.zul @@ -0,0 +1,10 @@ + + + + + String gridZul = "grid.zul"; + + + + + \ No newline at end of file diff --git a/src/main/webapp/main/orders/created/orderForm.zul b/src/main/webapp/main/orders/created/orderForm.zul index e58714f1..e9eb0e5c 100644 --- a/src/main/webapp/main/orders/created/orderForm.zul +++ b/src/main/webapp/main/orders/created/orderForm.zul @@ -146,9 +146,12 @@ ${labels.SuppliersFormCompany} :