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:
sockenklaus
2020-06-09 15:45:33 +02:00
parent 31e10f7194
commit e53bd6fe1c
4 changed files with 75 additions and 3 deletions

View File

@@ -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;
}
}
}