Commit eab4f333 by Tuomas Riihimäki

Added comments to database classes

1 parent 2126e11a
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
*/ */
package fi.insomnia.bortal.model; package fi.insomnia.bortal.model;
import java.math.BigDecimal;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
...@@ -24,8 +25,9 @@ import javax.persistence.TemporalType; ...@@ -24,8 +25,9 @@ import javax.persistence.TemporalType;
import javax.persistence.Version; import javax.persistence.Version;
/** /**
* * The system can send bills to the users.
* * When user pays bill a AccountEvent row is created for product whose price is +1
* and Bills paidDate is changed to not null.
*/ */
@Entity @Entity
@Table(name = "bills") @Table(name = "bills")
...@@ -40,40 +42,94 @@ public class Bill implements EventChildInterface { ...@@ -40,40 +42,94 @@ public class Bill implements EventChildInterface {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@EmbeddedId @EmbeddedId
private EventPk id;; private EventPk id;
/**
* When the bill is due to be paid.
*/
@Column(name = "due_date") @Column(name = "due_date")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar dueDate; private Calendar dueDate;
/**
* When the money has appeared on the bank account.
*/
@Column(name = "paid_date") @Column(name = "paid_date")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Calendar paidDate; private Calendar paidDate;
/**
* Reference number of the bill.
* @See http://www.fkl.fi/www/page/fk_www_1293
*/
@Column(name = "reference_number") @Column(name = "reference_number")
private String referenceNumber; private String referenceNumber;
/**
* Notes for the event organisators about the bill.
*/
@Lob @Lob
@Column(name = "notes") @Column(name = "notes")
private String notes; private String notes;
/**
* Bill may have multiple items on multiple rows.
*/
@OneToMany(mappedBy = "bill") @OneToMany(mappedBy = "bill")
private List<BillLine> billLines; private List<BillLine> billLines;
/**
* When the bill is paid this AccountEvent is created and this is a reference
* to that accountAction.
*/
@JoinColumns({ @JoinColumns({
@JoinColumn(name = "account_event_id", referencedColumnName = "entity_id", nullable = false, updatable = false, insertable = false), @JoinColumn(name = "account_event_id", referencedColumnName = "entity_id", updatable = false, insertable = false),
@JoinColumn(name = "account_event_event_id", referencedColumnName = "events_pk_id", nullable = false, updatable = false, insertable = false) }) @JoinColumn(name = "account_event_event_id", referencedColumnName = "events_pk_id", updatable = false, insertable = false) })
@OneToOne @OneToOne
private AccountEvent accountEvent; private AccountEvent accountEvent;
/**
* User who should pay this bill.
*/
@JoinColumn(name = "users_id", referencedColumnName = "users_id", nullable = false) @JoinColumn(name = "users_id", referencedColumnName = "users_id", nullable = false)
@ManyToOne(optional = false) @ManyToOne(optional = false)
private User user; private User user;
/**
* Which event the bill is assigned to.
*/
@ManyToOne @ManyToOne
@JoinColumn(name = "events_id", referencedColumnName = "events_id") @JoinColumn(name = "events_id", referencedColumnName = "events_id")
private Event event; private Event event;
/**
* Commodity function to calculate the total price of the bill.
* @return The total sum of the bill ( unitPrice * units * vat )
*/
public BigDecimal totalPrice()
{
BigDecimal total = BigDecimal.ZERO;
for(BillLine line: getBillLines())
{
total = total.add(line.getLinePrice());
}
return total;
}
/**
* Commodity function to return the vatless price of the bill
* @return The total VAT-less sum of the bill ( unitPrice * units )
*/
public BigDecimal totalPriceVatless()
{
BigDecimal total = BigDecimal.ZERO;
for(BillLine line: getBillLines())
{
total = total.add(line.getLinePriceVatless());
}
return total;
}
@Override @Override
public EventPk getId() { public EventPk getId() {
return id; return id;
......
...@@ -23,35 +23,50 @@ import javax.persistence.Version; ...@@ -23,35 +23,50 @@ import javax.persistence.Version;
*/ */
@Entity @Entity
@Table(name = "bill_lines") @Table(name = "bill_lines")
@NamedQueries( { @NamedQueries({
@NamedQuery(name = "BillLine.findAll", query = "SELECT b FROM BillLine b"), @NamedQuery(name = "BillLine.findAll", query = "SELECT b FROM BillLine b"),
@NamedQuery(name = "BillLine.findByProduct", query = "SELECT b FROM BillLine b WHERE b.name = :name"), @NamedQuery(name = "BillLine.findByProduct", query = "SELECT b FROM BillLine b WHERE b.name = :name"),
@NamedQuery(name = "BillLine.findByUnits", query = "SELECT b FROM BillLine b WHERE b.units = :units"), @NamedQuery(name = "BillLine.findByUnits", query = "SELECT b FROM BillLine b WHERE b.units = :units"),
@NamedQuery(name = "BillLine.findByUnitPrice", query = "SELECT b FROM BillLine b WHERE b.unitPrice = :unitPrice"), @NamedQuery(name = "BillLine.findByUnitPrice", query = "SELECT b FROM BillLine b WHERE b.unitPrice = :unitPrice"),
@NamedQuery(name = "BillLine.findByVat", query = "SELECT b FROM BillLine b WHERE b.vat = :vat") }) @NamedQuery(name = "BillLine.findByVat", query = "SELECT b FROM BillLine b WHERE b.vat = :vat") })
public class BillLine implements EventChildInterface{ public class BillLine implements EventChildInterface {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final BigDecimal DEFAULT_VAT = BigDecimal.ZERO; private static final BigDecimal DEFAULT_VAT = BigDecimal.ZERO;
@EmbeddedId @EmbeddedId
private EventPk id; private EventPk id;
/**
* Product name shown on the bill
*/
@Column(name = "name", nullable = false) @Column(name = "name", nullable = false)
private String name; private String name;
/**
* How many units the of the product has been purchased eg. 14 (Entrance
* tickets), 1.5 (l) eh.. something..
*/
@Column(name = "units", nullable = false, precision = 24, scale = 4) @Column(name = "units", nullable = false, precision = 24, scale = 4)
private BigDecimal units; private BigDecimal units = BigDecimal.ZERO;
/**
* How much one(1) unit of this product costs
*
*/
@Column(name = "unit_price", nullable = false, precision = 24, scale = 4) @Column(name = "unit_price", nullable = false, precision = 24, scale = 4)
private BigDecimal unitPrice; private BigDecimal unitPrice = BigDecimal.ZERO;
/**
* How much VAT this product contains ( 0, 0.22 ) etc
*/
@Column(name = "vat", nullable = false, precision = 3, scale = 2) @Column(name = "vat", nullable = false, precision = 3, scale = 2)
private BigDecimal vat = DEFAULT_VAT; private BigDecimal vat = DEFAULT_VAT;
/**
* Which bill this bill line belongs to
*/
@JoinColumns({ @JoinColumns({
@JoinColumn(name = "bills_id", referencedColumnName = "entity_id", nullable = false, updatable = false, insertable = false), @JoinColumn(name = "bills_id", referencedColumnName = "entity_id", nullable = false, updatable = false, insertable = false),
@JoinColumn(name="bills_event_id",referencedColumnName = "events_pk_id", nullable = false, updatable = false, insertable = false) @JoinColumn(name = "bills_event_id", referencedColumnName = "events_pk_id", nullable = false, updatable = false, insertable = false) })
})
@ManyToOne @ManyToOne
private Bill bill; private Bill bill;
...@@ -59,6 +74,25 @@ public class BillLine implements EventChildInterface{ ...@@ -59,6 +74,25 @@ public class BillLine implements EventChildInterface{
@Column(nullable = false) @Column(nullable = false)
private int jpaVersionField; private int jpaVersionField;
/**
* Calculate the total price for the items on this line
* @return
*/
public BigDecimal getLinePrice()
{
BigDecimal vatMultiplicand = BigDecimal.ONE.add(getVat());
return getLinePriceVatless().multiply(vatMultiplicand);
}
/**
* Calculate the total VAT-less price for the items on this lin
* @return
*/
public BigDecimal getLinePriceVatless()
{
return getUnitPrice().multiply(getUnits());
}
public BillLine() { public BillLine() {
} }
...@@ -75,6 +109,8 @@ public class BillLine implements EventChildInterface{ ...@@ -75,6 +109,8 @@ public class BillLine implements EventChildInterface{
this.setVat(vat); this.setVat(vat);
} }
public String getName() { public String getName() {
return name; return name;
} }
......
...@@ -20,13 +20,12 @@ import javax.persistence.Table; ...@@ -20,13 +20,12 @@ import javax.persistence.Table;
import javax.persistence.Version; import javax.persistence.Version;
/** /**
* * ID-card templates for the event.
*/ */
@Entity @Entity
@Table(name = "card_templates") @Table(name = "card_templates")
@NamedQueries( { @NamedQueries( {
@NamedQuery(name = "CardTemplate.findAll", query = "SELECT c FROM CardTemplate c"), @NamedQuery(name = "CardTemplate.findAll", query = "SELECT c FROM CardTemplate c"),
@NamedQuery(name = "CardTemplate.findByName", query = "SELECT c FROM CardTemplate c WHERE c.name = :name") }) @NamedQuery(name = "CardTemplate.findByName", query = "SELECT c FROM CardTemplate c WHERE c.name = :name") })
public class CardTemplate implements EventChildInterface{ public class CardTemplate implements EventChildInterface{
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!