From 9088a88b9ab4ddfa96e9cd584d6d5b5a9f6f633b Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Sat, 8 Nov 2014 15:12:03 +0100 Subject: [PATCH] =?UTF-8?q?Na=20formul=C3=A1=C5=99=20objedn=C3=A1vky=20k?= =?UTF-8?q?=20adrese=20dodavatele=20bylo=20p=C5=99id=C3=A1no=20tla=C4=8D?= =?UTF-8?q?=C3=ADtko=20"Hledat=20v=20ARESu".=20Tla=C4=8D=C3=ADtko=20je=20a?= =?UTF-8?q?ktivn=C3=AD,=20pokud=20nen=C3=AD=20vybran=C3=A1=20adresa=20z=20?= =?UTF-8?q?comba.=20closes=20#171?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../info/bukova/isspst/ui/BindingForm.java | 10 ++- .../ui/main/orders/created/OrderForm.java | 85 +++++++++++++++++-- .../WEB-INF/locales/zk-label.properties | 1 + .../webapp/main/orders/created/orderForm.zul | 39 ++++++--- 4 files changed, 114 insertions(+), 21 deletions(-) diff --git a/src/main/java/info/bukova/isspst/ui/BindingForm.java b/src/main/java/info/bukova/isspst/ui/BindingForm.java index 2c84623b..118729da 100644 --- a/src/main/java/info/bukova/isspst/ui/BindingForm.java +++ b/src/main/java/info/bukova/isspst/ui/BindingForm.java @@ -44,7 +44,15 @@ public class BindingForm extends SimpleForm { // } try { - PropertyUtils.setProperty(object, key, getField(key)); + if (PropertyUtils.getPropertyType(object, key).isPrimitive() + && (getField(key) == null)) + { + PropertyUtils.setProperty(object, key, 0); + } + else + { + PropertyUtils.setProperty(object, key, getField(key)); + } } catch (NoSuchMethodException e) { 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 b374199a..a2773232 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 @@ -4,14 +4,18 @@ import info.bukova.isspst.data.Address; import info.bukova.isspst.data.AddressEmb; import info.bukova.isspst.data.Order; import info.bukova.isspst.data.OrderItem; +import info.bukova.isspst.services.IsspstException; import info.bukova.isspst.services.addressbook.AdbService; +import info.bukova.isspst.services.addressbook.AddressFinder; import info.bukova.isspst.services.orders.OrderService; import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.ui.FormViewModel; import info.bukova.isspst.validators.OrderFormValidator; import java.math.BigDecimal; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,9 +23,13 @@ import org.zkoss.bind.BindUtils; import org.zkoss.bind.SimpleForm; 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.select.annotation.WireVariable; +import org.zkoss.zul.Messagebox; +import org.zkoss.zul.Window; import org.zkoss.zul.impl.InputElement; public class OrderForm extends FormViewModel @@ -29,8 +37,12 @@ public class OrderForm extends FormViewModel private final static Logger log = LoggerFactory.getLogger(OrderForm.class.getName()); @WireVariable - protected AdbService adbService; - + private AdbService adbService; + @WireVariable + private AddressFinder addressFinderAres; + @WireVariable + private AddressFinder addressFinderTaxID; + @WireVariable protected GlobalSettingsService settingsService; @@ -61,14 +73,19 @@ public class OrderForm extends FormViewModel { this.orderFormValidator = new OrderFormValidator(); - if (this.getDataBean().getSuplier() == null) + if (getDataBean().getSuplier() != null) + { + if (getDataBean().getSuplier().getAddress().getId() != 0) + { + this.selectedSuppAddrItem = this.getDataBean().getSuplier().getAddress(); + } + this.suppCompany = getDataBean().getSuplier().getCompany(); + } + else { 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()); @@ -289,4 +306,60 @@ public class OrderForm extends FormViewModel // jiných objednávek orderService.updateApprovedItems(this.getDataBean(), orderedChanged); } + + @Command + @NotifyChange({"dataBean", "suppCompany"}) + public void searchAddress() + { + getDataForm().bind(); + + Address adr = getDataBean().getSuplier().getAddress(); + + if (adr.getIc() != 0) + { + try + { + adbService.fillFoundData(addressFinderTaxID, adr); + getDataBean().setSuplier(new AddressEmb(adr)); + suppCompany = adr.getCompany(); + } + catch (IsspstException e) + { + Messagebox.show("Chyba při hledání adresy", "Chyba", Messagebox.OK, Messagebox.ERROR); + return; + } + + } + else + { + Map> arg = new HashMap>(); + try { + arg.put("result", adbService.lookForAddr(addressFinderAres, adr)); + } catch (IsspstException e) { + Messagebox.show("Chyba při hledání adresy", "Chyba", Messagebox.OK, Messagebox.ERROR); + return; + } + + Window resWin = (Window) Executions.createComponents("/lists/addressbook/addrFindResult.zul", null, arg); + resWin.doModal(); + } + } + + @GlobalCommand + @NotifyChange({"dataBean", "suppCompany"}) + public void selectAddress(@BindingParam("selected") Address selected, @BindingParam("window") Window window) { + try { + adbService.fillFoundData(addressFinderTaxID, selected); + } catch (IsspstException e) { + e.printStackTrace(); + } + + Address adr = getDataBean().getSuplier().getAddress(); + adbService.mergeAddress(adr, selected, true); + getDataBean().setSuplier(new AddressEmb(adr)); + suppCompany = adr.getCompany(); + + if (window != null) + window.detach(); + } } diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 1c4075f7..2cc2ee12 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -172,6 +172,7 @@ GlobalSettingsHours=Hodin GlobalSettingsUploadStamp=Nahrát obrázek razítka GlobalSettingsStamp=Razítko GlobalSettingsReqEnable=Povolení požadavků +GlobalSettingsInsertUrl=Vložit URL záznamu UserSettings=Uživatelské nastavení diff --git a/src/main/webapp/main/orders/created/orderForm.zul b/src/main/webapp/main/orders/created/orderForm.zul index f11d9b9d..9c97d689 100644 --- a/src/main/webapp/main/orders/created/orderForm.zul +++ b/src/main/webapp/main/orders/created/orderForm.zul @@ -146,19 +146,29 @@ ${labels.SuppliersFormCompany} : - - - + + + + + +