1 package org.paneris.bibliomania;
2
3 import java.sql.Timestamp;
4 import java.util.Enumeration;
5
6 import org.melati.poem.AccessPoemException;
7 import org.paneris.bibliomania.generated.ShopOrderItemBase;
8
9 public class ShopOrderItem extends ShopOrderItemBase {
10 public ShopOrderItem() {}
11
12
13
14 public void setStatus(OrderStatus cooked)
15 throws AccessPoemException {
16 super.setStatus(cooked);
17 BibliomaniaDatabase db = (BibliomaniaDatabase)getDatabase();
18
19
20 if (getFufilleddate_unsafe() == null &&
21 cooked == db.getOrderStatusTable().getFufilled()) {
22 setFufilleddate_unsafe(now());
23 }
24
25
26 ShopOrder orderL = getOrder();
27 Enumeration e = orderL.getItems();
28 boolean notAuthorised = false;
29 boolean authorised = false;
30 boolean partFufilled = false;
31 boolean fufilled = false;
32 while (e.hasMoreElements()) {
33 ShopOrderItem item = (ShopOrderItem)e.nextElement();
34
35 if (item.getStatus() == db.getOrderStatusTable().getNotAuthorised())
36 notAuthorised = true;
37 if (item.getStatus() == db.getOrderStatusTable().getAuthorised())
38 authorised = true;
39 if (item.getStatus() == db.getOrderStatusTable().getPartFufilled())
40 partFufilled = true;
41 if (item.getStatus() == db.getOrderStatusTable().getFufilled())
42 fufilled = true;
43 }
44
45 if (fufilled && !partFufilled && !authorised && !notAuthorised) {
46 orderL.setStatus(db.getOrderStatusTable().getFufilled());
47 return;
48 }
49
50 if (fufilled || partFufilled) {
51 orderL.setStatus(db.getOrderStatusTable().getPartFufilled());
52 return;
53 }
54
55 if (notAuthorised) {
56 orderL.setStatus(db.getOrderStatusTable().getNotAuthorised());
57 return;
58 }
59
60 orderL.setStatus(db.getOrderStatusTable().getAuthorised());
61 }
62
63 public void setFufilleddate_unsafe(Timestamp cooked) {
64
65 BibliomaniaDatabase db = (BibliomaniaDatabase)getDatabase();
66 if (getStatus() != db.getOrderStatusTable().getFufilled() || cooked != null) {
67 super.setFufilleddate_unsafe(cooked);
68 }
69 }
70
71 protected void writeLock() {
72 super.writeLock();
73 if (getDate_unsafe() == null) {
74 setDate_unsafe(now());
75 }
76 }
77
78 private static java.sql.Timestamp now() {
79 return new java.sql.Timestamp(new java.util.Date().getTime());
80 }
81
82 }