1
2
3
4
5 package org.kuali.ole.module.purap.dataaccess.impl;
6
7 import org.apache.ojb.broker.query.Criteria;
8 import org.apache.ojb.broker.query.QueryByCriteria;
9 import org.kuali.ole.module.purap.PurapConstants;
10 import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceItemMapping;
11 import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceLoadSummary;
12 import org.kuali.ole.module.purap.dataaccess.ElectronicInvoicingDao;
13 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
14 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
15
16 import java.util.HashMap;
17 import java.util.Iterator;
18 import java.util.List;
19 import java.util.Map;
20
21 public class ElectronicInvoicingDaoOjb extends PlatformAwareDaoBaseOjb implements ElectronicInvoicingDao {
22
23 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicInvoicingDaoOjb.class);
24
25 public ElectronicInvoicingDaoOjb() {
26 super();
27 }
28
29 public ElectronicInvoiceLoadSummary getElectronicInvoiceLoadSummary(Integer loadId, String vendorDunsNumber) {
30 LOG.debug("getElectronicInvoiceLoadSummary() started");
31
32 Criteria criteria = new Criteria();
33 criteria.addEqualTo("id", loadId);
34 criteria.addEqualTo("vendorDunsNumber", vendorDunsNumber);
35
36 return (ElectronicInvoiceLoadSummary) getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ElectronicInvoiceLoadSummary.class, criteria));
37 }
38
39 public List getPendingElectronicInvoices() {
40 LOG.debug("getPendingElectronicInvoices() started");
41
42 Criteria criteria = new Criteria();
43 criteria.addEqualTo("status.code", PurapConstants.PaymentRequestStatuses.APPDOC_PENDING_E_INVOICE);
44 criteria.addEqualTo("isElectronicInvoice", Boolean.TRUE);
45 List invoices = (List) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PaymentRequestDocument.class, criteria));
46 for (Iterator iter = invoices.iterator(); iter.hasNext(); ) {
47 PaymentRequestDocument p = (PaymentRequestDocument) iter.next();
48 }
49
50 return invoices;
51 }
52
53 public Map getDefaultItemMappingMap() {
54 LOG.debug("getDefaultItemMappingMap() started");
55 Criteria criteria = new Criteria();
56 criteria.addIsNull("vendorHeaderGeneratedIdentifier");
57 criteria.addIsNull("vendorDetailAssignedIdentifier");
58 criteria.addEqualTo("active", true);
59 return this.getItemMappingMap(criteria);
60 }
61
62 public Map getItemMappingMap(Integer vendorHeaderId, Integer vendorDetailId) {
63 if (LOG.isDebugEnabled()) {
64 LOG.debug("getItemMappingMap() started for vendor id " + vendorHeaderId + "-" + vendorDetailId);
65 }
66 Criteria criteria = new Criteria();
67 criteria.addEqualTo("vendorHeaderGeneratedIdentifier", vendorHeaderId);
68 criteria.addEqualTo("vendorDetailAssignedIdentifier", vendorDetailId);
69 criteria.addEqualTo("active", true);
70 return this.getItemMappingMap(criteria);
71 }
72
73 protected Map getItemMappingMap(Criteria criteria) {
74 Map hm = new HashMap();
75 List itemMappings = (List) getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ElectronicInvoiceItemMapping.class, criteria));
76
77 for (Iterator iter = itemMappings.iterator(); iter.hasNext(); ) {
78 ElectronicInvoiceItemMapping mapping = (ElectronicInvoiceItemMapping) iter.next();
79 hm.put(mapping.getInvoiceItemTypeCode(), mapping);
80 }
81 return hm;
82 }
83 }