diff --git a/src/main/java/info/bukova/isspst/data/RequirementSubject.java b/src/main/java/info/bukova/isspst/data/RequirementSubject.java index cd4d6268..08f81012 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementSubject.java +++ b/src/main/java/info/bukova/isspst/data/RequirementSubject.java @@ -131,4 +131,20 @@ public abstract class RequirementSubject implements OwnedDataModel { this.valid = valid; } + @Override + public boolean equals(Object obj) + { + if (obj != null) + { + if (obj instanceof RequirementSubject) + { + RequirementSubject item = (RequirementSubject) obj; + + return (this.getId() == item.getId()); + } + } + + return false; + } + } 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 2ee44f3f..cabbefaf 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementService.java @@ -7,5 +7,6 @@ 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 69e37b1a..db5865aa 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementServiceImpl.java @@ -5,6 +5,7 @@ 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; @@ -73,4 +74,53 @@ public class RequirementServiceImpl extends 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 + * materiálu nebo služeb. + * + * @see + * info.bukova.isspst.services.requirement.RequirementService#loadGroups + * (info.bukova.isspst.data.Requirement) + */ + @Transactional + @LazyLoader("form") + @Override + public void loadGroups(Requirement req) + { + if (req == null) + { + return; + } + + Requirement reqDb = this.getById(req.getId()); + + // Načíst položky požadavku + List items = reqDb.getItems(); + + for (int i = 0; i < items.size(); i++) + { + RequirementItem item = items.get(i); + + try + { + // K položce získat skupinu materiálnu nebo služby + RequirementSubject subject = item.getReqSubject(); + // Pokud ID skupiny nebylo nalezeno, padá do výjimky + // Pokud ID skupiny bylo nalezeno, přinutí zavolání metody + // načíst záznam se skupinou = lazy load + subject.getCode(); + // Zapsat načtená data o skupině + item.setReqSubject(subject); + } + catch (Throwable e) + { + item.setReqSubject(null); + } + } + + // Zaktualizovat položky záznamu tak, aby byly odkazy na skupiny + // materiálů a služeb konzistentní + req.setItems(items); + } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java index b6c0fcf1..37819778 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/material/ReqMaterialForm.java @@ -1,21 +1,34 @@ package info.bukova.isspst.ui.main.orders.material; +import info.bukova.isspst.data.RequirementSubject; +import info.bukova.isspst.services.reqsubjects.MaterialService; import info.bukova.isspst.ui.main.orders.requirements.RequirementForm; +import info.bukova.isspst.ui.main.orders.services.ReqServicesForm; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; public class ReqMaterialForm extends RequirementForm { - // private final static Logger log = - // LoggerFactory.getLogger(ReqServicesForm.class.getName()); + @SuppressWarnings("unused") + private final static Logger log = LoggerFactory.getLogger(ReqServicesForm.class.getName()); + + @WireVariable + private MaterialService materialService; + @SuppressWarnings("unchecked") @Init(superclass = true) public void init() { - super.init(); + // Získat seznam všech skupin materiálu pro výběr z comba + this.setRequirementGroups((List) (List) materialService.getAll()); } @Command diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index f809d82f..8b276556 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -38,13 +38,28 @@ public class RequirementForm extends FormViewModel @WireVariable private WorkgroupService workgroupService; - + @WireVariable private RequirementTypeService reqTypeService; - + @WireVariable private RequirementService requirementService; + /** + * Seznam obsahující kód a název skupiny materálu/služby + */ + private List requirementGroups; + + public List getRequirementGroups() + { + return requirementGroups; + } + + public void setRequirementGroups(List requirementGroups) + { + this.requirementGroups = requirementGroups; + } + private RequirementItem selectedItem; private int selItemIndex; @@ -54,7 +69,7 @@ public class RequirementForm extends FormViewModel private RequirementFormValidator requirementFormValidator; private List syncItems; - + private List centres; public List getCentres() @@ -101,16 +116,16 @@ public class RequirementForm extends FormViewModel { this.requirementFormValidator = requirementFormValidator; } - + @Init(superclass = true) - public void init() + public void initRequirementForm() { this.setSelItemIndex(-1); this.setBigDecimalConverter(new BigDecimalConverter()); this.setRequirementFormValidator(new RequirementFormValidator()); this.setSyncItems(this.getDataBean().getItems()); requirementService.loadType(getDataBean()); - this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); + this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); } public List getSyncItems() @@ -123,14 +138,6 @@ public class RequirementForm extends FormViewModel this.syncItems = syncItems; } - @Command - public void addSelectedItem() - { - // Window window = (Window) - // Executions.createComponents("/main/selectItems.zul", null, null); - // window.doModal(); - } - @Command public void onFocusItem(@BindingParam("item") RequirementItem item, @BindingParam("ctrl") InputElement ctrl) { @@ -230,4 +237,47 @@ public class RequirementForm extends FormViewModel BindUtils.postNotifyChange(null, null, form, "*"); } } + + @Command + @NotifyChange({ "selectedItem", "syncItems" }) + public void onChangeGroup() + { + // Někdo změnil skupinu materiálu nebo služby + if (this.selectedItem == null) + { + log.warn("Zavolat z formuláře onFocus pro nastavení vybrané položky!"); + return; + } + + // Zjistit, zda je propojená skupina materiálu nebo služeb + RequirementSubject subject = this.selectedItem.getReqSubject(); + + if (subject != null) + { + // Skupina materiálu nebo služeb je propojená, nastavit k zadanému + // kódu i správný název skupiny materiálu nebo služby + this.selectedItem.setName(subject.getName()); + } + } + + @Command + @NotifyChange({ "selectedItem", "syncItems" }) + public void addNewItem() + { + RequirementItem item = new RequirementItem(); + + item.setReqSubject(null); + + item.setCode(""); + item.setName(""); + item.setQuantity(BigDecimal.valueOf(1)); + item.setUnitPrice(BigDecimal.valueOf(0)); + item.setTotal(BigDecimal.valueOf(0)); + item.setDescription(""); + item.setMunit(null); + + this.setSelectedItem(item); + this.getDataBean().getItems().add(item); + this.setSelItemIndex(this.getDataBean().getItems().indexOf(item)); + } } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java index bd017a4d..e9922c35 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/services/ReqServicesForm.java @@ -1,21 +1,33 @@ package info.bukova.isspst.ui.main.orders.services; +import info.bukova.isspst.data.RequirementSubject; +import info.bukova.isspst.services.reqsubjects.ServiceItemService; import info.bukova.isspst.ui.main.orders.requirements.RequirementForm; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Window; public class ReqServicesForm extends RequirementForm { - // private final static Logger log = - // LoggerFactory.getLogger(ReqServicesForm.class.getName()); + @SuppressWarnings("unused") + private final static Logger log = LoggerFactory.getLogger(ReqServicesForm.class.getName()); + + @WireVariable + private ServiceItemService serviceItemService; + @SuppressWarnings("unchecked") @Init(superclass = true) public void init() { - super.init(); + // Získat seznam všech skupin služeb pro výběr z comba + this.setRequirementGroups((List) (List) serviceItemService.getAll()); } @Command diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 53503b22..f1eac0d1 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -287,6 +287,7 @@ LoginViaGoogle=Přihlásit účtem Google DateFormat=dd. MM. yyyy AddItem=Přidat položku +SelectGroup=Vybrat skupinu... RemoveItem=Smazat Amount=Částka diff --git a/src/main/webapp/app/index.zul b/src/main/webapp/app/index.zul index 22368533..0574bdf3 100644 --- a/src/main/webapp/app/index.zul +++ b/src/main/webapp/app/index.zul @@ -1,4 +1,4 @@ - + diff --git a/src/main/webapp/app/info.zul b/src/main/webapp/app/info.zul index b1a6f57b..ac5216c7 100644 --- a/src/main/webapp/app/info.zul +++ b/src/main/webapp/app/info.zul @@ -1,4 +1,4 @@ - + - - + + - + \ No newline at end of file diff --git a/src/main/webapp/main/orders/material/selectMaterial.zul b/src/main/webapp/main/orders/material/selectMaterial.zul index 53ed73db..2059b768 100644 --- a/src/main/webapp/main/orders/material/selectMaterial.zul +++ b/src/main/webapp/main/orders/material/selectMaterial.zul @@ -5,13 +5,14 @@ closable="true" border="normal" position="center" + vflex="1" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('info.bukova.isspst.ui.main.orders.material.SelectMaterialItems')"> - + diff --git a/src/main/webapp/main/orders/requirements/reqForm.zul b/src/main/webapp/main/orders/requirements/reqForm.zul index 459555ac..3b871242 100644 --- a/src/main/webapp/main/orders/requirements/reqForm.zul +++ b/src/main/webapp/main/orders/requirements/reqForm.zul @@ -1,6 +1,7 @@ + hflex="1" + vflex="1"> +