231 lines
4.2 KiB
Java
231 lines
4.2 KiB
Java
package com.yourcompany.babydatenbank.model;
|
|
|
|
import javax.persistence.*;
|
|
|
|
import org.hibernate.annotations.GenericGenerator;
|
|
import org.hibernate.validator.constraints.*;
|
|
import org.openxava.annotations.*;
|
|
|
|
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, discount;"+
|
|
"#originalPrice, discountedSellPrice;"+
|
|
"buyPrice, sellPrice;"+
|
|
"#buyDate, sellDate];" +
|
|
"remarks"
|
|
)
|
|
@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")
|
|
@GenericGenerator(name="system-uuid2", strategy = "uuid2")
|
|
@Column(length=36)
|
|
private String oid;
|
|
|
|
@Column(length=32)
|
|
private String name;
|
|
|
|
@Stereotype("IMAGE")
|
|
@Column(length=83886080)
|
|
private byte[] photo;
|
|
|
|
@ManyToOne
|
|
@NoModify
|
|
@DescriptionsList
|
|
private Size size;
|
|
|
|
@ManyToOne
|
|
@NoModify
|
|
@DescriptionsList
|
|
private Pattern pattern;
|
|
|
|
@ManyToOne
|
|
@NoModify
|
|
@DescriptionsList
|
|
private Category category;
|
|
|
|
@ManyToOne
|
|
@NoModify
|
|
@DescriptionsList
|
|
private Brand brand;
|
|
|
|
@ManyToOne
|
|
@NoCreate
|
|
@NoModify
|
|
@DescriptionsList(order="${number} ASC")
|
|
@OnChange(OnChangeArticleConditionAction.class)
|
|
private Condition condition;
|
|
|
|
@Stereotype("MONEY")
|
|
@Column(length=8)
|
|
private BigDecimal buyPrice;
|
|
|
|
@Stereotype("MONEY")
|
|
@Column(length=8)
|
|
private BigDecimal originalPrice;
|
|
|
|
@Stereotype("MONEY")
|
|
@Column(length=8)
|
|
private BigDecimal sellPrice;
|
|
|
|
@Stereotype("MEMO")
|
|
private String remarks;
|
|
|
|
@Stereotype("DATE")
|
|
private LocalDate buyDate;
|
|
|
|
@Stereotype("DATE")
|
|
private LocalDate sellDate;
|
|
|
|
|
|
@Stereotype("PERCENTAGE")
|
|
@Range(min=0, max=100)
|
|
@DisplaySize(value=8)
|
|
private int discount;
|
|
|
|
public String getOid() {
|
|
return oid;
|
|
}
|
|
|
|
public void setOid(String oid) {
|
|
this.oid = oid;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public byte[] getPhoto() {
|
|
return photo;
|
|
}
|
|
|
|
public void setPhoto(byte[] photo) {
|
|
this.photo = photo;
|
|
}
|
|
|
|
public Size getSize() {
|
|
return size;
|
|
}
|
|
|
|
public void setSize(Size size) {
|
|
this.size = size;
|
|
}
|
|
|
|
public Pattern getPattern() {
|
|
return pattern;
|
|
}
|
|
|
|
public void setPattern(Pattern pattern) {
|
|
this.pattern = pattern;
|
|
}
|
|
|
|
public BigDecimal getBuyPrice() {
|
|
return buyPrice;
|
|
}
|
|
|
|
public void setBuyPrice(BigDecimal buyPrice) {
|
|
this.buyPrice = buyPrice;
|
|
}
|
|
|
|
public BigDecimal getOriginalPrice() {
|
|
return originalPrice;
|
|
}
|
|
|
|
public void setOriginalPrice(BigDecimal originalPrice) {
|
|
this.originalPrice = originalPrice;
|
|
}
|
|
|
|
public BigDecimal getSellPrice() {
|
|
return sellPrice;
|
|
}
|
|
|
|
public void setSellPrice(BigDecimal sellPrice) {
|
|
this.sellPrice = sellPrice;
|
|
}
|
|
|
|
public String getRemarks() {
|
|
return remarks;
|
|
}
|
|
|
|
public void setRemarks(String remarks) {
|
|
this.remarks = remarks;
|
|
}
|
|
|
|
public Category getCategory() {
|
|
return category;
|
|
}
|
|
|
|
public void setCategory(Category category) {
|
|
this.category = category;
|
|
}
|
|
|
|
public Brand getBrand() {
|
|
return brand;
|
|
}
|
|
|
|
public void setBrand(Brand brand) {
|
|
this.brand = brand;
|
|
}
|
|
|
|
public Condition getCondition() {
|
|
return condition;
|
|
}
|
|
|
|
public void setCondition(Condition condition) {
|
|
this.condition = condition;
|
|
}
|
|
|
|
public LocalDate getBuyDate() {
|
|
return buyDate;
|
|
}
|
|
|
|
public void setBuyDate(LocalDate buyDate) {
|
|
this.buyDate = buyDate;
|
|
}
|
|
|
|
public LocalDate getSellDate() {
|
|
return sellDate;
|
|
}
|
|
|
|
public void setSellDate(LocalDate sellDate) {
|
|
this.sellDate = sellDate;
|
|
}
|
|
|
|
public int getDiscount() {
|
|
return discount;
|
|
}
|
|
|
|
public void setDiscount(int discount) {
|
|
this.discount = discount;
|
|
}
|
|
|
|
@Stereotype("MONEY")
|
|
@Calculation("(100 - discount) / 100 * originalPrice")
|
|
@Column(length=8)
|
|
public BigDecimal getDiscountedSellPrice() {
|
|
try {
|
|
return getOriginalPrice().multiply(BigDecimal.ONE.subtract(new BigDecimal(getDiscount()).divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN)));
|
|
} catch(Exception e) {
|
|
//Log.error(e);
|
|
return BigDecimal.ZERO;
|
|
}
|
|
|
|
}
|
|
}
|