1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.web.struts;
17
18 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
19 import org.kuali.ole.module.purap.businessobject.PurApItem;
20 import org.kuali.ole.module.purap.document.AccountsPayableDocument;
21 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
22 import org.kuali.ole.module.purap.util.PurApItemUtils;
23 import org.kuali.ole.sys.OLEPropertyConstants;
24 import org.kuali.ole.sys.context.SpringContext;
25
26 import javax.servlet.http.HttpServletRequest;
27 import java.util.List;
28 import java.util.Map;
29
30
31
32
33 public class AccountsPayableFormBase extends PurchasingAccountsPayableFormBase {
34
35 protected PurApItem newPurchasingItemLine;
36 protected boolean calculated;
37 protected int countOfAboveTheLine = 0;
38 protected int countOfBelowTheLine = 0;
39
40
41
42
43 public AccountsPayableFormBase() {
44 super();
45 calculated = false;
46 }
47
48 public PurApItem getNewPurchasingItemLine() {
49 return newPurchasingItemLine;
50 }
51
52 public void setNewPurchasingItemLine(PurApItem newPurchasingItemLine) {
53 this.newPurchasingItemLine = newPurchasingItemLine;
54 }
55
56 public PurApItem getAndResetNewPurchasingItemLine() {
57 PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
58 setNewPurchasingItemLine(setupNewPurchasingItemLine());
59 return aPurchasingItemLine;
60 }
61
62
63
64
65
66
67 public PurApItem setupNewPurchasingItemLine() {
68 return null;
69 }
70
71 public boolean isCalculated() {
72 return calculated;
73 }
74
75 public void setCalculated(boolean calculated) {
76 this.calculated = calculated;
77 }
78
79 public int getCountOfAboveTheLine() {
80 return countOfAboveTheLine;
81 }
82
83 public void setCountOfAboveTheLine(int countOfAboveTheLine) {
84 this.countOfAboveTheLine = countOfAboveTheLine;
85 }
86
87 public int getCountOfBelowTheLine() {
88 return countOfBelowTheLine;
89 }
90
91 public void setCountOfBelowTheLine(int countOfBelowTheLine) {
92 this.countOfBelowTheLine = countOfBelowTheLine;
93 }
94
95
96
97
98 @Override
99 public void populate(HttpServletRequest request) {
100 super.populate(request);
101 AccountsPayableDocument apDoc = (AccountsPayableDocument) this.getDocument();
102
103
104 if (apDoc.getPurchaseOrderIdentifier() != null) {
105 apDoc.setPurchaseOrderDocument(SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(apDoc.getPurchaseOrderIdentifier()));
106 }
107
108
109 updateItemCounts();
110 }
111
112
113
114
115
116
117 @Override
118 protected void populateAccountingLinesForResponse(String methodToCall, Map parameterMap) {
119 super.populateAccountingLinesForResponse(methodToCall, parameterMap);
120
121 populateItemAccountingLines(parameterMap);
122 }
123
124
125
126
127
128
129 @Override
130 protected void populateItemAccountingLines(Map parameterMap) {
131 int itemCount = 0;
132 for (PurApItem item : ((AccountsPayableDocument) getDocument()).getItems()) {
133 populateAccountingLine(item.getNewSourceLine(), OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.ITEM + "[" + itemCount + "]." + OLEPropertyConstants.NEW_SOURCE_LINE, parameterMap);
134
135 int sourceLineCount = 0;
136 for (PurApAccountingLine purApLine : item.getSourceAccountingLines()) {
137 populateAccountingLine(purApLine, OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.ITEM + "[" + itemCount + "]." + OLEPropertyConstants.SOURCE_ACCOUNTING_LINE + "[" + sourceLineCount + "]", parameterMap);
138 sourceLineCount += 1;
139 }
140 }
141 }
142
143
144
145
146 public void updateItemCounts() {
147 List<PurApItem> items = ((AccountsPayableDocument) this.getDocument()).getItems();
148 countOfBelowTheLine = PurApItemUtils.countBelowTheLineItems(items);
149 countOfAboveTheLine = items.size() - countOfBelowTheLine;
150 }
151
152 }