1 package org.paneris.jammyjoes.model;
2
3 import java.sql.Date;
4 import java.util.Map;
5
6 import org.paneris.jammyjoes.model.generated.ShopOrderItemBase;
7
8 public class ShopOrderItem extends ShopOrderItemBase {
9 public ShopOrderItem() {
10 }
11
12
13 public final void delete(Map map) {
14 deleteTransaction();
15 super.delete(map);
16 }
17
18 public void deleteTransaction() {
19 StockTransaction st = getStocktransaction();
20 setStocktransaction(null);
21 if (st != null)
22 st.delete();
23 }
24
25 public void setTransaction() {
26 JammyjoesDatabaseTables tables = getJammyjoesDatabaseTables();
27 StockTransactionType type = tables.getStockTransactionTypeTable().getInternetSale();
28 if (getOrder().getType().equals(tables.getOrderTypeTable().getTelephoneOrder())) {
29 type = tables.getStockTransactionTypeTable().getTelephoneSale();
30 }
31 if (getOrder().getStatus().equals(tables.getOrderStatusTable().getIncomplete())) {
32 deleteTransaction();
33 } else {
34 StockTransactionTable stt = tables.getStockTransactionTable();
35 StockTransaction st = getStocktransaction();
36 if (st == null) {
37 st =
38 getProduct().newStockTransaction(
39 new Date(getOrder().getDate().getTime()),
40 type,
41 getQuantity());
42 stt.create(st);
43 setStocktransaction(st);
44 } else {
45 st.setDate(new Date(getOrder().getDate().getTime()));
46 st.setType(type);
47 st.setQuantity(getQuantity());
48 }
49 }
50 }
51
52 public void postWrite() {
53 setTransaction();
54 }
55 }