1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.businessobject.lookup;
17
18 import java.sql.Date;
19 import java.util.Collection;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.commons.lang.StringUtils;
25 import org.kuali.ole.gl.Constant;
26 import org.kuali.ole.gl.businessobject.Entry;
27 import org.kuali.ole.gl.businessobject.inquiry.EntryInquirableImpl;
28 import org.kuali.ole.gl.businessobject.inquiry.InquirableFinancialDocument;
29 import org.kuali.ole.gl.service.EntryService;
30 import org.kuali.ole.gl.service.ScrubberValidator;
31 import org.kuali.ole.sys.OLEConstants;
32 import org.kuali.ole.sys.OLEKeyConstants;
33 import org.kuali.ole.sys.OLEPropertyConstants;
34 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
35 import org.kuali.ole.sys.businessobject.UniversityDate;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.ole.sys.service.UniversityDateService;
38 import org.kuali.rice.core.api.datetime.DateTimeService;
39 import org.kuali.rice.kns.lookup.HtmlData;
40 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
41 import org.kuali.rice.krad.bo.BusinessObject;
42 import org.kuali.rice.krad.exception.ValidationException;
43 import org.kuali.rice.krad.util.GlobalVariables;
44 import org.kuali.rice.krad.util.KRADConstants;
45
46
47
48
49 public class EntryLookupableHelperServiceImpl extends AbstractGeneralLedgerLookupableHelperServiceImpl {
50 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EntryLookupableHelperServiceImpl.class);
51
52 private ScrubberValidator scrubberValidator;
53 private EntryService entryService;
54
55
56
57
58
59
60
61 @Override
62 public void validateSearchParameters(Map fieldValues) {
63 super.validateSearchParameters(fieldValues);
64
65 String valueFiscalYear = (String) fieldValues.get("universityFiscalYear");
66 if (!StringUtils.isEmpty(valueFiscalYear)) {
67 try {
68 int year = Integer.parseInt(valueFiscalYear);
69 }
70 catch (NumberFormatException e) {
71 GlobalVariables.getMessageMap().putError("universityFiscalYear", OLEKeyConstants.ERROR_CUSTOM, new String[] { "Fiscal Year must be a four-digit number" });
72 throw new ValidationException("errors in search criteria");
73 }
74 }
75
76 if (!allRequiredsForAccountSearch(fieldValues) && !allRequiredsForDocumentSearch(fieldValues)) {
77 GlobalVariables.getMessageMap().putError("universityFiscalYear", OLEKeyConstants.ERROR_GL_LOOKUP_ENTRY_NON_MATCHING_REQUIRED_FIELDS, new String[] {});
78 throw new ValidationException("errors in search criteria");
79 }
80 }
81
82
83
84
85
86
87 protected boolean allRequiredsForAccountSearch(Map fieldValues) {
88 final String fiscalYearAsString = (String)fieldValues.get("universityFiscalYear");
89 final String chartOfAccountsCode = (String)fieldValues.get("chartOfAccountsCode");
90 final String accountNumber = (String)fieldValues.get("accountNumber");
91 final String fiscalPeriodCode = (String)fieldValues.get("universityFiscalPeriodCode");
92 return !StringUtils.isBlank(fiscalYearAsString) && !StringUtils.isBlank(chartOfAccountsCode) && !StringUtils.isBlank(accountNumber) && !StringUtils.isBlank(fiscalPeriodCode);
93 }
94
95
96
97
98
99
100 protected boolean allRequiredsForDocumentSearch(Map fieldValues) {
101 final String fiscalYearAsString = (String)fieldValues.get("universityFiscalYear");
102 final String documentNumber = (String)fieldValues.get("documentNumber");
103 return !StringUtils.isBlank(fiscalYearAsString) && !StringUtils.isBlank(documentNumber);
104 }
105
106
107
108
109
110
111
112
113 @Override
114 public HtmlData getInquiryUrl(BusinessObject businessObject, String propertyName) {
115 if (OLEPropertyConstants.DOCUMENT_NUMBER.equals(propertyName)) {
116 if (businessObject instanceof Entry) {
117 Entry entry = (Entry) businessObject;
118 return new AnchorHtmlData(new InquirableFinancialDocument().getInquirableDocumentUrl(entry), KRADConstants.EMPTY_STRING, "view entry "+entry.toString());
119 }
120 }
121 return (new EntryInquirableImpl()).getInquiryUrl(businessObject, propertyName);
122 }
123
124
125
126
127
128
129
130 @Override
131 public List getSearchResults(Map fieldValues) {
132 setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION));
133 setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY));
134
135
136 String pendingEntryOption = this.getSelectedPendingEntryOption(fieldValues);
137
138 String debitCreditOption = this.getDebitCreditOption(fieldValues);
139
140
141 Collection searchResultsCollection = getLookupService().findCollectionBySearch(getBusinessObjectClass(), fieldValues);
142
143
144 updateByPendingLedgerEntry(searchResultsCollection, fieldValues, pendingEntryOption, false, false);
145
146
147 Long actualSize = new Long(entryService.getEntryRecordCount(fieldValues));
148
149 return this.buildSearchResultList(searchResultsCollection, actualSize);
150 }
151
152
153
154
155
156
157
158
159
160
161
162
163 @Override
164 protected void updateEntryCollection(Collection entryCollection, Map fieldValues, boolean isApproved, boolean isConsolidated, boolean isCostShareInclusive) {
165 LOG.debug("updateEntryCollection started");
166
167
168 Map pendingEntryFieldValues = BusinessObjectFieldConverter.convertToTransactionFieldValues(fieldValues);
169
170
171 Iterator pendingEntryIterator = getGeneralLedgerPendingEntryService().findPendingLedgerEntriesForEntry(pendingEntryFieldValues, isApproved);
172
173 String pendingOption = isApproved ? Constant.APPROVED_PENDING_ENTRY : Constant.ALL_PENDING_ENTRY;
174 UniversityDate today = SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate();
175 String currentFiscalPeriodCode = today.getUniversityFiscalAccountingPeriod();
176 Integer currentFiscalYear = today.getUniversityFiscalYear();
177 Date postDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
178
179 while (pendingEntryIterator.hasNext()) {
180 GeneralLedgerPendingEntry pendingEntry = (GeneralLedgerPendingEntry) pendingEntryIterator.next();
181
182
183 if (pendingEntry.getUniversityFiscalYear() == null) {
184 pendingEntry.setUniversityFiscalYear(currentFiscalYear);
185 }
186
187 if (pendingEntry.getUniversityFiscalPeriodCode() == null) {
188 pendingEntry.setUniversityFiscalPeriodCode(currentFiscalPeriodCode);
189 }
190
191 scrubberValidator.validateForInquiry(pendingEntry);
192
193 Entry entry = new Entry(pendingEntry, postDate);
194
195 String approvedCode = pendingEntry.getFinancialDocumentApprovedCode();
196 String description = Constant.DocumentApprovedCode.getDescription(approvedCode);
197 entry.getDummyBusinessObject().setPendingEntryOption(description);
198
199 entryCollection.add(entry);
200 }
201 }
202
203
204
205
206
207
208 public void setScrubberValidator(ScrubberValidator scrubberValidator) {
209 this.scrubberValidator = scrubberValidator;
210 }
211
212
213
214
215
216
217 public void setEntryService(EntryService entryService) {
218 this.entryService = entryService;
219 }
220 }