DBA Data[Home] [Help]

PACKAGE BODY: APPS.AR_TRANSACTION_GRP

Source


1 PACKAGE BODY AR_TRANSACTION_GRP AS
2 /* $Header: ARXGTRXB.pls 120.5 2005/09/07 19:55:31 mraymond noship $ */
3 
4 pg_debug      CONSTANT VARCHAR2(1)  := nvl(fnd_profile.value('AFLOG_ENABLED'),'N');
5 G_PKG_NAME    CONSTANT VARCHAR2(30) := 'AR_TRANSACTION_GRP';
6 G_MODULE_NAME CONSTANT VARCHAR2(30) := 'AR.PLSQL.AR_TRANSACTION_GRP' ;
7 
8 --Private procedures
9 
10 /*===========================================================================+
11  | PROCEDURE                                                                 |
12  |      trx_debug                                                            |
13  |                                                                           |
14  | DESCRIPTION                                                               |
15  |     Wrapper procedure so that it becomes easy to convert to logging       |
16  |     infrastructure later if needed                                        |
17  |                                                                           |
18  | SCOPE - PRIVATE                                                           |
19  |                                                                           |
20  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED                                    |
21  |       None                                                                |
22  |                                                                           |
23  | ARGUMENTS  :                                                              |
24  |   IN:                                                                     |
25  |     p_message_name                                                        |
26  |   OUT:                                                                    |
27  |     None                                                                  |
28  |   IN/ OUT:                                                                |
29  |     None                                                                  |
30  |                                                                           |
31  | RETURNS    : NONE                                                         |
32  |                                                                           |
33  | NOTES                                                                     |
34  |                                                                           |
35  | MODIFICATION HISTORY                                                      |
36  |                                                                           |
37  +===========================================================================*/
38 PROCEDURE trx_debug( p_message_name IN VARCHAR2) IS
39 
40   BEGIN
41     arp_util.debug(p_message_name);
42   END trx_debug;
43 
44 /*===========================================================================+
45  | PROCEDURE                                                                 |
46  |      fetch_trx_type                                                       |
47  |                                                                           |
48  | DESCRIPTION                                                               |
49  |     Fetches a record from ra_cust_trx_type for a customer_trx_id          |
50  |                                                                           |
51  | SCOPE - PRIVATE                                                           |
52  |                                                                           |
53  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED                                    |
54  |       None                                                                |
55  |                                                                           |
56  | ARGUMENTS  :                                                              |
57  |   IN:                                                                     |
58  |    p_customer_trx_id                                                      |
59  |   OUT:                                                                    |
60  |     p_trx_type_rec                                                        |
61  |   IN/ OUT:                                                                |
62  |     None
63  |                                                                           |
64  | RETURNS    : NONE                                                         |
65  |                                                                           |
66  | NOTES                                                                     |
67  |                                                                           |
68  | MODIFICATION HISTORY                                                      |
69  |                                                                           |
70  +===========================================================================*/
71 
72 PROCEDURE fetch_trx_type( p_trx_type_rec     OUT NOCOPY ra_cust_trx_types%rowtype,
73                           p_customer_trx_id  IN  ra_customer_trx.customer_trx_id%type,
74                           x_return_status    OUT NOCOPY VARCHAR2
75 						)
76 IS
77   BEGIN
78     x_return_status := FND_API.G_RET_STS_SUCCESS;
79     SELECT  trxtype.type,
80             trxtype.name,
81             trxtype.allow_overapplication_flag ,
82 			trxtype.natural_application_only_flag,
83 			trxtype.creation_sign
84        INTO p_trx_type_rec.type,
85     	    p_trx_type_rec.name,
86             p_trx_type_rec.allow_overapplication_flag,
87             p_trx_type_rec.natural_application_only_flag,
88             p_trx_type_rec.creation_sign
89     FROM   ra_cust_trx_types trxtype, ra_customer_trx header
90     WHERE  header.customer_trx_id = p_customer_trx_id
91       AND  trxtype.cust_trx_type_id = header.cust_trx_type_id;
92 
93     EXCEPTION
94       WHEN  OTHERS THEN
95         x_return_status := FND_API.G_RET_STS_ERROR ;
96         IF pg_debug = 'Y' THEN
97           trx_debug ('Exception: ar_transaction_grp.fetch_trx_type' ||sqlerrm);
98         END IF;
99   END fetch_trx_type;
100 
101 
102 --Public procedures
103 /*===========================================================================+
104  | PROCEDURE                                                                 |
105  |      Complete_Transaction                                                 |
106  |                                                                           |
107  | DESCRIPTION                                                               |
108  |      Completes the transaction after the following checks                 |
109  |           1. Validate Tax enforcement                                     |
110  |           2. Validate if transaction can be completed                     |
111  |           3. Perform document sequence number handling                    |
112  |           4. If all fine then update ra_customer_trx with complete_flag =Y|
113  |              and call to maintain the payment schedules                   |
114  |                                                                           |
115  | SCOPE - PUBLIC                                                            |
116  |                                                                           |
117  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED                                    |
118  |       arp_ct_pkg.lock_fetch_p                                             |
119  |       arp_trx_complete_chk.do_completion_checking                         |
120  |       FND_SEQNUM.GET_SEQ_VAL                                              |
121  |       arp_ct_pkg.update_p                                                 |
122  |       ARP_PROCESS_HEADER_POST_COMMIT.post_commit                          |
123  |                                                                           |
124  | ARGUMENTS  :                                                              |
125  |   IN:                                                                     |
126  |     p_api_version                                                         |
127  |     p_init_msg_list                                                       |
128  |     p_commit                                                              |
129  |     p_validation_level	                                                 |
130  |     p_customer_trx_id                                                     |
131  |   OUT:                                                                    |
132  |     x_return_status                                                       |
133  |     x_msg_count                                                           |
134  |     x_mssg_data                                                           |
135  |   IN/ OUT:                                                                |
136  |     None
137  |                                                                           |
138  | RETURNS    : NONE                                                         |
139  |                                                                           |
140  | NOTES                                                                     |
141  |                                                                           |
142  | MODIFICATION HISTORY                                                      |
143  |                                                                           |
144  +===========================================================================*/
145 
146 PROCEDURE COMPLETE_TRANSACTION(
147       p_api_version           IN      	  NUMBER,
148       p_init_msg_list         IN      	  VARCHAR2 := NULL,
149       p_commit                IN      	  VARCHAR2 := NULL,
150       p_validation_level	  IN          NUMBER   := NULL,
151       p_customer_trx_id       IN          ra_customer_trx.customer_trx_id%type,
152       x_return_status         OUT NOCOPY  VARCHAR2,
153       x_msg_count             OUT NOCOPY  NUMBER,
154       x_msg_data              OUT NOCOPY  VARCHAR2) IS
155 
156       l_api_name              CONSTANT  VARCHAR2(30) := 'COMPLETE_TRANSACTION';
157       l_api_version           CONSTANT NUMBER        := 1.0;
158 
159       l_trx_rec               ra_customer_trx%rowtype;
160       l_trx_type_rec          ra_cust_trx_types%rowtype;
161       l_doc_sequence_id       ra_customer_trx.doc_sequence_id%TYPE;
162       l_doc_sequence_value    ra_customer_trx.doc_sequence_value%TYPE;
163       l_line_number           NUMBER;
164       l_gl_tax_code           VARCHAR2(50);
165       l_validation_status     BOOLEAN;
166       l_error_count           NUMBER;
167       l_status                NUMBER;
168 	  l_copy_doc_num_flag     VARCHAR2(1);
169 	  l_unique_seq_number     VARCHAR2(255);
170 	  l_so_source_code        VARCHAR2(255);
171 	  l_init_msg_list         VARCHAR2(1);
172 	  l_commit                VARCHAR2(1);
173 	  l_validation_level      NUMBER;
174 
175    BEGIN
176 
177      /*-------------------------------------------+
178 	  | Initialize local variables                |
179       +-------------------------------------------*/
180       IF p_commit = NULL THEN
181         l_commit := FND_API.G_FALSE;
182       ELSE
183         l_commit := p_commit;
184       END IF;
185 
186       IF p_init_msg_list = NULL THEN
187         l_init_msg_list := FND_API.G_FALSE;
188       ELSE
189         l_init_msg_list := p_init_msg_list;
190       END IF;
191 
192       IF p_validation_level = NULL THEN
193         l_validation_level := FND_API.G_VALID_LEVEL_FULL;
194       ELSE
195         l_validation_level := p_validation_level;
196       END IF;
197 
198 	  l_unique_seq_number :=  fnd_profile.value('UNIQUE:SEQ_NUMBERS');
199 	  l_so_source_code    :=  oe_profile.value('SO_SOURCE_CODE');
200 
201       --------------------------------------------------------------
202       IF pg_debug = 'Y' THEN
203            trx_debug ('AR_TRANSACTION_GRP.COMPLETE_TRANSACTION(+)');
204       END IF;
205 
206       SAVEPOINT Complete_Transaction;
207      /*--------------------------------------------------+
208       |   Standard call to check for call compatibility  |
209       +--------------------------------------------------*/
210 
211       IF NOT FND_API.Compatible_API_Call(
212                           l_api_version,
213                           p_api_version,
214                           l_api_name,
215                           G_PKG_NAME) THEN
216           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
217       END IF;
218 
219      /*--------------------------------------------------------------+
220       |   Initialize message list if l_init_msg_list is set to TRUE  |
221       +--------------------------------------------------------------*/
222 
223       IF FND_API.to_Boolean( l_init_msg_list ) THEN
224          FND_MSG_PUB.initialize;
225       END IF;
226 
227      /*-----------------------------------------+
228       |   Initialize return status to SUCCESS   |
229       +-----------------------------------------*/
230       x_return_status := FND_API.G_RET_STS_SUCCESS;
231 
232 
233      /*-----------------------------------------------------+
234       | Lock and fetch the header record for customer trx id |
235       +-----------------------------------------------------*/
236       IF pg_debug = 'Y'  THEN
237         trx_debug ('Calling ar_ct_pkg.lock_fetch_p(+) ');
238       END IF;
239 
240       arp_ct_pkg.lock_fetch_p (l_trx_rec,
241                                p_customer_trx_id);
242 
243        IF pg_debug = 'Y'  THEN
244          trx_debug ('ar_ct_pkg.lock_fetch_p(-) ');
245       END IF;
246 
247      /*----------------------------------------------+
248       | Get the transaction type for trx type id     |
249       +----------------------------------------------*/
250       fetch_trx_type ( l_trx_type_rec,
251                        p_customer_trx_id,
252                        x_return_status
253                      );
254       IF x_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
255            ROLLBACK to Complete_Transaction;
256            return;
257       END IF;
258 
259       /*------------------------------+
260       |          Tax Handling         |
261       +-------------------------------*/
262 
263       /* Enforce natural account feature is obsolete for R12
264          and the logic behind it is now supported internally
265          within the etax product.  The local code for it here
266          has been removed */
267 
268       /*-----------------------------------------+
269       |Validate if transaction can be completed  |
270       +------------------------------------------*/
271       IF pg_debug = 'Y'  THEN
272          trx_debug ('Calling arp_trx_complete_chk.do_completion_checking(+) ');
273       END IF;
274       arp_trx_complete_chk.do_completion_checking(p_customer_trx_id,
275                                             	  l_so_source_code,
276                                                   arp_global.sysparam.ta_installed_flag,
277                                                   l_error_count);
278 
279       IF ( l_error_count > 0 ) THEN
280         ROLLBACK to Complete_Transaction;
281    	    x_return_status := FND_API.G_RET_STS_ERROR ;
282   	    FND_MESSAGE.Set_Name('AR', 'AR_TW_CANT_COMPLETE');
283         FND_MSG_PUB.Add;
284      	FND_MSG_PUB.Count_And_Get (p_count => x_msg_count     	,
285         		                   p_data  => x_msg_data
286                                   );
287         return;
288       END IF;
289 
290       IF pg_debug = 'Y'  THEN
291          trx_debug ('arp_trx_complete_chk.do_completion_checking(-) ');
295       | Document sequencing changes: assign document number here only if Document    |
292          trx_debug ('Calling fnd_seqnum.get_seq_val(+) ');
293       END IF;
294       /*-----------------------------------------------------------------------------+
296 	  | Number Generation Level profile is set to 'When the Transaction is completed'|
297       +-------------------------------------------------------------------------------*/
298       IF (l_unique_seq_number IN ('A','P') AND l_trx_rec.doc_sequence_value IS NULL) THEN
299          l_status := FND_SEQNUM.GET_SEQ_VAL(222,
300                                             l_trx_type_rec.name,
301                                             arp_global.sysparam.set_of_books_id,
302                                             'M',
303                                             l_trx_rec.trx_date,
304                                             l_doc_sequence_value,
305                                             l_doc_sequence_id);
306 
307          IF l_doc_sequence_value IS NOT NULL THEN
308            l_trx_rec.doc_sequence_id    := l_doc_sequence_id;
309            l_trx_rec.doc_sequence_value := l_doc_sequence_value;
310          ELSIF l_unique_seq_number = 'A' THEN
311            ROLLBACK to Complete_Transaction;
312     	   x_return_status := FND_API.G_RET_STS_ERROR ;
313            FND_MESSAGE.Set_Name('FND', 'UNIQUE-ALWAYS USED');
314            FND_MSG_PUB.Add;
315            FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
316         		                      p_data  => x_msg_data
317                                      );
318            return;
319         END IF;
320      END IF;
321      IF pg_debug = 'Y'  THEN
322          trx_debug ('fnd_seqnum.get_seq_val(-) ');
323       END IF;
324 
325       /*-----------------------------------------------------------------------------------+
326       | Copy document number to transaction number if "copy document to transaction number"|
327 	  | flag is checked in batch source                                                    |
328       +------------------------------------------------------------------------------------*/
329 
330       SELECT copy_doc_number_flag
331 	    INTO l_copy_doc_num_flag
332       FROM   RA_BATCH_SOURCES batch, RA_CUSTOMER_TRX header
333 	  WHERE  batch.batch_source_id = header.batch_source_id
334     	AND  header.customer_trx_id = p_customer_trx_id;
335 
336       IF NVL (l_copy_doc_num_flag, 'N')  = 'Y'
337 	     AND l_trx_rec.doc_sequence_value is not null
338 		 AND l_trx_rec.old_trx_number is null THEN
339             l_trx_rec.old_trx_number := l_trx_rec.trx_number;
340             l_trx_rec.trx_number := l_doc_sequence_value;
341       END IF;
342 
343       IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
344          l_trx_rec.complete_flag := 'Y';
345          arp_ct_pkg.update_p(l_trx_rec,p_customer_trx_id);
346          IF pg_debug = 'Y'  THEN
347             trx_debug ('Calling ARP_PROCESS_HEADER_POST_COMMIT.post_commit(+)');
348          END IF;
349          ARP_PROCESS_HEADER_POST_COMMIT.post_commit (
350                    p_form_name                  => 'AR_TRANSACTION_GRP',
351                    p_form_version               => 1,
352                    p_customer_trx_id            => p_customer_trx_id,
353                    p_previous_customer_trx_id   => l_trx_rec.previous_customer_trx_id,
354                    p_complete_flag              => 'Y',
355                    p_trx_open_receivables_flag  => l_trx_type_rec.accounting_affect_flag,
356                    p_prev_open_receivables_flag => null,
357                    p_creation_sign              => l_trx_type_rec.creation_sign,
358                    p_allow_overapplication_flag => l_trx_type_rec.allow_overapplication_flag,
359                    p_natural_application_flag   => l_trx_type_rec.natural_application_only_flag,
360                    p_cash_receipt_id            => null,
361                    p_error_mode                 => null
362                    );
363           IF pg_debug = 'Y' THEN
364             trx_debug ('ARP_PROCESS_HEADER_POST_COMMIT.post_commit(-)');
365           END IF;
366        END IF;
367 
368       /*-----------------------------------+
369 	  | Standard check of l_commit.          |
370       +------------------------------------*/
371       IF FND_API.To_Boolean( l_commit ) THEN
372         COMMIT;
373       END IF;
374 
375       /*-----------------------------------------------------------------------+
376 	  | Standard call to get message count and if count is 1, get message info |
377       +------------------------------------------------------------------------*/
378       FND_MSG_PUB.Count_And_Get (p_count => x_msg_count     	,
379         		                 p_data  => x_msg_data
380                                  );
381 
382 
383       IF pg_debug = 'Y' THEN
384         trx_debug ('AR_TRANSACTION_GRP.COMPLETE_TRANSACTION(-)');
385       END IF;
386 
387       EXCEPTION
388         WHEN FND_API.G_EXC_ERROR THEN
389 	    	ROLLBACK TO Complete_Transaction;
390     		x_return_status := FND_API.G_RET_STS_ERROR ;
391 	    	FND_MSG_PUB.Count_And_Get (
392 			                           p_count => x_msg_count     	,
393         		                       p_data  => x_msg_data
394                                    	  );
395     	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
396 	    	ROLLBACK TO Complete_Transaction;
397     		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
398 	    	FND_MSG_PUB.Count_And_Get (
399 			                           p_count => x_msg_count     	,
403 	    	ROLLBACK TO Complete_Transaction;
400         		                       p_data  => x_msg_data
401                                    	  );
402     	WHEN OTHERS THEN
404 		    x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
405        		IF 	FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
406      	    	FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME ,
407      	    	     	    			l_api_name
408 										);
409     		END IF;
410 
411 	    	FND_MSG_PUB.Count_And_Get (
412 			                           p_count => x_msg_count,
413         		                       p_data  => x_msg_data
414                                    	  );
415 
416   END COMPLETE_TRANSACTION;
417 
418 /*===========================================================================+
419  | PROCEDURE                                                                 |
420  |      Incomplete_Transaction                                               |
421  |                                                                           |
422  | DESCRIPTION                                                               |
423  |      Incompletes the transaction after the following checks               |
424  |           1. It should not have been posted to GL                         |
425  |           2. There should not exist any activity against it               |
426  |           3. There should not be a chargeback for the transaction         |
427  |           4. There should not be debit memo reversal on the transaction   |
428  |           4. If none of above then update ra_customer_trx with            |
429  |              complete_flag =N and call to maintain the payment schedules  |
430  |                                                                           |
431  | SCOPE - PUBLIC                                                            |
432  |                                                                           |
433  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED                                    |
434  |       arp_ct_pkg.lock_fetch_p                                             |
435  |       arpt_sql_func_util.get_posted_flag                                  |
436  |       arpt_sql_func_util.get_activity_flag
437  |       arp_ct_pkg.update_p                                                 |
438  |       ARP_PROCESS_HEADER_POST_COMMIT.post_commit                          |
439  |                                                                           |
440  | ARGUMENTS  :                                                              |
441  |   IN:                                                                     |
442  |     p_api_version                                                         |
443  |     p_init_msg_list                                                       |
444  |     p_commit                                                              |
445  |     p_validation_level	                                                 |
446  |     p_customer_trx_id                                                     |
447  |   OUT:                                                                    |
448  |     x_return_status                                                       |
449  |     x_msg_count                                                           |
450  |     x_mssg_data                                                           |
451  |   IN/ OUT:                                                                |
452  |     None
453  |                                                                           |
454  | RETURNS    : NONE                                                         |
455  |                                                                           |
456  | NOTES                                                                     |
457  |                                                                           |
458  | MODIFICATION HISTORY                                                      |
459  |                                                                           |
460  +===========================================================================*/
461 
462 PROCEDURE INCOMPLETE_TRANSACTION(
463       p_api_version           IN      	  NUMBER,
464       p_init_msg_list         IN      	  VARCHAR2 := NULL,
465       p_commit                IN      	  VARCHAR2 := NULL,
466       p_validation_level	  IN          NUMBER   := NULL,
467       p_customer_trx_id       IN          ra_customer_trx.customer_trx_id%type,
468       x_return_status         OUT NOCOPY  VARCHAR2,
469       x_msg_count             OUT NOCOPY  NUMBER,
470       x_msg_data              OUT NOCOPY  VARCHAR2) IS
471 
472       l_api_name              CONSTANT  VARCHAR2(30) := 'INCOMPLETE_TRANSACTION';
473       l_api_version           CONSTANT NUMBER        := 1.0;
474 
475       l_trx_rec               ra_customer_trx%rowtype;
476       l_trx_type_rec          ra_cust_trx_types%rowtype;
477       l_posted_flag 		  VARCHAR2(1);
478       l_activity_flag		  VARCHAR2(1);
479 
480  	  l_init_msg_list         VARCHAR2(1);
481 	  l_commit                VARCHAR2(1);
482 	  l_validation_level      NUMBER;
483 
484    BEGIN
485 
486      /*-------------------------------------------+
487 	  | Initialize local variables                |
488       +-------------------------------------------*/
489       IF p_commit = NULL THEN
490         l_commit := FND_API.G_FALSE;
491       ELSE
492         l_commit := p_commit;
493       END IF;
494 
495       IF p_init_msg_list = NULL THEN
496         l_init_msg_list := FND_API.G_FALSE;
497       ELSE
501       IF p_validation_level = NULL THEN
498         l_init_msg_list := p_init_msg_list;
499       END IF;
500 
502         l_validation_level := FND_API.G_VALID_LEVEL_FULL;
503       ELSE
504         l_validation_level := p_validation_level;
505       END IF;
506 
507       IF pg_debug = 'Y' THEN
508        trx_debug ('AR_TRANSACTION_GRP.INCOMPLETE_TRANSACTION(+)' );
509       END IF;
510 
511       SAVEPOINT Incomplete_Transaction;
512      /*--------------------------------------------------+
513       |   Standard call to check for call compatibility  |
514       +--------------------------------------------------*/
515 
516       IF NOT FND_API.Compatible_API_Call(
517                           l_api_version,
518                           p_api_version,
519                           l_api_name,
520                           G_PKG_NAME) THEN
521           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
522       END IF;
523 
524      /*--------------------------------------------------------------+
525       |   Initialize message list if l_init_msg_list is set to TRUE  |
526       +--------------------------------------------------------------*/
527 
528       IF FND_API.to_Boolean( l_init_msg_list ) THEN
529          FND_MSG_PUB.initialize;
530       END IF;
531 
532      /*-----------------------------------------+
533       |   Initialize return status to SUCCESS   |
534       +-----------------------------------------*/
535       x_return_status := FND_API.G_RET_STS_SUCCESS;
536 
537      /*-----------------------------------------------------+
538       | Lock and fetch the header record for customer trx id |
539       +-----------------------------------------------------*/
540       IF pg_debug = 'Y'  THEN
541          trx_debug ('Calling arp_ct_pkg.lock_fetch_p(+) ');
542       END IF;
543 
544       arp_ct_pkg.lock_fetch_p (l_trx_rec,
545                            p_customer_trx_id);
546 
547       IF pg_debug = 'Y'  THEN
548          trx_debug ('arp_ct_pkg.lock_fetch_p(-) ');
549       END IF;
550 
551      /*----------------------------------------------+
552       | Get the transaction type for trx type id     |
553       +----------------------------------------------*/
554       fetch_trx_type ( l_trx_type_rec,
555                        p_customer_trx_id,
556                        x_return_status
557                      );
558 
559       IF x_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
560            ROLLBACK to Incomplete_Transaction;
561            return;
562       END IF;
563 
564      /*--------------------------------------------------------------+
565       | Check for activities, etc on invoice before incompleting     |
566       +--------------------------------------------------------------*/
567       IF l_trx_rec.complete_flag ='Y' THEN
568         IF pg_debug = 'Y' THEN
569           trx_debug ('Calling arpt_sql_funct_util.get_posted_flag(+)');
570         END IF;
571 
572         l_posted_flag := arpt_sql_func_util.get_posted_flag(
573                                          p_customer_trx_id,
574                                          l_trx_type_rec.post_to_gl,
575                                          l_trx_rec.complete_flag );
576         IF (l_posted_flag = 'Y') THEN
577           ROLLBACK to Incomplete_Transaction;
578     	  x_return_status := FND_API.G_RET_STS_ERROR ;
579           FND_MESSAGE.Set_Name('AR', 'AR_TAPI_CANT_UPDATE_POSTED');
580           FND_MSG_PUB.Add;
581        	  FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
582            		                     p_data  => x_msg_data
583                                     );
584 		  return;
585         END IF;
586         IF pg_debug = 'Y' THEN
587            trx_debug ('arpt_sql_funct_util.get_posted_flag(-)');
588            trx_debug ('Calling arpt_sql_funct_util.get_activity_flag(+)');
589         END IF;
590 
591         l_activity_flag := arpt_sql_func_util.get_activity_flag(
592                                          p_customer_trx_id,
593                                          l_trx_type_rec.accounting_affect_flag,
594                                          l_trx_rec.complete_flag,
595                                          l_trx_type_rec.type,
596                                          l_trx_rec.initial_customer_trx_id,
597                                          l_trx_rec.previous_customer_trx_id
598                                          );
599         IF (l_activity_flag = 'Y') THEN
600           ROLLBACK to Incomplete_Transaction;
601     	  x_return_status := FND_API.G_RET_STS_ERROR ;
602           FND_MESSAGE.Set_Name('AR', 'AR_TW_NO_RECREATE_PS');
603           FND_MSG_PUB.Add;
604        	  FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
605            		                     p_data  => x_msg_data
606                                     );
607           return;
608         ELSIF (l_activity_flag = 'G') THEN
609           ROLLBACK to Incomplete_Transaction;
610     	  x_return_status := FND_API.G_RET_STS_ERROR ;
611           FND_MESSAGE.Set_Name('AR', 'AR_TAPI_CANT_UPDATE_POSTED');
612           FND_MSG_PUB.Add;
613           FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
614         		                     p_data  => x_msg_data
615                                     );
616 		  return;
617         END IF;
618         IF pg_debug = 'Y' THEN
619            trx_debug ('arpt_sql_funct_util.get_activity_flag(-)');
620         END IF;
621 
622         IF ( l_trx_rec.created_from  IN ('ARXREV', 'REL9_ARXREV') ) THEN
623           ROLLBACK to Incomplete_Transaction;
624     	  x_return_status := FND_API.G_RET_STS_ERROR ;
625           FND_MESSAGE.Set_Name('AR', 'AR_TAPI_CANT_UPDATE_DM_REV');
626           FND_MSG_PUB.Add;
627           FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
628         		                     p_data  => x_msg_data
629                                     );
630           return;
631         END IF;
632 
633         IF ( l_trx_type_rec.type = 'CB' )  THEN
634           ROLLBACK to Incomplete_Transaction;
635     	  x_return_status := FND_API.G_RET_STS_ERROR ;
636           FND_MESSAGE.Set_Name('AR', 'AR_TAPI_CANT_UPDATE_CB');
637           FND_MSG_PUB.Add;
638           FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
639         		                     p_data  => x_msg_data
640                                     );
641 		  return;
642         END IF;
643 
644         IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
645               l_trx_rec.complete_flag := 'N';
646               arp_ct_pkg.update_p(l_trx_rec,p_customer_trx_id);
647               IF pg_debug = 'Y' THEN
648                 trx_debug ('Calling ARP_PROCESS_HEADER_POST_COMMIT.post_commit(+)');
649               END IF;
650               ARP_PROCESS_HEADER_POST_COMMIT.post_commit (
651                    p_form_name                  => 'AR_TRANSACTION_GRP',
652                    p_form_version               => 1,
653                    p_customer_trx_id            => p_customer_trx_id,
654                    p_previous_customer_trx_id   => l_trx_rec.previous_customer_trx_id,
655                    p_complete_flag              => 'N',
656                    p_trx_open_receivables_flag  => l_trx_type_rec.accounting_affect_flag,
657                    p_prev_open_receivables_flag => null,
658                    p_creation_sign              => l_trx_type_rec.creation_sign,
659                    p_allow_overapplication_flag => l_trx_type_rec.allow_overapplication_flag,
660                    p_natural_application_flag   => l_trx_type_rec.natural_application_only_flag,
661                    p_cash_receipt_id            => null,
662                    p_error_mode                 => null
663                    );
664               IF pg_debug = 'Y' THEN
665                 trx_debug ('ARP_PROCESS_HEADER_POST_COMMIT.post_commit(-)' );
666               END IF;
667         END IF;
668       END IF; --complete_flag ='Y'
669 
670       /*-----------------------------------+
671 	  | Standard check of l_commit.          |
672       +------------------------------------*/
673       IF FND_API.To_Boolean( l_commit ) THEN
674         COMMIT;
675       END IF;
676 
677       /*-----------------------------------------------------------------------+
678 	  | Standard call to get message count and if count is 1, get message info |
679       +------------------------------------------------------------------------*/
680       FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
681         		                 p_data  => x_msg_data
682                                  );
683 
684 
685       IF pg_debug = 'Y' THEN
686         trx_debug ('AR_TRANSACTION_GRP.INCOMPLETE_TRANSACTION(-)');
687       END IF;
688 
689       EXCEPTION
690         WHEN FND_API.G_EXC_ERROR THEN
691 	    	ROLLBACK TO Incomplete_Transaction;
692     		x_return_status := FND_API.G_RET_STS_ERROR ;
693 	    	FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
694         		                       p_data  => x_msg_data
695                                    	  );
696     	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
697 	    	ROLLBACK TO Incomplete_Transaction;
698     		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
699 	    	FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
700         		                       p_data  => x_msg_data
701                                    	  );
702     	WHEN OTHERS THEN
703 	    	ROLLBACK TO Incomplete_Transaction;
704 		    x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
705        		IF 	FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
706      	    	FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME ,
707      	    	     	    			l_api_name
708 										);
709     		END IF;
710 
711 	    	FND_MSG_PUB.Count_And_Get (p_count => x_msg_count,
712         		                       p_data  => x_msg_data
713                                    	  );
714 
715   END INCOMPLETE_TRANSACTION;
716 
717 END AR_TRANSACTION_GRP;