1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.dataaccess.impl;
17
18 import org.apache.log4j.Logger;
19 import org.apache.ojb.broker.query.Criteria;
20 import org.apache.ojb.broker.query.QueryByCriteria;
21 import org.apache.ojb.broker.query.ReportQueryByCriteria;
22 import org.kuali.ole.module.purap.PurapConstants;
23 import org.kuali.ole.module.purap.PurapPropertyConstants;
24 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
25 import org.kuali.ole.module.purap.document.dataaccess.PaymentRequestDao;
26 import org.kuali.ole.module.purap.util.VendorGroupingHelper;
27 import org.kuali.ole.sys.OLEPropertyConstants;
28 import org.kuali.rice.core.api.util.type.KualiDecimal;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30 import org.springframework.transaction.annotation.Transactional;
31
32 import java.sql.Date;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Collection;
36 import java.util.List;
37
38
39
40
41 @Transactional
42 public class PaymentRequestDaoOjb extends PlatformAwareDaoBaseOjb implements PaymentRequestDao {
43 private static Logger LOG = Logger.getLogger(PaymentRequestDaoOjb.class);
44
45
46
47
48
49
50
51
52
53 public List<PaymentRequestDocument> getPaymentRequestsToExtract(boolean onlySpecialPayments, String chartCode, Date onOrBeforePaymentRequestPayDate) {
54 LOG.debug("getPaymentRequestsToExtract() started");
55
56 Criteria criteria = new Criteria();
57 if (chartCode != null) {
58 criteria.addEqualTo("processingCampusCode", chartCode);
59 }
60
61 criteria.addIsNull("extractedTimestamp");
62 criteria.addEqualTo("holdIndicator", Boolean.FALSE);
63
64 if (onlySpecialPayments) {
65 Criteria a = new Criteria();
66
67 Criteria c1 = new Criteria();
68 c1.addNotNull("specialHandlingInstructionLine1Text");
69 Criteria c2 = new Criteria();
70 c2.addNotNull("specialHandlingInstructionLine2Text");
71 Criteria c3 = new Criteria();
72 c3.addNotNull("specialHandlingInstructionLine3Text");
73 Criteria c4 = new Criteria();
74 c4.addEqualTo("paymentAttachmentIndicator", Boolean.TRUE);
75
76 c1.addOrCriteria(c2);
77 c1.addOrCriteria(c3);
78 c1.addOrCriteria(c4);
79
80
81
82
83
84
85
86
87
88
89
90 criteria.addAndCriteria(c1);
91 }
92
93
94
95
96
97
98
99
100
101
102
103 return (List<PaymentRequestDocument>) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PaymentRequestDocument.class, criteria));
104 }
105
106
107
108
109 public List<PaymentRequestDocument> getImmediatePaymentRequestsToExtract(String chartCode) {
110 LOG.debug("getImmediatePaymentRequestsToExtract() started");
111
112 Criteria criteria = new Criteria();
113 if (chartCode != null) {
114 criteria.addEqualTo("processingCampusCode", chartCode);
115 }
116
117
118 criteria.addIsNull("extractedTimestamp");
119 criteria.addEqualTo("immediatePaymentIndicator", Boolean.TRUE);
120
121 return (List<PaymentRequestDocument>) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PaymentRequestDocument.class, criteria));
122 }
123
124
125
126
127
128 @Deprecated
129 public List<PaymentRequestDocument> getPaymentRequestsToExtract(String campusCode, Integer paymentRequestIdentifier, Integer purchaseOrderIdentifier, Integer vendorHeaderGeneratedIdentifier, Integer vendorDetailAssignedIdentifier, Date currentSqlDateMidnight) {
130 LOG.debug("getPaymentRequestsToExtract() started");
131
132 Criteria criteria = new Criteria();
133 criteria.addEqualTo("processingCampusCode", campusCode);
134
135 criteria.addIsNull("extractedTimestamp");
136 criteria.addEqualTo("holdIndicator", Boolean.FALSE);
137
138
139
140
141
142
143
144
145
146
147 if (paymentRequestIdentifier != null) {
148 criteria.addEqualTo("purapDocumentIdentifier", paymentRequestIdentifier);
149 }
150 if (purchaseOrderIdentifier != null) {
151 criteria.addEqualTo("purchaseOrderIdentifier", purchaseOrderIdentifier);
152 }
153 criteria.addEqualTo("vendorHeaderGeneratedIdentifier", vendorHeaderGeneratedIdentifier);
154 criteria.addEqualTo("vendorDetailAssignedIdentifier", vendorDetailAssignedIdentifier);
155
156 return (List<PaymentRequestDocument>) getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(PaymentRequestDocument.class, criteria));
157 }
158
159
160
161
162
163 public Collection<PaymentRequestDocument> getPaymentRequestsToExtractForVendor(String campusCode, VendorGroupingHelper vendor, Date onOrBeforePaymentRequestPayDate) {
164 LOG.debug("getPaymentRequestsToExtract() started");
165
166 Criteria criteria = new Criteria();
167 criteria.addEqualTo("processingCampusCode", campusCode);
168
169 criteria.addIsNull("extractedTimestamp");
170 criteria.addEqualTo("holdIndicator", Boolean.FALSE);
171
172
173
174
175
176
177
178
179
180
181
182 criteria.addEqualTo("vendorHeaderGeneratedIdentifier", vendor.getVendorHeaderGeneratedIdentifier());
183 criteria.addEqualTo("vendorDetailAssignedIdentifier", vendor.getVendorDetailAssignedIdentifier());
184 criteria.addEqualTo("vendorCountryCode", vendor.getVendorCountry());
185 criteria.addLike("vendorPostalCode", vendor.getVendorPostalCode() + "%");
186
187 return getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PaymentRequestDocument.class, criteria));
188 }
189
190
191
192
193 public List<String> getEligibleForAutoApproval(Date todayAtMidnight) {
194
195 Criteria criteria = new Criteria();
196 criteria.addLessOrEqualThan(PurapPropertyConstants.PAYMENT_REQUEST_PAY_DATE, todayAtMidnight);
197 criteria.addNotEqualTo("holdIndicator", "Y");
198 criteria.addNotEqualTo("paymentRequestedCancelIndicator", "Y");
199
200 List<String> returnList = getDocumentNumbersOfPaymentRequestByCriteria(criteria, false);
201
202 return returnList;
203 }
204
205
206
207
208 public List<String> getEligibleForAutoApproval() {
209
210 Criteria criteria = new Criteria();
211 criteria.addNotEqualTo("holdIndicator", "Y");
212 criteria.addNotEqualTo("paymentRequestedCancelIndicator", "Y");
213
214 List<String> returnList = getDocumentNumbersOfPaymentRequestByCriteria(criteria, false);
215
216 return returnList;
217 }
218
219
220
221
222
223 public String getDocumentNumberByPaymentRequestId(Integer id) {
224 Criteria criteria = new Criteria();
225 criteria.addEqualTo(PurapPropertyConstants.PURAP_DOC_ID, id);
226 return getDocumentNumberOfPaymentRequestByCriteria(criteria);
227 }
228
229
230
231
232 public List<String> getDocumentNumbersByPurchaseOrderId(Integer poPurApId) {
233 List<String> returnList = new ArrayList<String>();
234 Criteria criteria = new Criteria();
235 criteria.addEqualTo(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, poPurApId);
236 returnList = getDocumentNumbersOfPaymentRequestByCriteria(criteria, false);
237
238 return returnList;
239 }
240
241
242
243
244
245
246
247 protected String getDocumentNumberOfPaymentRequestByCriteria(Criteria criteria) {
248 LOG.debug("getDocumentNumberOfPaymentRequestByCriteria() started");
249 List<String> returnList = getDocumentNumbersOfPaymentRequestByCriteria(criteria, false);
250
251 if (returnList.isEmpty()) {
252 return null;
253 }
254
255 if (returnList.size() > 1) {
256
257 String errorMsg = "Expected single document number for given criteria but multiple (at least 2) were returned";
258 LOG.error(errorMsg);
259 throw new RuntimeException();
260
261 } else {
262 return (returnList.get(0));
263 }
264 }
265
266
267
268
269
270
271
272
273
274 protected List<String> getDocumentNumbersOfPaymentRequestByCriteria(Criteria criteria, boolean orderByAscending) {
275 LOG.debug("getDocumentNumberOfPaymentRequestByCriteria() started");
276 ReportQueryByCriteria rqbc = new ReportQueryByCriteria(PaymentRequestDocument.class, criteria);
277 if (orderByAscending) {
278 rqbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER);
279 } else {
280 rqbc.addOrderByDescending(OLEPropertyConstants.DOCUMENT_NUMBER);
281 }
282
283 List<String> returnList = new ArrayList<String>();
284
285 List<PaymentRequestDocument> prDocs = (List<PaymentRequestDocument>) getPersistenceBrokerTemplate().getCollectionByQuery(rqbc);
286 for (PaymentRequestDocument prDoc : prDocs) {
287 returnList.add(prDoc.getDocumentNumber());
288 }
289
290 return returnList;
291 }
292
293
294
295
296
297
298
299 protected List<PaymentRequestDocument> getPaymentRequestsByQueryByCriteria(QueryByCriteria qbc) {
300 LOG.debug("getPaymentRequestsByQueryByCriteria() started");
301 return (List<PaymentRequestDocument>) getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
302 }
303
304
305
306
307
308
309
310
311
312 public List<PaymentRequestDocument> getActivePaymentRequestsByVendorNumberInvoiceNumber(Integer vendorHeaderGeneratedId, Integer vendorDetailAssignedId, String invoiceNumber) {
313 LOG.debug("getActivePaymentRequestsByVendorNumberInvoiceNumber() started");
314 Criteria criteria = new Criteria();
315 criteria.addEqualTo("vendorHeaderGeneratedIdentifier", vendorHeaderGeneratedId);
316 criteria.addEqualTo("vendorDetailAssignedIdentifier", vendorDetailAssignedId);
317 criteria.addEqualTo("invoiceNumber", invoiceNumber);
318 QueryByCriteria qbc = new QueryByCriteria(PaymentRequestDocument.class, criteria);
319 return this.getPaymentRequestsByQueryByCriteria(qbc);
320 }
321
322
323
324
325
326
327
328
329
330 public List<PaymentRequestDocument> getActivePaymentRequestsByVendorNumber(Integer vendorHeaderGeneratedId, Integer vendorDetailAssignedId) {
331 LOG.debug("getActivePaymentRequestsByVendorNumber started");
332 Criteria criteria = new Criteria();
333 criteria.addEqualTo("vendorHeaderGeneratedIdentifier", vendorHeaderGeneratedId);
334 criteria.addEqualTo("vendorDetailAssignedIdentifier", vendorDetailAssignedId);
335 QueryByCriteria qbc = new QueryByCriteria(PaymentRequestDocument.class, criteria);
336 return this.getPaymentRequestsByQueryByCriteria(qbc);
337 }
338
339
340
341
342
343
344 public List<PaymentRequestDocument> getActivePaymentRequestsByPOIdInvoiceAmountInvoiceDate(Integer poId, KualiDecimal vendorInvoiceAmount, Date invoiceDate) {
345 LOG.debug("getActivePaymentRequestsByVendorNumberInvoiceNumber() started");
346 Criteria criteria = new Criteria();
347 criteria.addEqualTo("purchaseOrderIdentifier", poId);
348 criteria.addEqualTo("vendorInvoiceAmount", vendorInvoiceAmount);
349 criteria.addEqualTo("invoiceDate", invoiceDate);
350 QueryByCriteria qbc = new QueryByCriteria(PaymentRequestDocument.class, criteria);
351 return this.getPaymentRequestsByQueryByCriteria(qbc);
352 }
353
354 public List<String> getActivePaymentRequestDocumentNumbersForPurchaseOrder(Integer purchaseOrderId) {
355 LOG.debug("getActivePaymentRequestsByVendorNumberInvoiceNumber() started");
356
357 List<String> returnList = new ArrayList<String>();
358 Criteria criteria = new Criteria();
359
360 criteria.addEqualTo(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, purchaseOrderId);
361 returnList = getDocumentNumbersOfPaymentRequestByCriteria(criteria, false);
362
363 return returnList;
364 }
365
366 public List<String> getPaymentRequestInReceivingStatus() {
367 Criteria criteria = new Criteria();
368 criteria.addNotEqualTo("holdIndicator", "Y");
369 criteria.addNotEqualTo("paymentRequestedCancelIndicator", "Y");
370
371 List<String> returnList = new ArrayList<String>();
372 returnList = getDocumentNumbersOfPaymentRequestByCriteria(criteria, false);
373
374 return returnList;
375
376 }
377 }
378