DBA Data[Home] [Help]

PACKAGE BODY: APPS.ARP_PROCESS_DIST

Source


1 PACKAGE BODY ARP_PROCESS_DIST AS
2 /* $Header: ARTELGDB.pls 120.8.12010000.3 2008/11/12 11:22:27 rasarasw ship $ */
3 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
4 
5 pg_number_dummy       number;
6 
7 /*===========================================================================+
8  | PROCEDURE                                                                 |
9  |    set_flags								     |
10  |                                                                           |
11  | DESCRIPTION                                                               |
12  |    Sets various change and status flags for the current record.  	     |
13  |                                                                           |
14  | SCOPE - PRIVATE                                                           |
15  |                                                                           |
16  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
17  |    arp_util.debug                                                         |
18  |                                                                           |
19  | ARGUMENTS  : IN:                                                          |
20  | 		     p_cust_trx_line_gl_dist_id				     |
21  |		     p_new_dist_rec 					     |
22  |              OUT:                                                         |
23  |		     p_posted_flag 					     |
24  |		     p_ccid_changed_flag  				     |
25  |		     p_amount_percent_changed_flag 			     |
26  |          IN/ OUT:							     |
27  |                    None						     |
28  |                                                                           |
29  | RETURNS    : NONE                                                         |
30  |                                                                           |
31  | NOTES                                                                     |
32  |                                                                           |
33  | MODIFICATION HISTORY                                                      |
34  |     19-JUL-95  Charlie Tomberg     Created                                |
35  |     12-OCT-95  Martin Johnson      Replaced arp_trx_util.set_posted_flag  |
36  |                                     with IF statment to determine if      |
37  |                                     dist is posted (set_posted_flag       |
38  |                                     determines if trx is posted)          |
39  |                                                                           |
40  +===========================================================================*/
41 
42 PROCEDURE set_flags(p_cust_trx_line_gl_dist_id IN
43                        ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type,
44                     p_new_dist_rec       IN ra_cust_trx_line_gl_dist%rowtype,
45                     p_posted_flag                  OUT NOCOPY boolean,
46                     p_ccid_changed_flag            OUT NOCOPY boolean,
47                     p_amount_percent_changed_flag  OUT NOCOPY boolean) IS
48 
49   l_old_dist_rec  		  ra_cust_trx_line_gl_dist%rowtype;
50   l_posted_flag                   boolean;
51   l_ccid_changed_flag         boolean;
52   l_amount_percent_changed_flag   boolean;
53 
54 BEGIN
55 
56    arp_util.debug('arp_process_dist.set_flags()+');
57 
58    arp_ctlgd_pkg.fetch_p( l_old_dist_rec,
59                           p_cust_trx_line_gl_dist_id);
60 
61 
62    IF     (
63              l_old_dist_rec.code_combination_id <>
64                                      p_new_dist_rec.code_combination_id AND
65              p_new_dist_rec.code_combination_id <> pg_number_dummy
66           )
67    THEN   l_ccid_changed_flag := TRUE;
68    ELSE   l_ccid_changed_flag := FALSE;
69    END IF;
70 
71    IF     (
72             (
73                nvl(l_old_dist_rec.amount, 0) <> nvl(p_new_dist_rec.amount, 0)
74              AND
75                p_new_dist_rec.amount <> pg_number_dummy
76             ) OR
77             (
78                nvl(l_old_dist_rec.percent, 0) <> nvl(p_new_dist_rec.percent, 0)
79              AND
80                p_new_dist_rec.percent <> pg_number_dummy
81             )
82           )
83    THEN  l_amount_percent_changed_flag := TRUE;
84    ELSE  l_amount_percent_changed_flag := FALSE;
85    END IF;
86 
87    IF ( l_old_dist_rec.gl_posted_date IS NULL )
88      THEN l_posted_flag := FALSE;
89      ELSE l_posted_flag := TRUE;
90    END IF;
91 
92    p_posted_flag	         := l_posted_flag;
93    p_ccid_changed_flag	 	 := l_ccid_changed_flag;
94    p_amount_percent_changed_flag := l_amount_percent_changed_flag;
95 
96    arp_util.debug('p_posted_flag                 = ' ||
97                   arp_trx_util.boolean_to_varchar2(l_posted_flag));
98 
99    arp_util.debug('p_ccid_changed_flag           = ' ||
100                  arp_trx_util.boolean_to_varchar2( l_ccid_changed_flag));
101 
102    arp_util.debug('p_amount_percent_changed_flag = ' ||
103                   arp_trx_util.boolean_to_varchar2(
104                                          l_amount_percent_changed_flag));
105 
106    arp_util.debug('arp_process_dist.set_flags()-');
107 
108 EXCEPTION
109   WHEN OTHERS THEN
110 
111   /*---------------------------------------------+
112    |  Display parameters and raise the exception |
113    +---------------------------------------------*/
114 
115    arp_util.debug('EXCEPTION:  arp_process_dist.set_flags()');
116 
117    arp_util.debug('');
118    arp_util.debug('---------- parameters for set_flags() ---------');
119 
120    arp_util.debug('p_cust_trx_line_gl_dist_id = ' ||
121                   p_cust_trx_line_gl_dist_id);
122 
123    arp_util.debug('');
124 
125    arp_util.debug('---------- new distribution record ----------');
126    arp_ctlgd_pkg.display_dist_rec( p_new_dist_rec );
127    arp_util.debug('');
128 
129    RAISE;
130 
131 END;
132 
133 /*===========================================================================+
134  | PROCEDURE validate_and_default_gl_date                                    |
135  |                                                                           |
136  | DESCRIPTION                                                               |
137  |    Returns a default GL date                                              |
138  |                                                                           |
139  | SCOPE - PRIVATE                                                           |
140  |                                                                           |
141  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
142  |    arp_util.debug                                                         |
143  |                                                                           |
144  | ARGUMENTS  : IN:                                                          |
145  |                    p_gl_date                                              |
146  |                    p_trx_date                                             |
147  |                    p_invoicing_rule_id                                    |
148  |              OUT:                                                         |
149  |                    None						     |
150  |          IN/ OUT:							     |
151  |                    p_default_gl_date                                      |
152  |                                                                           |
153  | RETURNS    : NONE                                                         |
154  |                                                                           |
155  | NOTES                                                                     |
156  |                                                                           |
157  | MODIFICATION HISTORY                                                      |
158  |     08-NOV-95  Martin Johnson      Created                                |
159  |                                                                           |
160  +===========================================================================*/
161 
162 
163 PROCEDURE validate_and_default_gl_date(
164                p_gl_date           IN date,
165                p_trx_date          IN date,
166                p_invoicing_rule_id IN
167                  ra_customer_trx.invoicing_rule_id%type,
168                p_default_gl_date   IN OUT NOCOPY date)
169 IS
170 
171    l_result                boolean;
172    l_gl_date               date;
173    l_trx_date              date;
174    l_defaulting_rule_used  varchar2(300);
175    l_error_message         varchar2(300);
176 
177 BEGIN
178 
179    IF PG_DEBUG in ('Y', 'C') THEN
180       arp_util.debug('arp_process_dist.validate_and_default_gl_date()+');
181    END IF;
182 
183    /* bug-7147479  Use GL Date as passed.Commented out the below lines of code
184       which assigns null when invoicing rule id is not null*/
185    l_gl_date  := p_gl_date;
186    l_trx_date := p_trx_date;
187    /*IF ( p_invoicing_rule_id IS NOT NULL)
188      THEN
189 
190        l_gl_date  := null;
191        l_trx_date := null;
192 
193      ELSE
194 
195        l_gl_date  := p_gl_date;
196        l_trx_date := p_trx_date;
197 
198    END IF;*/
199 
200    l_result := arp_util.validate_and_default_gl_date(
201                                      l_gl_date,
202                                      l_trx_date,
203                                      null,
204                                      null,
205                                      null,
206                                      null,
207                                      null,
208                                      null,
209                                      null,
210                                      p_invoicing_rule_id,
211                                      arp_global.set_of_books_id,
212                                      222,
213                                      p_default_gl_date,
214                                      l_defaulting_rule_used,
215                                      l_error_message );
216 
217    IF PG_DEBUG in ('Y', 'C') THEN
218       arp_util.debug(   'p_default_gl_date: ' ||
219                                 TO_CHAR(p_default_gl_date, 'DD-MON-YYYY') );
220       arp_util.debug(   'l_defaulting_rule_used: ' ||
221                                 l_defaulting_rule_used );
222       arp_util.debug(   'l_error_message: ' || l_error_message );
223    END IF;
224 
225    IF ( not l_result )
226      THEN
227        fnd_message.set_name('AR', 'GENERIC_MESSAGE');
228        fnd_message.set_token('GENERIC_TEXT', l_error_message);
229        app_exception.raise_exception;
230 
231      ELSIF ( p_default_gl_date IS NULL )
232        THEN
233          fnd_message.set_name('AR', 'AR_DIST_BACKOUT_GL_DATE');
234          app_exception.raise_exception;
235 
236    END IF;
237 
238    IF PG_DEBUG in ('Y', 'C') THEN
239       arp_util.debug('arp_process_dist.validate_and_default_gl_date()-');
240    END IF;
241 
242 EXCEPTION
243   WHEN OTHERS THEN
244 
245      /*---------------------------------------------+
246       |  Display parameters and raise the exception |
247       +---------------------------------------------*/
248 
249       IF PG_DEBUG in ('Y', 'C') THEN
250          arp_util.debug(
251             'EXCEPTION:  arp_process_dist.validate_and_default_gl_date()');
252          arp_util.debug(  '');
253          arp_util.debug(
254         '---------- parameters for validate_and_default_gl_date() ---------');
255          arp_util.debug(  'p_gl_date           = ' || p_gl_date );
256          arp_util.debug(  'p_trx_date          = ' || p_trx_date );
257          arp_util.debug(  'p_invoicing_rule_id = ' || p_invoicing_rule_id );
258       END IF;
259 
260       RAISE;
261 
262 END validate_and_default_gl_date;
263 
264 /*===========================================================================+
265  | PROCEDURE                                                                 |
266  |    backout_ccid							     |
267  |                                                                           |
268  | DESCRIPTION                                                               |
269  |    Inserts two records to backout the existing dist record.	             |
270  |    This procedure is called if backout is required and the dist's         |
271  |    code_combination_id has changed.	 		      	             |
272  |                                                                           |
273  | SCOPE - PRIVATE                                                           |
274  |                                                                           |
275  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
276  |    arp_util.debug                                                         |
277  |                                                                           |
278  | ARGUMENTS  : IN:                                                          |
279  |		      p_old_dist_rec					     |
280  |		      p_new_dist_rec					     |
281  |                    p_header_gl_date                                       |
282  |                    p_trx_date                                             |
283  |                    p_invoicing_rule_id                                    |
284  |		      p_exchange_rate					     |
285  |		      p_currency_code					     |
286  |		      p_precision					     |
287  |		      p_mau						     |
288  |              OUT:                                                         |
289  |                    None						     |
290  |          IN/ OUT:							     |
291  |                    None						     |
292  |                                                                           |
293  | RETURNS    : NONE                                                         |
294  |                                                                           |
295  | NOTES                                                                     |
296  |                                                                           |
297  | MODIFICATION HISTORY                                                      |
298  |     19-JUL-95  Charlie Tomberg     Created                                |
299  |     08-NOV-95  Martin Johnson      Made cust_trx_line_salesrep_id and     |
300  |                                      gl_posted_date null for new dist.    |
301  |                                      Call validate_and_default_gl_date()  |
302  |                                      to get gl_date.                      |
303  |                                                                           |
304  +===========================================================================*/
305 
306 PROCEDURE backout_ccid(
307                p_old_dist_rec      IN ra_cust_trx_line_gl_dist%rowtype,
308                p_new_dist_rec      IN ra_cust_trx_line_gl_dist%rowtype,
309                p_header_gl_date    IN date,
313                p_currency_code     IN fnd_currencies.currency_code%type,
310                p_trx_date          IN date,
311                p_invoicing_rule_id IN ra_customer_trx.invoicing_rule_id%type,
312                p_exchange_rate     IN ra_customer_trx.exchange_rate%type,
314                p_precision         IN fnd_currencies.precision%type,
315                p_mau               IN
316                                   fnd_currencies.minimum_accountable_unit%type
317                       )  IS
318 
319    l_cust_trx_line_gl_dist_id
320                    ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type;
321 
322    l_old_dist_rec   ra_cust_trx_line_gl_dist%rowtype;
323    l_new_dist_rec   ra_cust_trx_line_gl_dist%rowtype;
324 
325    /* Bug 3598021 - 3630436 */
326    l_orig_dist_rec  ra_cust_trx_line_gl_dist%rowtype;
327 
328    l_default_gl_date       date;
329 
330 BEGIN
331 
332    arp_util.debug('arp_process_dist.backout_ccid()+');
333 
334    l_old_dist_rec := p_old_dist_rec;
335    l_new_dist_rec := p_new_dist_rec;
336 
337 
338    /*--------------------------+
339     |    insert the new row    |
340     +--------------------------*/
341 
342 
343    /*---------------------------------------------------------------+
344     |    If a new value was specified in the dist rec passed into   |
345     |    update_dist() use that value. Otherwise, use the  	    |
346     |    value from the original dist line.               	    |
347     +---------------------------------------------------------------*/
348 
349    arp_ctlgd_pkg.merge_dist_recs( l_old_dist_rec,
350                                   l_new_dist_rec,
351                                   l_new_dist_rec);
352 
353    /* Bug 7039029 JVARKEY cust_trx_line_salesrep_id should be retained in
354       the newly created distribution*/
355    --l_new_dist_rec.cust_trx_line_salesrep_id := null;
356    l_new_dist_rec.gl_posted_date := null;
357 
358    /*Bug-7147479 Pass GL DATE in l_default_gl_Date and
359  	Pass NVL(l_old_dist_rec.gl_date,p_header_gl_date)
360      The purpose is to use the GL Date on the old line if it is valid
361    */
362    l_default_gl_date:=NVL(l_old_dist_rec.gl_date,p_header_gl_date);
363    validate_and_default_gl_date(NVL(l_old_dist_rec.gl_date,p_header_gl_date),
364                                 p_trx_date,
365                                 p_invoicing_rule_id,
366                                 l_default_gl_date );
367 
368    l_new_dist_rec.gl_date          := l_default_gl_date;
369    l_new_dist_rec.original_gl_date := l_default_gl_date;
370 
371    /*-----------------------------------------------------------+
372     |    Call the table handler to insert the new dist record   |
373     +-----------------------------------------------------------*/
374 
375    arp_ctlgd_pkg.insert_p( l_new_dist_rec,
376                            l_cust_trx_line_gl_dist_id,
377                            p_exchange_rate,
378                            p_currency_code,
379                            p_precision,
380                            p_mau);
381 
382    /* 6325023 - the point of the rec_offset_flag was to keep header level UNEARN
383        rows (all of them) together to make troubleshooting data issues easier.
384        I am removing the code here that sets the rec_offset_flags of the older/
385        existing rows to null as that is contrary to the point of this column
386    /+ Bug 3598021  - 3630436 +/
387    IF l_old_dist_rec.rec_offset_flag = 'Y'
388    THEN
389       ARP_CTLGD_PKG.set_to_dummy(l_orig_dist_rec );
390       l_orig_dist_rec.rec_offset_flag := NULL;
391       ARP_CTLGD_PKG.update_p( l_orig_dist_rec ,
392                                 l_old_dist_rec.cust_trx_line_gl_dist_id );
393    END IF;
394 
395    END of bug 6325023 */
396 
397    /*-------------------------------------+
398     |    backout the original dist row    |
399     +-------------------------------------*/
400 
401    l_old_dist_rec.amount       := -1 * l_old_dist_rec.amount;
402 
403    l_old_dist_rec.acctd_amount := -1 * l_old_dist_rec.acctd_amount;
404 
405    l_old_dist_rec.percent      := -1 * l_old_dist_rec.percent;
406 
407    /* 6325023 - Keep the Srep ID populated.. no reason not to
408    l_old_dist_rec.cust_trx_line_salesrep_id := null; */
409 
410    l_old_dist_rec.gl_posted_date := null;
411 
412    l_old_dist_rec.gl_date          := l_default_gl_date;
413    l_old_dist_rec.original_gl_date := l_default_gl_date;
414 
415    /* 6325023 - do not null rec_offset_flag
416    /+ Bug 3598021 - 3630436  +/
417    l_old_dist_rec.rec_offset_flag := NULL;
418    END of bug 6325023 */
419 
420    arp_ctlgd_pkg.insert_p( l_old_dist_rec,
421                            l_cust_trx_line_gl_dist_id,
422                            p_exchange_rate,
423                            p_currency_code,
424                            p_precision,
425                            p_mau);
426 
427    arp_util.debug('arp_process_dist.backout_ccid()-');
428 
429 EXCEPTION
430   WHEN OTHERS THEN
431 
432      /*---------------------------------------------+
433       |  Display parameters and raise the exception |
434       +---------------------------------------------*/
435 
436       arp_util.debug('EXCEPTION:  arp_process_dist.backout_ccid()');
437       arp_util.debug('');
441       arp_util.debug('p_trx_date          = ' || p_trx_date);
438       arp_util.debug('---------- parameters for backout_ccid() ---------');
439 
440       arp_util.debug('p_header_gl_date    = ' || p_header_gl_date);
442       arp_util.debug('p_invoicing_rule_id = ' || p_invoicing_rule_id);
443       arp_util.debug('p_exchange_rate     = ' || p_exchange_rate);
444       arp_util.debug('p_currency_code     = ' || p_currency_code);
445       arp_util.debug('p_precision         = ' || p_precision );
446       arp_util.debug('p_mau               = ' || p_mau );
447 
448       arp_util.debug('');
449 
450       RAISE;
451 
452 END;
453 
454 /*===========================================================================+
455  | PROCEDURE                                                                 |
456  |    backout_amount							     |
457  |                                                                           |
458  | DESCRIPTION                                                               |
459  |    Inserts one record to backout the existing dist record.		     |
460  |    This procedure is called if backout is required and the amount or      |
461  |    percent of a dist record has changed.				     |
462  |                                                                           |
463  | SCOPE - PRIVATE                                                           |
464  |                                                                           |
465  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
466  |    arp_util.debug                                                         |
467  |                                                                           |
468  | ARGUMENTS  : IN:                                                          |
469  | 		      p_old_dist_rec					     |
470  | 		      p_new_dist_rec					     |
471  |                    p_header_gl_date                                       |
472  |                    p_trx_date                                             |
473  |                    p_invoicing_rule_id                                    |
474  |		      p_exchange_rate					     |
475  |		      p_currency_code					     |
476  |		      p_precision					     |
477  |		      p_mau						     |
478  |              OUT:                                                         |
479  |                    None						     |
480  |          IN/ OUT:							     |
481  |                    None						     |
482  |                                                                           |
483  | RETURNS    : NONE                                                         |
484  |                                                                           |
485  | NOTES                                                                     |
486  |                                                                           |
487  | MODIFICATION HISTORY                                                      |
488  |     19-JUL-95  Charlie Tomberg     Created                                |
489  |     08-NOV-95  Martin Johnson      Made cust_trx_line_salesrep_id and     |
490  |                                      gl_posted_date null for new dist.    |
491  |                                      Call validate_and_default_gl_date()  |
492  |                                      to get gl_date.                      |
493  |                                                                           |
494  +===========================================================================*/
495 
496 
497 PROCEDURE backout_amount(
498                p_old_dist_rec      IN ra_cust_trx_line_gl_dist%rowtype,
499                p_new_dist_rec      IN ra_cust_trx_line_gl_dist%rowtype,
500                p_header_gl_date    IN date,
501                p_trx_date          IN date,
502                p_invoicing_rule_id IN ra_customer_trx.invoicing_rule_id%type,
503                p_exchange_rate     IN ra_customer_trx.exchange_rate%type,
504                p_currency_code     IN fnd_currencies.currency_code%type,
505                p_precision         IN fnd_currencies.precision%type,
506                p_mau               IN
507                                   fnd_currencies.minimum_accountable_unit%type
508                         )  IS
509 
510 
511    l_cust_trx_line_gl_dist_id
512                    ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type;
513 
514    l_old_dist_rec ra_cust_trx_line_gl_dist%rowtype;
515    l_new_dist_rec ra_cust_trx_line_gl_dist%rowtype;
516 
517    l_default_gl_date       date;
518 
519 BEGIN
520 
521    arp_util.debug('arp_process_dist.backout_amount()+');
522 
523    l_old_dist_rec := p_old_dist_rec;
524    l_new_dist_rec := p_new_dist_rec;
525 
526    /*---------------------------------------------------------------+
527     |    create an offsetting record  to preserve the audit trail   |
528     +---------------------------------------------------------------*/
529 
530 
531    l_new_dist_rec.amount  := l_new_dist_rec.amount - l_old_dist_rec.amount;
532 
533    l_new_dist_rec.percent := l_new_dist_rec.percent - l_old_dist_rec.percent;
534 
535    /*---------------------------------------------------------------+
536     |    If a new value was specified in the dist rec passed into   |
537     |    update_dist(), use that value. Otherwise, use the	    |
538     |    value from the original dist record.                	    |
539     +---------------------------------------------------------------*/
540 
541    arp_ctlgd_pkg.merge_dist_recs( l_old_dist_rec,
542                                   l_new_dist_rec,
546    |  Force insert_p() to recalculate the accounted amount  |
543                                   l_old_dist_rec);
544 
545   /*--------------------------------------------------------+
547    |  instead of using the value from the old dist record.  |
548    +--------------------------------------------------------*/
549 
550    l_old_dist_rec.acctd_amount := null;
551 
552    /* 6325023 - no reason to null srep ID
553    l_old_dist_rec.cust_trx_line_salesrep_id := null; */
554 
555    l_old_dist_rec.gl_posted_date := null;
556    /*Bug-7147479 Pass GL DATE in l_default_gl_Date and
557  	Pass NVL(l_old_dist_rec.gl_date,p_header_gl_date)
558      The purpose is to use the GL Date on the old line if it is valid
559    */
560    l_default_gl_date:=NVL(l_old_dist_rec.gl_date,p_header_gl_date);
561    validate_and_default_gl_date(NVL(l_old_dist_rec.gl_date,p_header_gl_date),
562                                 p_trx_date,
563                                 p_invoicing_rule_id,
564                                 l_default_gl_date );
565 
566    l_old_dist_rec.gl_date          := l_default_gl_date;
567    l_old_dist_rec.original_gl_date := l_default_gl_date;
568 
569   /*------------------------------------------------------------+
570    |  Call the table handler to create the backout dist record  |
571    +------------------------------------------------------------*/
572 
573    arp_ctlgd_pkg.insert_p( l_old_dist_rec,
574                            l_cust_trx_line_gl_dist_id,
575                            p_exchange_rate,
576                            p_currency_code,
577                            p_precision,
578                            p_mau);
579 
580 
581    arp_util.debug('arp_process_dist.backout_amount()-');
582 
583 EXCEPTION
584     WHEN OTHERS THEN
585 
586      /*---------------------------------------------+
587       |  Display parameters and raise the exception |
588       +---------------------------------------------*/
589 
590       arp_util.debug('EXCEPTION:  arp_process_dist.backout_amount()');
591       arp_util.debug('');
592       arp_util.debug('---------- parameters for backout_amount() ---------');
593 
594       arp_util.debug('p_header_gl_date    = ' || p_header_gl_date);
595       arp_util.debug('p_trx_date          = ' || p_trx_date);
596       arp_util.debug('p_invoicing_rule_id = ' || p_invoicing_rule_id);
597       arp_util.debug('p_exchange_rate     = ' || p_exchange_rate);
598       arp_util.debug('p_currency_code     = ' || p_currency_code);
599       arp_util.debug('p_precision         = ' || p_precision );
600       arp_util.debug('p_mau               = ' || p_mau );
601 
602       arp_util.debug('');
603 
604       RAISE;
605 
606 END;
607 
608 
609 /*===========================================================================+
610  | PROCEDURE                                                                 |
611  |    val_tax_from_revenue		               		             |
612  |                                                                           |
613  | DESCRIPTION                                                               |
614  |    Validate Revenue Account tax code is used at the Transaction line      |
615  |    if the system option enforces tax code from GL for a completed         |
616  |    transaction. Validation will be performed during completion for        |
617  |    incomplete transactions.                                               |
618  |    This is enforced for On-Account Credit Memos, Debit Memos and Invoices.|
619  |                                                                           |
620  | SCOPE - PRIVATE                                                           |
621  |                                                                           |
622  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
623  |    arp_util.debug                                                         |
624  |                                                                           |
625  | ARGUMENTS  : IN:                                                          |
626  |                    p_dist_rec					     |
627  |              OUT:                                                         |
628  |                    None                                                   |
629  |                                                                           |
630  | RETURNS    : NONE                                                         |
631  |                                                                           |
632  | NOTES                                                                     |
633  |                                                                           |
634  | MODIFICATION HISTORY                                                      |
635  |     02-Oct-97  Mahesh Sabapathy    Created                                |
636  |                                                                           |
637  +===========================================================================*/
638 
639 
640 PROCEDURE val_tax_from_revenue (
641 		p_dist_rec IN ra_cust_trx_line_gl_dist%rowtype ) IS
642 
643 BEGIN
644 
645    IF PG_DEBUG in ('Y', 'C') THEN
646       arp_util.debug('arp_process_dist.val_tax_from_revenue()+');
647    END IF;
648 
649    /* 4594101 - Removing validate_tax_enforcement
650          this is handled by etax during calculation */
651 
652    IF PG_DEBUG in ('Y', 'C') THEN
653       arp_util.debug('arp_process_dist.val_tax_from_revenue()-');
657     WHEN OTHERS THEN
654    END IF;
655 
656 EXCEPTION
658 
659        /*---------------------------------------------+
660         |  Display parameters and raise the exception |
661         +---------------------------------------------*/
662 
663         IF PG_DEBUG in ('Y', 'C') THEN
664            arp_util.debug(
665                'EXCEPTION:  arp_process_dist.val_tax_from_revenue()');
666            arp_util.debug('---------- val_tax_from_revenue() ---------');
667         END IF;
668         arp_ctlgd_pkg.display_dist_rec(p_dist_rec);
669 
670         RAISE;
671 
672 END val_tax_from_revenue;
673 
674 
675 /*===========================================================================+
676  | PROCEDURE                                                                 |
677  |    val_insert_dist		               		                     |
678  |                                                                           |
679  | DESCRIPTION                                                               |
680  |    Does validation necessary when a new dist is inserted.		     |
681  |                                                                           |
682  | SCOPE - PRIVATE                                                           |
683  |                                                                           |
684  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
685  |    arp_util.debug                                                         |
686  |                                                                           |
687  | ARGUMENTS  : IN:                                                          |
688  |                    p_dist_rec					     |
689  |              OUT:                                                         |
690  |                    None                                                   |
691  |                                                                           |
692  | RETURNS    : NONE                                                         |
693  |                                                                           |
694  | NOTES                                                                     |
695  |                                                                           |
696  | MODIFICATION HISTORY                                                      |
697  |     19-JUL-95  Charlie Tomberg     Created                                |
698  |                                                                           |
699  +===========================================================================*/
700 
701 
702 PROCEDURE val_insert_dist ( p_dist_rec IN ra_cust_trx_line_gl_dist%rowtype ) IS
703 
704 
705 BEGIN
706 
707    arp_util.debug('arp_process_dist.val_insert_dist()+');
708 
709 
710    arp_util.debug('arp_process_dist.val_val_insert_dist()-');
711 
712 EXCEPTION
713     WHEN OTHERS THEN
714 
715        /*---------------------------------------------+
716         |  Display parameters and raise the exception |
717         +---------------------------------------------*/
718 
719         arp_util.debug(
720                'EXCEPTION:  arp_process_dist.val_insert_dist()');
721 
722         arp_util.debug('---------- val_insert_dist() ---------');
723         arp_ctlgd_pkg.display_dist_rec(p_dist_rec);
724 
725         RAISE;
726 
727 END;
728 
729 /*===========================================================================+
730  | PROCEDURE                                                                 |
731  |    val_update_dist		          	                             |
732  |                                                                           |
733  | DESCRIPTION                                                               |
734  |    Does validation that is required when a dist is updated.		     |
735  |                                                                           |
736  | SCOPE - PRIVATE                                                           |
737  |                                                                           |
738  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
739  |    arp_util.debug                                                         |
740  |                                                                           |
741  | ARGUMENTS  : IN:                                                          |
742  |	  	      p_dist_rec					     |
743  |              OUT:                                                         |
744  |                    None                                                   |
745  |                                                                           |
746  | RETURNS    : NONE                                                         |
747  |                                                                           |
748  | NOTES                                                                     |
749  |                                                                           |
750  | MODIFICATION HISTORY                                                      |
751  |     19-JUL-95  Charlie Tomberg     Created                                |
752  |                                                                           |
753  +===========================================================================*/
754 
755 PROCEDURE val_update_dist ( p_dist_rec IN  ra_cust_trx_line_gl_dist%rowtype )
756                        IS
757 
758 
759 BEGIN
760 
761    arp_util.debug('arp_process_dist.val_update_dist()+');
762 
763 
767     WHEN OTHERS THEN
764    arp_util.debug('arp_process_dist.val_val_update_dist()-');
765 
766 EXCEPTION
768 
769        /*---------------------------------------------+
770         |  Display parameters and raise the exception |
771         +---------------------------------------------*/
772 
773         arp_util.debug(
774                'EXCEPTION:  arp_process_dist.val_update_dist()');
775 
776 
777         arp_util.debug('---------- val_update_dist() ---------');
778         arp_ctlgd_pkg.display_dist_rec(p_dist_rec);
779 
780         RAISE;
781 
782 END;
783 
784 /*===========================================================================+
785  | PROCEDURE                                                                 |
786  |    val_delete_dist			                                     |
787  |                                                                           |
788  | DESCRIPTION                                                               |
789  |    Does validation that is required when a dist is deleted.		     |
790  |                                                                           |
791  | SCOPE - PRIVATE                                                           |
792  |                                                                           |
793  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
794  |    arp_util.debug                                                         |
795  |                                                                           |
796  | ARGUMENTS  : IN:                                                          |
797  |	  	      p_dist_rec					     |
798  |              OUT:                                                         |
799  |                    None                                                   |
800  |                                                                           |
801  | RETURNS    : NONE                                                         |
802  |                                                                           |
803  | NOTES                                                                     |
804  |                                                                           |
805  | MODIFICATION HISTORY                                                      |
806  |     19-JUL-95  Charlie Tomberg     Created                                |
807  |                                                                           |
808  +===========================================================================*/
809 
810 PROCEDURE val_delete_dist ( p_dist_rec IN ra_cust_trx_line_gl_dist%rowtype ) IS
811 
812 
813 BEGIN
814 
815    arp_util.debug('arp_process_dist.val_delete_dist()+');
816 
817 
818    arp_util.debug('arp_process_dist.val_delete_dist()-');
819 
820 EXCEPTION
821     WHEN OTHERS THEN
822 
823        /*---------------------------------------------+
824         |  Display parameters and raise the exception |
825         +---------------------------------------------*/
826 
827         arp_util.debug('EXCEPTION:  arp_process_dist.val_delete_dist()');
828 
829 
830         arp_util.debug('---------- val_update_dist() ---------');
831         arp_ctlgd_pkg.display_dist_rec(p_dist_rec);
832 
833        RAISE;
834 
835 END;
836 
837 
838 /*===========================================================================+
839  | PROCEDURE                                                                 |
840  |    insert_dist							     |
841  |                                                                           |
842  | DESCRIPTION                                                               |
843  |    Inserts a record into ra_cust_trx_line_gl_dist			     |
844  |                                                                           |
845  | SCOPE - PUBLIC                                                            |
846  |                                                                           |
847  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
848  |    arp_util.debug                                                         |
849  |                                                                           |
850  | ARGUMENTS  : IN:                                                          |
851  |		      p_form_name					     |
852  |		      p_form_version					     |
853  |		      p_dist_rec					     |
854  |		      p_cust_trx_line_gl_dist_id 			     |
855  |		      p_exchange_rate					     |
856  |		      p_currency_code					     |
857  |		      p_precision					     |
858  |		      p_mau						     |
859  |              OUT:                                                         |
860  |                    p_cust_trx_line_gl_dist_id                             |
861  |          IN/ OUT:							     |
862  |                    None						     |
863  |                                                                           |
864  | RETURNS    : NONE                                                         |
865  |                                                                           |
866  | NOTES                                                                     |
867  |                                                                           |
868  | MODIFICATION HISTORY                                                      |
869  |     12-JUL-95  Charlie Tomberg     Created                                |
870  |                                                                           |
871  +===========================================================================*/
872 
873 
877            p_dist_rec	   IN ra_cust_trx_line_gl_dist%rowtype,
874 PROCEDURE insert_dist(
875            p_form_name     IN varchar2,
876            p_form_version  IN number,
878            p_exchange_rate IN ra_customer_trx.exchange_rate%type DEFAULT 1,
879            p_currency_code IN fnd_currencies.currency_code%type  DEFAULT null,
880            p_precision     IN fnd_currencies.precision%type      DEFAULT null,
881            p_mau           IN fnd_currencies.minimum_accountable_unit%type
882                               DEFAULT null,
883            p_cust_trx_line_gl_dist_id  OUT NOCOPY
884               ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type)
885                    IS
886 
887 
888    l_cust_trx_line_gl_dist_id
889                    ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type;
890 
891 --bug#2750340
892    l_ev_rec        arp_xla_events.xla_events_type;
893 BEGIN
894 
895       arp_util.debug('arp_process_dist.insert_dist()+');
896 
897       /*----------------------------------------------+
898        |   Check the form version to determine if it  |
899        |   is compatible with the entity handler.     |
900        +----------------------------------------------*/
901 
902       arp_trx_validate.ar_entity_version_check(p_form_name, p_form_version);
903 
904       /*-------------------------+
905        |  Do required validation |
906        +-------------------------*/
907 
908       arp_process_dist.val_insert_dist(p_dist_rec);
909 
910       /*----------------------------------------------------------------+
911        | Lock rows in other tables that reference this customer_trx_id  |
912        +----------------------------------------------------------------*/
913 
914       arp_trx_util.lock_transaction(p_dist_rec.customer_trx_id);
915 
916 
917       arp_ctlgd_pkg.insert_p( p_dist_rec,
918                               p_cust_trx_line_gl_dist_id,
919                               p_exchange_rate,
920                               p_currency_code,
921                               p_precision,
922                               p_mau);
923 
924 
925        /*----------------------------------------------------+
926         |  Validate tax from revenue account.                |
927         +----------------------------------------------------*/
928       val_tax_from_revenue( p_dist_rec );
929 
930 --bug#2750340
931       --------------------------------------------------------------
932       --  Need to call AR XLA events because when user insert the
933       --  a distribution directly through Trx WB, the distributions
934       --  are created by this api.
935       --  Call XLA event with the doc id
936       --------------------------------------------------------------
937       l_ev_rec.xla_from_doc_id   := p_dist_rec.customer_trx_id;
938       l_ev_rec.xla_to_doc_id     := p_dist_rec.customer_trx_id;
939       l_ev_rec.xla_req_id        := NULL;
940       l_ev_rec.xla_doc_table     := 'CT';
941       l_ev_rec.xla_doc_event     := NULL;
942       l_ev_rec.xla_mode          := 'O';
943       l_ev_rec.xla_call          := 'B';
944       l_ev_rec.xla_fetch_size    := 999;
945       arp_xla_events.create_events(p_xla_ev_rec => l_ev_rec );
946 
947       arp_util.debug('arp_process_dist.insert_dist()-');
948 
949 EXCEPTION
950   WHEN OTHERS THEN
951 
952     arp_util.debug('EXCEPTION:  arp_process_dist.insert_dist()');
953 
954    /*---------------------------------------------+
955     |  Display parameters and raise the exception |
956     +---------------------------------------------*/
957 
958     arp_util.debug('EXCEPTION:  arp_process_dist.set_flags()');
959 
960     arp_util.debug('');
961     arp_util.debug('---------- insert_dist() ---------');
962 
963     arp_util.debug('p_form_name         = ' || p_form_name);
964     arp_util.debug('p_form_version      = ' || p_form_version);
965     arp_util.debug('p_exchange_rate     = ' || p_exchange_rate);
966     arp_util.debug('p_currency_code     = ' || p_currency_code);
967     arp_util.debug('p_precision         = ' || p_precision );
968     arp_util.debug('p_mau               = ' || p_mau );
969 
970     arp_util.debug('');
971     arp_ctlgd_pkg.display_dist_rec( p_dist_rec );
972     arp_util.debug('');
973 
974     RAISE;
975 
976 END;
977 
978 /*===========================================================================+
979  | PROCEDURE                                                                 |
980  |    update_dist						    	     |
981  |                                                                           |
982  | DESCRIPTION                                                               |
983  |    Updates a record in ra_cust_trx_line_gl_dist			     |
984  |                                                                           |
985  | SCOPE - PUBLIC                                                            |
986  |                                                                           |
987  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
988  |    arp_util.debug                                                         |
989  |                                                                           |
990  | ARGUMENTS  : IN:                                                          |
991  |		      p_form_name					     |
992  |		      p_form_version					     |
993  |		      p_cust_trx_line_gl_dist_id  			     |
997  |                    p_trx_date                                             |
994  |		      p_customer_trx_id		  			     |
995  |		      p_dist_rec					     |
996  |                    p_header_gl_date                                       |
998  |                    p_invoicing_rule_id                                    |
999  |		      p_exchange_rate					     |
1000  |		      p_currency_code					     |
1001  |		      p_precision					     |
1002  |		      p_mau						     |
1003  |              OUT:                                                         |
1004  |		      p_backout_done_flag                                    |
1005  |          IN/ OUT:							     |
1006  |                    None						     |
1007  |                                                                           |
1008  | RETURNS    : NONE                                                         |
1009  |                                                                           |
1010  | NOTES                                                                     |
1011  |                                                                           |
1012  | MODIFICATION HISTORY                                                      |
1013  |     19-JUL-95  Charlie Tomberg     Created                                |
1014  |     07-NOV-95  Martin Johnson      Added OUT parameter p_backout_done_flag|
1015  |                                    Added IN parameters p_header_gl_date,  |
1016  |                                      p_trx_date, p_invoicing_rule_id      |
1017  |     28-MAY-03  Herve   Yu          Added XLA plug ins bug#2979254         |
1018  |                                                                           |
1019  +===========================================================================*/
1020 
1021 
1022 PROCEDURE update_dist(
1023            p_form_name                 IN varchar2,
1024            p_form_version              IN number,
1025            p_backout_flag              IN boolean,
1026            p_cust_trx_line_gl_dist_id  IN
1027                     ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type,
1028            p_customer_trx_id	       IN ra_customer_trx.customer_trx_id%type,
1029            p_dist_rec		       IN OUT NOCOPY ra_cust_trx_line_gl_dist%rowtype,
1030            p_header_gl_date            IN date,
1031            p_trx_date                  IN date,
1032            p_invoicing_rule_id         IN
1033                     ra_customer_trx.invoicing_rule_id%type,
1034            p_backout_done_flag         OUT NOCOPY boolean,
1035            p_exchange_rate             IN ra_customer_trx.exchange_rate%type
1036                                           DEFAULT 1,
1037            p_currency_code             IN fnd_currencies.currency_code%type
1038                                           DEFAULT null,
1039            p_precision                 IN fnd_currencies.precision%type
1040                                           DEFAULT null,
1041            p_mau                       IN
1042                                    fnd_currencies.minimum_accountable_unit%type
1043                                    DEFAULT null )
1044                    IS
1045 
1046 
1047    l_cust_trx_line_gl_dist_id
1048                    ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type;
1049 
1050    l_old_dist_rec	   ra_cust_trx_line_gl_dist%rowtype;
1051 
1052    l_backout_flag	   boolean;
1053    l_posted_flag	   boolean;
1054    l_ccid_changed_flag     boolean;
1055    l_amount_percent_changed_flag   boolean;
1056 
1057    /* Variables l_open_rec, l_ctt_type, l_previous_customer_trx_id
1058       l_ae_doc_rec added for bug 1580221 */
1059 
1060    l_open_rec VARCHAR2(1);
1061    l_ctt_type VARCHAR2(20);
1062    l_previous_customer_trx_id NUMBER;
1063    l_ae_doc_rec arp_acct_main.ae_doc_rec_type;
1064 
1065 --BUG#2750340
1066    l_ev_rec           arp_xla_events.xla_events_type;
1067 
1068 BEGIN
1069 
1070       arp_util.debug('arp_process_dist.update_dist()+');
1071 
1072       /*----------------------------------------------+
1073        |   Check the form version to determine if it  |
1074        |   is compatible with the entity handler.     |
1075        +----------------------------------------------*/
1076 
1077       arp_trx_validate.ar_entity_version_check(p_form_name, p_form_version);
1078 
1079       set_flags(p_cust_trx_line_gl_dist_id,
1080                 p_dist_rec,
1081                 l_posted_flag,
1082                 l_ccid_changed_flag,
1083                 l_amount_percent_changed_flag);
1084 
1085       /*-------------------------+
1086        |  Do required validation |
1087        +-------------------------*/
1088 
1089       arp_process_dist.val_update_dist(p_dist_rec);
1090 
1091       /*----------------------------------------------------------------+
1092        | Lock rows in other tables that reference this customer_trx_id  |
1093        +----------------------------------------------------------------*/
1094 
1095       arp_trx_util.lock_transaction(p_customer_trx_id);
1096 
1097       /*------------------------------------------------------------------+
1098        |  Set the backout flag to true if the transaction has been posted |
1099        |  and the amounts or the account has changed.	                  |
1100        +------------------------------------------------------------------*/
1101 
1102       IF  ( l_posted_flag = TRUE  AND
1103             (
1104               l_ccid_changed_flag           = TRUE   OR
1105               l_amount_percent_changed_flag = TRUE
1106             )
1107           )
1111 
1108       THEN l_backout_flag := TRUE;
1109            arp_util.debug('revised backout flag: TRUE');
1110       ELSE l_backout_flag := p_backout_flag;
1112            arp_util.debug('revised backout flag: ' ||
1113                           arp_trx_util.boolean_to_varchar2(l_backout_flag ));
1114 
1115       END IF;
1116 
1117 	/*------------------------------------------------------+
1118          |  If    backout is not required 			|
1119          |  THEN  do a simple update				|
1120          |  ELSE IF   the ccid has changed			|
1121          |       THEN create two offsetting records		|
1122          |       ELSE IF   the amount has changed		|
1123          |            THEN create one offsetting record		|
1124          |            ELSE do a simple update			|
1125 	 +------------------------------------------------------*/
1126 
1127       IF   (l_backout_flag = FALSE)
1128       THEN
1129  	      /*--------------------------------------+
1130                |  Do a simple update with no backout. |
1131                +--------------------------------------*/
1132 
1133  	      /*-----------------------------------------------+
1134                |  Break the link to ra_cust_trx_line_salesreps |
1135                |  if the amount or account has been changed    |
1136                +-----------------------------------------------*/
1137 
1138   /* Bug 4053374 Link should be kept intact */
1139   /*             IF      (
1140                           p_dist_rec.cust_trx_line_salesrep_id IS NOT NULL AND
1141                           (
1142                              l_amount_percent_changed_flag = TRUE  OR
1143                              l_ccid_changed_flag           = TRUE  OR
1144                              p_dist_rec.code_combination_id = -1
1145                           )
1146                        )
1147                THEN    p_dist_rec.cust_trx_line_salesrep_id := null;
1148                END IF; */
1149 
1150  	      /*------------------------------------------------+
1151                |  Call the table handler to do a simple update  |
1152                +------------------------------------------------*/
1153 
1154                arp_util.debug('simple update - case 1');
1155                arp_ctlgd_pkg.update_p( p_dist_rec,
1156                                        p_cust_trx_line_gl_dist_id,
1157                                        p_exchange_rate,
1158                                        p_currency_code,
1159                                        p_precision,
1160                                        p_mau);
1161 
1162 	       /* Following IF clause added for bug 1580221. */
1163 
1164                IF  (l_ccid_changed_flag = TRUE AND
1165                    l_amount_percent_changed_flag = FALSE AND
1166                    p_dist_rec.account_class = 'REC' ) THEN
1167                    BEGIN
1168                    SELECT ctt.accounting_affect_flag,
1169                           ctt.type,
1170                           ct.previous_customer_trx_id
1171                      INTO
1172                           l_open_rec,
1173                           l_ctt_type,
1174                           l_previous_customer_trx_id
1175                      FROM ra_cust_trx_types ctt,
1176                           ra_customer_trx ct
1177                     WHERE ct.customer_trx_id   = p_customer_trx_id
1178                       AND ct.cust_trx_type_id  = ctt.cust_trx_type_id;
1179                     EXCEPTION
1180                     WHEN OTHERS THEN
1181                        RAISE;
1182                     END;
1183                     IF  (l_open_rec = 'Y' AND
1184                          l_ctt_type = 'CM' AND
1185                          l_previous_customer_trx_id IS NOT NULL)
1186                     THEN
1187                        DECLARE
1188                        CURSOR del_app_dist IS
1189                        SELECT app.receivable_application_id app_id,
1190                               app.customer_trx_id           trx_id
1191                          FROM    ar_receivable_applications app
1192                         WHERE  app.applied_customer_trx_id  = l_previous_customer_trx_id
1193                           AND  app.customer_trx_id = p_customer_trx_id
1194 			  AND  app.posting_control_id = -3
1195                           AND  NVL(app.confirmed_flag,'Y') = 'Y'
1196                           AND  EXISTS (SELECT 'x'
1197                                        FROM  ar_distributions ard
1198                                        WHERE  ard.source_table = 'RA'
1199                                        AND  ard.source_id    = app.receivable_application_id);
1200                       BEGIN
1201                       FOR l_rec_del_app in del_app_dist LOOP
1202                          l_ae_doc_rec.document_type           := 'CREDIT_MEMO';
1203                          l_ae_doc_rec.document_id             := l_rec_del_app.trx_id;
1204                          l_ae_doc_rec.accounting_entity_level := 'ONE';
1205                          l_ae_doc_rec.source_table            := 'RA';
1206                          l_ae_doc_rec.source_id               := l_rec_del_app.app_id;
1207                          l_ae_doc_rec.source_id_old           := '';
1208                          l_ae_doc_rec.other_flag              := '';
1209 
1210                          l_ae_doc_rec.pay_sched_upd_yn        := 'Y';
1211 
1212                          arp_acct_main.Delete_Acct_Entry(l_ae_doc_rec);
1213                          arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
1214                       END LOOP;
1215                       END;
1216                     END IF;
1217                END IF;
1221       ELSE
1218 
1219                p_backout_done_flag := FALSE;
1220 
1222            arp_ctlgd_pkg.fetch_p(l_old_dist_rec, p_cust_trx_line_gl_dist_id);
1223 
1224            IF  ( l_ccid_changed_flag = TRUE )
1225            THEN
1226 
1227   	        /*------------------------------------------------+
1228                  |  Insert 2 rows into ra_cust_trx_line_gl_dist   |
1229                  |       1. amount = -<db amount>,		  |
1230                  |          ccid = <db (old) ccid>		  |
1231                  |       2. amount = <displayed amount>,	  |
1232                  |          ccid = <new ccid>			  |
1233                  +------------------------------------------------*/
1234 
1235                 backout_ccid(l_old_dist_rec,
1236                              p_dist_rec,
1237                              p_header_gl_date,
1238                              p_trx_date,
1239                              p_invoicing_rule_id,
1240                              p_exchange_rate,
1241                              p_currency_code,
1242                              p_precision,
1243                              p_mau);
1244 
1245                 p_backout_done_flag := TRUE;
1246 
1247            ELSE IF (l_amount_percent_changed_flag = TRUE)
1248                 THEN
1249 
1250     	            /*------------------------------------------------+
1251                      |  Insert one new row to backout the old amount. |
1252                      |  amount = <displayed amount> - <db amount>     |
1253                      +------------------------------------------------*/
1254 
1255                      backout_amount(l_old_dist_rec,
1256                                     p_dist_rec,
1257                                     p_header_gl_date,
1258                                     p_trx_date,
1259                                     p_invoicing_rule_id,
1260                                     p_exchange_rate,
1261                                     p_currency_code,
1262                                     p_precision,
1263                                     p_mau);
1264 
1265                      p_backout_done_flag := TRUE;
1266 
1267                 ELSE
1268 
1269     	            /*--------------------------------------+
1270                      |  Do a simple update with no backout. |
1271                      |  Nothing of consequence has changed. |
1272                      +--------------------------------------*/
1273 
1274                      arp_util.debug('simple update - case 2');
1275 
1276                      arp_ctlgd_pkg.update_p(p_dist_rec,
1277                                             p_cust_trx_line_gl_dist_id,
1278                                             p_exchange_rate,
1279                                             p_currency_code,
1280                                             p_precision,
1281                                             p_mau);
1282 
1283                      p_backout_done_flag := FALSE;
1284 
1285                 END IF;
1286 
1287            END IF;
1288       END IF;
1289 
1290        /*----------------------------------------------------+
1291         |  Validate tax from revenue account.                |
1292         +----------------------------------------------------*/
1293       val_tax_from_revenue( p_dist_rec );
1294 
1295 --BUG#2750340
1296       --------------------------------------------------------------
1297       --  Need to call AR XLA events because when user update the
1298       --  a distribution directly through Trx WB, the distributions
1299       --  are created by this api.
1300       --  Call XLA event with the doc id to avoid missing any
1301       --  distributions unstamped
1302       --------------------------------------------------------------
1303       l_ev_rec.xla_from_doc_id   := p_dist_rec.customer_trx_id;
1304       l_ev_rec.xla_to_doc_id     := p_dist_rec.customer_trx_id;
1305       l_ev_rec.xla_req_id        := NULL;
1306       l_ev_rec.xla_doc_table     := 'CT';
1307       l_ev_rec.xla_doc_event     := NULL;
1308       l_ev_rec.xla_mode          := 'O';
1309       l_ev_rec.xla_call          := 'B';
1310       l_ev_rec.xla_fetch_size    := 999;
1311       arp_xla_events.create_events(p_xla_ev_rec => l_ev_rec );
1312 
1313      arp_util.debug('arp_process_dist.update_dist()-');
1314 
1315 EXCEPTION
1316   WHEN OTHERS THEN
1317 
1318   /*---------------------------------------------+
1319    |  Display parameters and raise the exception |
1320    +---------------------------------------------*/
1321 
1322     arp_util.debug('EXCEPTION:  arp_process_dist.update_dist()');
1323     arp_util.debug('---------- parameters for update_dist() ---------');
1324     arp_util.debug('p_form_name                 = ' || p_form_name);
1325     arp_util.debug('p_form_version              = ' || p_form_version);
1326 
1327 
1328     arp_util.debug('p_backout_flag              = ' ||
1329                              arp_trx_util.boolean_to_varchar2(p_backout_flag));
1330 
1331     arp_util.debug('p_cust_trx_line_gl_dist_id  = ' ||
1332                    p_cust_trx_line_gl_dist_id);
1333 
1334     arp_util.debug('p_customer_trx_id           = ' ||
1335                    p_customer_trx_id);
1336 
1337     arp_util.debug('p_header_gl_date            = ' || p_header_gl_date );
1338     arp_util.debug('p_trx_date                  = ' || p_trx_date);
1339     arp_util.debug('p_invoicing_rule_id         = ' || p_invoicing_rule_id);
1340 
1344     arp_util.debug('p_mau                       = ' || p_mau );
1341     arp_util.debug('p_exchange_rate             = ' || p_exchange_rate);
1342     arp_util.debug('p_currency_code             = ' || p_currency_code);
1343     arp_util.debug('p_precision                 = ' || p_precision );
1345 
1346     arp_ctlgd_pkg.display_dist_rec( p_dist_rec );
1347 
1348     RAISE;
1349 
1350 END;
1351 
1352 /*===========================================================================+
1353  | PROCEDURE                                                                 |
1354  |    delete_dist							     |
1355  |                                                                           |
1356  | DESCRIPTION                                                               |
1357  |    Deletes a record fromra_cust_trx_line_gl_dist.			     |
1358  |                                                                           |
1359  | SCOPE - PUBLIC                                                            |
1360  |                                                                           |
1361  | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED                                   |
1362  |    arp_util.debug                                                         |
1363  |                                                                           |
1364  | ARGUMENTS  : IN:                                                          |
1365  |		      p_form_name					     |
1366  |		      p_form_version					     |
1367  |		      p_cust_trx_line_gl_dist_id 			     |
1368  |		      p_customer_trx_id 				     |
1369  |		      p_dist_rec					     |
1370  |              OUT:                                                         |
1371  |                    None						     |
1372  |          IN/ OUT:							     |
1373  |                    None						     |
1374  |                                                                           |
1375  | RETURNS    : NONE                                                         |
1376  |                                                                           |
1377  | NOTES                                                                     |
1378  |                                                                           |
1379  | MODIFICATION HISTORY                                                      |
1380  |     19-JUL-95  Charlie Tomberg     Created                                |
1381  |                                                                           |
1382  +===========================================================================*/
1383 
1384 
1385 PROCEDURE delete_dist(
1386            p_form_name                 IN varchar2,
1387            p_form_version              IN number,
1388            p_cust_trx_line_gl_dist_id  IN
1389                     ra_cust_trx_line_gl_dist.cust_trx_line_gl_dist_id%type,
1390            p_customer_trx_id	       IN ra_customer_trx.customer_trx_id%type,
1391            p_dist_rec		       IN ra_cust_trx_line_gl_dist%rowtype)
1392                    IS
1393 
1394 
1395 BEGIN
1396 
1397       arp_util.debug('arp_process_dist.delete_dist()+');
1398 
1399       /*----------------------------------------------+
1400        |   Check the form version to determine if it  |
1401        |   is compatible with the entity handler.     |
1402        +----------------------------------------------*/
1403 
1404       arp_trx_validate.ar_entity_version_check(p_form_name, p_form_version);
1405 
1406       /*-------------------------+
1407        |  Do required validation |
1408        +-------------------------*/
1409 
1410       arp_process_dist.val_delete_dist(p_dist_rec);
1411 
1412       /*----------------------------------------------------------------+
1413        | Lock rows in other tables that reference this customer_trx_id  |
1414        +----------------------------------------------------------------*/
1415 
1416       arp_trx_util.lock_transaction(p_customer_trx_id);
1417 
1418        /*----------------------------------------------------+
1419         |  call the table-handler to delete the dist record  |
1420         +----------------------------------------------------*/
1421 
1422       arp_ctlgd_pkg.delete_p( p_cust_trx_line_gl_dist_id );
1423 
1424        /*----------------------------------------------------+
1425         |  Validate tax from revenue account.                |
1426         +----------------------------------------------------*/
1427       val_tax_from_revenue( p_dist_rec );
1428 
1429       arp_util.debug('arp_process_dist.delete_dist()-');
1430 
1431 EXCEPTION
1432  WHEN OTHERS THEN
1433 
1434    /*---------------------------------------------+
1435     |  Display parameters and raise the exception |
1436     +---------------------------------------------*/
1437 
1438     arp_util.debug('EXCEPTION:  arp_process_dist.delete_dist()');
1439 
1440     arp_util.debug('---------- delete_dist() ---------');
1441 
1442     arp_util.debug('p_form_name                  = ' || p_form_name);
1443     arp_util.debug('p_form_version               = ' || p_form_version);
1444 
1445     arp_util.debug('p_cust_trx_line_gl_dist_id  = ' ||
1446                    p_cust_trx_line_gl_dist_id);
1447 
1448     arp_ctlgd_pkg.display_dist_rec( p_dist_rec );
1449 
1450     RAISE;
1451 
1452 END;
1453 
1454 
1455   /*---------------------------------------------+
1456    |   Package initialization section.           |
1457    +---------------------------------------------*/
1458 
1459 BEGIN
1460 
1461    pg_number_dummy    := arp_ctlgd_pkg.get_number_dummy;
1462 
1463 END ARP_PROCESS_DIST;