1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.gl.batch.ScrubberStep;
19 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
20 import org.kuali.ole.module.purap.businessobject.PurApItem;
21 import org.kuali.ole.sys.OLEConstants;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.ole.sys.document.validation.GenericValidation;
24 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25 import org.kuali.rice.core.api.datetime.DateTimeService;
26 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
27 import org.kuali.rice.kns.util.KNSGlobalVariables;
28
29 import java.util.Date;
30 import java.util.List;
31
32 public class InvoiceExpiredAccountWarningValidation extends GenericValidation {
33
34 private PurApItem itemForValidation;
35 private DateTimeService dateTimeService;
36 private ParameterService parameterService;
37
38 public boolean validate(AttributedDocumentEvent event) {
39 boolean valid = true;
40 List<PurApAccountingLine> accountingLines = itemForValidation.getSourceAccountingLines();
41 for (PurApAccountingLine accountingLine : accountingLines) {
42 if (accountingLine.getAccount().isExpired()) {
43 Date current = dateTimeService.getCurrentDate();
44 Date accountExpirationDate = accountingLine.getAccount().getAccountExpirationDate();
45 String expirationExtensionDays = parameterService.getParameterValueAsString(ScrubberStep.class, OLEConstants.SystemGroupParameterNames.GL_SCRUBBER_VALIDATION_DAYS_OFFSET);
46 int expirationExtensionDaysInt = 3 * 30;
47
48 if (expirationExtensionDays.trim().length() > 0) {
49
50 expirationExtensionDaysInt = new Integer(expirationExtensionDays).intValue();
51 }
52
53 if (!accountingLine.getAccount().isForContractsAndGrants() ||
54 dateTimeService.dateDiff(accountExpirationDate, current, false) < expirationExtensionDaysInt) {
55 KNSGlobalVariables.getMessageList().add(OLEKeyConstants.ERROR_ACCOUNT_EXPIRED);
56 valid &= false;
57 break;
58 }
59 }
60 }
61 return valid;
62 }
63
64 public DateTimeService getDateTimeService() {
65 return dateTimeService;
66 }
67
68 public void setDateTimeService(DateTimeService dateTimeService) {
69 this.dateTimeService = dateTimeService;
70 }
71
72 public PurApItem getItemForValidation() {
73 return itemForValidation;
74 }
75
76 public void setItemForValidation(PurApItem itemForValidation) {
77 this.itemForValidation = itemForValidation;
78 }
79
80 public ParameterService getParameterService() {
81 return parameterService;
82 }
83
84 public void setParameterService(ParameterService parameterService) {
85 this.parameterService = parameterService;
86 }
87
88 }