001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * Created on Aug 7, 2004
018: *
019: */
020: package org.kuali.module.pdp.dao.ojb;
021:
022: import java.math.BigDecimal;
023: import java.sql.Timestamp;
024: import java.util.ArrayList;
025: import java.util.Calendar;
026: import java.util.GregorianCalendar;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: import org.apache.ojb.broker.query.Criteria;
031: import org.apache.ojb.broker.query.QueryByCriteria;
032: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
033: import org.kuali.core.exceptions.UserNotFoundException;
034: import org.kuali.core.service.UniversalUserService;
035: import org.kuali.module.pdp.bo.Batch;
036: import org.kuali.module.pdp.bo.PaymentDetail;
037: import org.kuali.module.pdp.bo.PaymentDetailSearch;
038: import org.kuali.module.pdp.bo.PaymentGroupHistory;
039: import org.kuali.module.pdp.bo.PaymentProcess;
040: import org.kuali.module.pdp.bo.UserRequired;
041: import org.kuali.module.pdp.dao.PaymentDetailSearchDao;
042: import org.kuali.module.pdp.utilities.GeneralUtilities;
043:
044: /**
045: * @author jsissom
046: */
047: public class PaymentDetailSearchDaoOjb extends PlatformAwareDaoBaseOjb
048: implements PaymentDetailSearchDao {
049: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
050: .getLogger(PaymentDetailSearchDaoOjb.class);
051: private UniversalUserService userService;
052:
053: // TODO hard code
054: private static String HELD_TAX_ALL = "HTXA";
055:
056: public PaymentDetailSearchDaoOjb() {
057: super ();
058: }
059:
060: public void setUniversalUserService(UniversalUserService us) {
061: userService = us;
062: }
063:
064: public List getAllPaymentsForSearchCriteria(
065: PaymentDetailSearch pds, int pdsl) {
066: LOG
067: .info("getAllPaymentsForSearchCriteria(PaymentDetailSearch) starting");
068: Criteria criteria = new Criteria();
069:
070: if ((!(pds.getCustPaymentDocNbr() == null))
071: && (!(pds.getCustPaymentDocNbr().equals("")))) {
072: criteria.addLike("custPaymentDocNbr", "%"
073: + pds.getCustPaymentDocNbr() + "%");
074: }
075: if ((!(pds.getInvoiceNbr() == null))
076: && (!(pds.getInvoiceNbr().equals("")))) {
077: criteria.addLike("invoiceNbr", "%" + pds.getInvoiceNbr()
078: + "%");
079: }
080: if ((!(pds.getRequisitionNbr() == null))
081: && (!(pds.getRequisitionNbr().equals("")))) {
082: criteria.addLike("requisitionNbr", "%"
083: + pds.getRequisitionNbr() + "%");
084: }
085: if ((!(pds.getPurchaseOrderNbr() == null))
086: && (!(pds.getPurchaseOrderNbr().equals("")))) {
087: criteria.addLike("purchaseOrderNbr", "%"
088: + pds.getPurchaseOrderNbr() + "%");
089: }
090: if ((!(pds.getCustomerInstitutionNumber() == null))
091: && (!(pds.getCustomerInstitutionNumber().equals("")))) {
092: criteria.addLike("paymentGroup.customerInstitutionNumber",
093: "%" + pds.getCustomerInstitutionNumber() + "%");
094: }
095: if ((!(pds.getPayeeName() == null))
096: && (!(pds.getPayeeName().equals("")))) {
097: criteria.addLike("paymentGroup.payeeName", "%"
098: + pds.getPayeeName().toUpperCase() + "%");
099: }
100: if ((!(pds.getPayeeId() == null))
101: && (!(pds.getPayeeId().equals("")))) {
102: criteria.addEqualTo("paymentGroup.payeeId", pds
103: .getPayeeId());
104: }
105: if ((!(pds.getPayeeIdTypeCd() == null))
106: && (!(pds.getPayeeIdTypeCd().equals("")))) {
107: criteria.addLike("paymentGroup.payeeIdTypeCd", "%"
108: + pds.getPayeeIdTypeCd() + "%");
109: }
110: if (!(GeneralUtilities.isStringEmpty(pds.getPymtAttachment()))) {
111: criteria.addLike("paymentGroup.pymtAttachment", "%"
112: + pds.getPymtAttachment() + "%");
113: }
114: if (!(GeneralUtilities.isStringEmpty(pds
115: .getPymtSpecialHandling()))) {
116: criteria.addLike("paymentGroup.pymtSpecialHandling", "%"
117: + pds.getPymtSpecialHandling() + "%");
118: }
119: if (!(GeneralUtilities.isStringEmpty(pds.getProcessImmediate()))) {
120: criteria.addLike("paymentGroup.processImmediate", "%"
121: + pds.getProcessImmediate() + "%");
122: }
123: if ((!(pds.getDisbursementNbr() == null))
124: && (!(pds.getDisbursementNbr() == new Integer(0)))) {
125: criteria.addEqualTo("paymentGroup.disbursementNbr", pds
126: .getDisbursementNbr());
127: }
128: if ((!(pds.getProcessId() == null))
129: && (!(pds.getProcessId() == new Integer(0)))) {
130: criteria.addEqualTo("paymentGroup.process.id", pds
131: .getProcessId());
132: }
133: if ((!(pds.getPaymentId() == null))
134: && (!(pds.getPaymentId() == new Integer(0)))) {
135: criteria.addEqualTo("id", pds.getPaymentId());
136: }
137: if ((!(pds.getNetPaymentAmount() == null))
138: && (!(pds.getNetPaymentAmount() == new BigDecimal(0.00)))) {
139: criteria.addEqualTo("netPaymentAmount", pds
140: .getNetPaymentAmount());
141: }
142: if (!(pds.getBeginDisbursementDate() == null)) {
143: criteria.addGreaterOrEqualThan(
144: "paymentGroup.disbursementDate", pds
145: .getBeginDisbursementDate());
146: }
147: if (!(pds.getEndDisbursementDate() == null)) {
148: GregorianCalendar gc = new GregorianCalendar();
149: gc.setTime(pds.getEndDisbursementDate());
150: gc.add(Calendar.DATE, 1);
151: criteria.addLessOrEqualThan(
152: "paymentGroup.disbursementDate", new Timestamp(gc
153: .getTimeInMillis()));
154: }
155: if (!(pds.getBeginPaymentDate() == null)) {
156: criteria.addGreaterOrEqualThan("paymentGroup.paymentDate",
157: pds.getBeginPaymentDate());
158: }
159: if (!(pds.getEndPaymentDate() == null)) {
160: GregorianCalendar gc = new GregorianCalendar();
161: gc.setTime(pds.getEndPaymentDate());
162: gc.add(Calendar.DATE, 1);
163: criteria.addLessOrEqualThan("paymentGroup.paymentDate",
164: new Timestamp(gc.getTimeInMillis()));
165: }
166: if ((!(pds.getPaymentStatusCode() == null))
167: && (!(pds.getPaymentStatusCode().equals("")))) {
168: if (HELD_TAX_ALL.equals(pds.getPaymentStatusCode())) {
169: criteria.addLike("paymentGroup.paymentStatus.code",
170: "HTX%");
171: } else {
172: criteria.addEqualTo("paymentGroup.paymentStatus.code",
173: pds.getPaymentStatusCode());
174: }
175: }
176: if ((!(pds.getDisbursementTypeCode() == null))
177: && (!(pds.getDisbursementTypeCode().equals("")))) {
178: criteria.addEqualTo("paymentGroup.disbursementType.code",
179: pds.getDisbursementTypeCode());
180: }
181: if ((!(pds.getChartCode() == null))
182: && (!(pds.getChartCode().equals("")))) {
183: criteria.addLike(
184: "paymentGroup.batch.customerProfile.chartCode", "%"
185: + pds.getChartCode() + "%");
186: }
187: if ((!(pds.getOrgCode() == null))
188: && (!(pds.getOrgCode().equals("")))) {
189: criteria.addLike(
190: "paymentGroup.batch.customerProfile.orgCode", "%"
191: + pds.getOrgCode() + "%");
192: }
193: if ((!(pds.getSubUnitCode() == null))
194: && (!(pds.getSubUnitCode().equals("")))) {
195: criteria.addLike(
196: "paymentGroup.batch.customerProfile.subUnitCode",
197: "%" + pds.getSubUnitCode() + "%");
198: }
199:
200: QueryByCriteria qbc = new QueryByCriteria(PaymentDetail.class,
201: criteria);
202: qbc.addOrderBy("paymentGroup.payeeName", true);
203: int total = pdsl + 1;
204: qbc.setEndAtIndex(total);
205: LOG.debug("getAllPaymentsForSearchCriteria() Query = "
206: + qbc.toString());
207: List l = (List) getPersistenceBrokerTemplate()
208: .getCollectionByQuery(qbc);
209: updateUser(l);
210:
211: return l;
212:
213: }
214:
215: public List getAllPaymentsWithCancelReissueDisbNbr(
216: PaymentDetailSearch pds) {
217: LOG
218: .info("getAllPaymentsWithCancelReissueDisbNbr(PaymentDetailSearch) starting");
219: Criteria criteria = new Criteria();
220:
221: // if ((!(pds.getCustPaymentDocNbr() == null)) && (!(pds.getCustPaymentDocNbr().equals("")))) {
222: // criteria.addLike("custPaymentDocNbr","%" + pds.getCustPaymentDocNbr() + "%");
223: // }
224: // if ((!(pds.getInvoiceNbr() == null)) && (!(pds.getInvoiceNbr().equals("")))) {
225: // criteria.addLike("invoiceNbr","%" + pds.getInvoiceNbr() + "%");
226: // }
227: // if ((!(pds.getRequisitionNbr() == null)) && (!(pds.getRequisitionNbr().equals("")))) {
228: // criteria.addLike("requisitionNbr","%" + pds.getRequisitionNbr() + "%");
229: // }
230: // if ((!(pds.getPurchaseOrderNbr() == null)) && (!(pds.getPurchaseOrderNbr().equals("")))) {
231: // criteria.addLike("purchaseOrderNbr","%" + pds.getPurchaseOrderNbr() + "%");
232: // }
233: if ((!(pds.getCustomerInstitutionNumber() == null))
234: && (!(pds.getCustomerInstitutionNumber().equals("")))) {
235: criteria.addLike("paymentGroup.customerIuNbr", "%"
236: + pds.getCustomerInstitutionNumber() + "%");
237: }
238: if ((!(pds.getPayeeName() == null))
239: && (!(pds.getPayeeName().equals("")))) {
240: criteria.addLike("paymentGroup.payeeName", "%"
241: + pds.getPayeeName().toUpperCase() + "%");
242: }
243: if ((!(pds.getPayeeId() == null))
244: && (!(pds.getPayeeId().equals("")))) {
245: criteria.addEqualTo("paymentGroup.payeeId", pds
246: .getPayeeId());
247: }
248: if ((!(pds.getPayeeIdTypeCd() == null))
249: && (!(pds.getPayeeIdTypeCd().equals("")))) {
250: criteria.addLike("paymentGroup.payeeIdTypeCd", "%"
251: + pds.getPayeeIdTypeCd() + "%");
252: }
253: if (!(GeneralUtilities.isStringEmpty(pds.getPymtAttachment()))) {
254: criteria.addLike("paymentGroup.pymtAttachment", "%"
255: + pds.getPymtAttachment() + "%");
256: }
257: if (!(GeneralUtilities.isStringEmpty(pds
258: .getPymtSpecialHandling()))) {
259: criteria.addLike("origPmtSpecHandling", "%"
260: + pds.getPymtSpecialHandling() + "%");
261: }
262: if (!(GeneralUtilities.isStringEmpty(pds.getProcessImmediate()))) {
263: criteria.addLike("origProcessImmediate", "%"
264: + pds.getProcessImmediate() + "%");
265: }
266: if ((!(pds.getDisbursementNbr() == null))
267: && (!(pds.getDisbursementNbr() == new Integer(0)))) {
268: criteria.addEqualTo("origDisburseNbr", pds
269: .getDisbursementNbr());
270: }
271: if ((!(pds.getProcessId() == null))
272: && (!(pds.getProcessId() == new Integer(0)))) {
273: criteria
274: .addEqualTo("paymentProcess.id", pds.getProcessId());
275: }
276: // if ((!(pds.getPaymentId() == null)) && (!(pds.getPaymentId() == new Integer(0)))) {
277: // criteria.addEqualTo("id",pds.getPaymentId());
278: // }
279: if ((!(pds.getNetPaymentAmount() == null))
280: && (!(pds.getNetPaymentAmount() == new BigDecimal(0.00)))) {
281: criteria.addEqualTo(
282: "paymentGroup.paymentDetails.netPaymentAmount", pds
283: .getNetPaymentAmount());
284: }
285: if (!(pds.getBeginDisbursementDate() == null)) {
286: criteria.addGreaterOrEqualThan("origDisburseDate", pds
287: .getBeginDisbursementDate());
288: }
289: if (!(pds.getEndDisbursementDate() == null)) {
290: GregorianCalendar gc = new GregorianCalendar();
291: gc.setTime(pds.getEndDisbursementDate());
292: gc.add(Calendar.DATE, 1);
293: criteria.addLessOrEqualThan("origDisburseDate",
294: new Timestamp(gc.getTimeInMillis()));
295: }
296: if (!(pds.getBeginPaymentDate() == null)) {
297: criteria.addGreaterOrEqualThan("origPaymentDate", pds
298: .getBeginPaymentDate());
299: }
300: if (!(pds.getEndPaymentDate() == null)) {
301: GregorianCalendar gc = new GregorianCalendar();
302: gc.setTime(pds.getEndPaymentDate());
303: gc.add(Calendar.DATE, 1);
304: criteria.addLessOrEqualThan("origPaymentDate",
305: new Timestamp(gc.getTimeInMillis()));
306: }
307: if ((!(pds.getPaymentStatusCode() == null))
308: && (!(pds.getPaymentStatusCode().equals("")))) {
309: criteria.addEqualTo("origPaymentStatus.code", pds
310: .getPaymentStatusCode());
311: }
312: if ((!(pds.getDisbursementTypeCode() == null))
313: && (!(pds.getDisbursementTypeCode().equals("")))) {
314: criteria.addEqualTo("disbursementType.code", pds
315: .getDisbursementTypeCode());
316: }
317: if ((!(pds.getChartCode() == null))
318: && (!(pds.getChartCode().equals("")))) {
319: criteria.addLike(
320: "paymentGroup.batch.customerProfile.chartCode", "%"
321: + pds.getChartCode() + "%");
322: }
323: if ((!(pds.getOrgCode() == null))
324: && (!(pds.getOrgCode().equals("")))) {
325: criteria.addLike(
326: "paymentGroup.batch.customerProfile.orgCode", "%"
327: + pds.getOrgCode() + "%");
328: }
329: if ((!(pds.getSubUnitCode() == null))
330: && (!(pds.getSubUnitCode().equals("")))) {
331: criteria.addLike(
332: "paymentGroup.batch.customerProfile.subUnitCode",
333: "%" + pds.getSubUnitCode() + "%");
334: }
335: QueryByCriteria qbc = new QueryByCriteria(
336: PaymentGroupHistory.class, criteria);
337: qbc.addOrderBy("paymentGroup.payeeName", true);
338: LOG.debug("getAllPaymentsWithCancelReissueDisbNbr() Query = "
339: + qbc.toString());
340: List l = (List) getPersistenceBrokerTemplate()
341: .getCollectionByQuery(qbc);
342:
343: List finalResults = new ArrayList();
344: for (Iterator iter = l.iterator(); iter.hasNext();) {
345: PaymentGroupHistory pgh = (PaymentGroupHistory) iter.next();
346: finalResults.addAll(pgh.getPaymentGroup()
347: .getPaymentDetails());
348: }
349:
350: return finalResults;
351: }
352:
353: private void updateUser(List l) {
354: for (Iterator iter = l.iterator(); iter.hasNext();) {
355: PaymentDetail p = (PaymentDetail) iter.next();
356: if (p.getPaymentGroup().getBatch() != null) {
357: updateBatchUser(p.getPaymentGroup().getBatch());
358: }
359: if (p.getPaymentGroup().getProcess() != null) {
360: updateProcessUser(p.getPaymentGroup().getProcess());
361: }
362: if (p.getPaymentGroup().getPaymentGroupHistory() != null) {
363: updateChangeUser(p.getPaymentGroup()
364: .getPaymentGroupHistory());
365: }
366: }
367: }
368:
369: private void updateChangeUser(List l) {
370: for (Iterator iter = l.iterator(); iter.hasNext();) {
371: updateChangeUser((PaymentGroupHistory) iter.next());
372: }
373: }
374:
375: private void updateChangeUser(PaymentGroupHistory b) {
376: UserRequired ur = (UserRequired) b;
377: try {
378: ur.updateUser(userService);
379: } catch (UserNotFoundException e) {
380: b.setChangeUser(null);
381: }
382: }
383:
384: private void updateBatchUser(Batch b) {
385: UserRequired ur = (UserRequired) b;
386: try {
387: ur.updateUser(userService);
388: } catch (UserNotFoundException e) {
389: b.setSubmiterUser(null);
390: }
391: }
392:
393: private void updateProcessUser(PaymentProcess b) {
394: UserRequired ur = (UserRequired) b;
395: try {
396: ur.updateUser(userService);
397: } catch (UserNotFoundException e) {
398: b.setProcessUser(null);
399: }
400: }
401: }
|