diff --git a/src/main/java/info/bukova/isspst/BigDecimalUtils.java b/src/main/java/info/bukova/isspst/BigDecimalUtils.java index c16f8804..6a237683 100644 --- a/src/main/java/info/bukova/isspst/BigDecimalUtils.java +++ b/src/main/java/info/bukova/isspst/BigDecimalUtils.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.commons.lang.StringUtils.strip; public class BigDecimalUtils { @@ -23,6 +24,17 @@ public class BigDecimalUtils String valueS = value.toPlainString(); String searchS = search.toPlainString(); + + if (valueS.contains(".") || valueS.contains(",")) { + valueS = strip(valueS, "0"); + valueS = strip(valueS, ".,"); + } + + if (searchS.contains(".") || searchS.contains(",")) { + searchS = strip(searchS, "0"); + searchS = strip(searchS, ".,"); + } + boolean result = (valueS.compareTo(searchS) == 0); String s = "search='" + searchS + "', value='" + valueS + "', equal=" + (result ? "true" : "false"); diff --git a/src/main/java/info/bukova/isspst/filters/RequirementFilter.java b/src/main/java/info/bukova/isspst/filters/RequirementFilter.java index 1a13940f..1c2a6fab 100644 --- a/src/main/java/info/bukova/isspst/filters/RequirementFilter.java +++ b/src/main/java/info/bukova/isspst/filters/RequirementFilter.java @@ -1,5 +1,6 @@ package info.bukova.isspst.filters; +import info.bukova.isspst.BigDecimalUtils; import info.bukova.isspst.BooleanUtils; import info.bukova.isspst.DateTimeUtils; import info.bukova.isspst.StringUtils; @@ -48,7 +49,8 @@ public class RequirementFilter implements Filter boolean foundDeliveryDate = DateTimeUtils.isEqualByDateForFilter(item.getDeliveryDate(), condition.getDeliveryDate()); boolean foundUser = User.isEqualByUserForFilter(item.getOwnedBy(), condition.getOwnedBy()); boolean foundProject = BooleanUtils.isEqualByBooleanValue(item.getProject(), condition.getProject()); - return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject); + boolean foundSumTotal = BigDecimalUtils.isEqualByDecimalForFilter(item.getSumTotal(), condition.getSumTotal()); + return (foundNumser && foundReqDate && foundCenter && foundDescription && foundDeliveryDate && foundUser && foundProject && foundSumTotal); } @Factory diff --git a/src/main/java/info/bukova/isspst/ui/BigDecimalFilterConverter.java b/src/main/java/info/bukova/isspst/ui/BigDecimalFilterConverter.java new file mode 100644 index 00000000..ed55c886 --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/BigDecimalFilterConverter.java @@ -0,0 +1,69 @@ +package info.bukova.isspst.ui; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.zkoss.bind.BindContext; +import org.zkoss.bind.Converter; +import org.zkoss.util.Locales; +import org.zkoss.zk.ui.Component; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.ParseException; +import java.util.Locale; + +public class BigDecimalFilterConverter implements Converter +{ + private final static Logger log = LoggerFactory.getLogger(BigDecimalFilterConverter.class.getName()); + + @Override + public BigDecimal coerceToBean(String str, Component component, BindContext cx) + { +// BigDecimal val = BigDecimal.ZERO; + BigDecimal val = null; + + if (str != null) + { + try + { + Locale loc = Locales.getCurrent(); + DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(loc); + 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) + { + Locale loc = Locales.getCurrent(); + + if (val == null) + { + return ""; + //val = BigDecimal.ZERO; + } + + val = val.setScale(2, BigDecimal.ROUND_DOWN); + + DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(loc); + format.setMaximumFractionDigits(2); + format.setMinimumFractionDigits(0); + format.setGroupingUsed(true); + format.setGroupingSize(3); + String formatted = format.format(val); + return formatted; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java b/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java index a753f618..63cdb7f2 100644 --- a/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java +++ b/src/main/java/info/bukova/isspst/ui/DocumentViewModel.java @@ -16,6 +16,18 @@ import org.zkoss.zul.Messagebox; public class DocumentViewModel { + protected BigDecimalFilterConverter standardBigDecimalFilterConverter; + + public BigDecimalFilterConverter getStandardBigDecimalFilterConverter() + { + return standardBigDecimalFilterConverter; + } + + public void setStandardBigDecimalFilterConverter(BigDecimalFilterConverter standardBigDecimalFilterConverter) + { + this.standardBigDecimalFilterConverter = standardBigDecimalFilterConverter; + } + protected BigDecimalConverter standardBigDecimalConverter; protected BoolConverter standardBoolConverter; @@ -53,6 +65,7 @@ public class DocumentViewModel @Init public void initDocumentViewModel() { + this.standardBigDecimalFilterConverter = new BigDecimalFilterConverter(); this.standardBigDecimalConverter = new BigDecimalConverter(); this.standardBoolConverter = new BoolConverter(); } diff --git a/src/main/webapp/main/orders/requirements/reqListMy.zul b/src/main/webapp/main/orders/requirements/reqListMy.zul index ee7c9de9..9e466811 100644 --- a/src/main/webapp/main/orders/requirements/reqListMy.zul +++ b/src/main/webapp/main/orders/requirements/reqListMy.zul @@ -120,7 +120,7 @@