View Javadoc
1   /*
2    * Copyright 2007 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.document.InvoiceDocument;
19  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
20  import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
21  import org.kuali.ole.module.purap.util.VendorGroupingHelper;
22  import org.kuali.ole.vnd.businessobject.PaymentTermType;
23  import org.kuali.rice.core.api.util.type.KualiDecimal;
24  import org.kuali.rice.kew.api.exception.WorkflowException;
25  
26  import java.sql.Date;
27  import java.util.Collection;
28  import java.util.HashMap;
29  import java.util.List;
30  
31  /**
32   * Defines methods that must be implemented by a InvoiceService implementation.
33   */
34  public interface InvoiceService extends AccountsPayableDocumentSpecificService {
35  
36      /**
37       * Obtains a list of invoice documents given the purchase order id.
38       *
39       * @param poDocId The purchase order id to be used to obtain a list of invoice documents.
40       * @return The List of invoice documents given the purchase order id.
41       */
42      public List<InvoiceDocument> getInvoicesByPurchaseOrderId(Integer poDocId);
43  
44      /**
45       * Obtains a list of invoice documents given the purchase order id, the invoice amount
46       * and the invoice date.
47       *
48       * @param poId          The purchase order id used to obtain the invoice documents.
49       * @param invoiceAmount The invoice amount used to obtain the invoice documents.
50       * @param invoiceDate   The invoice date used to obtain the invoice documents.
51       * @return The List of invoice documents that match the given criterias (purchase order id, invoice amount and invoice date).
52       */
53      public List getInvoicesByPOIdInvoiceAmountInvoiceDate(Integer poId, KualiDecimal invoiceAmount, Date invoiceDate);
54  
55      /**
56       * Obtains a list of invoice documents given the vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifier and the invoice number.
57       *
58       * @param vendorHeaderGeneratedIdentifier
59       *                                       The vendorHeaderGeneratedIdentifier used to obtain the invoice documents.
60       * @param vendorDetailAssignedIdentifier The vendorDetailAssignedIdentifier used to obtain the invoice documents.
61       * @return The List of invoice documents that match the given criterias.
62       */
63      public List getInvoicesByVendorNumber(Integer vendorHeaderGeneratedIdentifier, Integer vendorDetailAssignedIdentifier);
64  
65      /**
66       * Obtains a list of invoice documents given the vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifier and the invoice number.
67       *
68       * @param vendorHeaderGeneratedIdentifier
69       *                                       The vendorHeaderGeneratedIdentifier used to obtain the invoice documents.
70       * @param vendorDetailAssignedIdentifier The vendorDetailAssignedIdentifier used to obtain the invoice documents.
71       * @param invoiceNumber                  The invoice number used to obtain the invoice documents.
72       * @return The List of invoice documents that match the given criterias.
73       */
74      public List getInvoicesByVendorNumberInvoiceNumber(Integer vendorHeaderGeneratedIdentifier, Integer vendorDetailAssignedIdentifier, String invoiceNumber);
75  
76  
77      /**
78       * Determines whether the invoice date is after today.
79       *
80       * @param invoiceDate The invoice date to be determined whether it's after today.
81       * @return boolean true if the given invoice date is after today.
82       */
83      public boolean isInvoiceDateAfterToday(Date invoiceDate);
84  
85      /**
86       * Performs the processing to check whether the invoice is a duplicate and if so, adds
87       * the information about the type of duplication into the resulting HashMap to be returned by this method.
88       *
89       * @param document The invoice document to be processed/checked for duplicates.
90       * @return The HashMap containing "PREQDuplicateInvoice" as the key and the string
91       *         describing the types of duplication as the value.
92       */
93      public HashMap<String, String> invoiceDuplicateMessages(InvoiceDocument document);
94  
95      /**
96       * Calculate based on the terms and calculate a date 10 days from today. Pick the one that is the farthest out. We always
97       * calculate the discount date, if there is one.
98       *
99       * @param invoiceDate The invoice date to be used in the pay date calculation.
100      * @param terms       The payment term type to be used in the pay date calculation.
101      * @return The resulting pay date given the invoice date and the terms.
102      */
103     public Date calculatePayDate(Date invoiceDate, PaymentTermType terms);
104 
105     /**
106      * Marks a invoice on hold.
107      *
108      * @param document The invoice document to be marked as on hold.
109      * @param note     The note to be added to the invoice document while being marked as on hold.
110      * @return The InvoiceDocument with updated information.
111      * @throws Exception
112      */
113     public InvoiceDocument addHoldOnInvoice(InvoiceDocument document, String note) throws Exception;
114 
115     /**
116      * Removes a hold on a invoice.
117      *
118      * @param document The invoice document whose hold is to be removed.
119      * @param note     The note to be added to the invoice document while its hold is being removed.
120      * @return The InvoiceDocument with updated information.
121      * @throws Exception
122      */
123     public InvoiceDocument removeHoldOnInvoice(InvoiceDocument document, String note) throws Exception;
124 
125     /**
126      * Obtains the invoice document given the purapDocumentIdentifier.
127      *
128      * @param poDocId The purapDocumentIdentifier of the invoice document to be obtained.
129      * @return The invoice document whose purapDocumentIdentifier matches with the input parameter.
130      */
131     public InvoiceDocument getInvoiceById(Integer poDocId);
132 
133     /**
134      * Obtains the invoice document given the document number.
135      *
136      * @param documentNumber The document number to be used to obtain the invoice document.
137      * @return The invoice document whose document number matches with the given input parameter.
138      */
139     public InvoiceDocument getInvoiceByDocumentNumber(String documentNumber);
140 
141     /**
142      * Marks a invoice as requested to be canceled.
143      *
144      * @param document The invoice document to be marked as requested to be canceled.
145      * @param note     The note to be added to the invoice document while being marked as requested to be canceled.
146      * @throws Exception
147      */
148     public void requestCancelOnInvoice(InvoiceDocument document, String note) throws Exception;
149 
150     /**
151      * Returns true if the invoice has been extracted
152      *
153      * @param document The invoice document to be determined whether it is extracted.
154      * @return boolean true if the invoice document is extracted.
155      */
156     public boolean isExtracted(InvoiceDocument document);
157 
158     /**
159      * Removes a request cancel on invoice.
160      *
161      * @param document The invoice document to be used for request cancel.
162      * @param note     The note to be added to the invoice document upon the removal of the request cancel.
163      * @throws Exception
164      */
165     public void removeRequestCancelOnInvoice(InvoiceDocument document, String note) throws Exception;
166 
167     /**
168      * Resets a Invoice that had an associated Invoice or Credit Memo cancelled externally.
169      *
170      * @param invoice The extracted invoice document to be resetted.
171      * @param note    The note to be added to the invoice document upon its reset.
172      */
173     public void resetExtractedInvoice(InvoiceDocument invoice, String note);
174 
175     /**
176      * Cancels a PREQ that has already been extracted if allowed.
177      *
178      * @param invoice The extracted invoice document to be canceled.
179      * @param note    The note to be added to the invoice document.
180      */
181     public void cancelExtractedInvoice(InvoiceDocument invoice, String note);
182 
183     /**
184      * Get all the invoices that are immediate and need to be extracted to PDP.
185      *
186      * @param chartCode The chart code to be used as one of the criterias to retrieve the invoice documents.
187      * @return The iterator of the list of the resulting invoice documents returned by the invoiceDao.
188      */
189     public Collection<InvoiceDocument> getImmediateInvoicesToExtract(String chartCode);
190 
191     /**
192      * Get all the invoices that match a credit memo.
193      *
194      * @param cmd The credit memo document to be used to obtain the invoices.
195      * @return The iterator of the resulting invoice documents returned by the invoiceDao.
196      */
197     public Collection<InvoiceDocument> getInvoicesToExtractByCM(String campusCode, VendorCreditMemoDocument cmd);
198 
199     /**
200      * Get all the invoices that match a vendor.
201      *
202      * @param vendor
203      * @param onOrBeforeInvoicePayDate only invoices with a pay date on or before this date will be extracted
204      * @return Collection of the resulting invoice documents returned by the invoiceDao.
205      */
206     public Collection<InvoiceDocument> getInvoicesToExtractByVendor(String campusCode, VendorGroupingHelper vendor, Date onOrBeforeInvoicePayDate);
207 
208     /**
209      * Get all the invoices that need to be extracted.
210      *
211      * @return The Collection of the resulting invoice documents returned by the invoiceDao.
212      */
213     public Collection<InvoiceDocument> getInvoicesToExtract(Date onOrBeforeInvoicePayDate);
214 
215     /**
216      * Get all the special invoices for a single chart that need to be extracted.
217      *
218      * @param chartCode The chart code to be used as one of the criterias to retrieve the invoice documents.
219      * @return The Collection of the resulting invoice documents returned by the invoiceDao.
220      */
221     public Collection<InvoiceDocument> getInvoicesToExtractSpecialPayments(String chartCode, Date onOrBeforeInvoicePayDate);
222 
223     /**
224      * Get all the regular invoices for a single campus.
225      *
226      * @param chartCode The chart code to be used as one of the criterias to retrieve the invoice documents.
227      * @return The collection of the resulting invoice documents returned by the invoiceDao.
228      */
229     public Collection<InvoiceDocument> getInvoiceToExtractByChart(String chartCode, Date onOrBeforeInvoicePayDate);
230 
231     /**
232      * Recalculate the invoice.
233      *
234      * @param pr             The invoice document to be calculated.
235      * @param updateDiscount boolean true if we also want to calculate the discount items for the invoice.
236      */
237     public void calculateInvoice(InvoiceDocument pr, boolean updateDiscount);
238 
239     /**
240      * Performs calculations on the tax edit area, generates and adds NRA tax charge items as below the line items, with their accounting lines;
241      * the calculation will activate updates on the account summary tab and the general ledger entries as well.
242      * <p/>
243      * The non-resident alien (NRA) tax lines consist of four possible sets of tax lines:
244      * - Federal tax lines
245      * - Federal Gross up tax lines
246      * - State tax lines
247      * - State Gross up tax lines
248      * <p/>
249      * Federal tax lines are generated if the federal tax rate in the invoice is not zero.
250      * State tax lines are generated if the state tax rate in the invoice is not zero.
251      * Gross up tax lines are generated if the tax gross up indicator is set on the invoice and the tax rate is not zero.
252      *
253      * @param preq The invoice the NRA tax lines will be added to.
254      */
255     public void calculateTaxArea(InvoiceDocument preq);
256 
257     /**
258      * Populate invoice.
259      *
260      * @param preq  The invoice document to be populated.
261      */
262     // public void populateInvoice(InvoiceDocument preq);
263 
264     /**
265      * Populate and save invoice.
266      *
267      * @param preq The invoice document to be populated and saved.
268      */
269     public void populateAndSaveInvoice(InvoiceDocument preq) throws WorkflowException;
270 
271     /**
272      * Retrieve a list of PREQs that aren't approved, check to see if they match specific requirements, then auto-approve them if
273      * possible.
274      *
275      * @return boolean true if the auto approval of invoices has at least one error.
276      */
277     public boolean autoApproveInvoices();
278 
279     /**
280      * Checks whether the invoice document is eligible for auto approval. If so, then updates
281      * the status of the document to auto approved and calls the documentService to blanket approve
282      * the document, then returns false.
283      * If the document is not eligible for auto approval then returns true.
284      *
285      * @param docNumber           The invoice document number (not the invoice ID) to be auto approved.
286      * @param defaultMinimumLimit The default minimum limit amount to be used in determining the eligibility of the document to be auto approved.
287      * @return boolean true if the invoice document is not eligible for auto approval.
288      * @throws RuntimeException To indicate to Spring transactional management that the transaction for this document should be rolled back
289      */
290     public boolean autoApproveInvoice(String docNumber, KualiDecimal defaultMinimumLimit);
291 
292     /**
293      * Checks whether the invoice document is eligible for auto approval. If so, then updates
294      * the status of the document to auto approved and calls the documentService to blanket approve
295      * the document, then returns false.
296      * If the document is not eligible for auto approval then returns true.
297      *
298      * @param doc                 The invoice document to be auto approved.
299      * @param defaultMinimumLimit The default minimum limit amount to be used in determining the eligibility of the document to be auto approved.
300      * @return boolean true if the invoice document is not eligible for auto approval.
301      * @throws RuntimeException To indicate to Spring transactional management that the transaction for this document should be rolled back
302      */
303     public boolean autoApproveInvoice(InvoiceDocument doc, KualiDecimal defaultMinimumLimit);
304 
305     /**
306      * Mark a invoice as being paid and set the invoice's paid date as the processDate.
307      *
308      * @param pr          The invoice document to be marked as paid and paid date to be set.
309      * @param processDate The date to be set as the invoice's paid date.
310      */
311     public void markPaid(InvoiceDocument pr, Date processDate);
312 
313     /**
314      * This method specifies whether the invoice document has a discount item.
315      *
316      * @param preq The invoice document to be verified whether it has a discount item.
317      * @return boolean true if the invoice document has at least one discount item.
318      */
319     public boolean hasDiscountItem(InvoiceDocument preq);
320 
321     /**
322      * Changes the current vendor to the vendor passed in.
323      *
324      * @param preq
325      * @param headerId
326      * @param detailId
327      */
328     public void changeVendor(InvoiceDocument preq, Integer headerId, Integer detailId);
329 
330     /**
331      * A method to create the description for the invoice document.
332      *
333      * @param purchaseOrderIdentifier The purchase order identifier to be used as part of the description.
334      * @param vendorName              The vendor name to be used as part of the description.
335      * @return The resulting description string for the invoice document.
336      */
337     public String createPreqDocumentDescription(Integer purchaseOrderIdentifier, String vendorName);
338 
339     /**
340      * Determines if there are active invoices for a purchase order.
341      *
342      * @param purchaseOrderIdentifier
343      * @return
344      */
345     public boolean hasActiveInvoicesForPurchaseOrder(Integer purchaseOrderIdentifier);
346 
347     public void processInvoiceInReceivingStatus();
348 
349     /**
350      * Invoices created in the previous fiscal year get backdated if we're at the beginning of the new fiscal year (i.e.
351      * prior to first closing)
352      *
353      * @param invoiceDocument
354      * @return
355      */
356     public boolean allowBackpost(InvoiceDocument invoiceDocument);
357 
358     public boolean isPurchaseOrderValidForInvoiceDocumentCreation(InvoiceDocument invoiceDocument, PurchaseOrderDocument po);
359 
360     /**
361      * Removes additional charge items that are not eligible on the invoice document.
362      *
363      * @param document
364      */
365     public void removeIneligibleAdditionalCharges(InvoiceDocument document);
366 
367     public boolean encumberedItemExistsForInvoicing(PurchaseOrderDocument document);
368 
369     /**
370      * Clears tax info.
371      *
372      * @param document The disbursement voucher document being modified.
373      */
374     public void clearTax(InvoiceDocument document);
375 
376     /**
377      * Checks whether the invoice document is eligible for auto approval. If so, then updates
378      * the status of the document to auto approved and calls the documentService to blanket approve
379      * the document, then returns false.
380      * If the document is not eligible for auto approval then returns true.
381      *
382      * @param docNumber The invoice document number (not the invoice ID) to be auto approved.
383      * @return boolean true if the invoice document is not eligible for auto approval.
384      * @throws RuntimeException To indicate to Spring transactional management that the transaction for this document should be rolled back
385      */
386     public boolean autoApprovePaymentRequest(String docNumber);
387 
388     public String getParameter(String namespaceCode, String componentCode, String parameterName);
389 
390     public boolean getParameterBoolean(String namespaceCode, String componentCode, String parameterName);
391 
392 }
393