Adding function to calculate discounts.
TODO: Discount won't show as Number without decimal fraction although it is handled as such...
This commit is contained in:
@@ -17,6 +17,7 @@ pattern=Muster
|
||||
brand=Marke
|
||||
condition=Zustand
|
||||
size=Gr<EFBFBD><EFBFBD>e
|
||||
discountedSellPrice=Preis nach Rabatt
|
||||
|
||||
articleCount=Anzahl Artikel
|
||||
originalPriceSum=Summe Originalpreise
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.yourcompany.babydatenbank.actions;
|
||||
|
||||
import org.openxava.actions.*;
|
||||
import org.openxava.jpa.*;
|
||||
|
||||
import com.yourcompany.babydatenbank.model.*;
|
||||
|
||||
public class OnChangeArticleConditionAction extends OnChangePropertyBaseAction {
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
try {
|
||||
Condition c = XPersistence.getManager().find(Condition.class, getNewValue().toString());
|
||||
|
||||
getView().setValue("discount", c.getDefaultDiscount());
|
||||
}
|
||||
catch(NullPointerException e) {
|
||||
getView().setValue("discount", 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,17 +4,24 @@ import javax.persistence.*;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.openxava.annotations.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.yourcompany.babydatenbank.actions.*;
|
||||
|
||||
import java.math.*;
|
||||
import java.time.*;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Entity
|
||||
@View(members=
|
||||
"name;" +
|
||||
"photo;"+
|
||||
"#category, pattern;"+
|
||||
"#brand, size;"+
|
||||
"buyAndSell[condition;"+
|
||||
"#originalPrice, buyPrice, sellPrice;"+
|
||||
"buyAndSell["+
|
||||
"#condition, discount;"+
|
||||
"#originalPrice, discountedSellPrice;"+
|
||||
"buyPrice, sellPrice;"+
|
||||
"#buyDate, sellDate];" +
|
||||
"remarks"
|
||||
)
|
||||
@@ -57,6 +64,7 @@ public class Article {
|
||||
@NoCreate
|
||||
@NoModify
|
||||
@DescriptionsList(order="${number} ASC")
|
||||
@OnChange(OnChangeArticleConditionAction.class)
|
||||
private Condition condition;
|
||||
|
||||
@Stereotype("MONEY")
|
||||
@@ -79,6 +87,11 @@ public class Article {
|
||||
|
||||
@Stereotype("DATE")
|
||||
private LocalDate sellDate;
|
||||
|
||||
@Column(length=8)
|
||||
@Digits(integer=3,fraction=0)
|
||||
@Max(value=100)
|
||||
private BigDecimal discount;
|
||||
|
||||
public String getOid() {
|
||||
return oid;
|
||||
@@ -191,6 +204,25 @@ public class Article {
|
||||
public void setSellDate(LocalDate sellDate) {
|
||||
this.sellDate = sellDate;
|
||||
}
|
||||
|
||||
public BigDecimal getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
||||
public void setDiscount(BigDecimal discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
|
||||
@Column(length=8)
|
||||
@Stereotype("MONEY")
|
||||
public BigDecimal getDiscountedSellPrice() {
|
||||
try {
|
||||
return getOriginalPrice().multiply(BigDecimal.ONE.subtract(getDiscount().divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN)));
|
||||
} catch(Exception e) {
|
||||
//Log.error(e);
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.yourcompany.babydatenbank.model;
|
||||
|
||||
import java.math.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.openxava.annotations.*;
|
||||
|
||||
@@ -18,6 +22,11 @@ public class Condition {
|
||||
|
||||
@Column(length=32)
|
||||
private String description;
|
||||
|
||||
@Column(length=8)
|
||||
@Max(value=100)
|
||||
@Digits(integer=3, fraction=0)
|
||||
private BigDecimal defaultDiscount;
|
||||
|
||||
public String getOid() {
|
||||
return oid;
|
||||
@@ -42,5 +51,13 @@ public class Condition {
|
||||
public void setNumber(int number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public BigDecimal getDefaultDiscount() {
|
||||
return defaultDiscount;
|
||||
}
|
||||
|
||||
public void setDefaultDiscount(BigDecimal defaultDiscount) {
|
||||
this.defaultDiscount = defaultDiscount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user