01: package com.odal.petstore.domain;
02:
03: import com.odal.petstore.persistence.gen.pos.LineItemPO;
04: import com.odal.petstore.persistence.gen.bean.LineItemPoBean;
05:
06: import java.math.BigDecimal;
07:
08: /**
09: * @author Gennady Krizhevsky
10: */
11: public class LineItem extends LineItemPoBean {
12:
13: private Item item;
14: private BigDecimal total;
15:
16: public LineItem() {
17: }
18:
19: public LineItem(long lineNum, long orderId) {
20: super (lineNum, orderId);
21: }
22:
23: public LineItem(int lineNumber, CartItem cartItem) {
24: super .setLineNum(lineNumber);
25: super .setQuantity(cartItem.getQuantity());
26: super .setItemId(cartItem.getItem().getItemId());
27: super .setUnitPrice(cartItem.getItem().getListPrice());
28: this .item = cartItem.getItem();
29: }
30:
31: public void setQuantity(long quantity) {
32: super .setQuantity(quantity);
33: calculateTotal();
34: }
35:
36: public Item getItem() {
37: return item;
38: }
39:
40: public void setItem(Item item) {
41: this .item = item;
42: calculateTotal();
43: }
44:
45: public BigDecimal getTotal() {
46: return total;
47: }
48:
49: private void calculateTotal() {
50: if (item != null && item.getListPrice() != null) {
51: total = item.getListPrice().multiply(
52: new BigDecimal(getQuantity()));
53: } else {
54: total = null;
55: }
56: }
57: }
|