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.apache.struts.upload.FormFile;
19 import org.kuali.ole.integration.purap.CapitalAssetLocation;
20 import org.kuali.ole.module.purap.PurapConstants;
21 import org.kuali.ole.module.purap.PurapParameterConstants;
22 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
23 import org.kuali.ole.module.purap.businessobject.PurApAccountingLineBase;
24 import org.kuali.ole.module.purap.businessobject.PurApItem;
25 import org.kuali.ole.module.purap.document.PurchasingDocument;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.ole.sys.businessobject.AccountingLine;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.ole.sys.service.impl.OleParameterConstants;
30 import org.kuali.rice.core.api.config.property.ConfigurationService;
31 import org.kuali.rice.core.web.format.PhoneNumberFormatter;
32 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
33 import org.kuali.rice.kns.web.ui.ExtraButton;
34 import org.kuali.rice.krad.util.KRADConstants;
35
36 import java.math.BigDecimal;
37 import java.util.ArrayList;
38 import java.util.List;
39 import java.util.Map;
40
41
42
43
44 public abstract class PurchasingFormBase extends PurchasingAccountsPayableFormBase {
45
46 protected Boolean notOtherDeliveryBuilding = true;
47 protected Boolean hideDistributeAccounts = true;
48 protected PurApItem newPurchasingItemLine;
49 protected FormFile itemImportFile;
50 protected String distributePurchasingCommodityCode;
51 protected String distributePurchasingCommodityDescription;
52 protected boolean calculated;
53
54 protected String initialZipCode;
55
56
57
58 protected Integer accountDistributionnextSourceLineNumber;
59 protected List<PurApAccountingLine> accountDistributionsourceAccountingLines;
60 protected PurApAccountingLine accountDistributionnewSourceLine;
61
62 protected CapitalAssetLocation newPurchasingCapitalAssetLocationLine;
63
64 protected BigDecimal totalPercentageOfAccountDistributionsourceAccountingLines;
65
66 protected String locationBuildingFromLookup;
67 protected String locationCampusFromLookup;
68
69
70
71
72 public PurchasingFormBase() {
73 super();
74 this.setNewPurchasingItemLine(setupNewPurchasingItemLine());
75 newPurchasingItemLine.setItemTypeCode("ITEM");
76
77 this.accountDistributionnextSourceLineNumber = new Integer(1);
78 setAccountDistributionsourceAccountingLines(new ArrayList());
79 this.setAccountDistributionnewSourceLine(setupNewAccountDistributionAccountingLine());
80
81 this.setNewPurchasingCapitalAssetLocationLine(this.setupNewPurchasingCapitalAssetLocationLine());
82
83 setFormatterType("document.vendorFaxNumber", PhoneNumberFormatter.class);
84
85 calculated = false;
86 }
87
88
89 public Boolean getNotOtherDeliveryBuilding() {
90 return notOtherDeliveryBuilding;
91 }
92
93 public void setNotOtherDeliveryBuilding(Boolean notOtherDeliveryBuilding) {
94 this.notOtherDeliveryBuilding = notOtherDeliveryBuilding;
95 }
96
97 public Boolean getHideDistributeAccounts() {
98 return hideDistributeAccounts;
99 }
100
101 public void setHideDistributeAccounts(Boolean hideDistributeAccounts) {
102 this.hideDistributeAccounts = hideDistributeAccounts;
103 }
104
105 public Integer getAccountDistributionnextSourceLineNumber() {
106 return accountDistributionnextSourceLineNumber;
107 }
108
109 public void setAccountDistributionnextSourceLineNumber(Integer accountDistributionnextSourceLineNumber) {
110 this.accountDistributionnextSourceLineNumber = accountDistributionnextSourceLineNumber;
111 }
112
113 public List<PurApAccountingLine> getAccountDistributionsourceAccountingLines() {
114 return accountDistributionsourceAccountingLines;
115 }
116
117 public void setAccountDistributionsourceAccountingLines(List<PurApAccountingLine> accountDistributionAccountingLines) {
118 this.accountDistributionsourceAccountingLines = accountDistributionAccountingLines;
119 }
120
121 public BigDecimal getTotalPercentageOfAccountDistributionsourceAccountingLines() {
122 this.totalPercentageOfAccountDistributionsourceAccountingLines = new BigDecimal(0);
123 for (PurApAccountingLine line : this.getAccountDistributionsourceAccountingLines()) {
124 if (line.getAccountLinePercent() != null) {
125 setTotalPercentageOfAccountDistributionsourceAccountingLines(this.totalPercentageOfAccountDistributionsourceAccountingLines.add(line.getAccountLinePercent()));
126 }
127 }
128 return this.totalPercentageOfAccountDistributionsourceAccountingLines;
129 }
130
131 public void setTotalPercentageOfAccountDistributionsourceAccountingLines(BigDecimal total) {
132 this.totalPercentageOfAccountDistributionsourceAccountingLines = total;
133 }
134
135 public PurApAccountingLine getAccountDistributionnewSourceLine() {
136 return accountDistributionnewSourceLine;
137 }
138
139 public void setAccountDistributionnewSourceLine(PurApAccountingLine accountDistributionnewSourceLine) {
140 this.accountDistributionnewSourceLine = accountDistributionnewSourceLine;
141 }
142
143 public PurApItem getNewPurchasingItemLine() {
144 return newPurchasingItemLine;
145 }
146
147 public void setNewPurchasingItemLine(PurApItem newPurchasingItemLine) {
148 this.newPurchasingItemLine = newPurchasingItemLine;
149 }
150
151 public FormFile getItemImportFile() {
152 return itemImportFile;
153 }
154
155 public void setItemImportFile(FormFile itemImportFile) {
156 this.itemImportFile = itemImportFile;
157 }
158
159
160
161
162
163
164
165 public PurApAccountingLine getAccountDistributionsourceAccountingLine(int index) {
166 while (accountDistributionsourceAccountingLines.size() <= index) {
167 accountDistributionsourceAccountingLines.add(setupNewAccountDistributionAccountingLine());
168 }
169 return accountDistributionsourceAccountingLines.get(index);
170 }
171
172
173
174
175
176
177 public PurApItem getAndResetNewPurchasingItemLine() {
178 PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
179 setNewPurchasingItemLine(setupNewPurchasingItemLine());
180 return aPurchasingItemLine;
181 }
182
183
184
185
186 public PurApItem setupNewPurchasingItemLine() {
187 return null;
188 }
189
190
191
192
193 public PurApAccountingLineBase setupNewPurchasingAccountingLine() {
194 return null;
195 }
196
197
198
199
200 public PurApAccountingLineBase setupNewAccountDistributionAccountingLine() {
201 return null;
202 }
203
204
205
206
207
208
209
210
211
212 public void addAccountDistributionsourceAccountingLine(PurApAccountingLine line) {
213 line.setSequenceNumber(this.getAccountDistributionnextSourceLineNumber());
214 this.accountDistributionsourceAccountingLines.add(line);
215 this.accountDistributionnextSourceLineNumber = new Integer(this.getAccountDistributionnextSourceLineNumber().intValue() + 1);
216 this.setAccountDistributionnewSourceLine(setupNewAccountDistributionAccountingLine());
217 }
218
219 public String getDistributePurchasingCommodityCode() {
220 return distributePurchasingCommodityCode;
221 }
222
223 public void setDistributePurchasingCommodityCode(String distributePurchasingCommodityCode) {
224 this.distributePurchasingCommodityCode = distributePurchasingCommodityCode;
225 }
226
227 public String getDistributePurchasingCommodityDescription() {
228 return distributePurchasingCommodityDescription;
229 }
230
231 public void setDistributePurchasingCommodityDescription(String distributePurchasingCommodityDescription) {
232 this.distributePurchasingCommodityDescription = distributePurchasingCommodityDescription;
233 }
234
235 public Class getItemCapitalAssetClass() {
236 return null;
237 }
238
239 public Class getCapitalAssetLocationClass() {
240 return null;
241 }
242
243
244
245
246 public CapitalAssetLocation setupNewPurchasingCapitalAssetLocationLine() {
247 CapitalAssetLocation location = null;
248 try {
249 location = (CapitalAssetLocation) getCapitalAssetLocationClass().newInstance();
250 } catch (InstantiationException e) {
251 throw new RuntimeException("Unable to get class");
252 } catch (IllegalAccessException e) {
253 throw new RuntimeException("Unable to get class");
254 } catch (NullPointerException e) {
255 throw new RuntimeException("Can't instantiate Purchasing Account from base");
256 }
257
258 return location;
259 }
260
261 public void setNewPurchasingCapitalAssetLocationLine(CapitalAssetLocation newCapitalAssetLocationLine) {
262 this.newPurchasingCapitalAssetLocationLine = newCapitalAssetLocationLine;
263 }
264
265 public CapitalAssetLocation getNewPurchasingCapitalAssetLocationLine() {
266 return newPurchasingCapitalAssetLocationLine;
267 }
268
269 public CapitalAssetLocation getAndResetNewPurchasingCapitalAssetLocationLine() {
270 CapitalAssetLocation assetLocation = getNewPurchasingCapitalAssetLocationLine();
271 setNewPurchasingCapitalAssetLocationLine(setupNewPurchasingCapitalAssetLocationLine());
272 return assetLocation;
273 }
274
275 public void resetNewPurchasingCapitalAssetLocationLine() {
276 setNewPurchasingCapitalAssetLocationLine(setupNewPurchasingCapitalAssetLocationLine());
277 }
278
279
280 public String getPurchasingItemCapitalAssetAvailability() {
281 String availability = PurapConstants.CapitalAssetAvailability.NONE;
282 PurchasingDocument pd = (PurchasingDocument) this.getDocument();
283
284 if ((PurapConstants.CapitalAssetSystemTypes.ONE_SYSTEM.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.MODIFY.equals(pd.getCapitalAssetSystemStateCode())) ||
285 (PurapConstants.CapitalAssetSystemTypes.MULTIPLE.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.MODIFY.equals(pd.getCapitalAssetSystemStateCode()))) {
286
287 availability = PurapConstants.CapitalAssetAvailability.ONCE;
288
289 } else if ((PurapConstants.CapitalAssetSystemTypes.INDIVIDUAL.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.MODIFY.equals(pd.getCapitalAssetSystemStateCode()))) {
290
291 availability = PurapConstants.CapitalAssetAvailability.EACH;
292
293 }
294
295 return availability;
296 }
297
298 public String getPurchasingCapitalAssetSystemAvailability() {
299 String availability = PurapConstants.CapitalAssetAvailability.NONE;
300 PurchasingDocument pd = (PurchasingDocument) this.getDocument();
301
302 if ((PurapConstants.CapitalAssetSystemTypes.ONE_SYSTEM.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.NEW.equals(pd.getCapitalAssetSystemStateCode()))) {
303
304 availability = PurapConstants.CapitalAssetAvailability.ONCE;
305
306 } else if ((PurapConstants.CapitalAssetSystemTypes.INDIVIDUAL.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.NEW.equals(pd.getCapitalAssetSystemStateCode()))) {
307
308 availability = PurapConstants.CapitalAssetAvailability.EACH;
309
310 }
311
312 return availability;
313 }
314
315 public String getPurchasingCapitalAssetSystemCommentsAvailability() {
316 String availability = PurapConstants.CapitalAssetAvailability.NONE;
317 PurchasingDocument pd = (PurchasingDocument) this.getDocument();
318
319 if ((PurapConstants.CapitalAssetSystemTypes.ONE_SYSTEM.equals(pd.getCapitalAssetSystemTypeCode()) || PurapConstants.CapitalAssetSystemTypes.MULTIPLE.equals(pd.getCapitalAssetSystemTypeCode()))) {
320
321 availability = PurapConstants.CapitalAssetAvailability.ONCE;
322
323 } else if (PurapConstants.CapitalAssetSystemTypes.INDIVIDUAL.equals(pd.getCapitalAssetSystemTypeCode())) {
324
325 availability = PurapConstants.CapitalAssetAvailability.EACH;
326
327 }
328
329 return availability;
330 }
331
332 public String getPurchasingCapitalAssetSystemDescriptionAvailability() {
333 String availability = PurapConstants.CapitalAssetAvailability.NONE;
334 PurchasingDocument pd = (PurchasingDocument) this.getDocument();
335
336 if ((PurapConstants.CapitalAssetSystemTypes.ONE_SYSTEM.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.NEW.equals(pd.getCapitalAssetSystemStateCode())) ||
337 (PurapConstants.CapitalAssetSystemTypes.MULTIPLE.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.NEW.equals(pd.getCapitalAssetSystemStateCode()))) {
338
339 availability = PurapConstants.CapitalAssetAvailability.ONCE;
340
341 }
342
343 return availability;
344 }
345
346 public String getPurchasingCapitalAssetLocationAvailability() {
347 String availability = PurapConstants.CapitalAssetAvailability.NONE;
348 PurchasingDocument pd = (PurchasingDocument) this.getDocument();
349
350 if ((PurapConstants.CapitalAssetSystemTypes.ONE_SYSTEM.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.NEW.equals(pd.getCapitalAssetSystemStateCode()))) {
351 availability = PurapConstants.CapitalAssetAvailability.ONCE;
352 } else if ((PurapConstants.CapitalAssetSystemTypes.INDIVIDUAL.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.NEW.equals(pd.getCapitalAssetSystemStateCode()))) {
353 availability = PurapConstants.CapitalAssetAvailability.EACH;
354 }
355
356 return availability;
357 }
358
359 public String getPurchasingCapitalAssetCountAssetNumberAvailability() {
360 String availability = PurapConstants.CapitalAssetAvailability.NONE;
361 PurchasingDocument pd = (PurchasingDocument) this.getDocument();
362
363 if ((PurapConstants.CapitalAssetSystemTypes.ONE_SYSTEM.equals(pd.getCapitalAssetSystemTypeCode()) && PurapConstants.CapitalAssetSystemStates.NEW.equals(pd.getCapitalAssetSystemStateCode()))) {
364 availability = PurapConstants.CapitalAssetAvailability.ONCE;
365 }
366
367 return availability;
368 }
369
370
371
372
373
374
375
376 @Override
377 public List<ExtraButton> getExtraButtons() {
378 extraButtons.clear();
379
380 String appExternalImageURL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY);
381
382
383 if (canUserCalculate()) {
384 addExtraButton("methodToCall.calculate", appExternalImageURL + "buttonsmall_calculate.gif", "Calculate");
385 }
386
387 return extraButtons;
388 }
389
390 public String getLocationBuildingFromLookup() {
391 return locationBuildingFromLookup;
392 }
393
394 public void setLocationBuildingFromLookup(String locationBuildingFromLookup) {
395 this.locationBuildingFromLookup = locationBuildingFromLookup;
396 }
397
398 public String getLocationCampusFromLookup() {
399 return locationCampusFromLookup;
400 }
401
402 public void setLocationCampusFromLookup(String locationCampusFromLookup) {
403 this.locationCampusFromLookup = locationCampusFromLookup;
404 }
405
406 public String getInitialZipCode() {
407 return initialZipCode;
408 }
409
410 public void setInitialZipCode(String initialZipCode) {
411 this.initialZipCode = initialZipCode;
412 }
413
414 public boolean isCalculated() {
415 return calculated;
416 }
417
418 public void setCalculated(boolean calculated) {
419 this.calculated = calculated;
420 }
421
422 public boolean canUserCalculate() {
423 return documentActions != null && documentActions.containsKey(KRADConstants.KUALI_ACTION_CAN_EDIT);
424 }
425
426
427
428
429
430 @Override
431 protected void repopulateOverrides(AccountingLine line, String accountingLinePropertyName, Map parameterMap) {
432
433 }
434
435
436
437
438 public String getLineItemImportInstructionsUrl() {
439 return SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.EXTERNALIZABLE_HELP_URL_KEY) + SpringContext.getBean(ParameterService.class).getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.LINE_ITEM_IMPORT);
440 }
441 }