1 package org.kuali.ole.select.lookup;
2
3 import org.kuali.ole.select.bo.OLEInvoiceBo;
4 import org.kuali.ole.select.document.OleInvoiceDocument;
5 import org.kuali.ole.sys.context.SpringContext;
6 import org.kuali.rice.core.api.datetime.DateTimeService;
7 import org.kuali.rice.krad.lookup.LookupableImpl;
8 import org.kuali.rice.krad.service.KRADServiceLocator;
9 import org.kuali.rice.krad.web.form.LookupForm;
10
11 import java.sql.*;
12 import java.text.DateFormat;
13 import java.text.ParseException;
14 import java.text.SimpleDateFormat;
15 import java.util.*;
16 import java.util.Date;
17
18 public class OLEInvoiceLookupableImpl extends LookupableImpl {
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 @Override
38 public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
39 Map<String, Object> map = new HashMap<String, Object>();
40
41 for (Map.Entry<String, String> entry : searchCriteria.entrySet()) {
42 if (!entry.getValue().equals("") && entry.getValue() != null) {
43
44 if (entry.getKey().equals("invoiceDate")) {
45 DateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy");
46 try {
47 java.util.Date date = sourceFormat.parse(entry.getValue().toString());
48 Timestamp timestamp = new Timestamp(date.getTime());
49 map.put(entry.getKey(), timestamp);
50 } catch (ParseException e) {
51 e.printStackTrace();
52 }
53 } else {
54 map.put(entry.getKey(), entry.getValue());
55 }
56 }
57
58 }
59 List<OleInvoiceDocument> oleInvoiceDocuments = new ArrayList<OleInvoiceDocument>();
60 if (map.size() == 0) {
61 oleInvoiceDocuments = (List<OleInvoiceDocument>) KRADServiceLocator.getBusinessObjectService().findAll(OleInvoiceDocument.class);
62 } else {
63 oleInvoiceDocuments = (List<OleInvoiceDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OleInvoiceDocument.class, map);
64 }
65 List<OLEInvoiceBo> searchResults = new ArrayList<OLEInvoiceBo>();
66 for (OleInvoiceDocument oleInvoiceDocument : oleInvoiceDocuments) {
67 if (oleInvoiceDocument.getIsSaved()) {
68 OLEInvoiceBo oleInvoiceBo = new OLEInvoiceBo();
69 oleInvoiceBo.setInvoiceDate(oleInvoiceDocument.getInvoiceDate());
70 oleInvoiceBo.setInvoiceNbr(oleInvoiceDocument.getPurapDocumentIdentifier().toString());
71 oleInvoiceBo.setInvoiceNumber(oleInvoiceDocument.getInvoiceNumber());
72 oleInvoiceBo.setDocumentNumber(oleInvoiceDocument.getDocumentNumber());
73 searchResults.add(oleInvoiceBo);
74 }
75 }
76 sortSearchResults(form, searchResults);
77 return searchResults;
78 }
79 }