diff --git a/src/main/java/info/bukova/isspst/AppInitListener.java b/src/main/java/info/bukova/isspst/AppInitListener.java index e9227b1b..d18c9188 100644 --- a/src/main/java/info/bukova/isspst/AppInitListener.java +++ b/src/main/java/info/bukova/isspst/AppInitListener.java @@ -80,92 +80,74 @@ public class AppInitListener implements ServletContextListener { { MUnit mUnit = new MUnit(); - mUnit.setCode("ks"); mUnit.setName("ks"); mUnit.setDescription("kus (množství)"); mUnitsService.add(mUnit); - mUnit.setCode("SI-m"); mUnit.setName("m"); mUnit.setDescription("metr (délka)"); mUnitsService.add(mUnit); - mUnit.setCode("VEDL-km"); mUnit.setName("km"); mUnit.setDescription("kilometr (délka)"); mUnitsService.add(mUnit); - mUnit.setCode("SI-kg"); mUnit.setName("kg"); mUnit.setDescription("kilogram (hmotnost)"); mUnitsService.add(mUnit); - mUnit.setCode("VEDL-g"); mUnit.setName("g"); mUnit.setDescription("gram (hmotnost)"); mUnitsService.add(mUnit); - mUnit.setCode("VEDL-dkg"); mUnit.setName("dkg"); mUnit.setDescription("dekagram (hmotnost)"); mUnitsService.add(mUnit); - mUnit.setCode("VEDL-t"); mUnit.setName("t"); mUnit.setDescription("tuna (hmotnost)"); mUnitsService.add(mUnit); - mUnit.setCode("SI-s"); mUnit.setName("s"); mUnit.setDescription("sekunda (čas)"); mUnitsService.add(mUnit); - mUnit.setCode("VEDL-min"); mUnit.setName("min"); mUnit.setDescription("minuta (čas)"); mUnitsService.add(mUnit); - mUnit.setCode("VEDL-hod"); mUnit.setName("hod"); mUnit.setDescription("hodina (čas)"); mUnitsService.add(mUnit); - mUnit.setCode("ODV-m2"); - mUnit.setName("m[up]2[/up]"); + mUnit.setName("m²"); mUnit.setDescription("metr čtverečný (plocha)"); mUnitsService.add(mUnit); - mUnit.setCode("ODV-ha"); mUnit.setName("ha"); mUnit.setDescription("hektar = 10.000 m² (plocha)"); mUnitsService.add(mUnit); - mUnit.setCode("ODV-m3"); mUnit.setName("m³"); mUnit.setDescription("metr krychlový (objem)"); mUnitsService.add(mUnit); - mUnit.setCode("ODV-l"); mUnit.setName("l"); mUnit.setDescription("litr = 10E-3 m³ (objem)"); mUnitsService.add(mUnit); - mUnit.setCode("SI-A"); mUnit.setName("A"); mUnit.setDescription("ampér (elektrický proud)"); mUnitsService.add(mUnit); - mUnit.setCode("SI-K"); mUnit.setName("K"); mUnit.setDescription("kelvin (termodynamická teplota)"); mUnitsService.add(mUnit); - mUnit.setCode("SI-cd"); mUnit.setName("cd"); mUnit.setDescription("kandela (svítivost)"); mUnitsService.add(mUnit); - mUnit.setCode("SI-mol"); mUnit.setName("mol"); mUnit.setDescription("mol (látkové množství)"); mUnitsService.add(mUnit); diff --git a/src/main/java/info/bukova/isspst/StringUtils.java b/src/main/java/info/bukova/isspst/StringUtils.java index f3728dfd..5292bb87 100644 --- a/src/main/java/info/bukova/isspst/StringUtils.java +++ b/src/main/java/info/bukova/isspst/StringUtils.java @@ -50,4 +50,26 @@ public class StringUtils { search = StringUtils.nullStr(search).toLowerCase(); return value.contains(search); } + + public static String encodeSpecialChars(String value) + { + if (value != null) + { + value = value.replace("²", "[up]2[/up]"); + value = value.replace("³", "[up]3[/up]"); + } + + return value; + } + + public static String decodeSpecialChars(String value) + { + if (value != null) + { + value = value.replace("[up]2[/up]", "²"); + value = value.replace("[up]3[/up]", "³"); + } + + return value; + } } diff --git a/src/main/java/info/bukova/isspst/data/MUnit.java b/src/main/java/info/bukova/isspst/data/MUnit.java index 55438e21..a7fcdc12 100644 --- a/src/main/java/info/bukova/isspst/data/MUnit.java +++ b/src/main/java/info/bukova/isspst/data/MUnit.java @@ -1,90 +1,38 @@ package info.bukova.isspst.data; +import info.bukova.isspst.StringUtils; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import org.hibernate.validator.constraints.NotBlank; - @Entity @Table(name = "MUNIT") -public class MUnit extends BaseData implements DataModel { - - @Column(name = "CODE", unique = true) - private String code; - +public class MUnit extends BaseData +{ @Column(name = "NAME") private String name; @Column(name = "DESCRIPTION") private String description; - /** - * @return the code - */ - @NotBlank(message = "{MUnitsFormCodeConstr}") - public String getCode() { - return code; - } - - /** - * @param code - * the code to set - */ - public void setCode(String code) { - this.code = code; - } - - /** - * @return the name - */ - public String getName() { - return this.name; - } - - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } - - public String getNameSpecial() + public String getName() { - String special = this.getName(); - - if (special != null) - { - special = special.replace("[up]2[/up]", "²"); - } - - return special; + return StringUtils.decodeSpecialChars(this.name); } - - public void setNameSpecial(String special) - { - if (special != null) - { - special = special.replace("²", "[up]2[/up]"); - - } - this.setName(special); + public void setName(String name) + { + this.name = StringUtils.encodeSpecialChars(name); } - /** - * @return the description - */ - public String getDescription() { - return description; + public String getDescription() + { + return StringUtils.decodeSpecialChars(this.description); } - /** - * @param description - * the description to set - */ - public void setDescription(String description) { - this.description = description; + public void setDescription(String description) + { + this.description = StringUtils.encodeSpecialChars(description); } } diff --git a/src/main/java/info/bukova/isspst/data/MUnitEmb.java b/src/main/java/info/bukova/isspst/data/MUnitEmb.java index 19ee5cfc..1217f952 100644 --- a/src/main/java/info/bukova/isspst/data/MUnitEmb.java +++ b/src/main/java/info/bukova/isspst/data/MUnitEmb.java @@ -1,81 +1,86 @@ package info.bukova.isspst.data; +import info.bukova.isspst.StringUtils; + import javax.persistence.Column; import javax.persistence.Embeddable; @Embeddable -public class MUnitEmb { +public class MUnitEmb +{ @Column(name = "MUNIT_ID") private Integer id; - @Column(name = "MUNIT_CODE") - private String code; - @Column(name = "MUNIT_DESCRIPTION") - private String description; + @Column(name = "MUNIT_NAME") private String name; - - public MUnitEmb() { + @Column(name = "MUNIT_DESCRIPTION") + private String description; + + public MUnitEmb() + { } - - public MUnitEmb(MUnit munit) { - this.id = munit.getId(); - this.code = munit.getCode(); - this.description = munit.getDescription(); - this.name = munit.getName(); + + public MUnitEmb(MUnit munit) + { + this.setId(munit.getId()); + this.setDescription(munit.getDescription()); + this.setName(munit.getName()); } - public Integer getId() { - return id; + public Integer getId() + { + return this.id; } - public void setId(Integer id) { + public void setId(Integer id) + { this.id = id; } - public String getCode() { - return code; + public String getName() + { + return StringUtils.decodeSpecialChars(this.name); } - public void setCode(String code) { - this.code = code; + public void setName(String name) + { + this.name = StringUtils.encodeSpecialChars(name); } - public String getDescription() { - return description; + public String getDescription() + { + return StringUtils.decodeSpecialChars(this.description); } - public void setDescription(String description) { - this.description = description; + public void setDescription(String description) + { + this.description = StringUtils.encodeSpecialChars(description); } - public String getName() { - return name; - } + public boolean eqWith(MUnit munit) + { + if (munit == null) + { + return false; + } - public void setName(String name) { - this.name = name; + return this.getId() == munit.getId() && this.getName().equals(munit.getName()) && this.getDescription().equals(munit.getDescription()); } - - public boolean eqWith(MUnit munit) { - return this.id == munit.getId() - && this.code.equals(munit.getCode()) - && this.name.equals(munit.getName()) - && this.description.equals(munit.getDescription()); - } - + @Override - public boolean equals(Object munit) { + public boolean equals(Object munit) + { return munit != null && (munit instanceof MUnitEmb) - && this.id == ((MUnitEmb)munit).getId() - && (this.code == ((MUnitEmb)munit).getCode() || this.code.equals(((MUnitEmb)munit).getCode())) - && (this.name == ((MUnitEmb)munit).getName() || this.name.equals(((MUnitEmb)munit).getName())) - && (this.description == ((MUnitEmb)munit).getDescription() || this.description.equals(((MUnitEmb)munit).getDescription())); + && this.getId() == ((MUnitEmb) munit).getId() + && (this.getName() == ((MUnitEmb) munit).getName() || this.getName().equals(((MUnitEmb) munit).getName())) + && (this.getDescription() == ((MUnitEmb) munit).getDescription() || this.getDescription().equals(((MUnitEmb) munit).getDescription())); } - + @Override - public String toString() { - return this.code + " - " + this.name; + public String toString() + { + return this.getName(); } } diff --git a/src/main/java/info/bukova/isspst/data/Requirement.java b/src/main/java/info/bukova/isspst/data/Requirement.java index eb97623a..0363ae35 100644 --- a/src/main/java/info/bukova/isspst/data/Requirement.java +++ b/src/main/java/info/bukova/isspst/data/Requirement.java @@ -1,5 +1,7 @@ package info.bukova.isspst.data; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -8,38 +10,28 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; -import org.hibernate.annotations.LazyCollection; -import org.hibernate.annotations.LazyCollectionOption; - @Entity @Table(name = "REQUIREMENT") -public class Requirement extends BaseData implements DataModel +public class Requirement extends RequirementBase { - @Column(name = "NUMSER", unique = true) - private String numser; - - @Column(name = "REQDATE") - private Date reqDate; + @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @JoinColumn(name = "REQUIREMENT_ID") + private List items; @Column(name = "DELIVERYDATE") private Date deliveryDate; - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "WORKGROUP_ID") - private Workgroup workgroup; + @Column(name = "SUMTOTAL") + private BigDecimal sumTotal; - @Column(name = "DESCRIPTION") - private String description; + public Requirement() + { + this.setItems(new ArrayList()); + } - @OneToMany(cascade=CascadeType.ALL) - @JoinColumn(name = "REQUIREMENT_ID") - @LazyCollection(LazyCollectionOption.FALSE) - private List items; - public List getItems() { return items; @@ -50,26 +42,6 @@ public class Requirement extends BaseData implements DataModel this.items = items; } - public String getNumser() - { - return numser; - } - - public void setNumser(String numser) - { - this.numser = numser; - } - - public Date getReqDate() - { - return reqDate; - } - - public void setReqDate(Date reqDate) - { - this.reqDate = reqDate; - } - public Date getDeliveryDate() { return deliveryDate; @@ -80,23 +52,13 @@ public class Requirement extends BaseData implements DataModel this.deliveryDate = deliveryDate; } - public Workgroup getWorkgroup() - { - return workgroup; - } - - public void setWorkgroup(Workgroup workgroup) - { - this.workgroup = workgroup; - } - - public String getDescription() + public BigDecimal getSumTotal() { - return description; + return sumTotal; } - public void setDescription(String description) + public void setSumTotal(BigDecimal sumTotal) { - this.description = description; + this.sumTotal = sumTotal; } } diff --git a/src/main/java/info/bukova/isspst/data/RequirementBase.java b/src/main/java/info/bukova/isspst/data/RequirementBase.java index bdd572c5..399267aa 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementBase.java +++ b/src/main/java/info/bukova/isspst/data/RequirementBase.java @@ -72,6 +72,16 @@ public class RequirementBase extends BaseData { this.reqDate = reqDate; } + public String getDescription() + { + return description; + } + + public void setDescription(String description) + { + this.description = description; + } + public Workgroup getWorkgroup() { return workgroup; } @@ -96,14 +106,6 @@ public class RequirementBase extends BaseData { this.state = state; } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - public Workgroup getCentre() { return centre; } diff --git a/src/main/java/info/bukova/isspst/data/RequirementItem.java b/src/main/java/info/bukova/isspst/data/RequirementItem.java index 642a3283..6525de4e 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementItem.java +++ b/src/main/java/info/bukova/isspst/data/RequirementItem.java @@ -35,7 +35,7 @@ public class RequirementItem private BigDecimal quantity; @Embedded - private MUnitEmb mUnit; + private MUnitEmb munit; @Column(name = "UNITPRICE", precision=15, scale=4) private BigDecimal unitPrice; @@ -96,12 +96,12 @@ public class RequirementItem this.quantity = quantity; } - public MUnitEmb getMUnit() { - return mUnit; + public MUnitEmb getMunit() { + return munit; } - public void setMUnit(MUnitEmb mUnit) { - this.mUnit = mUnit; + public void setMunit(MUnitEmb munit) { + this.munit = munit; } public BigDecimal getUnitPrice() @@ -133,4 +133,20 @@ public class RequirementItem { this.description = description; } + + @Override + public boolean equals(Object obj) + { + if (obj != null) + { + if (obj instanceof RequirementItem) + { + RequirementItem item = (RequirementItem)obj; + + return (this.getId() == item.getId()); + } + } + + return false; + } } diff --git a/src/main/java/info/bukova/isspst/filters/MUnitFilter.java b/src/main/java/info/bukova/isspst/filters/MUnitFilter.java index 4b467a2a..b3478171 100644 --- a/src/main/java/info/bukova/isspst/filters/MUnitFilter.java +++ b/src/main/java/info/bukova/isspst/filters/MUnitFilter.java @@ -1,6 +1,6 @@ package info.bukova.isspst.filters; -import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.MUnit; import org.hamcrest.Description; @@ -30,10 +30,11 @@ public class MUnitFilter implements Filter { } @Override - public boolean matchesSafely(MUnit item) { - return nullStr(item.getCode()).toLowerCase().contains(nullStr(condMUnit.getCode()).toLowerCase()) - && nullStr(item.getName()).toLowerCase().contains(nullStr(condMUnit.getName()).toLowerCase()) - && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condMUnit.getDescription()).toLowerCase()); + public boolean matchesSafely(MUnit item) + { + boolean nameIsEqual = StringUtils.isEqualForFilter(item.getName(), condMUnit.getName()); + boolean descriptionIsEqual = StringUtils.isEqualForFilter(item.getDescription(), condMUnit.getDescription()); + return (nameIsEqual && descriptionIsEqual); } @Factory diff --git a/src/main/java/info/bukova/isspst/filters/MaterialFilter.java b/src/main/java/info/bukova/isspst/filters/MaterialFilter.java index d3b39d4e..3f105ab8 100644 --- a/src/main/java/info/bukova/isspst/filters/MaterialFilter.java +++ b/src/main/java/info/bukova/isspst/filters/MaterialFilter.java @@ -1,6 +1,6 @@ package info.bukova.isspst.filters; -import static info.bukova.isspst.StringUtils.nullStr; +import info.bukova.isspst.StringUtils; import info.bukova.isspst.data.Material; import org.hamcrest.Description; @@ -30,10 +30,14 @@ public class MaterialFilter implements Filter { } @Override - public boolean matchesSafely(Material item) { - return nullStr(item.getCode()).toLowerCase().contains(nullStr(condMaterial.getCode()).toLowerCase()) - && nullStr(item.getName()).toLowerCase().contains(nullStr(condMaterial.getName()).toLowerCase()) - && nullStr(item.getDescription()).toLowerCase().contains(nullStr(condMaterial.getDescription()).toLowerCase()); + public boolean matchesSafely(Material item) + { + boolean isEqualCode = StringUtils.isEqualForFilter(item.getCode(), this.condMaterial.getCode()); + boolean isEqualName = StringUtils.isEqualForFilter(item.getName(), this.condMaterial.getName()); + boolean isEqualMUnitName = (this.condMaterial.getMunit() == null) || (item.getMunit().getId() == this.condMaterial.getMunit().getId()); + boolean isEqualDescription = StringUtils.isEqualForFilter(item.getDescription(), this.condMaterial.getDescription()); + + return isEqualCode && isEqualName && isEqualDescription && isEqualMUnitName; } @Factory diff --git a/src/main/java/info/bukova/isspst/services/munits/MUnitService.java b/src/main/java/info/bukova/isspst/services/munits/MUnitService.java index 7b8d2947..6e2f9edb 100644 --- a/src/main/java/info/bukova/isspst/services/munits/MUnitService.java +++ b/src/main/java/info/bukova/isspst/services/munits/MUnitService.java @@ -1,8 +1,12 @@ package info.bukova.isspst.services.munits; import info.bukova.isspst.data.MUnit; +import info.bukova.isspst.data.MUnitEmb; import info.bukova.isspst.services.Service; -public interface MUnitService extends Service { +import java.util.List; +public interface MUnitService extends Service +{ + public List getEmbAll(); } diff --git a/src/main/java/info/bukova/isspst/services/munits/MUnitServiceImpl.java b/src/main/java/info/bukova/isspst/services/munits/MUnitServiceImpl.java index e929663d..1186027e 100644 --- a/src/main/java/info/bukova/isspst/services/munits/MUnitServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/munits/MUnitServiceImpl.java @@ -1,8 +1,29 @@ package info.bukova.isspst.services.munits; import info.bukova.isspst.data.MUnit; +import info.bukova.isspst.data.MUnitEmb; import info.bukova.isspst.services.AbstractService; -public class MUnitServiceImpl extends AbstractService implements MUnitService{ +import java.util.ArrayList; +import java.util.List; +import org.springframework.transaction.annotation.Transactional; + +public class MUnitServiceImpl extends AbstractService implements MUnitService +{ + @Override + @Transactional + public List getEmbAll() + { + List munitList = this.getAll(); + List munitEmbList = new ArrayList(); + + for (MUnit m : munitList) + { + MUnitEmb muEmb = new MUnitEmb(m); + munitEmbList.add(muEmb); + } + + return munitEmbList; + } } diff --git a/src/main/java/info/bukova/isspst/ui/BigDecimalConverter.java b/src/main/java/info/bukova/isspst/ui/BigDecimalConverter.java new file mode 100644 index 00000000..87257978 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/BigDecimalConverter.java @@ -0,0 +1,62 @@ +package info.bukova.isspst.ui; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.ParseException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.zkoss.bind.BindContext; +import org.zkoss.bind.Converter; +import org.zkoss.zk.ui.Component; + +public class BigDecimalConverter implements Converter +{ + private final static Logger log = LoggerFactory.getLogger(BigDecimalConverter.class.getName()); + + @Override + public BigDecimal coerceToBean(String str, Component component, BindContext cx) + { + BigDecimal val = BigDecimal.ZERO; + + if (str != null) + { + try + { + DecimalFormat format = new DecimalFormat(); + format.setParseBigDecimal(true); + val = (BigDecimal) format.parse(str); + } + catch (NumberFormatException e) + { + log.warn(str, e); + } + catch (ParseException e) + { + log.warn(str, e); + } + } + + return val; + } + + @Override + public String coerceToUi(BigDecimal val, Component component, BindContext cx) + { + if (val == null) + { + val = BigDecimal.ZERO; + } + + val = val.setScale(2, BigDecimal.ROUND_DOWN); + + DecimalFormat format = new DecimalFormat(); + format.setMaximumFractionDigits(2); + format.setMinimumFractionDigits(2); + format.setGroupingUsed(true); + format.setGroupingSize(3); + + return format.format(val); + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/FormViewModel.java b/src/main/java/info/bukova/isspst/ui/FormViewModel.java index 98460e30..f7adbd5f 100644 --- a/src/main/java/info/bukova/isspst/ui/FormViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/FormViewModel.java @@ -47,6 +47,16 @@ public class FormViewModel { return dataBean; } + public boolean isNewRec() + { + return this.newRec; + } + + public boolean isEditRec() + { + return !this.newRec; + } + @Command @NotifyChange("errMessages") public void save(@BindingParam("window") Window win) { diff --git a/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialForm.java b/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialForm.java index 3f789bc3..519ad0f4 100644 --- a/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialForm.java +++ b/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialForm.java @@ -1,17 +1,15 @@ package info.bukova.isspst.ui.reqsubjects; -import java.util.ArrayList; -import java.util.List; - -import org.zkoss.bind.annotation.Init; -import org.zkoss.zk.ui.select.annotation.WireVariable; - -import info.bukova.isspst.data.MUnit; import info.bukova.isspst.data.MUnitEmb; import info.bukova.isspst.data.Material; import info.bukova.isspst.services.munits.MUnitService; import info.bukova.isspst.ui.FormViewModel; +import java.util.List; + +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; + public class MaterialForm extends FormViewModel { @WireVariable @@ -19,13 +17,9 @@ public class MaterialForm extends FormViewModel { private List munits; @Init(superclass = true) - public void init() { - List mu = munitService.getAll(); - munits = new ArrayList(); - for (MUnit m : mu) { - MUnitEmb muEmb = new MUnitEmb(m); - munits.add(muEmb); - } + public void init() + { + this.munits = munitService.getEmbAll(); } public List getMunits() { diff --git a/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialList.java b/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialList.java index ab730b9a..0596021b 100644 --- a/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialList.java +++ b/src/main/java/info/bukova/isspst/ui/reqsubjects/MaterialList.java @@ -1,24 +1,45 @@ package info.bukova.isspst.ui.reqsubjects; -import org.zkoss.bind.annotation.Init; -import org.zkoss.zk.ui.select.annotation.WireVariable; - +import info.bukova.isspst.data.MUnitEmb; import info.bukova.isspst.data.Material; import info.bukova.isspst.filters.MaterialFilter; +import info.bukova.isspst.services.munits.MUnitService; import info.bukova.isspst.services.reqsubjects.MaterialService; 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 MaterialList extends ListViewModel { @WireVariable private MaterialService materialService; + @WireVariable + private MUnitService munitService; + + private List munitList; + @Init public void init() { service = materialService; dataClass = Material.class; formZul = "materialForm.zul"; dataFilter = new MaterialFilter(getFilterTemplate()); + + this.setMunitList(munitService.getEmbAll()); + } + + public List getMunitList() + { + return munitList; + } + + public void setMunitList(List munitList) + { + this.munitList = munitList; } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/requirement/RequirementForm.java index 2bb5ce11..ff097c07 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/RequirementForm.java @@ -1,57 +1,70 @@ package info.bukova.isspst.ui.requirement; +import info.bukova.isspst.data.Material; import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.RequirementItem; +import info.bukova.isspst.data.RequirementSubject; import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.requirement.RequirementService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.BigDecimalConverter; import info.bukova.isspst.ui.FormViewModel; +import info.bukova.isspst.validators.RequirementFormValidator; +import java.math.BigDecimal; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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.Window; +import org.zkoss.zul.impl.InputElement; public class RequirementForm extends FormViewModel { + private final static Logger log = LoggerFactory.getLogger(RequirementForm.class.getName()); + @WireVariable private UserService userService; @WireVariable private WorkgroupService workgroupService; - public List getCentres() - { - return workgroupService.getUserCentres(userService.getCurrent()); - } - @WireVariable private RequirementService requirementService; - private RequirementItem item; + private RequirementItem selectedItem; private int selItemIndex; + + private BigDecimalConverter bigDecimalConverter; + + private RequirementFormValidator requirementFormValidator; - @Init(superclass = true) - public void init() + private List syncItems; + + public List getCentres() { - this.setSelItemIndex(-1); + return workgroupService.getUserCentres(userService.getCurrent()); } - public RequirementItem getItem() + public RequirementItem getSelectedItem() { - return item; + return selectedItem; } - public void setItem(RequirementItem item) + public void setSelectedItem(RequirementItem selectedItem) { - this.item = item; + this.selectedItem = selectedItem; } public int getSelItemIndex() @@ -64,20 +77,149 @@ public class RequirementForm extends FormViewModel this.selItemIndex = selItemIndex; } + public BigDecimalConverter getBigDecimalConverter() + { + return bigDecimalConverter; + } + + public void setBigDecimalConverter(BigDecimalConverter bigDecimalConverter) + { + this.bigDecimalConverter = bigDecimalConverter; + } + + public RequirementFormValidator getRequirementFormValidator() + { + return requirementFormValidator; + } + + public void setRequirementFormValidator(RequirementFormValidator requirementFormValidator) + { + this.requirementFormValidator = requirementFormValidator; + } + + @Init(superclass = true) + public void init() + { + this.setSelItemIndex(-1); + this.setBigDecimalConverter(new BigDecimalConverter()); + this.setRequirementFormValidator(new RequirementFormValidator()); + this.setSyncItems(this.getDataBean().getItems()); + } + + public List getSyncItems() + { + return syncItems; + } + + public void setSyncItems(List syncItems) + { + this.syncItems = syncItems; + } + @Command - @NotifyChange({ "dataBean", "selItemIndex" }) - public void addItem() + public void addSelectedItem() { Window window = (Window) Executions.createComponents("/requirements/selectitems/selectItems.zul", null, null); window.doModal(); } + @Command + public void onFocusItem(@BindingParam("item") RequirementItem item, @BindingParam("ctrl") InputElement ctrl) + { + this.selItemIndex = this.getDataBean().getItems().indexOf(item); + this.selectedItem = item; + + if (ctrl != null) + { + ctrl.select(); + } + } + @Command @NotifyChange({ "dataBean", "selItemIndex" }) public void removeItem(@BindingParam("item") RequirementItem item) { -// requirementService.removeItem(getDataBean(), item); - selItemIndex = -1; + this.getDataBean().getItems().remove(item); + this.setSelItemIndex(-1); + } + + @GlobalCommand("insertSelectedItem") + @NotifyChange({ "syncItems", "selItemIndex" }) + public void insertSelectedItem(@BindingParam("selected") RequirementSubject selected, @BindingParam("window") Window window) + { + if (selected != null) + { + RequirementItem item = new RequirementItem(); + boolean isMaterial = (selected instanceof Material); + //boolean isServiceItem = (selected instanceof ServiceItem); + + item.setReqSubject(selected); + + item.setCode(selected.getCode()); + item.setName(selected.getName()); + item.setQuantity(BigDecimal.valueOf(1)); + item.setUnitPrice(BigDecimal.valueOf(0)); + item.setTotal(BigDecimal.valueOf(0)); + item.setDescription(selected.getDescription()); + + if (isMaterial) + { + Material materialItem = (Material) selected; + item.setMunit(materialItem.getMunit()); + } + + this.setSelectedItem(item); + this.getDataBean().getItems().add(item); + this.setSelItemIndex(this.getDataBean().getItems().indexOf(item)); + } + + if (window != null) + { + window.detach(); + } } + @Command + @NotifyChange({ "selectedItem", "syncItems" }) + public void recalculate(@BindingParam("form") SimpleForm form, @BindingParam("changed") String source) + { + if (this.selectedItem == null) + { + log.warn("Zavolat z formuláře onFocus pro nastavení vybrané položky!"); + return; + } + + // Recalculate selecte item + if ((source != null) && (source.equals("total"))) + { + BigDecimal quantity = this.selectedItem.getQuantity(); + + if (quantity.equals(BigDecimal.ZERO)) + { + this.selectedItem.setUnitPrice(BigDecimal.ZERO); + } + else + { + this.selectedItem.setUnitPrice(this.selectedItem.getTotal().divide(quantity, 2, BigDecimal.ROUND_HALF_UP)); + } + } + else + { + this.selectedItem.setTotal(this.selectedItem.getQuantity().multiply(this.selectedItem.getUnitPrice())); + } + + // Calculate total price at form + if (form != null) + { + BigDecimal sumTotal = new BigDecimal(0); + + for (RequirementItem item : this.getDataBean().getItems()) + { + sumTotal = sumTotal.add(item.getTotal()); + } + + form.setField("sumTotal", sumTotal); + BindUtils.postNotifyChange(null, null, form, "*"); + } + } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/RequirementList.java b/src/main/java/info/bukova/isspst/ui/requirement/RequirementList.java index 064d430c..18480c5e 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/RequirementList.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/RequirementList.java @@ -1,10 +1,16 @@ package info.bukova.isspst.ui.requirement; import info.bukova.isspst.data.Requirement; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.filters.RequirementFilter; import info.bukova.isspst.services.requirement.RequirementService; +import info.bukova.isspst.services.users.UserService; +import info.bukova.isspst.services.workgroups.WorkgroupService; +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; @@ -13,12 +19,38 @@ public class RequirementList extends ListViewModel { @WireVariable private RequirementService requirementService; + @WireVariable + private UserService userService; + + @WireVariable + private WorkgroupService workgroupService; + + private BigDecimalConverter bigDecimalConverter; + + public List getCentres() + { + return workgroupService.getUserCentres(userService.getCurrent()); + } + + public BigDecimalConverter getBigDecimalConverter() + { + return bigDecimalConverter; + } + + public void setBigDecimalConverter(BigDecimalConverter bigDecimalConverter) + { + this.bigDecimalConverter = bigDecimalConverter; + } + @Init - public void init() { + public void init() + { + service = requirementService; dataClass = Requirement.class; formZul = "requirementsForm.zul"; dataFilter = new RequirementFilter(getFilterTemplate()); - } + this.bigDecimalConverter = new BigDecimalConverter(); + } } diff --git a/src/main/java/info/bukova/isspst/ui/requirement/SelectItems.java b/src/main/java/info/bukova/isspst/ui/requirement/SelectItems.java new file mode 100644 index 00000000..9bfec51a --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/SelectItems.java @@ -0,0 +1,254 @@ +package info.bukova.isspst.ui.requirement; + +import info.bukova.isspst.data.MUnitEmb; +import info.bukova.isspst.data.Material; +import info.bukova.isspst.data.RequirementSubject; +import info.bukova.isspst.data.ServiceItem; +import info.bukova.isspst.filters.MaterialFilter; +import info.bukova.isspst.filters.ServiceItemFilter; +import info.bukova.isspst.services.munits.MUnitService; +import info.bukova.isspst.services.reqsubjects.MaterialService; +import info.bukova.isspst.services.reqsubjects.ServiceItemService; + +import java.util.List; + +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.Init; +import org.zkoss.bind.annotation.NotifyChange; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +public class SelectItems +{ + @WireVariable + private MaterialService materialService; + + private List materialList; + + private List fullMaterialList; + + + private boolean activeFilterMaterial; + + private Material filterTmpMaterial; + + private MaterialFilter dataFilterMaterial; + + + @WireVariable + private ServiceItemService serviceItemService; + + private List serviceItemList; + + private List fullServiceItemList; + + + private boolean activeFilterService; + + private ServiceItem filterTmpService; + + private ServiceItemFilter dataFilterService; + + + private RequirementSubject selectedItem; + + @WireVariable + private MUnitService munitService; + + private List munitList; + + + @Init + public void init() + { + this.setFullMaterialList(materialService.getAll()); + this.setMaterialList(this.getFullMaterialList()); + + this.setActiveFilterMaterial(false); + this.setFilterTmpMaterial(new Material()); + this.setDataFilterMaterial(new MaterialFilter(this.getFilterTmpMaterial())); + + + this.setFullServiceItemList(serviceItemService.getAll()); + this.setServiceItemList(this.getFullServiceItemList()); + + this.setActiveFilterService(false); + this.setFilterTmpService(new ServiceItem()); + this.setDataFilterService(new ServiceItemFilter(this.getFilterTmpService())); + + this.setMunitList(munitService.getEmbAll()); + } + + public List getMaterialList() + { + return materialList; + } + + public void setMaterialList(List materialList) + { + this.materialList = materialList; + } + + public List getFullMaterialList() + { + return fullMaterialList; + } + + public void setFullMaterialList(List fullMaterialList) + { + this.fullMaterialList = fullMaterialList; + } + + public boolean isActiveFilterMaterial() + { + return activeFilterMaterial; + } + + public void setActiveFilterMaterial(boolean activeFilterMaterial) + { + this.activeFilterMaterial = activeFilterMaterial; + } + + public Material getFilterTmpMaterial() + { + return this.filterTmpMaterial; + } + + private void setFilterTmpMaterial(Material material) + { + this.filterTmpMaterial = material; + } + + public MaterialFilter getDataFilterMaterial() + { + return dataFilterMaterial; + } + + public void setDataFilterMaterial(MaterialFilter dataFilterMaterial) + { + this.dataFilterMaterial = dataFilterMaterial; + } + + public List getServiceItemList() + { + return serviceItemList; + } + + public void setServiceItemList(List serviceItemList) + { + this.serviceItemList = serviceItemList; + } + + public List getFullServiceItemList() + { + return fullServiceItemList; + } + + public void setFullServiceItemList(List fullServiceItemList) + { + this.fullServiceItemList = fullServiceItemList; + } + + public boolean isActiveFilterService() + { + return activeFilterService; + } + + public void setActiveFilterService(boolean activeFilterService) + { + this.activeFilterService = activeFilterService; + } + + public ServiceItem getFilterTmpService() + { + return this.filterTmpService; + } + + private void setFilterTmpService(ServiceItem serviceItem) + { + this.filterTmpService = serviceItem; + } + + public ServiceItemFilter getDataFilterService() + { + return dataFilterService; + } + + public void setDataFilterService(ServiceItemFilter dataFilterService) + { + this.dataFilterService = dataFilterService; + } + + public RequirementSubject getSelectedItem() + { + return selectedItem; + } + + public void setSelectedItem(RequirementSubject selectedItem) + { + this.selectedItem = selectedItem; + } + + public List getMunitList() + { + return munitList; + } + + public void setMunitList(List munitList) + { + this.munitList = munitList; + } + + @Command + @NotifyChange({ "activeFilterMaterial", "materialList", "selectedItem" }) + public void onFilterMaterial() + { + this.setSelectedItem(null); + + this.setActiveFilterMaterial(!this.isActiveFilterMaterial()); + + if (this.isActiveFilterMaterial()) + { + this.doFilterMaterial(); + } + else + { + this.setMaterialList(this.getFullMaterialList()); + } + } + + @Command + @NotifyChange("materialList") + public void doFilterMaterial() + { + this.setSelectedItem(null); + List result = this.materialService.filterList(this.getFullMaterialList(), this.getDataFilterMaterial()); + this.setMaterialList(result); + } + + @Command + @NotifyChange({ "activeFilterService", "serviceItemList", "selectedItem" }) + public void onFilterService() + { + this.setSelectedItem(null); + + this.setActiveFilterService(!this.isActiveFilterService()); + + if (this.isActiveFilterService()) + { + this.doFilterService(); + } + else + { + this.setServiceItemList(this.getFullServiceItemList()); + } + } + + @Command + @NotifyChange("serviceItemList") + public void doFilterService() + { + this.setSelectedItem(null); + List result = this.serviceItemService.filterList(this.getFullServiceItemList(), this.getDataFilterService()); + this.setServiceItemList(result); + } +} diff --git a/src/main/java/info/bukova/isspst/ui/requirements/SelectItems.java b/src/main/java/info/bukova/isspst/ui/requirements/SelectItems.java deleted file mode 100644 index 5eaf669e..00000000 --- a/src/main/java/info/bukova/isspst/ui/requirements/SelectItems.java +++ /dev/null @@ -1,82 +0,0 @@ -package info.bukova.isspst.ui.requirements; - -import info.bukova.isspst.data.Material; -import info.bukova.isspst.data.ServiceItem; -import info.bukova.isspst.services.reqsubjects.MaterialService; -import info.bukova.isspst.services.reqsubjects.ServiceItemService; - -import java.util.List; - -import org.zkoss.bind.annotation.Command; -import org.zkoss.bind.annotation.Init; -import org.zkoss.zk.ui.select.annotation.WireVariable; - -public class SelectItems -{ - @WireVariable - private MaterialService materialService; - - @WireVariable - private ServiceItemService serviceItemService; - - private List materialList; - - private List serviceItemList; - - private Material selectedMaterial; - - private ServiceItem selectedServiceItem; - - @Init - public void init() - { - this.setMaterialList(materialService.getAll()); - this.setServiceItemList(serviceItemService.getAll()); - } - - public List getMaterialList() - { - return materialList; - } - - public void setMaterialList(List materialList) - { - this.materialList = materialList; - } - - public List getServiceItemList() - { - return serviceItemList; - } - - public void setServiceItemList(List serviceItemList) - { - this.serviceItemList = serviceItemList; - } - - public Material getSelectedMaterial() - { - return selectedMaterial; - } - - public void setSelectedMaterial(Material selectedMaterial) - { - this.selectedMaterial = selectedMaterial; - } - - public ServiceItem getSelectedServiceItem() - { - return selectedServiceItem; - } - - public void setSelectedServiceItem(ServiceItem selectedServiceItem) - { - this.selectedServiceItem = selectedServiceItem; - } - - @Command - public void addItem() - { - //this - } -} diff --git a/src/main/java/info/bukova/isspst/ui/users/UserForm.java b/src/main/java/info/bukova/isspst/ui/users/UserForm.java index 864ca337..df4b1dec 100644 --- a/src/main/java/info/bukova/isspst/ui/users/UserForm.java +++ b/src/main/java/info/bukova/isspst/ui/users/UserForm.java @@ -75,12 +75,7 @@ public class UserForm extends FormViewModel public boolean isLoginFree() { - return loginFree || isEdit(); - } - - public boolean isEdit() - { - return getDataBean().getCreated() != null; + return loginFree || this.isEditRec(); } @Override diff --git a/src/main/java/info/bukova/isspst/validators/RequirementFormValidator.java b/src/main/java/info/bukova/isspst/validators/RequirementFormValidator.java new file mode 100644 index 00000000..7a0d3281 --- /dev/null +++ b/src/main/java/info/bukova/isspst/validators/RequirementFormValidator.java @@ -0,0 +1,33 @@ +package info.bukova.isspst.validators; + +import info.bukova.isspst.StringUtils; +import info.bukova.isspst.data.Workgroup; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.zkoss.bind.Property; +import org.zkoss.bind.ValidationContext; + +public class RequirementFormValidator extends BaseValidator +{ + private final static Logger log = LoggerFactory.getLogger(RequirementFormValidator.class.getName()); + + @Override + protected Logger getLogger() + { + return log; + } + + @Override + public void validate(ValidationContext ctx) + { + Property propertyWorkgroup = ctx.getProperties("workgroup")[0]; + Workgroup workgroup = (Workgroup) propertyWorkgroup.getValue(); + + if (workgroup == null) + { + this.errorMsg(ctx, StringUtils.localize("RequirementCenterIsEmpty"), "idReqCenter"); + return; + } + } +} diff --git a/src/main/webapp/WEB-INF/locales/validators.properties b/src/main/webapp/WEB-INF/locales/validators.properties index 3cce07c1..2d0eee6a 100644 --- a/src/main/webapp/WEB-INF/locales/validators.properties +++ b/src/main/webapp/WEB-INF/locales/validators.properties @@ -3,3 +3,4 @@ DataTypeErr=Chybný datový typ... UserPasswordIsEmpty=Uživatelské heslo musí být zadané... UserPasswordsAreNotSame=Znovu zadané heslo není stejné... +RequirementCenterIsEmpty=Musíte zadat středisko... diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index b11f2f29..df04bff0 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -47,10 +47,8 @@ AgendaOrdersHistory=Ukončené AgendaMUnits=Měrné jednotky MUnitsFormTitle=Měrná jednotka -MUnitsFormCode=Kód MUnitsFormName=Název MUnitsFormDescription=Popis -MUnitsGridColumnCode=Kód MUnitsGridColumnName=Název MUnitsGridColumnDescription=Popis @@ -204,5 +202,7 @@ false=Ne DateFormat=dd. MM. yyyy AddItem=Přidat položku... -RemoveItem=Smazat položku... +RemoveItem=Smazat + +Amount=Částka \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/spring/mail-services.xml b/src/main/webapp/WEB-INF/spring/mail-services.xml index a189bb9b..2002aed1 100644 --- a/src/main/webapp/WEB-INF/spring/mail-services.xml +++ b/src/main/webapp/WEB-INF/spring/mail-services.xml @@ -1,46 +1,46 @@ - - - - - - - - - - - - ${mail.useauth} - ${mail.usessl} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + ${mail.useauth} + ${mail.usessl} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/css/zk-modify.css b/src/main/webapp/css/zk-modify.css index a21baef4..6d13c000 100644 --- a/src/main/webapp/css/zk-modify.css +++ b/src/main/webapp/css/zk-modify.css @@ -25,4 +25,17 @@ .find-grid-textbox { width: 100%; +} + +.grid-textbox-max { + width: 100%; +} + +.grid-textbox-max-right { + width: 100%; + text-align: right; +} + +.row-title { + vertical-align: top; } \ No newline at end of file diff --git a/src/main/webapp/lists/material/material.zul b/src/main/webapp/lists/material/material.zul index 6a135bcb..e4e8d8d0 100644 --- a/src/main/webapp/lists/material/material.zul +++ b/src/main/webapp/lists/material/material.zul @@ -9,8 +9,8 @@ - - + + @@ -34,6 +34,25 @@ + +
+
+ + + +
+
+ +
+
+
@@ -50,8 +69,8 @@ + - diff --git a/src/main/webapp/lists/material/materialForm.zul b/src/main/webapp/lists/material/materialForm.zul index 54a9321d..7101d63d 100644 --- a/src/main/webapp/lists/material/materialForm.zul +++ b/src/main/webapp/lists/material/materialForm.zul @@ -22,22 +22,22 @@ - - ${labels.description} : - - - - ${labels.munit} : + + ${labels.description} : + + + + diff --git a/src/main/webapp/lists/munits/munitsForm.zul b/src/main/webapp/lists/munits/munitsForm.zul index f76ec269..e4916af2 100644 --- a/src/main/webapp/lists/munits/munitsForm.zul +++ b/src/main/webapp/lists/munits/munitsForm.zul @@ -9,12 +9,6 @@ - - ${labels.MUnitsFormCode} : - - - - ${labels.MUnitsFormName} : diff --git a/src/main/webapp/lists/munits/munitsGrid.zul b/src/main/webapp/lists/munits/munitsGrid.zul index 36cb0ff0..b7d00df8 100644 --- a/src/main/webapp/lists/munits/munitsGrid.zul +++ b/src/main/webapp/lists/munits/munitsGrid.zul @@ -7,26 +7,15 @@ - - +
- -
-
- -
-
-
- -
-
- +
@@ -47,8 +36,7 @@ diff --git a/src/main/webapp/requirements/actual/requirements.zul b/src/main/webapp/requirements/actual/requirements.zul index 9cf94a1e..cdd39b4d 100644 --- a/src/main/webapp/requirements/actual/requirements.zul +++ b/src/main/webapp/requirements/actual/requirements.zul @@ -25,14 +25,19 @@ label="${labels.RequirementsGridCenter}" sort="czech(description)" width="10%" /> - + + + sclass="find-grid-textbox" />
@@ -70,11 +74,12 @@
- diff --git a/src/main/webapp/requirements/actual/requirementsForm.zul b/src/main/webapp/requirements/actual/requirementsForm.zul index a6832141..6d58d45b 100644 --- a/src/main/webapp/requirements/actual/requirementsForm.zul +++ b/src/main/webapp/requirements/actual/requirementsForm.zul @@ -6,12 +6,15 @@ border="normal" position="center" apply="org.zkoss.bind.BindComposer" - viewModel="@id('vm') @init('info.bukova.isspst.ui.requirement.RequirementForm')"> + viewModel="@id('vm') @init('info.bukova.isspst.ui.requirement.RequirementForm')" + validationMessages="@id('vmsg')"> - + @@ -36,8 +39,8 @@ @@ -45,9 +48,12 @@ ${labels.RequirementsFormCenter} : + disabled="@load(vm.editRec)" + selectedItem="@bind(fx.workgroup)"> @@ -55,112 +61,140 @@ - ${labels.RequirementsFormDescription} : + ${labels.RequirementsFormDeliveryDate} : + + + + + + ${labels.Amount} : + id="idSumTotal" + readonly="true" + width="150px" + value="@bind(fx.sumTotal) @converter(vm.bigDecimalConverter)" /> - ${labels.RequirementsFormDeliveryDate} : + ${labels.RequirementsFormDescription} : - +