diff --git a/i18n/Babydatenbank-labels_de.properties b/i18n/Babydatenbank-labels_de.properties index 14eddcd..b0c7f5f 100644 --- a/i18n/Babydatenbank-labels_de.properties +++ b/i18n/Babydatenbank-labels_de.properties @@ -17,7 +17,7 @@ pattern=Muster brand=Marke condition=Zustand size=Größe -discountedSellPrice=Preis nach Rabatt +discountedSellPrice=Preisvorschlag articleCount=Anzahl Artikel originalPriceSum=Summe Originalpreise diff --git a/src/com/yourcompany/babydatenbank/formatters/PercentageFormatter.java b/src/com/yourcompany/babydatenbank/formatters/PercentageFormatter.java new file mode 100644 index 0000000..a9fc727 --- /dev/null +++ b/src/com/yourcompany/babydatenbank/formatters/PercentageFormatter.java @@ -0,0 +1,28 @@ +package com.yourcompany.babydatenbank.formatters; + +import java.math.*; + +import javax.servlet.http.*; + +import org.openxava.formatters.*; +import org.openxava.model.meta.*; +import org.openxava.util.*; + +/** + * For MONEY and DINERO stereotypes.

+ * + * @author Javier Paniza + */ + +public class PercentageFormatter implements IMetaPropertyFormatter { + + public String format(HttpServletRequest request, MetaProperty metaProperty, Object object) throws Exception { + if (object == null) return ""; + return object.toString(); + } + + public Object parse(HttpServletRequest request, MetaProperty metaProperty, String string) throws Exception { + if (Is.emptyString(string)) return null; + return new BigDecimal(string).setScale(0); + } +} diff --git a/src/com/yourcompany/babydatenbank/model/Article.java b/src/com/yourcompany/babydatenbank/model/Article.java index 95c56c6..aff9fc8 100644 --- a/src/com/yourcompany/babydatenbank/model/Article.java +++ b/src/com/yourcompany/babydatenbank/model/Article.java @@ -25,7 +25,7 @@ import javax.validation.constraints.*; "#buyDate, sellDate];" + "remarks" ) -@Tab(properties="name, photo, category.description, brand.description, pattern.description, size.description, condition.description, remarks", defaultOrder="${name} asc") +@Tab(properties="name, category.description, brand.description, pattern.description, size.description, condition.description, discountedSellPrice, remarks", defaultOrder="${name} asc") public class Article { @Id @Hidden @GeneratedValue(generator="system-uuid2") @@ -89,8 +89,11 @@ public class Article { private LocalDate sellDate; @Digits(integer=3, fraction = 0) + //@Max(value=100) + //@Stereotype("PERCENTAGE") + //@Column(length=11) private BigDecimal discount; - + public String getOid() { return oid; } @@ -211,8 +214,9 @@ public class Article { this.discount = discount; } - @Column(length=8) @Stereotype("MONEY") + @Calculation("(100 - discount) / 100 * originalPrice") + @Column(length=8) public BigDecimal getDiscountedSellPrice() { try { return getOriginalPrice().multiply(BigDecimal.ONE.subtract(getDiscount().divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN))); @@ -221,5 +225,5 @@ public class Article { return BigDecimal.ZERO; } - } + } } diff --git a/src/com/yourcompany/babydatenbank/model/Condition.java b/src/com/yourcompany/babydatenbank/model/Condition.java index a299b7a..6eeef82 100644 --- a/src/com/yourcompany/babydatenbank/model/Condition.java +++ b/src/com/yourcompany/babydatenbank/model/Condition.java @@ -9,6 +9,7 @@ import org.hibernate.annotations.GenericGenerator; import org.openxava.annotations.*; @Entity +@Tab(properties="number, description, defaultDiscount") public class Condition { @Id @Hidden @@ -23,9 +24,10 @@ public class Condition { @Column(length=32) private String description; - @Column(length=8) - @Max(value=100) + //@Column(length=8) + //@Max(value=100) @Digits(integer=3, fraction=0) + @Stereotype("PERCENTAGE") private BigDecimal defaultDiscount; public String getOid() { diff --git a/src/com/yourcompany/babydatenbank/model/Size.java b/src/com/yourcompany/babydatenbank/model/Size.java index 89d5d40..19671b1 100644 --- a/src/com/yourcompany/babydatenbank/model/Size.java +++ b/src/com/yourcompany/babydatenbank/model/Size.java @@ -1,5 +1,7 @@ package com.yourcompany.babydatenbank.model; +import java.util.*; + import javax.persistence.*; import org.openxava.annotations.*; import org.hibernate.annotations.GenericGenerator; @@ -16,6 +18,10 @@ public class Size { @Column(length=20, unique=true) private String description; + + @OneToMany(mappedBy="size") + @ListProperties("name, brand.description, category.description, size.description, condition.description") + private Collection

articles; public String getDescription() { return description; @@ -33,5 +39,16 @@ public class Size { this.oid = oid; } + public Collection
getArticles() { + return articles; + } + + public void setArticles(Collection
articles) { + this.articles = articles; + } + + public int getArticleCount() { + return this.articles.size(); + } } diff --git a/web/WEB-INF/lib/addons.jar b/web/WEB-INF/lib/addons.jar index 5c98ded..61f81da 100644 Binary files a/web/WEB-INF/lib/addons.jar and b/web/WEB-INF/lib/addons.jar differ diff --git a/web/xava/editors/percentageEditor.jsp b/web/xava/editors/percentageEditor.jsp new file mode 100644 index 0000000..5415109 --- /dev/null +++ b/web/xava/editors/percentageEditor.jsp @@ -0,0 +1,6 @@ + + + +% + + \ No newline at end of file diff --git a/xava/editors.xml b/xava/editors.xml new file mode 100644 index 0000000..d318080 --- /dev/null +++ b/xava/editors.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file