DBA Data[Home] [Help]

PACKAGE BODY: APPS.AP_HOLDS_PKG

Source


1 PACKAGE BODY AP_HOLDS_PKG AS
2 /* $Header: apiholdb.pls 120.15 2011/07/18 13:52:44 pgayen ship $ */
3 
4 
5 /*  */
6 G_PKG_NAME          CONSTANT VARCHAR2(30) := 'AP_HOLDS_PKG';
7 G_MSG_UERROR        CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR;
8 G_MSG_ERROR         CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_ERROR;
9 G_MSG_SUCCESS       CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_SUCCESS;
10 G_MSG_HIGH          CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_DEBUG_HIGH;
11 G_MSG_MEDIUM        CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_DEBUG_MEDIUM;
12 G_MSG_LOW           CONSTANT NUMBER       := FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW;
13 G_LINES_PER_FETCH   CONSTANT NUMBER       := 1000;
14 
15 G_CURRENT_RUNTIME_LEVEL CONSTANT NUMBER   := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
16 G_LEVEL_UNEXPECTED      CONSTANT NUMBER   := FND_LOG.LEVEL_UNEXPECTED;
17 G_LEVEL_ERROR           CONSTANT NUMBER   := FND_LOG.LEVEL_ERROR;
18 G_LEVEL_EXCEPTION       CONSTANT NUMBER   := FND_LOG.LEVEL_EXCEPTION;
19 G_LEVEL_EVENT           CONSTANT NUMBER   := FND_LOG.LEVEL_EVENT;
20 G_LEVEL_PROCEDURE       CONSTANT NUMBER   := FND_LOG.LEVEL_PROCEDURE;
21 G_LEVEL_STATEMENT       CONSTANT NUMBER   := FND_LOG.LEVEL_STATEMENT;
22 G_MODULE_NAME           CONSTANT VARCHAR2(100) := 'AP.PLSQL.AP_HOLDS_PKG.';
23 
24 PROCEDURE Insert_Row(X_Rowid                   IN OUT NOCOPY VARCHAR2,
25                        x_hold_id                 in out nocopy number, --5128839
26                        X_Invoice_Id                     NUMBER,
27                        X_Line_Location_Id               NUMBER,
28                        X_Hold_Lookup_Code               VARCHAR2,
29                        X_Last_Update_Date               DATE,
30                        X_Last_Updated_By                NUMBER,
31                        X_Held_By                        NUMBER,
32                        X_Hold_Date                      DATE,
33                        X_Hold_Reason                    VARCHAR2,
34                        X_Release_Lookup_Code            VARCHAR2,
35                        X_Release_Reason                 VARCHAR2,
36                        X_Status_Flag                    VARCHAR2,
37                        X_Last_Update_Login              NUMBER,
38                        X_Creation_Date                  DATE,
39                        X_Created_By                     NUMBER,
40 		       X_Responsibility_Id		NUMBER,
41                        X_Attribute1                     VARCHAR2,
42                        X_Attribute2                     VARCHAR2,
43                        X_Attribute3                     VARCHAR2,
44                        X_Attribute4                     VARCHAR2,
45                        X_Attribute5                     VARCHAR2,
46                        X_Attribute6                     VARCHAR2,
47                        X_Attribute7                     VARCHAR2,
48                        X_Attribute8                     VARCHAR2,
49                        X_Attribute9                     VARCHAR2,
50                        X_Attribute10                    VARCHAR2,
51                        X_Attribute11                    VARCHAR2,
52                        X_Attribute12                    VARCHAR2,
53                        X_Attribute13                    VARCHAR2,
54                        X_Attribute14                    VARCHAR2,
55                        X_Attribute15                    VARCHAR2,
56                        X_Attribute_Category             VARCHAR2,
57                        X_Org_Id                         NUMBER,
58 		       X_calling_sequence	IN	VARCHAR2
59   ) IS
60     CURSOR C IS SELECT rowid FROM AP_HOLDS
61                  WHERE invoice_id = X_Invoice_Id
62                  AND   (    (line_location_id = X_Line_Location_Id)
63                         or (line_location_id is NULL and X_Line_Location_Id is NULL))
64                  AND   hold_lookup_code = X_Hold_Lookup_Code;
65     current_calling_sequence    VARCHAR2(2000);
66     debug_info                  VARCHAR2(100);
67     l_user_releaseable_flag     VARCHAR2(1);
68     l_initiate_workflow_flag    VARCHAR2(1);
69 
70    BEGIN
71 
72 --     Update the calling sequence
73 --
74        current_calling_sequence := 'AP_HOLDS_PKG.INSERT_ROW<-' ||
75                                     X_calling_sequence;
76 
77 
78        select ap_holds_s.nextval
79        into x_hold_id
80        from dual;
81 
82        debug_info := 'Insert into AP_HOLDS';
83        INSERT INTO AP_HOLDS(
84               hold_id,
85               invoice_id,
86               line_location_id,
87               hold_lookup_code,
88               last_update_date,
89               last_updated_by,
90               held_by,
91               hold_date,
92               hold_reason,
93               release_lookup_code,
94               release_reason,
95               status_flag,
96               last_update_login,
97               creation_date,
98               created_by,
99               responsibility_id,
100               attribute1,
101               attribute2,
102               attribute3,
103               attribute4,
104               attribute5,
105               attribute6,
106               attribute7,
107               attribute8,
108               attribute9,
109               attribute10,
110               attribute11,
111               attribute12,
112               attribute13,
113               attribute14,
114               attribute15,
115               attribute_category,
116               org_id
117              ) VALUES (
118               x_hold_id,
119               X_Invoice_Id,
120               X_Line_Location_Id,
121               X_Hold_Lookup_Code,
122               X_Last_Update_Date,
123               X_Last_Updated_By,
124               X_Held_By,
125               X_Hold_Date,
126               X_Hold_Reason,
127               X_Release_Lookup_Code,
128               X_Release_Reason,
129               X_Status_Flag,
130               X_Last_Update_Login,
131               X_Creation_Date,
132               X_Created_By,
133 	      X_Responsibility_Id,
134               X_Attribute1,
135               X_Attribute2,
136               X_Attribute3,
137               X_Attribute4,
138               X_Attribute5,
139               X_Attribute6,
140               X_Attribute7,
141               X_Attribute8,
142               X_Attribute9,
143               X_Attribute10,
144               X_Attribute11,
145               X_Attribute12,
146               X_Attribute13,
147               X_Attribute14,
148               X_Attribute15,
149               X_Attribute_Category,
150               X_Org_Id
151              );
152 
153     -- See if this is user releaseable and
154     -- Workflow enabled hold. If so, start the
155     -- workflow.
156     /* bug 5206670. Hold Workflow */
157     SELECT nvl(user_releaseable_flag,'N'),
158            nvl(initiate_workflow_flag,'N')
159     INTO   l_user_releaseable_flag,
160            l_initiate_workflow_flag
161     FROM   ap_hold_codes
162     WHERE  hold_lookup_code = X_Hold_Lookup_Code;
163 
164     IF (l_user_releaseable_flag = 'Y' AND
165        l_initiate_workflow_flag = 'Y') THEN
166 
167        AP_WORKFLOW_PKG.create_hold_wf_process(x_hold_id);
168 
169     END IF;
170 
171     --Bug 4539462 DBI logging
172     AP_DBI_PKG.Maintain_DBI_Summary
173               (p_table_name => 'AP_HOLDS',
174                p_operation => 'I',
175                p_key_value1 => X_invoice_id,
176                 p_calling_sequence => current_calling_sequence);
177 
178     debug_info := 'Open cursor C';
179     OPEN C;
180     debug_info := 'Fetch cursor C';
181     FETCH C INTO X_Rowid;
182     if (C%NOTFOUND) then
183       debug_info := 'Close cursor C - ROW NOTFOUND';
184       CLOSE C;
185       Raise NO_DATA_FOUND;
186     end if;
187     debug_info := 'Close cursor C';
188     CLOSE C;
189 
190     EXCEPTION
191         WHEN OTHERS THEN
192            IF (SQLCODE <> -20001) THEN
193               FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
194               FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
195               FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',current_calling_sequence);
196               FND_MESSAGE.SET_TOKEN('PARAMETERS','ROWID = ' || X_Rowid ||
197                        			', INVOICE_ID == ' || TO_CHAR(X_Invoice_Id) ||
198                        			', LINE_LOCATION_ID = ' || TO_CHAR(X_Line_Location_Id) ||
199                        			', HOLD_LOOKUP_CODE = ' || X_Hold_Lookup_Code);
200               FND_MESSAGE.SET_TOKEN('DEBUG_INFO',debug_info);
201            END IF;
202            APP_EXCEPTION.RAISE_EXCEPTION;
203 
204 
205   END Insert_Row;
206 
207 
208 /*   */
209   PROCEDURE Lock_Row(X_Rowid                            VARCHAR2,
210 
211                      X_Invoice_Id                       NUMBER,
212                      X_Line_Location_Id                 NUMBER,
213                      X_Hold_Lookup_Code                 VARCHAR2,
214                      X_Held_By                          NUMBER,
215                      X_Hold_Date                        DATE,
216                      X_Hold_Reason                      VARCHAR2,
217                      X_Release_Lookup_Code              VARCHAR2,
218                      X_Release_Reason                   VARCHAR2,
219                      X_Status_Flag                      VARCHAR2,
220 		     X_Responsibility_Id		NUMBER,
221                      X_Attribute1                       VARCHAR2,
222                      X_Attribute2                       VARCHAR2,
223                      X_Attribute3                       VARCHAR2,
224                      X_Attribute4                       VARCHAR2,
225                      X_Attribute5                       VARCHAR2,
226                      X_Attribute6                       VARCHAR2,
227                      X_Attribute7                       VARCHAR2,
228                      X_Attribute8                       VARCHAR2,
229                      X_Attribute9                       VARCHAR2,
230                      X_Attribute10                      VARCHAR2,
231                      X_Attribute11                      VARCHAR2,
232                      X_Attribute12                      VARCHAR2,
233                      X_Attribute13                      VARCHAR2,
234                      X_Attribute14                      VARCHAR2,
235                      X_Attribute15                      VARCHAR2,
236                      X_Attribute_Category               VARCHAR2,
237                      X_Org_Id                           NUMBER,
238 		     X_calling_sequence		IN	VARCHAR2
239   ) IS
240     CURSOR C IS
241         SELECT *
242         FROM   AP_HOLDS
243         WHERE  rowid = X_Rowid
244         FOR UPDATE of Invoice_Id NOWAIT;
245     Recinfo C%ROWTYPE;
246     current_calling_sequence    VARCHAR2(2000);
247     debug_info                  VARCHAR2(100);
248 
249 
250   BEGIN
251 --  Update the calling sequence
252 --
253     current_calling_sequence := 'AP_HOLDS_PKG.LOCK_ROW<-' ||
254                                  X_calling_sequence;
255     debug_info := 'Open cursor C';
256     OPEN C;
257     debug_info := 'Fetch cursor C';
258     FETCH C INTO Recinfo;
259     if (C%NOTFOUND) then
260       debug_info := 'Close cursor C - ROW NOTFOUND';
261       CLOSE C;
262       FND_MESSAGE.Set_Name('FND', 'FORM_RECORD_DELETED');
263       APP_EXCEPTION.Raise_Exception;
264     end if;
265     debug_info := 'Close cursor C';
266     CLOSE C;
267     if (
268 
269                (Recinfo.invoice_id =  X_Invoice_Id)
270            AND (   (Recinfo.line_location_id =  X_Line_Location_Id)
271                 OR (    (Recinfo.line_location_id IS NULL)
272                     AND (X_Line_Location_Id IS NULL)))
273            AND (Recinfo.hold_lookup_code =  X_Hold_Lookup_Code)
274            AND (Recinfo.held_by =  X_Held_By)
275            AND (trunc(Recinfo.hold_date) =  trunc(X_Hold_Date)) --Bug 2909797,6143486
276            AND (   (Recinfo.hold_reason =  X_Hold_Reason)
277                 OR (    (Recinfo.hold_reason IS NULL)
278                     AND (X_Hold_Reason IS NULL)))
279            AND (   (Recinfo.release_lookup_code =  X_Release_Lookup_Code)
280                 OR (    (Recinfo.release_lookup_code IS NULL)
281                     AND (X_Release_Lookup_Code IS NULL)))
282            AND (   (Recinfo.release_reason =  X_Release_Reason)
283                 OR (    (Recinfo.release_reason IS NULL)
284                     AND (X_Release_Reason IS NULL)))
285            AND (   (Recinfo.status_flag =  X_Status_Flag)
286                 OR (    (Recinfo.status_flag IS NULL)
287                     AND (X_Status_Flag IS NULL)))
288            AND (   (Recinfo.Responsibility_Id =  X_Responsibility_Id)
289                 OR (    (Recinfo.Responsibility_Id IS NULL)
290                     AND (X_Responsibility_Id IS NULL)))
291            AND (   (Recinfo.attribute1 =  X_Attribute1)
292                 OR (    (Recinfo.attribute1 IS NULL)
293                     AND (X_Attribute1 IS NULL)))
294            AND (   (Recinfo.attribute2 =  X_Attribute2)
295                 OR (    (Recinfo.attribute2 IS NULL)
296                     AND (X_Attribute2 IS NULL)))
297            AND (   (Recinfo.attribute3 =  X_Attribute3)
298                 OR (    (Recinfo.attribute3 IS NULL)
299                     AND (X_Attribute3 IS NULL)))
300            AND (   (Recinfo.attribute4 =  X_Attribute4)
301                 OR (    (Recinfo.attribute4 IS NULL)
302                     AND (X_Attribute4 IS NULL)))
303            AND (   (Recinfo.attribute5 =  X_Attribute5)
304                 OR (    (Recinfo.attribute5 IS NULL)
305                     AND (X_Attribute5 IS NULL)))
306            AND (   (Recinfo.attribute6 =  X_Attribute6)
307                 OR (    (Recinfo.attribute6 IS NULL)
308                     AND (X_Attribute6 IS NULL)))
309            AND (   (Recinfo.attribute7 =  X_Attribute7)
310                 OR (    (Recinfo.attribute7 IS NULL)
311                     AND (X_Attribute7 IS NULL)))
312            AND (   (Recinfo.attribute8 =  X_Attribute8)
313                 OR (    (Recinfo.attribute8 IS NULL)
314                     AND (X_Attribute8 IS NULL)))
315            AND (   (Recinfo.attribute9 =  X_Attribute9)
316                 OR (    (Recinfo.attribute9 IS NULL)
317                     AND (X_Attribute9 IS NULL)))
318            AND (   (Recinfo.attribute10 =  X_Attribute10)
319                 OR (    (Recinfo.attribute10 IS NULL)
320                     AND (X_Attribute10 IS NULL)))
321            AND (   (Recinfo.attribute11 =  X_Attribute11)
322                 OR (    (Recinfo.attribute11 IS NULL)
323                     AND (X_Attribute11 IS NULL)))
324            AND (   (Recinfo.attribute12 =  X_Attribute12)
325                 OR (    (Recinfo.attribute12 IS NULL)
326                     AND (X_Attribute12 IS NULL)))
327            AND (   (Recinfo.attribute13 =  X_Attribute13)
328                 OR (    (Recinfo.attribute13 IS NULL)
329                     AND (X_Attribute13 IS NULL)))
330            AND (   (Recinfo.attribute14 =  X_Attribute14)
331                 OR (    (Recinfo.attribute14 IS NULL)
332                     AND (X_Attribute14 IS NULL)))
333            AND (   (Recinfo.attribute15 =  X_Attribute15)
334                 OR (    (Recinfo.attribute15 IS NULL)
335                     AND (X_Attribute15 IS NULL)))
336            AND (   (Recinfo.attribute_category =  X_Attribute_Category)
337                 OR (    (Recinfo.attribute_category IS NULL)
338                     AND (X_Attribute_Category IS NULL)))
339            AND (   (Recinfo.org_id =  X_Org_Id)
340                 OR (    (Recinfo.org_id IS NULL)
341                     AND (X_Org_Id IS NULL)))
342       ) then
343       return;
344     else
345       FND_MESSAGE.Set_Name('FND', 'FORM_RECORD_CHANGED');
346       APP_EXCEPTION.Raise_Exception;
347     end if;
348 
349     EXCEPTION
350       WHEN OTHERS THEN
351          IF (SQLCODE <> -20001) THEN
352            IF (SQLCODE = -54) THEN
353              FND_MESSAGE.SET_NAME('SQLAP','AP_RESOURCE_BUSY');
354            ELSE
355              FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
356              FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
357              FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',current_calling_sequence);
358              FND_MESSAGE.SET_TOKEN('PARAMETERS','ROWID = ' || X_Rowid ||
359                        			', INVOICE_ID == ' || TO_CHAR(X_Invoice_Id) ||
360                        			', LINE_LOCATION_ID = ' || TO_CHAR(X_Line_Location_Id) ||
361                        			', HOLD_LOOKUP_CODE = ' || X_Hold_Lookup_Code);
362              FND_MESSAGE.SET_TOKEN('DEBUG_INFO',debug_info);
363            END IF;
364 	 END IF;
365          APP_EXCEPTION.RAISE_EXCEPTION;
366 
367   END Lock_Row;
368 
369 
370 /*    */
371   PROCEDURE Update_Row(X_Rowid                          VARCHAR2,
372 
373                        X_Invoice_Id                     NUMBER,
374                        X_Line_Location_Id               NUMBER,
375                        X_Hold_Lookup_Code               VARCHAR2,
376                        X_Last_Update_Date               DATE,
377                        X_Last_Updated_By                NUMBER,
378                        X_Held_By                        NUMBER,
379                        X_Hold_Date                      DATE,
380                        X_Hold_Reason                    VARCHAR2,
381                        X_Release_Lookup_Code            VARCHAR2,
382                        X_Release_Reason                 VARCHAR2,
383                        X_Status_Flag                    VARCHAR2,
384                        X_Last_Update_Login              NUMBER,
385 		       X_Responsibility_Id		NUMBER,
386                        X_Attribute1                     VARCHAR2,
387                        X_Attribute2                     VARCHAR2,
388                        X_Attribute3                     VARCHAR2,
389                        X_Attribute4                     VARCHAR2,
390                        X_Attribute5                     VARCHAR2,
391                        X_Attribute6                     VARCHAR2,
392                        X_Attribute7                     VARCHAR2,
393                        X_Attribute8                     VARCHAR2,
394                        X_Attribute9                     VARCHAR2,
395                        X_Attribute10                    VARCHAR2,
396                        X_Attribute11                    VARCHAR2,
397                        X_Attribute12                    VARCHAR2,
398                        X_Attribute13                    VARCHAR2,
399                        X_Attribute14                    VARCHAR2,
400                        X_Attribute15                    VARCHAR2,
401                        X_Attribute_Category             VARCHAR2,
402                        X_Wf_Status                      VARCHAR2,
403 		       X_calling_sequence	IN	VARCHAR2
404 
405   ) IS
406 
407     l_invoice_amount		AP_INVOICES_ALL.INVOICE_AMOUNT%TYPE;
408     l_payment_status_flag       AP_INVOICES_ALL.PAYMENT_STATUS_FLAG%TYPE;
409     l_invoice_type_lookup_code  AP_INVOICES_ALL.INVOICE_TYPE_LOOKUP_CODE%TYPE;
410     l_tax_hold_codes		AP_ETAX_SERVICES_PKG.Rel_Hold_Codes_Type;
411     l_approval_status           VARCHAR2(100);
412     l_success			BOOLEAN := TRUE;
413     l_error_code		VARCHAR2(4000);
414     current_calling_sequence    VARCHAR2(2000);
415     debug_info                  VARCHAR2(100);
416     l_old_wf_status             AP_HOLDS_ALL.WF_STATUS%TYPE ; -- Bug 8266290
417     l_hold_id                   AP_HOLDS_ALL.HOLD_ID%TYPE   ; -- Bug 8266290
418   BEGIN
419 --  Update the calling sequence
420 --
421     current_calling_sequence := 'AP_HOLDS_PKG.UPDATE_ROW<-' ||
422                                  X_calling_sequence;
423 
424     -- Bug 8266290 : Start
425     SELECT  wf_status,
426             hold_id
427     INTO    l_old_wf_status,
428             l_hold_id
429     FROM    ap_holds
430     WHERE   rowid = X_Rowid ;
431 
432     /* Bug 9691312 : Changed the IF condition
433 	IF l_old_wf_status = 'STARTED' and
434        ( X_Wf_Status = 'STARTED' or X_Wf_Status = 'MANUALLYRELEASED' )  THEN */
435 	IF l_old_wf_status IN ( 'STARTED', 'NEGOTIATE' ) THEN
436         AP_WORKFLOW_PKG.abort_holds_workflow( l_hold_id ) ;
437     END IF ;
438     -- Bug 8266290 : End
439 
440     debug_info := 'Update AP_HOLDS';
441     UPDATE AP_HOLDS
442     SET
443        invoice_id                      =     X_Invoice_Id,
444        line_location_id                =     X_Line_Location_Id,
445        hold_lookup_code                =     X_Hold_Lookup_Code,
446        last_update_date                =     X_Last_Update_Date,
447        last_updated_by                 =     X_Last_Updated_By,
448        held_by                         =     X_Held_By,
449        hold_date                       =     X_Hold_Date,
450        hold_reason                     =     X_Hold_Reason,
451        release_lookup_code             =     X_Release_Lookup_Code,
452        release_reason                  =     X_Release_Reason,
453        status_flag                     =     X_Status_Flag,
454        last_update_login               =     X_Last_Update_Login,
455        Responsibility_Id	       =     X_Responsibility_Id,
456        attribute1                      =     X_Attribute1,
457        attribute2                      =     X_Attribute2,
458        attribute3                      =     X_Attribute3,
459        attribute4                      =     X_Attribute4,
460        attribute5                      =     X_Attribute5,
461        attribute6                      =     X_Attribute6,
462        attribute7                      =     X_Attribute7,
463        attribute8                      =     X_Attribute8,
464        attribute9                      =     X_Attribute9,
465        attribute10                     =     X_Attribute10,
466        attribute11                     =     X_Attribute11,
467        attribute12                     =     X_Attribute12,
468        attribute13                     =     X_Attribute13,
469        attribute14                     =     X_Attribute14,
470        attribute15                     =     X_Attribute15,
471        attribute_category              =     X_Attribute_Category,
472        /* bug 5206670. Hold Workflow */
473        wf_status                       =     Decode(X_Wf_Status,
474                                                     'STARTED', 'MANUALLYRELEASED',
475                                                     'NEGOTIATE', 'MANUALLYRELEASED', -- Bug 9691312
476                                                     X_WF_Status)
477     WHERE rowid = X_Rowid;
478 
479     --Bug 4539462 DBI logging
480     AP_DBI_PKG.Maintain_DBI_Summary
481               (p_table_name => 'AP_HOLDS',
482                p_operation => 'U',
483                p_key_value1 => X_invoice_id,
484                 p_calling_sequence => current_calling_sequence);
485 
486     --ETAX: Invwkb
487     --All the code below this comment is added for ETAX.
488     --Initialize the PL/SQL table
489     FOR num in 1..10 LOOP
490      l_tax_hold_codes(num) := NULL;
491     END LOOP;
492 
493 
494     --Unlike the code in quick_release we need to call this below api ,
495     --regardless of whether the invoice status
496     --after releasing this hold would go to 'APPROVED'or not, since this procedure
497     --is called record by record, there is no way to figure it whether the user is
498     --updating all the holds on the invoice, there by making the status 'APPROVED' or
499     --just releasing this particular hold.
500     IF (x_release_lookup_code IN ('TAX AMOUNT RANGE','TAX VARIANCE')) THEN
501 
502        l_tax_hold_codes(1) := x_release_lookup_code;
503 
504        l_success := ap_etax_services_pkg.release_tax_holds(
505 		                        p_invoice_id => x_invoice_id,
506 				        p_calling_mode => 'RELEASE TAX HOLDS',
507 				        p_tax_hold_code => l_tax_hold_codes,
508 				        p_all_error_messages => 'N',
509 				        p_error_code => l_error_code,
510 				        p_calling_sequence => current_calling_sequence);
511 
512        IF (NOT l_success) THEN
513          FND_MESSAGE.SET_NAME('SQLAP','AP_ETX_CANNOT_REL_TAX_HOLDS');
514          FND_MESSAGE.SET_TOKEN('REASON',l_error_code);
515 	 APP_EXCEPTION.RAISE_EXCEPTION;
516        END IF;
517 
518     END IF;
519 
520     SELECT invoice_amount,
521            payment_status_flag,
522 	   invoice_type_lookup_code
523     INTO l_invoice_amount,
524          l_payment_status_flag,
525          l_invoice_type_lookup_code
526     FROM ap_invoices
527     WHERE invoice_id = x_invoice_id;
528 
529     l_approval_status := ap_invoices_pkg.get_approval_status(x_invoice_id,
530                          		                     l_invoice_amount,
531                                                              l_payment_status_flag,
532                                                              l_invoice_type_lookup_code);
533 
534     IF (l_approval_status IN ('APPROVED','AVAILABLE','UNPAID','FULL'))THEN
535       IF (l_success) THEN
536 
537           l_success := ap_etax_pkg.calling_etax(
538 	                             p_invoice_id => x_invoice_id,
539 	                             p_calling_mode => 'FREEZE INVOICE',
540 	                             p_all_error_messages => 'N',
541 	                             p_error_code => l_error_code,
542 	                             p_calling_sequence => current_calling_sequence);
543 
544 	  IF (not l_success) THEN
545 
546              FND_MESSAGE.SET_NAME('SQLAP','AP_ETX_CANNOT_FRZ_INV');
547              FND_MESSAGE.SET_TOKEN('REASON',l_error_code);
548              APP_EXCEPTION.RAISE_EXCEPTION;
549 
550           END IF;
551 
552       END IF;
553     END IF;
554 
555 
556     --bugfix:4913913 commented out the code
557     /*
558     if (SQL%NOTFOUND) then
559       Raise NO_DATA_FOUND;
560     end if; */
561 
562     EXCEPTION
563         WHEN OTHERS THEN
564            IF (SQLCODE <> -20001) THEN
565               FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
566               FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
567               FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',current_calling_sequence);
568               FND_MESSAGE.SET_TOKEN('PARAMETERS','ROWID = ' || X_Rowid ||
569                        			', INVOICE_ID == ' || TO_CHAR(X_Invoice_Id) ||
570                        			', LINE_LOCATION_ID = ' || TO_CHAR(X_Line_Location_Id) ||
571                        			', HOLD_LOOKUP_CODE = ' || X_Hold_Lookup_Code);
572               FND_MESSAGE.SET_TOKEN('DEBUG_INFO',debug_info);
573            END IF;
574            APP_EXCEPTION.RAISE_EXCEPTION;
575 
576   END Update_Row;
577 
578 
579 /*   */
580   PROCEDURE Delete_Row(X_Rowid 				VARCHAR2,
581 		       X_calling_sequence	IN	VARCHAR2) IS
582 
583   current_calling_sequence    VARCHAR2(2000);
584   debug_info                  VARCHAR2(100);
585   l_invoice_id		      NUMBER;
586 
587   BEGIN
588 --  Update the calling sequence
589 --
590     current_calling_sequence := 'AP_HOLDS_PKG.DELETE_ROW<-' ||
591                                  X_calling_sequence;
592 
593     --Bug 4539462 Need the invoice_id
594     Select invoice_id
595     Into l_invoice_id
596     From ap_holds
597     Where rowid = X_Rowid;
598 
599     debug_info := 'Delete from AP_HOLDS';
600     DELETE FROM AP_HOLDS
601     WHERE rowid = X_Rowid;
602 
603     if (SQL%NOTFOUND) then
604       Raise NO_DATA_FOUND;
605     end if;
606 
607     --Bug 4539462 DBI logging
608     AP_DBI_PKG.Maintain_DBI_Summary
609               (p_table_name => 'AP_HOLDS',
610                p_operation => 'D',
611                p_key_value1 => l_invoice_id,
612                 p_calling_sequence => current_calling_sequence);
613 
614     EXCEPTION
615         WHEN OTHERS THEN
616            IF (SQLCODE <> -20001) THEN
617               FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
618               FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
619               FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',current_calling_sequence);
620               FND_MESSAGE.SET_TOKEN('PARAMETERS','ROWID = ' || X_Rowid);
621               FND_MESSAGE.SET_TOKEN('DEBUG_INFO',debug_info);
622            END IF;
623            APP_EXCEPTION.RAISE_EXCEPTION;
624 
625   END Delete_Row;
626 
627   -----------------------------------------------------------------------
628   -- PROCEDURE insert_single_hold inserts a single record into
629   -- the AP_HOLDS table given a record in ap_invoices.
630   -----------------------------------------------------------------------
631   PROCEDURE insert_single_hold  (X_invoice_id         IN number,
632                                  X_hold_lookup_code   IN varchar2,
633                                  X_hold_type IN varchar2 DEFAULT NULL,
634                                  X_hold_reason IN varchar2 DEFAULT NULL,
635                                  X_held_by IN number DEFAULT NULL,
636                                  X_calling_sequence IN varchar2 DEFAULT NULL)
637   IS
638     current_calling_sequence VARCHAR2(2000);
639     debug_info               VARCHAR2(100);
640     l_hold_reason 	     ap_holds.hold_reason%TYPE; --bug 1188566
641     -- Added for bug 9715670.
642     l_user_releaseable_flag     VARCHAR2(1);
643     l_initiate_workflow_flag    VARCHAR2(1);
644 
645     -- Bug 9715670.
646     -- Modified cursor to fetch user releasable flag and workflow flag also.
647     cursor hold_cursor is
648       select nvl(X_hold_reason, description),
649              nvl(user_releaseable_flag,'N'),
650              nvl(initiate_workflow_flag,'N')
651       from   ap_hold_codes
652       where  hold_type = nvl(X_hold_type,hold_type)
653       and    hold_lookup_code = X_hold_lookup_code;
654 
655       l_api_name varchar2(50);
656       l_hold_id  ap_holds_all.hold_id%type;
657 
658   BEGIN
659 
660     -- Update the calling sequence
661     --
662     current_calling_sequence :=
663               'AP_HOLDS_PKG.insert_single_hold<-'||
664                      X_calling_sequence;
665     l_api_name := 'Insert_Single_Hold';
666 
667     -- If no hold_code was passed to the procedure, abort the call
668     if (X_hold_lookup_code is null) then
669       return;
670     end if;
671 
672     -- If a hold reason was passed to the function, then we do not
673     -- need to get a description from AP_HOLD_CODES.  We don't want
674     -- to override the user-entered description
675 
676     -- Bug 9715670.
677     -- Moved cursor out of if to fetch user releasable flag
678     -- and workflow flag as well. After modification to the
679     -- cursor, if is not required.
680 
681     debug_info := 'Select from AP_HOLD_CODES';
682     IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
683           FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name,debug_info);
684     END IF;
685 
686     open hold_cursor;
687     fetch hold_cursor into l_hold_reason,
688                            l_user_releaseable_flag,
689                            l_initiate_workflow_flag;
690     close hold_cursor;
691 
692     debug_info := 'l_hold_reason is '||l_hold_reason;
693     IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
694         FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name,debug_info);
695     END IF;
696 
697     -- Bug 9715670. Commented following if.
698     /*if (X_hold_reason is null) then
699     --  debug_info := 'Select from AP_HOLD_CODES';
700     --  IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
701     --        FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name,debug_info);
702     --  END IF;
703 
704     --  open hold_cursor;
705     --  fetch hold_cursor into l_hold_reason;
706     --  close hold_cursor;
707 
708     --  debug_info := 'l_hold_reason is '||l_hold_reason;
709     --  IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
710     --      FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name,debug_info);
711     --  END IF;
712 
713     --else
714     --  l_hold_reason := X_hold_reason;
715     --end if;*/
716 
717     debug_info := 'Insert into AP_HOLDS';
718     IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
719       FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name,debug_info);
720     END IF;
721 
722     --bugfix:5523240
723     SELECT ap_holds_s.nextval
724     INTO   l_hold_id
725     FROM   DUAL;
726 
727     INSERT INTO AP_HOLDS
728          (INVOICE_ID, HOLD_LOOKUP_CODE, HOLD_DATE,
729           CREATED_BY, CREATION_DATE, LAST_UPDATE_LOGIN,
730           LAST_UPDATE_DATE, LAST_UPDATED_BY,
731           HELD_BY, HOLD_REASON, ORG_ID, HOLD_ID)
732     SELECT
733           X_invoice_id, X_hold_lookup_code, SYSDATE,
734           FND_GLOBAL.user_id, -- 7299826
735           SYSDATE,
736           FND_GLOBAL.LOGIN_ID, -- 7299826
737           SYSDATE,
738           FND_GLOBAL.user_id, -- 7299826
739           nvl(X_held_by,FND_GLOBAL.user_id), -- 7299826
740           l_hold_reason,
741           ORG_ID,L_HOLD_ID
742     FROM  ap_invoices
743     WHERE invoice_id = X_invoice_id
744     AND   not exists
745       (SELECT 'Already on this hold'
746        FROM   ap_holds
747         WHERE  invoice_id = X_invoice_id
748           AND    hold_lookup_code = X_hold_lookup_code
749           AND    release_lookup_code IS NULL);
750 
751     -- Bug 9715670.
752     -- Invoking workflow API to initiate holds workflow
753     -- if Workflow option is enabled for the hold.
754 
755     IF SQL%ROWCOUNT > 0 THEN
756       IF (l_user_releaseable_flag = 'Y' AND
757           l_initiate_workflow_flag = 'Y') THEN
758 
759          debug_info := 'Initiating workflow for the hold. l_hold_id = ' || l_hold_id;
760          IF (G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
761             FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name,debug_info);
762          END IF;
763 
764          AP_WORKFLOW_PKG.create_hold_wf_process(l_hold_id);
765 
766       END IF;
767     END IF;
768 
769     --Bug 4539462 DBI logging
770     AP_DBI_PKG.Maintain_DBI_Summary
771               (p_table_name => 'AP_HOLDS',
772                p_operation => 'I',
773                p_key_value1 => X_invoice_id,
774                 p_calling_sequence => current_calling_sequence);
775 
776         EXCEPTION
777           WHEN OTHERS THEN
778             IF (SQLCODE <> -20001) THEN
779               FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
780               FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
781               FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',
782                         current_calling_sequence);
783 
784               FND_MESSAGE.SET_TOKEN('PARAMETERS',
785                   'X_invoice_id  = '      ||X_invoice_id
786               ||', X_hold_lookup_code = '||X_hold_lookup_code
787               ||', X_hold_type = '       ||X_hold_type
788               ||', X_hold_reason = '     ||X_hold_reason
789               ||', X_held_by = '         ||X_held_by
790                                        );
791 
792               FND_MESSAGE.SET_TOKEN('DEBUG_INFO',debug_info);
793             END IF;
794           APP_EXCEPTION.RAISE_EXCEPTION;
795 
796   END insert_single_hold;
797 
798   -----------------------------------------------------------------------
799   -- PROCEDURE release_single_hold releases a hold by updating a single
800   -- record in AP_HOLDS with a release_lookup_code
801   -----------------------------------------------------------------------
802   PROCEDURE release_single_hold (X_invoice_id          IN number,
803                                  X_hold_lookup_code    IN varchar2,
804                                  X_release_lookup_code IN varchar2,
805                                  X_held_by IN number DEFAULT NULL,
806                                  X_calling_sequence IN varchar2 DEFAULT NULL)
807   IS
808     current_calling_sequence VARCHAR2(2000);
809     debug_info               VARCHAR2(100);
810     l_hold_reason        ap_hold_codes.description%TYPE;
811     l_last_updated_by       ap_invoices.last_updated_by%TYPE;
812     l_last_update_login       ap_invoices.last_update_login%TYPE;
813 
814     cursor invoice_who_cursor is
815       select last_updated_by,
816        last_update_login
817       from   ap_invoices
818       where  invoice_id = X_invoice_id;
819 
820   BEGIN
821 
822     -- Update the calling sequence
823     --
824     current_calling_sequence :=
825               'AP_HOLDS_PKG.release_single_hold<-'||
826                      X_calling_sequence;
827 
828     debug_info := 'Select from AP_INVOICES';
829 
830     open invoice_who_cursor;
831     fetch invoice_who_cursor into l_last_updated_by, l_last_update_login;
832     close invoice_who_cursor;
833 
834     debug_info := 'Update AP_HOLDS';
835 
836 	/* Bug 9691312 Begin */
837     FOR c_wf_status IN ( SELECT hold_id
838                            FROM ap_holds
839                           WHERE invoice_id          = X_invoice_id
840                             AND held_by             = nvl(X_held_by,held_by)
841                             AND release_lookup_code IS NULL
842                             AND hold_lookup_code    = X_hold_lookup_code
843                             AND wf_status           IN ( 'STARTED', 'NEGOTIATE' )
844                        )
845     LOOP
846         AP_WORKFLOW_PKG.abort_holds_workflow( c_wf_status.hold_id ) ;
847     END LOOP ;
848 	/* Bug 9691312 End */
849 
850     UPDATE ap_holds
851        SET release_lookup_code = X_release_lookup_code,
852            release_reason = (SELECT description
853                                FROM ap_lookup_codes
854                               WHERE lookup_type = 'HOLD CODE'
855                                 AND lookup_code = X_release_lookup_code),
856            last_updated_by = FND_GLOBAL.user_id, -- 7299826
857            last_update_date = SYSDATE,
858            last_update_login = FND_GLOBAL.login_id -- 7299826
859      WHERE invoice_id = X_invoice_id
860        AND held_by = nvl(X_held_by,held_by) -- 7299826
861        AND release_lookup_code IS NULL
862        AND hold_lookup_code = X_hold_lookup_code;
863 
864      --Bug 4539462 DBI logging
865      AP_DBI_PKG.Maintain_DBI_Summary
866               (p_table_name => 'AP_HOLDS',
867                p_operation => 'U',
868                p_key_value1 => X_invoice_id,
869                 p_calling_sequence => current_calling_sequence);
870 
871         EXCEPTION
872           WHEN OTHERS THEN
873             IF (SQLCODE <> -20001) THEN
874               FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
875               FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
876               FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',
877                         current_calling_sequence);
878               FND_MESSAGE.SET_TOKEN('PARAMETERS',
879                   'X_invoice_id = '        ||X_invoice_id
880               ||', X_hold_lookup_code = '  ||X_hold_lookup_code
881               ||', X_release_lookup_code= '||X_release_lookup_code
882               ||', X_held_by = '           ||X_held_by
883                                        );
884               FND_MESSAGE.SET_TOKEN('DEBUG_INFO',debug_info);
885             END IF;
886           APP_EXCEPTION.RAISE_EXCEPTION;
887 
888   END release_single_hold;
889 
890 
891   -----------------------------------------------------------------------
892   -- PROCEDURE quick_release release either ALL holds or one specificated
893   -- hold for each one invoice.
894   -- This procedure is called by Action window from APXINWKB
895   -----------------------------------------------------------------------
896   PROCEDURE quick_release (X_invoice_id    IN  NUMBER,
897          X_hold_lookup_code  IN  VARCHAR2,
898          X_release_lookup_code IN  VARCHAR2,
899          X_release_reason  IN  VARCHAR2,
900          X_responsibility_id  IN  NUMBER,
901          X_last_updated_by  IN  NUMBER,
902          X_last_update_date  IN  DATE,
903          X_holds_count  IN OUT NOCOPY  NUMBER,
904          X_approval_status_lookup_code IN OUT NOCOPY  VARCHAR2,
905          X_calling_sequence   IN  VARCHAR2)
906   IS
907     l_success         BOOLEAN := TRUE;
908     l_error_code      VARCHAR2(4000);
909     l_tax_hold_codes  AP_ETAX_SERVICES_PKG.Rel_Hold_Codes_Type;
910     --num         BINARY_INTEGER := 1; /*Bug 12747896 : commented the initialization*/
911     current_calling_sequence VARCHAR2(2000);
912     debug_info               VARCHAR2(100);
913 
914     cursor l_invoice_status_cursor is
915       select ap_invoices_pkg.get_holds_count(invoice_id),
916              ap_invoices_pkg.get_approval_status(
917                                  invoice_id,
918                                  invoice_amount,
919                                  payment_status_flag,
920                                  invoice_type_lookup_code)
921       from   ap_invoices
922       where  invoice_id = X_invoice_id;
923 
924     cursor tax_holds_cursor is
925       select hold_lookup_code
926       from ap_holds
927       where invoice_id = x_invoice_id
928       and hold_lookup_code IN ('TAX AMOUNT RANGE','TAX VARIANCE')
929       and release_lookup_code IS NULL;
930 
931   BEGIN
932 
933     -- Update the calling sequence
934     --
935     current_calling_sequence :=
936               'AP_HOLDS_PKG.quick_release<-'||
937                      X_calling_sequence;
938 
939     /*Bug 12747896: commented below initialization as it is not needed for associative arrays*/
940     /*FOR num IN 1..10 LOOP
941        l_tax_hold_codes(num) := NULL;
942     END LOOP;*/
943 
944     ------------------------------------------------------------------------
945     -- Update final_match_flag to 'N' if try to release 'CANT CLOSE PO' hold
946     ------------------------------------------------------------------------
947     debug_info := 'Update AP_INVOICE_DISTRIBUTIONS';
948 
949     UPDATE ap_invoice_distributions D
950     SET    final_match_flag = 'N'
951     WHERE  D.invoice_id = X_invoice_id
952     AND     ((X_hold_lookup_code = 'CANT CLOSE PO') OR
953          ((X_hold_lookup_code = 'ALL')
954              AND EXISTS(SELECT 'X'
955         FROM AP_HOLDS H
956        WHERE H.invoice_id = X_invoice_id
957          AND H.hold_lookup_code = 'CANT CLOSE PO'
958          AND H.release_lookup_code IS NULL)));
959 
960   /*Bug 12747896 begin:commented and converted the below cursor fetch into bulk */
961   /*OPEN tax_holds_cursor;
962      LOOP
963       FETCH tax_holds_cursor into l_tax_hold_codes(num);
964       EXIT when tax_holds_cursor%notfound;
965       num := num+1;
966      END LOOP;
967     CLOSE tax_holds_cursor; */
968 
969     OPEN tax_holds_cursor;
970      FETCH tax_holds_cursor bulk collect into l_tax_hold_codes;
971     CLOSE tax_holds_cursor;
972 
973    /*Bug 12747896 : END*/
974 
975     -- Bug 8266290 : Start
976     FOR c_wf_status IN ( SELECT   hold_id
977                          FROM     ap_holds H
978                          WHERE    H.invoice_id = X_invoice_id
979                          AND      X_hold_lookup_code IN (H.hold_lookup_code, 'ALL')
980                          AND      H.hold_lookup_code not in ('DIST VARIANCE', 'NO RATE',
981                                                              'CANT FUNDS CHECK', 'INSUFFICIENT FUNDS',
982                                                              'FINAL MATCHING', 'FUTURE PERIOD', 'CANT TRY PO CLOSE',
983                                                              'DIST ACCT INVALID', 'ERV ACCT INVALID', 'LIAB ACCT INVALID')
984                          AND      H.release_lookup_code is null
985                          AND      H.wf_status /* Bug 9691312 = 'STARTED' */ IN ( 'STARTED', 'NEGOTIATE' )
986                         )
987     LOOP
988         AP_WORKFLOW_PKG.abort_holds_workflow( c_wf_status.hold_id ) ;
989     END LOOP ;
990     -- Bug 8266290 : End
991 
992     ------------------------------------------------------------------------
993     -- Release single hold if pass hold_lookup_code or all holds if pass 'ALL'
994     -- in hold_lookup_code
995     ------------------------------------------------------------------------
996     debug_info := 'Update AP_HOLDS';
997 
998    UPDATE ap_holds H
999       SET H.release_lookup_code = X_release_lookup_code,
1000         H.release_reason      = X_release_reason,
1001     H.responsibility_id  = X_responsibility_id,
1002           H.last_update_date    = X_last_update_date,
1003         H.last_updated_by     = X_last_updated_by
1004     WHERE H.invoice_id = X_invoice_id
1005       AND X_hold_lookup_code IN (H.hold_lookup_code, 'ALL')
1006       AND H.hold_lookup_code not in ('DIST VARIANCE', 'NO RATE',
1007                        'CANT FUNDS CHECK', 'INSUFFICIENT FUNDS',
1008                        'FINAL MATCHING', 'FUTURE PERIOD', 'CANT TRY PO CLOSE',
1009                        'DIST ACCT INVALID', 'ERV ACCT INVALID', 'LIAB ACCT INVALID')
1010       AND H.release_lookup_code is null;
1011 
1012     --Bug 4539462 DBI logging
1013     AP_DBI_PKG.Maintain_DBI_Summary
1014               (p_table_name => 'AP_HOLDS',
1015                p_operation => 'U',
1016                p_key_value1 => X_invoice_id,
1017                 p_calling_sequence => current_calling_sequence);
1018 
1019     ------------------------------------------------------------------------
1020     -- Retrieve new invoice statuses
1021     ------------------------------------------------------------------------
1022     debug_info := 'Retrieving new invoice statuses';
1023 
1024     open l_invoice_status_cursor;
1025     fetch l_invoice_status_cursor into
1026     X_holds_count,
1027     X_approval_status_lookup_code;
1028     close l_invoice_status_cursor;
1029 
1030     --ETAX: Invwkb
1031     --If the invoice goes to 'APPROVED' status outside the context of 'Invoice validation'
1032     --process then we need to update ETAX with the same status, and also if we released
1033     --TAX holds , we need to update ETAX of the same so that tax holds are released on
1034     --detail tax lines in ETAX repository.
1035     IF (x_approval_status_lookup_code IN ('APPROVED','AVAILABLE','FULL','UNPAID')) THEN
1036 
1037     /*Bug 12747896 : commented using count method and added exists as it is more appropriate */
1038   --IF(l_tax_hold_codes.COUNT <> 0) THEN
1039     IF (l_tax_hold_codes.EXISTS(1)) THEN
1040 
1041             l_success := ap_etax_services_pkg.release_tax_holds(
1042                          p_invoice_id => x_invoice_id,
1043              p_calling_mode => 'RELEASE TAX HOLDS',
1044              p_tax_hold_code => l_tax_hold_codes,
1045              p_all_error_messages => 'N',
1046              p_error_code => l_error_code,
1047              p_calling_sequence => current_calling_sequence);
1048 
1049             IF (not l_success) THEN
1050                FND_MESSAGE.SET_NAME('SQLAP','AP_ETX_CANNOT_REL_TAX_HOLDS');
1051          FND_MESSAGE.SET_TOKEN('REASON',l_error_code);
1052          APP_EXCEPTION.RAISE_EXCEPTION;
1053       END IF;
1054 
1055         END IF;
1056 
1057         IF (l_success) THEN
1058 
1059            l_success := ap_etax_pkg.calling_etax(
1060               p_invoice_id => x_invoice_id,
1061         p_calling_mode => 'FREEZE INVOICE',
1062         p_all_error_messages => 'N',
1063         p_error_code => l_error_code,
1064         p_calling_sequence => current_calling_sequence);
1065 
1066            IF (not l_success) THEN
1067 
1068               FND_MESSAGE.SET_NAME('SQLAP','AP_ETX_CANNOT_FRZ_INV');
1069         FND_MESSAGE.SET_TOKEN('REASON',l_error_code);
1070         APP_EXCEPTION.RAISE_EXCEPTION;
1071 
1072            END IF;
1073 
1074         END IF;
1075 
1076     END IF; /* x_approval_status_ IN ... */
1077 
1078     ------------------------------------------------------------------------
1079     -- Commit changes to database
1080     ------------------------------------------------------------------------
1081     debug_info := 'Commit changes';
1082 
1083     COMMIT;
1084 
1085    EXCEPTION
1086           WHEN OTHERS THEN
1087             IF (SQLCODE <> -20001) THEN
1088               FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
1089               FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
1090               FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE',
1091                         current_calling_sequence);
1092               FND_MESSAGE.SET_TOKEN('PARAMETERS',
1093                   'X_invoice_id = '        ||TO_CHAR(X_invoice_id)
1094               ||', X_hold_lookup_code = '  ||X_hold_lookup_code
1095               ||', X_release_lookup_code= '||X_release_lookup_code
1096               ||', X_release_reason= '||X_release_reason
1097               ||', X_responsibility_id= '||TO_CHAR(X_responsibility_id)
1098               ||', X_last_updated_by= '||TO_CHAR(X_last_updated_by)
1099               ||', X_last_update_date= '||TO_CHAR(X_last_update_date)
1100               ||', X_holds_count= '||TO_CHAR(X_holds_count)
1101               ||', X_approval_status_lookup_code= '||
1102                            X_approval_status_lookup_code
1103 );
1104               FND_MESSAGE.SET_TOKEN('DEBUG_INFO',debug_info);
1105             END IF;
1106           APP_EXCEPTION.RAISE_EXCEPTION;
1107 
1108   END quick_release;
1109 
1110 
1111 
1112 
1113 
1114 
1115 
1116 
1117 END AP_HOLDS_PKG;
1118