DBA Data[Home] [Help]

PACKAGE BODY: APPS.AP_ETAX_PKG

Source


1 PACKAGE BODY AP_ETAX_PKG AS
2 /* $Header: apetaxpb.pls 120.15 2006/12/21 18:59:58 smyadam noship $ */
3 
4 /*=============================================================================
5  |  FUNCTION - Calling_eTax()
6  |
7  |  DESCRIPTION
8  |      Public function that will call the requested AP_ETAX_SERVICES_PKG  function
9  |      This API is called from different points throughout AP.
10  |      This API assumes the calling code controls the commit cycle.
11  |      This function returns TRUE if the call to the service is successful.
12  |      Otherwise, FALSE.
13  |
14  |  PARAMETERS
15  |      P_Invoice_Id - invoice id
16  |      P_Line_Number - This parameter will be used to allow this API to
17  |                      calculate tax only for the line specified in this
18  |                      parameter.  Additionally, this parameter will be used
19  |                      to determine the PREPAY line created for prepayment
20  |                      unapplications.
21  |      P_Calling_Mode - calling mode.  Identifies which service to call
22  |      P_Override_Status - only for calling_mode OVERRIDE TAX
23  |      P_Line_Number_To_Delete - required when calling mode is MARK TAX LINES DELETED
24  |      P_Interface_Invoice_Id - invoice id in the ap_invoices_interface table.
25  |                               this parameter is used only while calling the
26  |                               API to calculate tax from the import program
27  |      P_All_Error_Messages -  Determine if the calling point wants the returning
28  |                              of all or only 1 error message.  Calling point will
29  |                              pass Y in the case they want to handle the return of
30  |                              more than one message from the FND message pile. N
31  |                              if they just want 1 message to be returned.
32  |      P_error_code - Error code to be returned
33  |      P_calling_sequence -  Calling sequence
34  |
35  |  MODIFICATION HISTORY
36  |    DATE          Author         Action
37  |    07-OCT-2003   SYIDNER        Created
38  |    05-NOV-2003   SYIDNER        Included new P_Line_Number_To_Delete and
39  |                                 P_All_Error_Messages parameters
40  |    05-MAR-2004   SYIDNER        Included P_Line_Number as a new parameter
41  |
42  *============================================================================*/
43 
44   FUNCTION Calling_eTax(
45              P_Invoice_id              IN  NUMBER,
46              P_Line_Number             IN  NUMBER 			DEFAULT NULL,
47              P_Calling_Mode            IN  VARCHAR2,
48              P_Override_Status         IN  VARCHAR2 			DEFAULT NULL,
49              P_Line_Number_To_Delete   IN  NUMBER 			DEFAULT NULL,
50              P_Interface_Invoice_Id    IN  NUMBER 			DEFAULT NULL,
51 	     P_Event_Id		       IN  NUMBER			DEFAULT NULL,
52              P_All_Error_Messages      IN  VARCHAR2,
53              P_error_code              OUT NOCOPY VARCHAR2,
54              P_Calling_Sequence        IN  VARCHAR2) RETURN BOOLEAN
55 
56   IS
57     l_debug_info                 VARCHAR2(240);
58     l_curr_calling_sequence      VARCHAR2(4000);
59 
60     l_return_status              BOOLEAN := TRUE;
61 
62   BEGIN
63 
64     l_curr_calling_sequence := 'AP_ETAX_PKG.Calling_eTax<-' ||
65                                P_calling_sequence;
66 
67     ------------------------------------------------------------------
68     l_debug_info := 'Step 1: P_Calling_Mode is:'||P_Calling_Mode;
69     ------------------------------------------------------------------
70 
71 
72     IF (P_Calling_Mode IN ('CALCULATE', 'APPLY PREPAY')) THEN
73       -------------------------------------------------------------------
74       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Calculate';
75       -------------------------------------------------------------------
76 
77       IF NOT (AP_ETAX_SERVICES_PKG.Calculate(
78                                P_Invoice_id             => P_Invoice_Id,
79                                P_Line_Number            => P_Line_Number,
80                                P_Calling_Mode           => P_Calling_Mode,
81                                P_All_Error_Messages     => P_All_Error_Messages,
82                                P_Error_Code             => P_Error_Code,
83                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
84 
85         l_return_status := FALSE;
86       END IF;
87 
88     ELSIF (P_Calling_Mode = 'CALCULATE IMPORT') THEN
89       -------------------------------------------------------------------
90       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Calculate_Import';
91       -------------------------------------------------------------------
92 
93       IF NOT (AP_ETAX_SERVICES_PKG.Calculate_Import(
94                                P_Invoice_id             => P_Invoice_Id,
95                                P_Calling_Mode           => P_Calling_Mode,
96                                P_Interface_Invoice_Id   => P_Interface_Invoice_Id,
97                                P_All_Error_Messages     => P_All_Error_Messages,
98                                P_Error_Code             => P_Error_Code,
99                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
100 
101         l_return_status := FALSE;
102       END IF;
103 
104 
105     ELSIF (P_Calling_Mode IN ('DISTRIBUTE', 'DISTRIBUTE RECOUP')) THEN
106       -------------------------------------------------------------------
107       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Distribute';
108       -------------------------------------------------------------------
109 
110       IF NOT (AP_ETAX_SERVICES_PKG.Distribute(
111                                P_Invoice_id             => P_Invoice_Id,
112                                P_Line_Number            => P_Line_Number,
113                                P_Calling_Mode           => P_Calling_Mode,
114                                P_All_Error_Messages     => P_All_Error_Messages,
115                                P_Error_Code             => P_Error_Code,
116                                P_Calling_Sequence       => l_curr_calling_sequence))  THEN
117 
118         l_return_status := FALSE;
119       END IF;
120 
121     ELSIF (P_Calling_Mode = 'DISTRIBUTE IMPORT') THEN
122       -------------------------------------------------------------------
123       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Distribute_Import';
124       -------------------------------------------------------------------
125 
126       IF NOT (AP_ETAX_SERVICES_PKG.Distribute_Import(
127                                P_Invoice_id             => P_Invoice_Id,
128                                P_Calling_Mode           => P_Calling_Mode,
129                                P_All_Error_Messages     => P_All_Error_Messages,
130                                P_Error_Code             => P_Error_Code,
131                                P_Calling_Sequence       => l_curr_calling_sequence))  THEN
132 
133         l_return_status := FALSE;
134       END IF;
135 
136     ELSIF (P_Calling_Mode = 'IMPORT INTERFACE') THEN
137       -------------------------------------------------------------------
138       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Import_Interface';
139       -------------------------------------------------------------------
140 
141       IF NOT (AP_ETAX_SERVICES_PKG.Import_Interface(
142                                P_Invoice_id             => P_Invoice_Id,
143                                P_Calling_Mode           => P_Calling_Mode,
144                                P_Interface_Invoice_Id   => P_Interface_Invoice_Id,
145                                P_All_Error_Messages     => P_All_Error_Messages,
146                                P_Error_Code             => P_Error_Code,
147                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
148 
149         l_return_status := FALSE;
150       END IF;
151 
152     ELSIF (P_Calling_Mode = 'REVERSE INVOICE') THEN
153       -------------------------------------------------------------------
154       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Reverse_Invoice';
155       -------------------------------------------------------------------
156 
157       IF NOT (AP_ETAX_SERVICES_PKG.Reverse_Invoice(
158                                P_Invoice_id             => P_Invoice_Id,
159                                P_Calling_Mode           => P_Calling_Mode,
160                                P_All_Error_Messages     => P_All_Error_Messages,
161                                P_Error_Code             => P_Error_Code,
162                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
163 
164         l_return_status := FALSE;
165       END IF;
166 
167     ELSIF (P_Calling_Mode = 'OVERRIDE TAX') THEN
168       -------------------------------------------------------------------
169       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Override_Tax';
170       -------------------------------------------------------------------
171 
172       IF NOT (AP_ETAX_SERVICES_PKG.Override_Tax(
173                                P_Invoice_id             => P_Invoice_Id,
174                                P_Calling_Mode           => P_Calling_Mode,
175                                P_Override_Status        => P_Override_Status,
176 			       P_Event_Id		=> P_Event_Id,
177                                P_All_Error_Messages     => P_All_Error_Messages,
178                                P_Error_Code             => P_Error_Code,
179                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
180 
181         l_return_status := FALSE;
182       END IF;
183 
184     ELSIF (P_Calling_Mode = 'OVERRIDE RECOVERY') THEN
185       -------------------------------------------------------------------
186       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Override_Recovery';
187       -------------------------------------------------------------------
188 
189       IF NOT (AP_ETAX_SERVICES_PKG.Override_Recovery(
190                                P_Invoice_id             => P_Invoice_Id,
191                                P_Calling_Mode           => P_Calling_Mode,
192                                P_All_Error_Messages     => P_All_Error_Messages,
193                                P_Error_Code             => P_Error_Code,
194                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
195 
196         l_return_status := FALSE;
197       END IF;
198 
199     ELSIF (P_Calling_Mode IN  ('CANCEL INVOICE',
200                                'FREEZE INVOICE',
201                                'UNFREEZE INVOICE',
202 			       'DISCARD LINE',
203 			       'UNAPPLY PREPAY')) THEN  --bugfix:5697764
204       -------------------------------------------------------------------
205       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Global_Document_Update';
206       -------------------------------------------------------------------
207 
208       IF P_Calling_Mode IN ('DISCARD LINE', 'UNAPPLY PREPAY') THEN
209          IF NOT (AP_ETAX_SERVICES_PKG.Global_Document_Update(
210                                P_Invoice_id              => P_Invoice_Id,
211 			       P_Line_Number	 	 => P_Line_Number,
212                                P_Calling_Mode            => P_Calling_Mode,
213                                P_All_Error_Messages      => P_All_Error_Messages,
214                                P_Error_Code              => P_Error_Code,
215                                P_Calling_Sequence        => l_curr_calling_sequence)) THEN
216 
217             l_return_status := FALSE;
218           END IF;
219       ELSE
220           IF NOT (AP_ETAX_SERVICES_PKG.Global_Document_Update(
221                                P_Invoice_id              => P_Invoice_Id,
222                                P_Calling_Mode            => P_Calling_Mode,
223                                P_All_Error_Messages     => P_All_Error_Messages,
224                                P_Error_Code              => P_Error_Code,
225                                P_Calling_Sequence        => l_curr_calling_sequence)) THEN
226 
227             l_return_status := FALSE;
228           END IF;
229       END IF;
230 
231     ELSIF (P_Calling_Mode = 'MARK TAX LINES DELETED') THEN
232       -------------------------------------------------------------------
233       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Mark_Tax_Lines_Deleted';
234       -------------------------------------------------------------------
235 
236       IF NOT (AP_ETAX_SERVICES_PKG.Mark_Tax_Lines_Deleted(
237                                P_Invoice_id             => P_Invoice_Id,
238                                P_Calling_Mode           => P_Calling_Mode,
239                                P_Line_Number_To_Delete  => P_Line_Number_To_Delete,
240                                P_All_Error_Messages     => P_All_Error_Messages,
241                                P_Error_Code             => P_Error_Code,
242                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
243 
244         l_return_status := FALSE;
245       END IF;
246 
247 
248     ELSIF (P_Calling_Mode = 'VALIDATE') THEN
249       -------------------------------------------------------------------
250       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Validate_Invoice';
251       -------------------------------------------------------------------
252 
253       IF NOT (AP_ETAX_SERVICES_PKG.Validate_Invoice(
254                                P_Invoice_id             => P_Invoice_Id,
255                                P_Calling_Mode           => P_Calling_Mode,
256                                P_All_Error_Messages     => P_All_Error_Messages,
257                                P_Error_Code             => P_Error_Code,
258                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
259 
260         l_return_status := FALSE;
261       END IF;
262 
263     ELSIF (P_Calling_Mode = 'RECOUPMENT') THEN
264       -------------------------------------------------------------------
265       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Generate_Recouped_Tax';
266       -------------------------------------------------------------------
267 
268       IF NOT (AP_ETAX_SERVICES_PKG.Generate_Recouped_Tax(
269                                P_Invoice_id             => P_Invoice_Id,
270 			       P_Invoice_Line_Number	=> P_Line_Number,
271                                P_Calling_Mode           => P_Calling_Mode,
272                                P_All_Error_Messages     => P_All_Error_Messages,
273                                P_Error_Code             => P_Error_Code,
277       END IF;
274                                P_Calling_Sequence       => l_curr_calling_sequence)) THEN
275 
276         l_return_status := FALSE;
278 
279     ELSIF (P_Calling_Mode = 'DELETE_TAX_DIST') THEN
280       -------------------------------------------------------------------
281       l_debug_info := 'Step 2: Calling AP_ETAX_SERVICES_PKG.Delete_Tax_Distributions';
282       -------------------------------------------------------------------
283 
284       IF NOT (AP_ETAX_SERVICES_PKG.Delete_Tax_Distributions
285                         (p_invoice_id         => P_Invoice_Id,
286                          p_calling_mode       => P_Calling_Mode,
287                          p_all_error_messages => P_All_Error_Messages,
288                          p_error_code         => P_Error_Code,
289                          p_calling_sequence   => l_curr_calling_sequence)) THEN
290 
291         l_return_status := FALSE;
292       END IF;
293 
294     END IF;
295 
296     RETURN l_return_status;
297 
298   EXCEPTION
299     WHEN OTHERS THEN
300       IF (SQLCODE <> -20001) THEN
301         FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
302         FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
303         FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',l_curr_calling_sequence);
304         FND_MESSAGE.SET_TOKEN('PARAMETERS',
305           ' P_Invoice_Id = '||P_Invoice_Id||
306           ' P_Calling_Mode = '||P_Calling_Mode||
307           ' P_Override_Status = '||P_Override_Status||
308           ' P_Line_Number_To_Delete = '||P_Line_Number_To_Delete||
309           ' P_All_Error_Messages = '||P_All_Error_Messages||
310           ' P_Error_Code = '||P_Error_Code||
311           ' P_Calling_Sequence = '||P_Calling_Sequence);
312         FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
313 
314       END IF;
315       APP_EXCEPTION.RAISE_EXCEPTION;
316 
317   END Calling_eTax;
318 
319 
320 /*=============================================================================
321  |  FUNCTION - Calculate_Quote ()
322  |
323  |  DESCRIPTION
324  |      This function will return the tax amount and indicate if it is inclusive.
325  |      This will be called from the recurring invoices form. This is a special
326  |      case, as the invoices for which the tax is to be calculated are not yet
327  |      saved to the database and eBTax global temporary tables are populated
328  |      based on the parameters. A psuedo-line is inserted into the GTT and
329  |      removed after the tax amount is calculated.
330  |
331  |  PARAMETERS
332  |      P_Invoice_header_rec 	- Invoice header info
333  |      P_Invoice_Lines_Rec	- Invoice lines info
334  |      P_Calling_Mode 		- Calling mode. (CALCULATE_QUOTE)
335  |      P_All_Error_Messages 	- Should API return 1 error message or allow
336  |                                calling point to get them from message stack
337  |      P_error_code 		- Error code to be returned
338  |      P_calling_sequence 	- Calling sequence
339  |
340  |  MODIFICATION HISTORY
341  |    DATE          Author         Action
342  |    13-AUG-2003   Sanjay         Created
343  *============================================================================*/
344   FUNCTION Calculate_Quote(
345              P_Calling_Mode            IN  VARCHAR2,
346              P_All_Error_Messages      IN  VARCHAR2,
347              P_Invoice_Header_Rec      IN  ap_invoices_all%ROWTYPE	DEFAULT NULL,
348              P_Invoice_Lines_Rec       IN  ap_invoice_lines_all%ROWTYPE DEFAULT NULL,
349 	     P_Tax_Amount	       OUT NOCOPY NUMBER,
350 	     P_Tax_Amt_Included        OUT NOCOPY VARCHAR2,
351              P_error_code              OUT NOCOPY VARCHAR2,
352              P_Calling_Sequence        IN  VARCHAR2) RETURN BOOLEAN IS
353 
354        l_curr_calling_sequence      VARCHAR2(4000);
355        l_return_status              BOOLEAN := TRUE;
356 
357   BEGIN
358 
359        l_curr_calling_sequence := 'AP_ETAX_PKG.Calculate_Quote<-' || P_calling_sequence;
360 
361 
362        IF P_Calling_Mode = 'CALCULATE QUOTE' THEN
363 
364           IF NOT (AP_ETAX_SERVICES_PKG.CALCULATE_QUOTE(
365                                P_Invoice_Header_Rec	=> p_invoice_header_rec,
366                                P_Invoice_Lines_Rec	=> p_invoice_lines_rec,
367                                P_Calling_Mode		=> p_calling_mode,
368                                P_Tax_Amount		=> p_tax_amount,
369 			       P_Tax_Amt_Included       => P_Tax_Amt_Included,
370                                P_Error_Code		=> p_error_code,
371                                P_Calling_Sequence	=> p_calling_sequence )) THEN
372 
373              l_return_status := FALSE;
374           END IF;
375        END IF;
376 
377        RETURN l_return_status;
378 
379   EXCEPTION
380     WHEN OTHERS THEN
381       IF (SQLCODE <> -20001) THEN
382         FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
383         FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
384         FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',l_curr_calling_sequence);
385 
386       END IF;
387       APP_EXCEPTION.RAISE_EXCEPTION;
388 
389 RETURN l_return_status;
390 
391   END Calculate_Quote;
392 
393 /*=============================================================================
394  |  FUNCTION - callETax()
395  |
396  |  DESCRIPTION
397  |      Public function that will call the requested AP_ETAX_SERVICES_PKG function
398  |
399  |      This API is a wrapper of the calling_etax() api, mainly used by JDBC calls
400  |      from OA based applications.
401  |      This API will commit at the end.
402  |      This function returns 0 if the call to the service is successful.
403  |      Otherwise, 1.
404  |
405  |  PARAMETERS
406  |      x_Invoice_Id - invoice id
410  |                      to determine the PREPAY line created for prepayment
407  |      x_Line_Number - This parameter will be used to allow this API to
408  |                      calculate tax only for the line specified in this
409  |                      parameter.  Additionally, this parameter will be used
411  |                      unapplications.
412  |      x_Calling_Mode - calling mode.  Identifies which service to call
413  |      x_Override_Status - only for calling_mode OVERRIDE TAX
414  |      x_Line_Number_To_Delete - required when calling mode is MARK TAX LINES DELETED
415  |      x_Interface_Invoice_Id - invoice id in the ap_invoices_interface table.
416  |                               this parameter is used only while calling the
417  |                               API to calculate tax from the import program
418  |      x_All_Error_Messages -  Determine if the calling point wants the returning
419  |                              of all or only 1 error message.  Calling point will
420  |                              pass Y in the case they want to handle the return of
421  |                              more than one message from the FND message pile. N
422  |                              if they just want 1 message to be returned.
423  |      x_event_id - used by OVERRIDE TAX
424  |      x_error_code - Error code to be returned
425  |      x_calling_sequence -  Calling sequence
426  |
427  *============================================================================*/
428 
429   FUNCTION callETax(
430              x_Invoice_id              IN  NUMBER,
431              x_Line_Number             IN  NUMBER                       DEFAULT NULL,
432              x_Calling_Mode            IN  VARCHAR2,
433              x_Override_Status         IN  VARCHAR2                     DEFAULT NULL,
434              x_Line_Number_To_Delete   IN  NUMBER                       DEFAULT NULL,
435              x_Interface_Invoice_Id    IN  NUMBER                       DEFAULT NULL,
436              x_Event_Id                IN  NUMBER                       DEFAULT NULL,
437              x_All_Error_Messages      IN  VARCHAR2,
438              x_error_code              OUT NOCOPY VARCHAR2,
439              x_Calling_Sequence        IN  VARCHAR2) RETURN NUMBER
440 
441   IS
442     l_debug_info                 VARCHAR2(240);
443     l_curr_calling_sequence      VARCHAR2(4000);
444 
445   BEGIN
446 
447     l_curr_calling_sequence := 'AP_ETAX_PKG.callETax<-' ||
448                                x_calling_sequence;
449 
450     ------------------------------------------------------------------
451     l_debug_info := 'calling the calling_etax() api';
452     ------------------------------------------------------------------
453     IF NOT (ap_etax_pkg.calling_etax(
454                  p_invoice_id             => x_invoice_id,
455                  p_line_number            => x_line_number,
456                  p_calling_mode           => x_calling_mode,
457                  p_override_status        => x_override_status,
458                  p_line_number_to_delete  => x_line_number_to_delete,
459                  p_Interface_Invoice_Id   => x_interface_invoice_id,
460                  P_Event_Id               => x_event_id,
461                  p_all_error_messages     => x_all_error_messages,
462                  p_error_code             => x_error_code,
463                  p_calling_sequence       => l_curr_calling_sequence)) THEN
464        	RETURN 1; -- failed
465     ELSE
466 	RETURN 0; -- successful
467     END IF;
468 
469     -- make sure we commit here
470     commit;
471 
472   EXCEPTION
473     WHEN OTHERS THEN
474 /*
475       IF (SQLCODE <> -20001) THEN
476         FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
477         FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
478         FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',l_curr_calling_sequence);
479         FND_MESSAGE.SET_TOKEN('PARAMETERS',
480           ' x_Invoice_Id = '||x_Invoice_Id||
481           ' x_Calling_Mode = '||x_Calling_Mode||
482           ' x_Override_Status = '||x_Override_Status||
483           ' x_Line_Number_To_Delete = '||x_Line_Number_To_Delete||
484           ' x_All_Error_Messages = '||x_All_Error_Messages||
485           ' x_Error_Code = '||x_Error_Code||
486           ' x_Calling_Sequence = '||x_Calling_Sequence);
487         FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
488 
489       END IF;
490       APP_EXCEPTION.RAISE_EXCEPTION;
491 */
492 
493       RETURN 1;
494 
495   END callETax;
496 
497 END AP_ETAX_PKG;