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
|
brand=Marke
|
||||||
condition=Zustand
|
condition=Zustand
|
||||||
size=Gr<EFBFBD><EFBFBD>e
|
size=Gr<EFBFBD><EFBFBD>e
|
||||||
|
discountedSellPrice=Preis nach Rabatt
|
||||||
|
|
||||||
articleCount=Anzahl Artikel
|
articleCount=Anzahl Artikel
|
||||||
originalPriceSum=Summe Originalpreise
|
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.hibernate.annotations.GenericGenerator;
|
||||||
import org.openxava.annotations.*;
|
import org.openxava.annotations.*;
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
import com.yourcompany.babydatenbank.actions.*;
|
||||||
|
|
||||||
|
import java.math.*;
|
||||||
import java.time.*;
|
import java.time.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@View(members=
|
@View(members=
|
||||||
"name;" +
|
"name;" +
|
||||||
"photo;"+
|
"photo;"+
|
||||||
"#category, pattern;"+
|
"#category, pattern;"+
|
||||||
"#brand, size;"+
|
"#brand, size;"+
|
||||||
"buyAndSell[condition;"+
|
"buyAndSell["+
|
||||||
"#originalPrice, buyPrice, sellPrice;"+
|
"#condition, discount;"+
|
||||||
|
"#originalPrice, discountedSellPrice;"+
|
||||||
|
"buyPrice, sellPrice;"+
|
||||||
"#buyDate, sellDate];" +
|
"#buyDate, sellDate];" +
|
||||||
"remarks"
|
"remarks"
|
||||||
)
|
)
|
||||||
@@ -57,6 +64,7 @@ public class Article {
|
|||||||
@NoCreate
|
@NoCreate
|
||||||
@NoModify
|
@NoModify
|
||||||
@DescriptionsList(order="${number} ASC")
|
@DescriptionsList(order="${number} ASC")
|
||||||
|
@OnChange(OnChangeArticleConditionAction.class)
|
||||||
private Condition condition;
|
private Condition condition;
|
||||||
|
|
||||||
@Stereotype("MONEY")
|
@Stereotype("MONEY")
|
||||||
@@ -79,6 +87,11 @@ public class Article {
|
|||||||
|
|
||||||
@Stereotype("DATE")
|
@Stereotype("DATE")
|
||||||
private LocalDate sellDate;
|
private LocalDate sellDate;
|
||||||
|
|
||||||
|
@Column(length=8)
|
||||||
|
@Digits(integer=3,fraction=0)
|
||||||
|
@Max(value=100)
|
||||||
|
private BigDecimal discount;
|
||||||
|
|
||||||
public String getOid() {
|
public String getOid() {
|
||||||
return oid;
|
return oid;
|
||||||
@@ -191,6 +204,25 @@ public class Article {
|
|||||||
public void setSellDate(LocalDate sellDate) {
|
public void setSellDate(LocalDate sellDate) {
|
||||||
this.sellDate = 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;
|
package com.yourcompany.babydatenbank.model;
|
||||||
|
|
||||||
|
import java.math.*;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
import org.openxava.annotations.*;
|
import org.openxava.annotations.*;
|
||||||
|
|
||||||
@@ -18,6 +22,11 @@ public class Condition {
|
|||||||
|
|
||||||
@Column(length=32)
|
@Column(length=32)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@Column(length=8)
|
||||||
|
@Max(value=100)
|
||||||
|
@Digits(integer=3, fraction=0)
|
||||||
|
private BigDecimal defaultDiscount;
|
||||||
|
|
||||||
public String getOid() {
|
public String getOid() {
|
||||||
return oid;
|
return oid;
|
||||||
@@ -42,5 +51,13 @@ public class Condition {
|
|||||||
public void setNumber(int number) {
|
public void setNumber(int number) {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BigDecimal getDefaultDiscount() {
|
||||||
|
return defaultDiscount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultDiscount(BigDecimal defaultDiscount) {
|
||||||
|
this.defaultDiscount = defaultDiscount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user