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.service;
017    
018    import java.util.List;
019    import java.util.Set;
020    
021    import org.kuali.kfs.module.purap.businessobject.PurApAccountingLine;
022    import org.kuali.kfs.module.purap.businessobject.PurApItem;
023    import org.kuali.kfs.module.purap.document.PaymentRequestDocument;
024    import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
025    import org.kuali.kfs.module.purap.util.SummaryAccount;
026    import org.kuali.kfs.module.purap.util.UseTaxContainer;
027    import org.kuali.kfs.sys.businessobject.SourceAccountingLine;
028    import org.kuali.rice.kns.util.KualiDecimal;
029    
030    /**
031     * This class is used to generate Account Summaries for the Purchasing Accounts Payable Module account lists as well as to generate account lists that can be
032     * used for distribution to below the line items or any other items that may require distribution
033     */
034    public interface PurapAccountingService {
035    
036        /**
037         * unused see other generateAccountDistribution methods
038         * @deprecated
039         * @param accounts
040         * @param totalAmount
041         * @param percentScale
042         * @return
043         */
044        public List<PurApAccountingLine> generateAccountDistributionForProration(List<SourceAccountingLine> accounts, KualiDecimal totalAmount, Integer percentScale);
045    
046        /**
047         * 
048         * Determines an appropriate account distribution for a particular Purchasing Accounts Payable list of Accounts.  It does this by looking at the accounts that were provided
049         * which should be generated from a generateSummary method.  It then builds up a list of PurApAccountingLines (specified by the Class variable) and tries to determine the 
050         * appropriate percents to use on the new accounts, this may require some moving of percents to the last account as a slush. 
051         * 
052         * @param accounts the incoming source accounts from generateSummary
053         * @param totalAmount the total amount of the document
054         * @param percentScale the scale to round to
055         * @param clazz the class of the Purchasing Accounts Payable Account
056         * @return a list of new Purchasing Accounts Payable Accounts
057         */
058        public List<PurApAccountingLine> generateAccountDistributionForProration(List<SourceAccountingLine> accounts, KualiDecimal totalAmount, Integer percentScale, Class clazz);
059    
060        /**
061         * 
062         * Determines an appropriate account distribution for a particular Purchasing Accounts Payable list of Accounts.  It does this by looking at the accounts that were provided
063         * which should be generated from a generateSummary method.  It then builds up a list of PurApAccountingLines (specified by the Class variable) and tries to determine the 
064         * appropriate percents to use on the new accounts, this may require some moving of percents to the last account as a slush.  This is called when a document has a zero dollar
065         * total
066    
067         * @param accounts the incoming source accounts from generateSummary
068         * @param percentScale the scale to round to
069         * @param clazz the class of the Purchasing Accounts Payable Account
070         * @return a list of new Purchasing Accounts Payable Accounts
071         */
072        public List<PurApAccountingLine> generateAccountDistributionForProrationWithZeroTotal(PurchasingAccountsPayableDocument purapdoc);
073    
074        /**
075         * 
076         * This creates summary accounts based on a list of items.
077         * @param document the document to generate the summary accounts from
078         * @return a list of summary accounts.
079         */
080        public List<SummaryAccount> generateSummaryAccounts(PurchasingAccountsPayableDocument document);
081    
082        /**
083         * 
084         * This creates summary accounts based on a list of items excluding zero totals.
085         * @param document the document to generate the summary accounts from
086         * @return a list of summary accounts.
087         */
088        public List<SummaryAccount> generateSummaryAccountsWithNoZeroTotals(PurchasingAccountsPayableDocument document);
089    
090        
091    
092        /**
093         * 
094         * This creates summary accounts based on a list of items excluding zero totals and use tax.
095         * @param document the document to generate the summary accounts from
096         * @return a list of summary accounts.
097         */
098        public List<SummaryAccount> generateSummaryAccountsWithNoZeroTotalsNoUseTax(PurchasingAccountsPayableDocument document);
099    
100        
101        /**
102         * 
103         * Generates an account summary, that is it creates a list of source accounts
104         * by rounding up the Purchasing Accounts Payable accounts off of the Purchasing Accounts Payable items.
105         *
106         * @param document the document to generate the summary from
107         * @return a list of source accounts
108         */
109        public List<SourceAccountingLine> generateSummary(List<PurApItem> items);
110        
111        /**
112         * Generates an account summary with only taxable accounts.
113         * 
114         * @param items
115         * @return
116         */
117        public List<SourceAccountingLine> generateSummaryTaxableAccounts(List<PurApItem> items);
118        
119        /**
120         * 
121         * convenience method that generates a list of source accounts while excluding items with
122         * $0 amounts
123         * 
124         * @param items the items to generate source accounts from
125         * @return a list of source accounts "rolled up" from the purap accounts 
126         */
127        public List<SourceAccountingLine> generateSummaryWithNoZeroTotals(List<PurApItem> items);
128        
129        /**
130         * 
131         * convenience method that generates a list of source accounts while excluding items with
132         * $0 amounts and use tax
133         * 
134         * @param items the items to generate source accounts from
135         * @return a list of source accounts "rolled up" from the purap accounts 
136         */
137        public List<SourceAccountingLine> generateSummaryWithNoZeroTotalsNoUseTax(List<PurApItem> items);
138        
139        /**
140         * 
141         * convenience method that generates a list of source accounts while excluding items with
142         * $0 amounts and using the alternate amount
143         * 
144         * @param items the items to generate source accounts from
145         * @return a list of source accounts "rolled up" from the purap accounts 
146         */
147        public List<SourceAccountingLine> generateSummaryWithNoZeroTotalsUsingAlternateAmount(List<PurApItem> items);
148        
149        /**
150         * 
151         * convenience method that generates a list of source accounts while excluding items with
152         * the specified item types
153         * 
154         * @param items the items to generate source accounts from
155         * @param excludedItemTypeCodes the item types to exclude
156         * @return a list of source accounts "rolled up" from the purap accounts 
157         */
158        public List<SourceAccountingLine> generateSummaryExcludeItemTypes(List<PurApItem> items, Set excludedItemTypeCodes);
159    
160        /**
161         * 
162         * convenience method that generates a list of source accounts while excluding items with
163         * the specified item types and not including items with zero totals
164         * 
165         * @param items the items to generate source accounts from
166         * @param excludedItemTypeCodes the item types to exclude
167         * @return a list of source accounts "rolled up" from the purap accounts 
168         */
169        public List<SourceAccountingLine> generateSummaryExcludeItemTypesAndNoZeroTotals(List<PurApItem> items, Set excludedItemTypeCodes);
170    
171        /**
172         * 
173         * convenience method that generates a list of source accounts while only including items with
174         * the specified item types
175         * 
176         * @param items the items to generate source accounts from
177         * @param excludedItemTypeCodes the item types to include
178         * @return a list of source accounts "rolled up" from the purap accounts 
179         */
180        public List<SourceAccountingLine> generateSummaryIncludeItemTypes(List<PurApItem> items, Set includedItemTypeCodes);
181    
182        /**
183         * 
184         * convenience method that generates a list of source accounts while only including items with
185         * the specified item types and not including items with zero totals
186         * 
187         * @param items the items to generate source accounts from
188         * @param excludedItemTypeCodes the item types to include
189         * @return a list of source accounts "rolled up" from the purap accounts 
190         */
191        public List<SourceAccountingLine> generateSummaryIncludeItemTypesAndNoZeroTotals(List<PurApItem> items, Set includedItemTypeCodes);
192    
193        /**
194         * Updates account amounts based on the percents.  If this is a preq past full entry it updates the
195         * percents based on the amounts instead
196         * 
197         * @param document the document
198         */
199        public void updateAccountAmounts(PurchasingAccountsPayableDocument document);
200        
201        /**
202         * Updates a single items account amounts
203         * 
204         * @param item
205         */
206        public void updateItemAccountAmounts(PurApItem item);
207    
208        public List<PurApAccountingLine> getAccountsFromItem(PurApItem item);
209        
210        /**
211         * Deletes the ap summary accounts by the id of the doc type (Payment Request - PREQ or Credit Memo - CM)
212         * 
213         * @param purapDocumentIdentifier  The purapDocumentIdentifier of the document whose summary accounts are to be deleted.
214         */
215        public void deleteSummaryAccounts(Integer purapDocumentIdentifier, String docType);
216        
217        /**
218         * Retrieves the ap summary accounts by the id of the doc type (Payment Request - PREQ or Credit Memo - CM)
219         * 
220         * @param purapDocumentIdentifier  The purapDocumentIdentifier of the document.
221         */
222        public List getAccountsPayableSummaryAccounts(Integer purapDocumentIdentifier, String docType);
223    
224        /**
225         * 
226         * This method generates summary accounts for a vendor payment.
227         * @param document
228         * @return   This will get the proper amount on the items that is sent to the vendor
229         */
230        public List<SourceAccountingLine> generateSourceAccountsForVendorRemit(PurchasingAccountsPayableDocument document);
231        
232        /**
233         * Converts the amount to percent and updates the percent field on the CreditMemoAccount
234         * 
235         * @param pr The payment request document containing the accounts whose percentage would be set.
236         */
237        public void convertMoneyToPercent(PaymentRequestDocument pr);
238        
239        /**
240         * Generates use tax helper class for a purap document
241         * @param document
242         * @return useTaxContainer
243         */
244        public List<UseTaxContainer> generateUseTaxAccount(PurchasingAccountsPayableDocument document);
245        
246        /**
247         * Checks whether the specified accounting line in the specified PurAP document is used for tax withholding. 
248         * This applies only to PaymentRequestDocument; otherwise it always returns false. 
249         * @param document the specified PurAP document
250         * @param account the specified accounting line
251         * @return true if the accounting line is a tax account
252         */
253        public boolean isTaxAccount(PurchasingAccountsPayableDocument document, SourceAccountingLine account);
254    
255        /**
256         * calculates values for a list of accounting lines based on an amount
257         * 
258         * @param <T>
259         * @param sourceAccountingLines
260         * @param totalAmount
261         */
262        public <T extends PurApAccountingLine> void updateAccountAmountsWithTotal(List<T> sourceAccountingLines, KualiDecimal totalAmount);
263    
264        /**
265         * Merges list 2 into list 1
266         * 
267         * @param list1
268         * @param list2
269         * @return
270         */
271        public List<SourceAccountingLine> mergeAccountingLineLists(List<SourceAccountingLine> accountingLines1, List<SourceAccountingLine> accountingLines2);
272        
273    }