001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.module.purap.document.service;
017    
018    import java.sql.Date;
019    import java.util.List;
020    import java.util.Map;
021    
022    import org.kuali.kfs.module.purap.businessobject.ItemType;
023    import org.kuali.kfs.module.purap.businessobject.PurApAccountingLine;
024    import org.kuali.kfs.module.purap.businessobject.PurApItem;
025    import org.kuali.kfs.module.purap.document.AccountsPayableDocument;
026    import org.kuali.kfs.module.purap.document.PurapItemOperations;
027    import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
028    import org.kuali.kfs.module.purap.document.PurchasingDocument;
029    import org.kuali.rice.kew.exception.WorkflowException;
030    import org.kuali.rice.kns.bo.Parameter;
031    import org.kuali.rice.kns.document.Document;
032    import org.kuali.rice.kns.util.KualiDecimal;
033    
034    /**
035     * Defines methods that must be implemented by classes providing a PurapService. 
036     */
037    public interface PurapService {
038    
039        /**
040         * Update the status for the given Purchasing/Accounts Payable document
041         * 
042         * @param document
043         * @param statusToSet
044         * @return
045         */
046        public boolean updateStatus(PurchasingAccountsPayableDocument document, String statusToSet);
047    
048        public List<String> getRelatedDocumentIds(Integer accountsPayablePurchasingDocumentLinkIdentifier);
049        
050        public void saveRoutingDataForRelatedDocuments(Integer accountsPayablePurchasingDocumentLinkIdentifier);
051        
052        /**
053         * Retrieve list of views for given identifier
054         * 
055         * @param clazz
056         * @param accountsPayablePurchasingDocumentLinkIdentifier
057         * @return List of views for given identifier
058         */
059        @SuppressWarnings("unchecked")
060        public List getRelatedViews(Class clazz, Integer accountsPayablePurchasingDocumentLinkIdentifier);
061    
062        /**
063         * Add the allowed below the line items to the given document
064         * 
065         * @param document   PurchasingAccountsPayableDocument
066         */
067        public void addBelowLineItems(PurchasingAccountsPayableDocument document);
068    
069        /**
070         * Retrieves the below the line items allowed from the parameter table for the given document
071         * 
072         * @param document  PurchasingAccountsPayableDocument
073         * @return Array list of below the line items 
074         */
075        public String[] getBelowTheLineForDocument(PurchasingAccountsPayableDocument document);
076    
077        /**
078         * Retrieve the below the line item for a doc by item type (unknown result if multiple of same below the line item
079         * type)
080         * 
081         * @param document the document
082         * @param iT the itemType
083         * @return below the line item by item type
084         */
085        public PurApItem getBelowTheLineByType(PurchasingAccountsPayableDocument document, ItemType iT);
086        
087        /**
088         * Return a Date object which is which is a given number of days away from today, in either direction. 
089         * 
090         * @param offsetDays
091         * @return  A java.sql.Date
092         */
093        public Date getDateFromOffsetFromToday(int offsetDays);
094    
095        /**
096         * Determine whether a given date is in the past.
097         * 
098         * @param compareDate An SQL date (not a DateFormatter date, or a util Date)
099         * @return True if the given date is before today.
100         */
101        public boolean isDateInPast(Date compareDate);
102    
103        /**
104         * Determine whether a given date is more than a given number of days away from the current date.
105         * 
106         * @param compareDate An SQL date (not a DateFormatter date, or a util Date)
107         * @param daysAway An int, positive for future days, negative for past days
108         * @return True if the given date is more than the given number of days away in either direction.
109         */
110        public boolean isDateMoreThanANumberOfDaysAway(Date compareDate, int daysAway);
111    
112        /**
113         * We are obliged not to simply use a dateDiff and compare the result to 365, because we have to worry about leap years.
114         * 
115         * @param compareDate An SQL date (not a DateFormatter date, or a util Date)
116         * @return True if the date given for comparison is more than a year in the past, not including today.
117         */
118        public boolean isDateAYearBeforeToday(Date compareDate);
119    
120        /**
121         * Retrieve the Automatic Purchase Order Limit amount based first on the derived contract limit (see
122         * {@link org.kuali.kfs.vnd.document.service.VendorService#getApoLimitFromContract(Integer, String, String)}) and if that is null
123         * then based on the {@link org.kuali.kfs.module.purap.businessobject.OrganizationParameter} associated with the given 'chart' and 'org' values.
124         * 
125         * @param vendorContractGeneratedIdentifier
126         * @param chart chart code to use when looking up limit amount on {@link org.kuali.kfs.vnd.businessobject.VendorContract} and
127         *        {@link org.kuali.kfs.module.purap.businessobject.OrganizationParameter}
128         * @param org organization code to use when looking up limit amount on {@link org.kuali.kfs.vnd.businessobject.VendorContract} and
129         *        {@link org.kuali.kfs.module.purap.businessobject.OrganizationParameter}
130         * @return a KualiDecimal if a valid limit amount is found or null if one is not found
131         */
132        public KualiDecimal getApoLimit(Integer vendorContractGeneratedIdentifier, String chart, String org);
133    
134        /**
135         * Determines if full entry mode has ended for this Purchasing/Accounts Payable document.
136         * 
137         * @param purapDocument PurchasingAccountsPayableDocument
138         * @return a boolean to indicate if document has completed full entry mode
139         */
140        public boolean isFullDocumentEntryCompleted(PurchasingAccountsPayableDocument purapDocument);
141    
142        /**
143         * Create a close or reopen purchase order document.
144         * 
145         * @param purapDocument PurchasingAccountsPayableDocument
146         */
147        public void performLogicForCloseReopenPO(PurchasingAccountsPayableDocument purapDocument);
148    
149        /**
150         * Performs the given logic with the given fake user id.  Need this to control the user.
151         * 
152         * @param requiredPersonPersonUserId
153         * @param logicToRun
154         * @param objects
155         * @return
156         * @throws WorkflowException
157         * @throws Exception
158         */
159        public Object performLogicWithFakedUserSession(String requiredPersonPersonUserId, LogicContainer logicToRun, Object... objects) throws WorkflowException, Exception;
160    
161        /**
162         * Sort the below the line elements of the given document
163         * 
164         * @param document  PurchasingAccountsPayableDocument to be sorted
165         */
166        public void sortBelowTheLine(PurchasingAccountsPayableDocument document);
167        
168        /**
169         * Remove items that have not been "entered" which means no data has been added to them so no more processing needs to continue
170         * on these items.
171         * 
172         * @param apDocument  AccountsPayableDocument which contains list of items to be reviewed
173         */
174        public void deleteUnenteredItems(PurapItemOperations document);
175        
176        /**
177         * Saves the document without doing validation by invoking the saveDocument method of documentService.
178         * 
179         * @param document The purchase order document to be saved.
180         */
181        public void saveDocumentNoValidation(Document document);
182        
183        /**
184         * Determines if a document is in a specified node.
185         * 
186         * @param document
187         * @param nodeName
188         * @return
189         */
190        public boolean isDocumentStoppedInRouteNode(PurchasingAccountsPayableDocument document, String nodeName);
191        
192        /**
193         * Returns true if the current date falls within the allowed range to encumber in the next fiscal year.
194         * 
195         * @return
196         */
197        public boolean allowEncumberNextFiscalYear();
198    
199        /**
200         * Returns a list of fiscal years that can be selected from on the document (built for Requisition and Purchase Order).
201         * Typically only the current year is returned. However, if the current date falls within the allowed range to encumber in the
202         * next fiscal year, the current year and the next current year is returned.
203         * 
204         * @return List<Integer>
205         */
206       public List<Integer> getAllowedFiscalYears();
207       
208       /**
209        * Returns true if today is within the APO allowed date range. If the difference between today and this years closing date is
210        * less than or equal to the number of days allowed for APO.
211        * 
212        * @return boolean
213        */
214       public boolean isTodayWithinApoAllowedRange();
215    
216       /**
217        * Calculates sales or use tax for each item if sales tax enabled and item is taxable.
218        * 
219        * @param purapDocument
220        */
221       public void calculateTax(PurchasingAccountsPayableDocument purapDocument);
222       
223       /**
224        * Clears the tax from a document.  Useful when changing from use to sales
225        * @param purapDocument document
226        * @param useTax the whether to clear use or sales
227        */
228       public void clearTax(PurchasingAccountsPayableDocument purapDocument, boolean useTax);
229       
230       /**
231        * Updates the use tax field, clearing old values if it has changed
232        * @param purapDocument document
233        * @param newUseTaxIndicatorValue useTaxIndicator to change to
234        */
235       public void updateUseTaxIndicator(PurchasingAccountsPayableDocument purapDocument, boolean newUseTaxIndicatorValue);
236       
237       /**
238        * 
239        * Proation for Trade in and Full Order Discount miscellaneous items.
240        * @param purDoc
241        */
242       public void prorateForTradeInAndFullOrderDiscount(PurchasingAccountsPayableDocument purDoc);
243       
244       /**
245        * Determines if the item is taxable based on a decision tree.
246        * 
247        * @param useTaxIndicator
248        * @param deliveryState
249        * @param item
250        * @return
251        */
252       public boolean isTaxable(boolean useTaxIndicator, String deliveryState, PurApItem item);
253    
254       /**
255        * Determines if the item is taxable based on a decision tree.
256        * Does not consider if item is entered, this is not used to calculate tax,
257        * just if the item is indeed taxable.
258        * 
259        * @param useTaxIndicator
260        * @param deliveryState
261        * @param item
262        * @return
263        */
264       public boolean isTaxableForSummary(boolean useTaxIndicator, String deliveryState, PurApItem item);       
265      
266       /**
267        * Retrieves the delivery state from the document 
268        * 
269        * @param purapDocument
270        * @return
271        */
272       public String getDeliveryState(PurchasingAccountsPayableDocument purapDocument);
273    
274       /**
275        * Determines if the accounting line is taxable based on account and object code.
276        * 
277        * @param acctLine
278        * @param deliveryStateTaxable
279        * @return
280        */
281       public boolean isAccountingLineTaxable(PurApAccountingLine acctLine, boolean deliveryStateTaxable);
282       
283       /**
284        * Determines if the delivery state is taxable or not. If parameter is Allow and delivery state in list, or parameter is Denied
285        * and delivery state is not in list then state is taxable.
286        * 
287        * @param deliveryState
288        * @return
289        */
290       public boolean isDeliveryStateTaxable(String deliveryState);
291       
292       public void clearAllTaxes(PurchasingAccountsPayableDocument apDoc);
293       
294       /**
295        * Determines if the item type specified conflict with the Account tax policy.
296        * 
297        * @param purchasingDocument purchasing document to check
298        * @param item item to check if in conflict with tax policy
299        * @return true if item is in conflict, false otherwise
300        */
301       public abstract boolean isItemTypeConflictWithTaxPolicy(PurchasingDocument purchasingDocument, PurApItem item);
302    }
303