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.ojb.broker.query.Criteria;
19 import org.apache.ojb.broker.query.ReportQueryByCriteria;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.document.CorrectionReceivingDocument;
22 import org.kuali.ole.module.purap.document.LineItemReceivingDocument;
23 import org.kuali.ole.module.purap.document.dataaccess.ReceivingDao;
24 import org.kuali.ole.sys.OLEPropertyConstants;
25 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26 import org.springframework.transaction.annotation.Transactional;
27
28 import java.sql.Date;
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35 @Transactional
36 public class ReceivingDaoOjb extends PlatformAwareDaoBaseOjb implements ReceivingDao {
37 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ReceivingDaoOjb.class);
38
39 public List<String> getDocumentNumbersByPurchaseOrderId(Integer id) {
40 Criteria criteria = new Criteria();
41 criteria.addEqualTo(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, id);
42
43 List<String> returnList = getDocumentNumbersOfReceivingLineByCriteria(criteria, false);
44
45 return returnList;
46 }
47
48 public List<String> getCorrectionReceivingDocumentNumbersByPurchaseOrderId(Integer id) {
49 Criteria criteria = new Criteria();
50 criteria.addEqualTo("lineItemReceivingDocument.purchaseOrderIdentifier", id);
51
52 List<String> returnList = getDocumentNumbersOfCorrectionReceivingByCriteria(criteria, false);
53
54 return returnList;
55 }
56
57 public List<String> getCorrectionReceivingDocumentNumbersByReceivingLineNumber(String receivingDocumentNumber) {
58 Criteria criteria = new Criteria();
59 criteria.addEqualTo(PurapPropertyConstants.LINE_ITEM_RECEIVING_DOCUMENT_NUMBER, receivingDocumentNumber);
60
61 List<String> returnList = getDocumentNumbersOfCorrectionReceivingByCriteria(criteria, false);
62
63 return returnList;
64 }
65
66
67
68
69
70
71
72
73
74 protected List<String> getDocumentNumbersOfReceivingLineByCriteria(Criteria criteria, boolean orderByAscending) {
75 ReportQueryByCriteria rqbc = new ReportQueryByCriteria(LineItemReceivingDocument.class, criteria);
76 if (orderByAscending) {
77 rqbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER);
78 } else {
79 rqbc.addOrderByDescending(OLEPropertyConstants.DOCUMENT_NUMBER);
80 }
81
82 List<LineItemReceivingDocument> lineItemRecvDocs = (List<LineItemReceivingDocument>) getPersistenceBrokerTemplate().getCollectionByQuery(rqbc);
83
84 List<String> returnList = new ArrayList<String>();
85
86 for (LineItemReceivingDocument lineItemRecvDoc : lineItemRecvDocs) {
87 returnList.add(lineItemRecvDoc.getDocumentNumber());
88 }
89
90 return returnList;
91 }
92
93 protected List<String> getDocumentNumbersOfCorrectionReceivingByCriteria(Criteria criteria, boolean orderByAscending) {
94 ReportQueryByCriteria rqbc = new ReportQueryByCriteria(CorrectionReceivingDocument.class, criteria);
95 if (orderByAscending) {
96 rqbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER);
97 } else {
98 rqbc.addOrderByDescending(OLEPropertyConstants.DOCUMENT_NUMBER);
99 }
100
101 List<CorrectionReceivingDocument> correctionRecvDocs = (List<CorrectionReceivingDocument>) getPersistenceBrokerTemplate().getCollectionByQuery(rqbc);
102
103 List<String> returnList = new ArrayList<String>();
104
105 for (CorrectionReceivingDocument correctionRecvDoc : correctionRecvDocs) {
106 returnList.add(correctionRecvDoc.getDocumentNumber());
107 }
108
109 return returnList;
110 }
111
112 public List<String> duplicateBillOfLadingNumber(Integer poId, String billOfLadingNumber) {
113 Criteria criteria = new Criteria();
114 criteria.addEqualTo(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, poId);
115 criteria.addEqualTo(PurapPropertyConstants.SHIPMENT_BILL_OF_LADING_NUMBER, billOfLadingNumber);
116
117 List<String> returnList = getDocumentNumbersOfReceivingLineByCriteria(criteria, false);
118
119 return returnList;
120 }
121
122 public List<String> duplicatePackingSlipNumber(Integer poId, String packingSlipNumber) {
123 Criteria criteria = new Criteria();
124 criteria.addEqualTo(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, poId);
125 criteria.addEqualTo(PurapPropertyConstants.SHIPMENT_PACKING_SLIP_NUMBER, packingSlipNumber);
126 List<String> returnList = getDocumentNumbersOfReceivingLineByCriteria(criteria, false);
127
128 return returnList;
129 }
130
131 public List<String> duplicateVendorDate(Integer poId, Date vendorDate) {
132 Criteria criteria = new Criteria();
133 criteria.addEqualTo(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, poId);
134 criteria.addEqualTo(PurapPropertyConstants.SHIPMENT_RECEIVED_DATE, vendorDate);
135 List<String> returnList = getDocumentNumbersOfReceivingLineByCriteria(criteria, false);
136
137 return returnList;
138 }
139 }