1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.dataaccess.impl;
17
18 import java.util.ArrayList;
19 import java.util.Calendar;
20 import java.util.GregorianCalendar;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.QueryByCriteria;
26 import org.apache.ojb.broker.query.QueryFactory;
27 import org.kuali.ole.fp.businessobject.CashieringItemInProcess;
28 import org.kuali.ole.fp.businessobject.CashieringTransaction;
29 import org.kuali.ole.fp.businessobject.Check;
30 import org.kuali.ole.fp.businessobject.CheckBase;
31 import org.kuali.ole.fp.businessobject.CoinDetail;
32 import org.kuali.ole.fp.businessobject.CurrencyDetail;
33 import org.kuali.ole.fp.document.dataaccess.CashManagementDao;
34 import org.kuali.ole.sys.OLEConstants;
35 import org.kuali.ole.sys.util.TransactionalServiceUtils;
36 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
37 import org.springframework.dao.DataAccessException;
38
39 public class CashManagementDaoOjb extends PlatformAwareDaoBaseOjb implements CashManagementDao {
40 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CashManagementDaoOjb.class);
41
42 public CashManagementDaoOjb() {
43 super();
44 }
45
46
47
48
49 public List<CashieringItemInProcess> findOpenItemsInProcessByCampusCode(String campusCode) throws DataAccessException {
50 List<CashieringItemInProcess> openItems = new ArrayList<CashieringItemInProcess>();
51 Criteria criteria = new Criteria();
52 criteria.addEqualTo("campusCode", campusCode);
53 criteria.addColumnIsNull("ITM_CLOSED_DT");
54
55 QueryByCriteria openItemsQuery = QueryFactory.newQuery(CashieringItemInProcess.class, criteria);
56 return new ArrayList<CashieringItemInProcess>( getPersistenceBrokerTemplate().getCollectionByQuery(openItemsQuery) );
57 }
58
59
60
61
62 public List<CashieringItemInProcess> findRecentlyClosedItemsInProcess(String campusCode) {
63 List<CashieringItemInProcess> closedItems = new ArrayList<CashieringItemInProcess>();
64
65 Criteria criteria = new Criteria();
66 criteria.addEqualTo("campusCode", campusCode);
67 criteria.addColumnNotNull("ITM_CLOSED_DT");
68 Calendar thirtyDaysAgo = new GregorianCalendar();
69 thirtyDaysAgo.add(Calendar.DAY_OF_YEAR, -30);
70 criteria.addGreaterThan("itemClosedDate", new java.sql.Date(thirtyDaysAgo.getTimeInMillis()));
71
72 QueryByCriteria closedItemsQuery = QueryFactory.newQuery(CashieringItemInProcess.class, criteria);
73 Iterator iter = getPersistenceBrokerTemplate().getIteratorByQuery(closedItemsQuery);
74 while (iter.hasNext()) {
75 closedItems.add((CashieringItemInProcess) iter.next());
76 }
77 return closedItems;
78 }
79
80
81
82
83
84 public CoinDetail findCoinDetailByCashieringStatus(String documentNumber, String documentTypeCode, String cashieringStatus) {
85 return (CoinDetail) retrieveCashDetail(documentNumber, documentTypeCode, cashieringStatus, CoinDetail.class);
86 }
87
88
89
90
91
92 public CurrencyDetail findCurrencyDetailByCashieringStatus(String documentNumber, String documentTypeCode, String cashieringStatus) {
93 return (CurrencyDetail) retrieveCashDetail(documentNumber, documentTypeCode, cashieringStatus, CurrencyDetail.class);
94 }
95
96
97
98
99
100
101
102
103
104 protected Criteria getCashDetailCriteria(String documentNumber, String documentTypeCode, String cashieringStatus) {
105 Criteria criteria = new Criteria();
106 criteria.addEqualTo("documentNumber", documentNumber);
107 criteria.addEqualTo("financialDocumentTypeCode", documentTypeCode);
108 criteria.addEqualTo("cashieringStatus", cashieringStatus);
109 return criteria;
110 }
111
112
113
114
115
116
117
118
119
120
121 protected Object retrieveCashDetail(String documentNumber, String documentTypeCode, String cashieringStatus, Class detailType) {
122 QueryByCriteria cashDetailQuery = QueryFactory.newQuery(detailType, getCashDetailCriteria(documentNumber, documentTypeCode, cashieringStatus));
123 Iterator iter = getPersistenceBrokerTemplate().getIteratorByQuery(cashDetailQuery);
124 return (iter.hasNext() ? iter.next() : null);
125 }
126
127
128
129
130 public List<Check> selectCashieringChecksForDeposit(String documentNumber, Integer depositLineNumber) {
131 QueryByCriteria depositedChecksQuery = QueryFactory.newQuery(CheckBase.class, createDepositedCashieringCheckCriteria(documentNumber, depositLineNumber));
132 return putResultsIntoCheckList(getPersistenceBrokerTemplate().getIteratorByQuery(depositedChecksQuery));
133 }
134
135
136
137
138
139
140
141
142 protected Criteria createDepositedCashieringCheckCriteria(String documentNumber, Integer depositLineNumber) {
143 Criteria criteria = getCashDetailCriteria(documentNumber, CashieringTransaction.DETAIL_DOCUMENT_TYPE, OLEConstants.CheckSources.CASH_MANAGEMENT);
144 criteria.addEqualTo("financialDocumentDepositLineNumber", depositLineNumber);
145 return criteria;
146 }
147
148
149
150
151
152
153
154 protected List<Check> putResultsIntoCheckList(Iterator iter) {
155 List<Check> result = new ArrayList<Check>();
156 while (iter.hasNext()) {
157 result.add((Check) iter.next());
158 }
159 return result;
160 }
161
162
163
164
165 public List<Check> selectUndepositedCashieringChecks(String documentNumber) {
166 QueryByCriteria undepositedChecksQuery = QueryFactory.newQuery(CheckBase.class, createUndepositedCashieringCheckCriteria(documentNumber));
167 return putResultsIntoCheckList(getPersistenceBrokerTemplate().getIteratorByQuery(undepositedChecksQuery));
168 }
169
170
171
172
173
174
175
176 protected Criteria createUndepositedCashieringCheckCriteria(String documentNumber) {
177 Criteria criteria = getCashDetailCriteria(documentNumber, CashieringTransaction.DETAIL_DOCUMENT_TYPE, OLEConstants.CheckSources.CASH_MANAGEMENT);
178 criteria.addColumnIsNull("FDOC_DPST_LN_NBR");
179 return criteria;
180 }
181
182
183
184
185 public List<Check> selectDepositedCashieringChecks(String documentNumber) {
186 QueryByCriteria depositedChecksQuery = QueryFactory.newQuery(CheckBase.class, createDepositedCashieringCheckCriteria(documentNumber));
187 return putResultsIntoCheckList(getPersistenceBrokerTemplate().getIteratorByQuery(depositedChecksQuery));
188 }
189
190
191
192
193
194
195
196 protected Criteria createDepositedCashieringCheckCriteria(String documentNumber) {
197 Criteria criteria = getCashDetailCriteria(documentNumber, CashieringTransaction.DETAIL_DOCUMENT_TYPE, OLEConstants.CheckSources.CASH_MANAGEMENT);
198 criteria.addColumnNotNull("FDOC_DPST_LN_NBR");
199 return criteria;
200 }
201
202
203
204
205
206
207
208 public List<CurrencyDetail> getAllCurrencyDetails(String documentNumber) {
209 QueryByCriteria allCurrencyDetailsQuery = QueryFactory.newQuery(CurrencyDetail.class, getAllCashDetailCriteria(documentNumber));
210 List<CurrencyDetail> result = new ArrayList<CurrencyDetail>();
211 for (Iterator iter = getPersistenceBrokerTemplate().getIteratorByQuery(allCurrencyDetailsQuery); iter.hasNext();) {
212 result.add((CurrencyDetail) iter.next());
213 }
214 return result;
215 }
216
217
218
219
220
221
222
223 public List<CoinDetail> getAllCoinDetails(String documentNumber) {
224 QueryByCriteria allCoinDetailsQuery = QueryFactory.newQuery(CoinDetail.class, getAllCashDetailCriteria(documentNumber));
225 List<CoinDetail> result = new ArrayList<CoinDetail>();
226 for (Iterator iter = getPersistenceBrokerTemplate().getIteratorByQuery(allCoinDetailsQuery); iter.hasNext();) {
227 result.add((CoinDetail) iter.next());
228 }
229 return result;
230 }
231
232
233
234
235
236
237
238 protected Criteria getAllCashDetailCriteria(String documentNumber) {
239 Criteria criteria = new Criteria();
240 criteria.addEqualTo("documentNumber", documentNumber);
241 criteria.addEqualTo("financialDocumentTypeCode", CashieringTransaction.DETAIL_DOCUMENT_TYPE);
242 return criteria;
243 }
244
245
246
247
248 public Integer selectNextAvailableCheckLineNumber(String documentNumber) {
249 if (documentNumber != null) {
250
251 Criteria criteria = new Criteria();
252 criteria.addEqualTo("documentNumber", documentNumber);
253 criteria.addEqualTo("cashieringStatus", OLEConstants.CheckSources.CASH_MANAGEMENT);
254 criteria.addEqualTo("financialDocumentTypeCode", CashieringTransaction.DETAIL_DOCUMENT_TYPE);
255
256 QueryByCriteria cmChecksQuery = QueryFactory.newQuery(CheckBase.class, criteria);
257 cmChecksQuery.addOrderByDescending("sequenceId");
258 Iterator allChecksIter = getPersistenceBrokerTemplate().getIteratorByQuery(cmChecksQuery);
259 if (allChecksIter.hasNext()) {
260 return new Integer((((Check) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(allChecksIter)).getSequenceId()).intValue() + 1);
261 }
262 else {
263 return new Integer(1);
264 }
265 }
266 else {
267 return null;
268 }
269 }
270
271 }