1 /*
2 * Copyright 2006 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.module.purap.document.service;
17
18 import org.kuali.ole.module.purap.businessobject.ItemType;
19 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
20 import org.kuali.ole.module.purap.businessobject.PurApItem;
21 import org.kuali.ole.module.purap.document.PurapItemOperations;
22 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
23 import org.kuali.ole.module.purap.document.PurchasingDocument;
24 import org.kuali.rice.core.api.util.type.KualiDecimal;
25 import org.kuali.rice.kew.api.exception.WorkflowException;
26 import org.kuali.rice.krad.document.Document;
27
28 import java.sql.Date;
29 import java.util.List;
30
31 /**
32 * Defines methods that must be implemented by classes providing a PurapService.
33 */
34 public interface PurapService {
35
36 public List<String> getRelatedDocumentIds(Integer accountsPayablePurchasingDocumentLinkIdentifier);
37
38 public void saveRoutingDataForRelatedDocuments(Integer accountsPayablePurchasingDocumentLinkIdentifier);
39
40 /**
41 * Retrieve list of views for given identifier
42 *
43 * @param clazz
44 * @param accountsPayablePurchasingDocumentLinkIdentifier
45 *
46 * @return List of views for given identifier
47 */
48 @SuppressWarnings("unchecked")
49 public List getRelatedViews(Class clazz, Integer accountsPayablePurchasingDocumentLinkIdentifier);
50
51 /**
52 * Add the allowed below the line items to the given document
53 *
54 * @param document PurchasingAccountsPayableDocument
55 */
56 public void addBelowLineItems(PurchasingAccountsPayableDocument document);
57
58 /**
59 * Retrieves the below the line items allowed from the parameter table for the given document
60 *
61 * @param document PurchasingAccountsPayableDocument
62 * @return Array list of below the line items
63 */
64 public String[] getBelowTheLineForDocument(PurchasingAccountsPayableDocument document);
65
66 /**
67 * Retrieve the below the line item for a doc by item type (unknown result if multiple of same below the line item
68 * type)
69 *
70 * @param document the document
71 * @param iT the itemType
72 * @return below the line item by item type
73 */
74 public PurApItem getBelowTheLineByType(PurchasingAccountsPayableDocument document, ItemType iT);
75
76 /**
77 * Return a Date object which is which is a given number of days away from today, in either direction.
78 *
79 * @param offsetDays
80 * @return A java.sql.Date
81 */
82 public Date getDateFromOffsetFromToday(int offsetDays);
83
84 /**
85 * Determine whether a given date is in the past.
86 *
87 * @param compareDate An SQL date (not a DateFormatter date, or a util Date)
88 * @return True if the given date is before today.
89 */
90 public boolean isDateInPast(Date compareDate);
91
92 /**
93 * Determine whether a given date is more than a given number of days away from the current date.
94 *
95 * @param compareDate An SQL date (not a DateFormatter date, or a util Date)
96 * @param daysAway An int, positive for future days, negative for past days
97 * @return True if the given date is more than the given number of days away in either direction.
98 */
99 public boolean isDateMoreThanANumberOfDaysAway(Date compareDate, int daysAway);
100
101 /**
102 * We are obliged not to simply use a dateDiff and compare the result to 365, because we have to worry about leap years.
103 *
104 * @param compareDate An SQL date (not a DateFormatter date, or a util Date)
105 * @return True if the date given for comparison is more than a year in the past, not including today.
106 */
107 public boolean isDateAYearBeforeToday(Date compareDate);
108
109 /**
110 * Retrieve the Automatic Purchase Order Limit amount based first on the derived contract limit (see
111 * {@link org.kuali.ole.vnd.document.service.VendorService#getApoLimitFromContract(Integer, String, String)}) and if that is null
112 * then based on the {@link org.kuali.ole.module.purap.businessobject.OrganizationParameter} associated with the given 'chart' and 'org' values.
113 *
114 * @param vendorContractGeneratedIdentifier
115 *
116 * @param chart chart code to use when looking up limit amount on {@link org.kuali.ole.vnd.businessobject.VendorContract} and
117 * {@link org.kuali.ole.module.purap.businessobject.OrganizationParameter}
118 * @param org organization code to use when looking up limit amount on {@link org.kuali.ole.vnd.businessobject.VendorContract} and
119 * {@link org.kuali.ole.module.purap.businessobject.OrganizationParameter}
120 * @return a KualiDecimal if a valid limit amount is found or null if one is not found
121 */
122 public KualiDecimal getApoLimit(Integer vendorContractGeneratedIdentifier, String chart, String org);
123
124 /**
125 * Determines if full entry mode has ended for this Purchasing/Accounts Payable document.
126 *
127 * @param purapDocument PurchasingAccountsPayableDocument
128 * @return a boolean to indicate if document has completed full entry mode
129 */
130 public boolean isFullDocumentEntryCompleted(PurchasingAccountsPayableDocument purapDocument);
131
132 /**
133 * Determines if full entry mode has ended for this Payment Request status
134 *
135 * @param purapDocumentStatus String
136 * @return a boolean to indicate if document has completed full entry mode
137 */
138 public boolean isPaymentRequestFullDocumentEntryCompleted(String purapDocumentStatus);
139
140 /**
141 * Determines if full entry mode has ended for this Invoice status
142 *
143 * @param purapDocumentStatus String
144 * @return a boolean to indicate if document has completed full entry mode
145 */
146 public boolean isInvoiceFullDocumentEntryCompleted(String purapDocumentStatus);
147
148 /**
149 * Determines if full entry mode has ended for this Vendor Credit Memo status
150 *
151 * @param purapDocumentStatus String
152 * @return a boolean to indicate if document has completed full entry mode
153 */
154 public boolean isVendorCreditMemoFullDocumentEntryCompleted(String purapDocumentStatus);
155
156
157 /**
158 * Create a close or reopen purchase order document.
159 *
160 * @param purapDocument PurchasingAccountsPayableDocument
161 */
162 public void performLogicForCloseReopenPO(PurchasingAccountsPayableDocument purapDocument);
163
164 /**
165 * Performs the given logic with the given fake user id. Need this to control the user.
166 *
167 * @param requiredPersonPersonUserId
168 * @param logicToRun
169 * @param objects
170 * @return
171 * @throws WorkflowException
172 * @throws Exception
173 */
174 public Object performLogicWithFakedUserSession(String requiredPersonPersonUserId, LogicContainer logicToRun, Object... objects) throws WorkflowException, Exception;
175
176 /**
177 * Sort the below the line elements of the given document
178 *
179 * @param document PurchasingAccountsPayableDocument to be sorted
180 */
181 public void sortBelowTheLine(PurchasingAccountsPayableDocument document);
182
183 /**
184 * Remove items that have not been "entered" which means no data has been added to them so no more processing needs to continue
185 * on these items.
186 *
187 * @param apDocument AccountsPayableDocument which contains list of items to be reviewed
188 */
189 public void deleteUnenteredItems(PurapItemOperations document);
190
191 /**
192 * Saves the document without doing validation by invoking the saveDocument method of documentService.
193 *
194 * @param document The purchase order document to be saved.
195 */
196 public void saveDocumentNoValidation(Document document);
197
198 /**
199 * Determines if a document is in a specified node.
200 *
201 * @param document
202 * @param nodeName
203 * @return
204 */
205 public boolean isDocumentStoppedInRouteNode(PurchasingAccountsPayableDocument document, String nodeName);
206
207 /**
208 * Returns true if the current date falls within the allowed range to encumber in the next fiscal year.
209 *
210 * @return
211 */
212 public boolean allowEncumberNextFiscalYear();
213
214 /**
215 * Returns a list of fiscal years that can be selected from on the document (built for Requisition and Purchase Order).
216 * Typically only the current year is returned. However, if the current date falls within the allowed range to encumber in the
217 * next fiscal year, the current year and the next current year is returned.
218 *
219 * @return List<Integer>
220 */
221 public List<Integer> getAllowedFiscalYears();
222
223 /**
224 * Returns true if today is within the APO allowed date range. If the difference between today and this years closing date is
225 * less than or equal to the number of days allowed for APO.
226 *
227 * @return boolean
228 */
229 public boolean isTodayWithinApoAllowedRange();
230
231 /**
232 * Calculates sales or use tax for each item if sales tax enabled and item is taxable.
233 *
234 * @param purapDocument
235 */
236 public void calculateTax(PurchasingAccountsPayableDocument purapDocument);
237
238 /**
239 * Clears the tax from a document. Useful when changing from use to sales
240 *
241 * @param purapDocument document
242 * @param useTax the whether to clear use or sales
243 */
244 public void clearTax(PurchasingAccountsPayableDocument purapDocument, boolean useTax);
245
246 /**
247 * Updates the use tax field, clearing old values if it has changed
248 *
249 * @param purapDocument document
250 * @param newUseTaxIndicatorValue useTaxIndicator to change to
251 */
252 public void updateUseTaxIndicator(PurchasingAccountsPayableDocument purapDocument, boolean newUseTaxIndicatorValue);
253
254 /**
255 * Proation for Trade in and Full Order Discount miscellaneous items.
256 *
257 * @param purDoc
258 */
259 public void prorateForTradeInAndFullOrderDiscount(PurchasingAccountsPayableDocument purDoc);
260
261 /**
262 * Determines if the item is taxable based on a decision tree.
263 *
264 * @param useTaxIndicator
265 * @param deliveryState
266 * @param item
267 * @return
268 */
269 public boolean isTaxable(boolean useTaxIndicator, String deliveryState, PurApItem item);
270
271 /**
272 * Determines if the item is taxable based on a decision tree.
273 * Does not consider if item is entered, this is not used to calculate tax,
274 * just if the item is indeed taxable.
275 *
276 * @param useTaxIndicator
277 * @param deliveryState
278 * @param item
279 * @return
280 */
281 public boolean isTaxableForSummary(boolean useTaxIndicator, String deliveryState, PurApItem item);
282
283 /**
284 * Retrieves the delivery state from the document
285 *
286 * @param purapDocument
287 * @return
288 */
289 public String getDeliveryState(PurchasingAccountsPayableDocument purapDocument);
290
291 /**
292 * Determines if the accounting line is taxable based on account and object code.
293 *
294 * @param acctLine
295 * @param deliveryStateTaxable
296 * @return
297 */
298 public boolean isAccountingLineTaxable(PurApAccountingLine acctLine, boolean deliveryStateTaxable);
299
300 /**
301 * Determines if the delivery state is taxable or not. If parameter is Allow and delivery state in list, or parameter is Denied
302 * and delivery state is not in list then state is taxable.
303 *
304 * @param deliveryState
305 * @return
306 */
307 public boolean isDeliveryStateTaxable(String deliveryState);
308
309 public void clearAllTaxes(PurchasingAccountsPayableDocument apDoc);
310
311 /**
312 * Determines if the item type specified conflict with the Account tax policy.
313 *
314 * @param purchasingDocument purchasing document to check
315 * @param item item to check if in conflict with tax policy
316 * @return true if item is in conflict, false otherwise
317 */
318 public abstract boolean isItemTypeConflictWithTaxPolicy(PurchasingDocument purchasingDocument, PurApItem item);
319 }
320