Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StockTransaction |
|
| 3.142857142857143;3.143 |
1 | package org.paneris.jammyjoes.model; | |
2 | ||
3 | import java.sql.Date; | |
4 | import java.util.Map; | |
5 | ||
6 | import org.melati.poem.AccessPoemException; | |
7 | import org.melati.poem.DeletionIntegrityPoemException; | |
8 | import org.melati.poem.ValidationPoemException; | |
9 | import org.paneris.jammyjoes.model.generated.StockTransactionBase; | |
10 | ||
11 | public class StockTransaction extends StockTransactionBase { | |
12 | ||
13 | 0 | public StockTransaction() {} |
14 | ||
15 | public void setDate(Date cooked) | |
16 | throws AccessPoemException, ValidationPoemException { | |
17 | 0 | if (cooked == null) cooked = new Date(new java.util.Date().getTime()); |
18 | 0 | super.setDate(cooked); |
19 | 0 | } |
20 | ||
21 | public final void delete(Map map) throws AccessPoemException, DeletionIntegrityPoemException { | |
22 | 0 | int currentValue = 0; |
23 | 0 | if (getQuantity() != null) currentValue = getQuantity().intValue(); |
24 | 0 | setThisProductQuantity(-currentValue); |
25 | 0 | super.delete(map); |
26 | 0 | } |
27 | ||
28 | public void setThisProductQuantity(int q) { | |
29 | 0 | if (q != 0) { |
30 | 0 | Product p = getProduct(); |
31 | 0 | StockTransactionType t = getType(); |
32 | 0 | if (p == null) throw new TransactionException("An attempt was made to set the quantity for a transaction that doesn't reference a product"); |
33 | 0 | if (t == null) throw new TransactionException("An attempt was made to set the quantity for a transaction that doesn't have a type"); |
34 | 0 | p.clearQuantities(); |
35 | 0 | int currentValue = 0; |
36 | 0 | if (p.getStocklevel() != null) currentValue = p.getStocklevel().intValue(); |
37 | 0 | if (t.getReducestock().booleanValue()) { |
38 | 0 | p.setStocklevel(currentValue - q); |
39 | } else { | |
40 | 0 | p.setStocklevel(currentValue + q); |
41 | } | |
42 | } | |
43 | 0 | } |
44 | ||
45 | // set the stock level on the record | |
46 | public void setQuantity(Integer cooked) | |
47 | throws AccessPoemException, ValidationPoemException { | |
48 | 0 | int currentValue = 0; |
49 | 0 | int newValue = 0; |
50 | 0 | if (getQuantity() != null) currentValue = getQuantity().intValue(); |
51 | 0 | if (cooked != null) newValue = cooked.intValue(); |
52 | 0 | setThisProductQuantity(newValue - currentValue); |
53 | 0 | super.setQuantity(cooked); |
54 | 0 | } |
55 | ||
56 | public void setTypeTroid(Integer raw) throws AccessPoemException { | |
57 | 0 | if (getType() != null && getType().getTroid() != raw) { |
58 | 0 | int currentValue = 0; |
59 | 0 | if (getQuantity() != null) currentValue = getQuantity().intValue(); |
60 | 0 | setThisProductQuantity(-currentValue); |
61 | 0 | super.setTypeTroid(raw); |
62 | 0 | setThisProductQuantity(currentValue); |
63 | 0 | } else { |
64 | 0 | super.setTypeTroid(raw); |
65 | } | |
66 | 0 | } |
67 | ||
68 | public void setProductTroid(Integer raw) throws AccessPoemException { | |
69 | 0 | if (getProduct() != null && getProduct().getTroid() != raw) { |
70 | 0 | int currentValue = 0; |
71 | 0 | if (getQuantity() != null) currentValue = getQuantity().intValue(); |
72 | 0 | setThisProductQuantity(-currentValue); |
73 | 0 | super.setProductTroid(raw); |
74 | 0 | setThisProductQuantity(currentValue); |
75 | 0 | } else { |
76 | 0 | super.setProductTroid(raw); |
77 | } | |
78 | 0 | } |
79 | ||
80 | } |