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.PurchasingAccountsPayableDocument;
21 import org.kuali.ole.module.purap.service.PurapAccountingService;
22 import org.kuali.ole.module.purap.util.SummaryAccount;
23 import org.kuali.ole.pdp.PdpPropertyConstants;
24 import org.kuali.ole.pdp.businessobject.PurchasingPaymentDetail;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEParameterKeyConstants;
27 import org.kuali.ole.sys.OLEPropertyConstants;
28 import org.kuali.ole.sys.businessobject.AccountingLine;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.service.impl.OleParameterConstants;
31 import org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase;
32 import org.kuali.rice.core.api.config.property.ConfigurationService;
33 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
34 import org.kuali.rice.kns.web.ui.ExtraButton;
35 import org.kuali.rice.krad.util.KRADConstants;
36 import org.kuali.rice.krad.util.ObjectUtils;
37 import org.kuali.rice.krad.util.UrlFactory;
38
39 import javax.servlet.http.HttpServletRequest;
40 import java.util.ArrayList;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Properties;
44
45
46
47
48 public class PurchasingAccountsPayableFormBase extends KualiAccountingDocumentFormBase {
49
50 protected transient List<SummaryAccount> summaryAccounts;
51 protected boolean readOnlyAccountDistributionMethod;
52
53
54
55
56 public PurchasingAccountsPayableFormBase() {
57 super();
58 clearSummaryAccounts();
59 setupAccountDistributionMethod();
60 }
61
62
63
64
65
66 protected void setupAccountDistributionMethod() {
67
68
69
70
71 this.setReadOnlyAccountDistributionMethod(true);
72
73
74
75
76 }
77
78
79
80
81
82 public void refreshAccountSummmary() {
83 clearSummaryAccounts();
84 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) getDocument();
85 summaryAccounts.addAll(SpringContext.getBean(PurapAccountingService.class).generateSummaryAccounts(purapDocument));
86 }
87
88
89
90
91 public void clearSummaryAccounts() {
92 summaryAccounts = new ArrayList<SummaryAccount>();
93 }
94
95
96
97
98 public List getBaselineSourceAccountingLines() {
99 List<AccountingLine> accounts = new ArrayList<AccountingLine>();
100 if (ObjectUtils.isNull(accounts) || accounts.isEmpty()) {
101 accounts = new ArrayList<AccountingLine>();
102 for (PurApItem item : ((PurchasingAccountsPayableDocument) getDocument()).getItems()) {
103 List<PurApAccountingLine> lines = item.getBaselineSourceAccountingLines();
104 for (PurApAccountingLine line : lines) {
105 accounts.add(line);
106 }
107
108 }
109 }
110 return accounts;
111 }
112
113 @Override
114 public void populate(HttpServletRequest request) {
115 super.populate(request);
116 PurchasingAccountsPayableDocument purapDoc = (PurchasingAccountsPayableDocument) this.getDocument();
117
118
119 purapDoc.fixItemReferences();
120 }
121
122 public List<SummaryAccount> getSummaryAccounts() {
123 if (summaryAccounts == null) {
124 refreshAccountSummmary();
125 }
126 return summaryAccounts;
127 }
128
129 public void setSummaryAccounts(List<SummaryAccount> summaryAccounts) {
130 this.summaryAccounts = summaryAccounts;
131 }
132
133
134
135
136
137
138 protected void addExtraButton(String property, String source, String altText) {
139
140 ExtraButton newButton = new ExtraButton();
141
142 newButton.setExtraButtonProperty(property);
143 newButton.setExtraButtonSource(source);
144 newButton.setExtraButtonAltText(altText);
145
146 extraButtons.add(newButton);
147 }
148
149
150
151
152
153
154 public String getDisbursementInfoUrl() {
155 String basePath = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.APPLICATION_URL_KEY);
156 ParameterService parameterService = SpringContext.getBean(ParameterService.class);
157
158 String orgCode = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_ORG_CODE);
159 String subUnitCode = parameterService.getParameterValueAsString(OleParameterConstants.PURCHASING_BATCH.class, OLEParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_SUB_UNIT_CODE);
160
161 Properties parameters = new Properties();
162 parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.SEARCH_METHOD);
163 parameters.put(OLEConstants.BACK_LOCATION, basePath + "/" + OLEConstants.MAPPING_PORTAL + ".do");
164 parameters.put(KRADConstants.DOC_FORM_KEY, "88888888");
165 parameters.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, PurchasingPaymentDetail.class.getName());
166 parameters.put(OLEConstants.HIDE_LOOKUP_RETURN_LINK, "true");
167 parameters.put(OLEConstants.SUPPRESS_ACTIONS, "false");
168 parameters.put(PdpPropertyConstants.PaymentDetail.PAYMENT_UNIT_CODE, orgCode);
169 parameters.put(PdpPropertyConstants.PaymentDetail.PAYMENT_SUBUNIT_CODE, subUnitCode);
170
171 String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + OLEConstants.LOOKUP_ACTION, parameters);
172
173 return lookupUrl;
174 }
175
176
177
178
179
180
181 @Override
182 protected void populateAccountingLinesForResponse(String methodToCall, Map parameterMap) {
183 super.populateAccountingLinesForResponse(methodToCall, parameterMap);
184
185 populateItemAccountingLines(parameterMap);
186 }
187
188
189
190
191
192
193 protected void populateItemAccountingLines(Map parameterMap) {
194 int itemCount = 0;
195 for (PurApItem item : ((PurchasingAccountsPayableDocument) getDocument()).getItems()) {
196 populateAccountingLine(item.getNewSourceLine(), OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.ITEM + "[" + itemCount + "]." + OLEPropertyConstants.NEW_SOURCE_LINE, parameterMap);
197
198 int sourceLineCount = 0;
199 for (PurApAccountingLine purApLine : item.getSourceAccountingLines()) {
200 populateAccountingLine(purApLine, OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.ITEM + "[" + itemCount + "]." + OLEPropertyConstants.SOURCE_ACCOUNTING_LINE + "[" + sourceLineCount + "]", parameterMap);
201 sourceLineCount += 1;
202 }
203 }
204 }
205
206
207
208
209
210
211
212 public boolean isReadOnlyAccountDistributionMethod() {
213 return readOnlyAccountDistributionMethod;
214 }
215
216
217
218
219
220
221
222 public void setReadOnlyAccountDistributionMethod(boolean readOnlyAccountDistributionMethod) {
223 this.readOnlyAccountDistributionMethod = readOnlyAccountDistributionMethod;
224 }
225 }