1 package ejava.jpa.examples.query;
2
3 import java.io.Serializable;
4
5 import java.math.BigDecimal;
6 import java.text.DateFormat;
7 import java.text.NumberFormat;
8 import java.text.SimpleDateFormat;
9 import java.util.Date;
10 import java.util.Locale;
11
12 public class Receipt implements Serializable {
13 private static final long serialVersionUID = 1L;
14 private long saleId;
15 private long customerId;
16 private Date date;
17 private double amount;
18
19 public Receipt(long saleId, long customerId, Date date, BigDecimal amount) {
20 this(customerId, saleId, date, amount.doubleValue());
21 }
22 public Receipt(long saleId, long customerId, Date date, double amount) {
23 this.customerId = customerId;
24 this.saleId = saleId;
25 this.date = date;
26 this.amount = amount;
27 }
28 public String toString() {
29 DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
30 NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
31 StringBuilder text = new StringBuilder();
32 text.append("sale=" + saleId);
33 text.append(", customer=" + customerId);
34 text.append(", date=" + (date==null ? null : df.format(date)));
35 text.append(", amount=" + nf.format(amount));
36 return text.toString();
37 }
38 public double getAmount() {
39 return amount;
40 }
41 public long getCustomerId() {
42 return customerId;
43 }
44 public Date getDate() {
45 return date;
46 }
47 public long getSaleId() {
48 return saleId;
49 }
50 }