1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.ar.businessobject.lookup;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.commons.collections.CollectionUtils;
28 import org.kuali.kfs.module.ar.businessobject.CollectionActivityInvoiceLookup;
29 import org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument;
30 import org.kuali.kfs.module.ar.document.service.ContractsGrantsCollectionActivityDocumentService;
31 import org.kuali.kfs.module.ar.report.service.ContractsGrantsReportHelperService;
32 import org.kuali.kfs.sys.KFSConstants;
33 import org.kuali.kfs.sys.KFSPropertyConstants;
34 import org.kuali.rice.core.web.format.Formatter;
35 import org.kuali.rice.kim.api.identity.Person;
36 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
37 import org.kuali.rice.kns.lookup.HtmlData;
38 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
39 import org.kuali.rice.kns.web.comparator.CellComparatorHelper;
40 import org.kuali.rice.kns.web.struts.form.LookupForm;
41 import org.kuali.rice.kns.web.ui.Column;
42 import org.kuali.rice.kns.web.ui.ResultRow;
43 import org.kuali.rice.krad.bo.BusinessObject;
44 import org.kuali.rice.krad.lookup.CollectionIncomplete;
45 import org.kuali.rice.krad.util.GlobalVariables;
46 import org.kuali.rice.krad.util.ObjectUtils;
47
48
49
50
51 public class CollectionActivityInvoiceLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
52 private org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CollectionActivityInvoiceLookupableHelperServiceImpl.class);
53 protected ContractsGrantsCollectionActivityDocumentService contractsGrantsCollectionActivityDocumentService;
54
55 protected ContractsGrantsReportHelperService contractsGrantsReportHelperService;
56
57
58
59
60
61
62
63 @Override
64 public List getSearchResults(Map fieldValues) {
65 List<CollectionActivityInvoiceLookup> results = new ArrayList<CollectionActivityInvoiceLookup>();
66 setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION));
67 setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY));
68 Long proposalNumber = new Long((String) fieldValues.get(KFSPropertyConstants.PROPOSAL_NUMBER));
69 Collection<ContractsGrantsInvoiceDocument> cgInvoices = getContractsGrantsCollectionActivityDocumentService().retrieveCollectionActivityEligibleContractsGrantsInvoicesByProposalNumber(proposalNumber);
70
71 for (ContractsGrantsInvoiceDocument invoiceDocument : cgInvoices) {
72 results.add(convert(invoiceDocument));
73 }
74
75 return new CollectionIncomplete<CollectionActivityInvoiceLookup>(results, (long) results.size());
76 }
77
78 protected CollectionActivityInvoiceLookup convert(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
79 CollectionActivityInvoiceLookup cl = new CollectionActivityInvoiceLookup();
80 cl.setProposalNumber(contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber());
81 cl.setInvoiceNumber(contractsGrantsInvoiceDocument.getDocumentNumber());
82
83 if (CollectionUtils.isNotEmpty(contractsGrantsInvoiceDocument.getAccountDetails())) {
84 cl.setAccountNumber(contractsGrantsInvoiceDocument.getAccountDetails().get(0).getAccountNumber());
85 }
86
87 cl.setInvoiceDate(contractsGrantsInvoiceDocument.getBillingDate());
88 cl.setInvoiceAmount(contractsGrantsInvoiceDocument.getSourceTotal());
89 cl.setBillingPeriod(contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getBillingPeriod());
90 if (ObjectUtils.isNotNull(contractsGrantsInvoiceDocument.getInvoiceGeneralDetail())) {
91 cl.setBillingFrequency(contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getBillingFrequencyCode());
92 }
93 cl.setPaymentAmount(getContractsGrantsCollectionActivityDocumentService().retrievePaymentAmountByDocumentNumber(contractsGrantsInvoiceDocument.getDocumentNumber()));
94 cl.setBalanceDue(cl.getInvoiceAmount().subtract(cl.getPaymentAmount()));
95 cl.setAge(contractsGrantsInvoiceDocument.getAge());
96 return cl;
97 }
98
99
100
101
102
103
104
105
106
107
108 @Override
109 public Collection performLookup(LookupForm lookupForm, Collection resultTable, boolean bounded) {
110 if (LOG.isDebugEnabled()) {
111 for (Object key : lookupForm.getFieldsForLookup().keySet()) {
112 LOG.debug("Key : " + key.toString() + " Value : " + lookupForm.getFieldsForLookup().get(key));
113 }
114 }
115
116 Collection displayList = getSearchResults(lookupForm.getFieldsForLookup());
117
118
119 HashMap<String, Class> propertyTypes = new HashMap<String, Class>();
120
121 boolean hasReturnableRow = false;
122
123 List pkNames = getBusinessObjectMetaDataService().listPrimaryKeyFieldNames(getBusinessObjectClass());
124 List returnKeys = getReturnKeys();
125
126 Person user = GlobalVariables.getUserSession().getPerson();
127
128
129 for (Object aDisplayList : displayList) {
130 BusinessObject element = (BusinessObject) aDisplayList;
131
132 BusinessObjectRestrictions businessObjectRestrictions = getBusinessObjectAuthorizationService().getLookupResultRestrictions(element, user);
133
134 if (ObjectUtils.isNotNull(getColumns())) {
135 List<Column> columns = getColumns();
136 for (Object column : columns) {
137
138 Column col = (Column) column;
139 Formatter formatter = col.getFormatter();
140
141
142 Object prop = ObjectUtils.getPropertyValue(element, col.getPropertyName());
143
144 String propValue = ObjectUtils.getFormattedPropertyValue(element, col.getPropertyName(), col.getFormatter());
145 Class propClass = getPropertyClass(element, col.getPropertyName());
146
147
148 if (ObjectUtils.isNotNull(prop)) {
149 propValue = getContractsGrantsReportHelperService().formatByType(prop, formatter);
150 }
151
152
153 col.setComparator(CellComparatorHelper.getAppropriateComparatorForPropertyClass(propClass));
154 col.setValueComparator(CellComparatorHelper.getAppropriateValueComparatorForPropertyClass(propClass));
155
156 propValue = super.maskValueIfNecessary(element.getClass(), col.getPropertyName(), propValue, businessObjectRestrictions);
157 col.setPropertyValue(propValue);
158
159 }
160 lookupForm.setLookupObjectId(((CollectionActivityInvoiceLookup) element).getInvoiceNumber());
161 HtmlData returnUrl = getReturnUrl(element, lookupForm, returnKeys, businessObjectRestrictions);
162 ResultRow row = new ResultRow(columns, returnUrl.constructCompleteHtmlTag(), getActionUrls(element, pkNames, businessObjectRestrictions));
163 row.setObjectId(((CollectionActivityInvoiceLookup) element).getInvoiceNumber());
164 row.setRowId(returnUrl.getName());
165 row.setReturnUrlHtmlData(returnUrl);
166 boolean isRowReturnable = isResultReturnable(element);
167 row.setRowReturnable(isRowReturnable);
168 if (isRowReturnable) {
169 hasReturnableRow = true;
170 }
171
172 resultTable.add(row);
173 }
174 lookupForm.setHasReturnableRow(hasReturnableRow);
175 }
176
177 return displayList;
178 }
179
180 public ContractsGrantsReportHelperService getContractsGrantsReportHelperService() {
181 return contractsGrantsReportHelperService;
182 }
183
184 public void setContractsGrantsReportHelperService(ContractsGrantsReportHelperService contractsGrantsReportHelperService) {
185 this.contractsGrantsReportHelperService = contractsGrantsReportHelperService;
186 }
187
188 public ContractsGrantsCollectionActivityDocumentService getContractsGrantsCollectionActivityDocumentService() {
189 return contractsGrantsCollectionActivityDocumentService;
190 }
191
192 public void setContractsGrantsCollectionActivityDocumentService(ContractsGrantsCollectionActivityDocumentService contractsGrantsCollectionActivityDocumentService) {
193 this.contractsGrantsCollectionActivityDocumentService = contractsGrantsCollectionActivityDocumentService;
194 }
195 }