[Home] [Help]
PACKAGE BODY: APPS.ARP_TRX_DEFAULTS
Source
1 PACKAGE BODY ARP_TRX_DEFAULTS AS
2 /* $Header: ARTUDFLB.pls 120.5 2005/10/30 03:58:39 appldev ship $ */
3
4 pg_text_dummy varchar2(10);
5 pg_flag_dummy varchar2(10);
6 pg_number_dummy number;
7 pg_date_dummy date;
8
9 pg_base_curr_code gl_sets_of_books.currency_code%type;
10 pg_base_precision fnd_currencies.precision%type;
11 pg_base_min_acc_unit fnd_currencies.minimum_accountable_unit%type;
12 pg_set_of_books_id ar_system_parameters.set_of_books_id%type;
13
14
15
16 /*===========================================================================+
17 | PROCEDURE |
18 | get_header_defaults() |
19 | |
20 | DESCRIPTION |
21 | Gets the header level default values for a transaction. |
22 | |
23 | SCOPE - PUBLIC |
24 | |
25 | EXETERNAL PROCEDURES/FUNCTIONS ACCESSED |
26 | arp_util.debug |
27 | |
28 | ARGUMENTS : IN: |
29 | p_batch_source_id |
30 | p_batch_batch_source_id |
31 | p_profile_batch_source_id |
32 | p_customer_trx_id |
33 | p_cust_trx_type_id |
34 | p_term_id |
35 | p_com_default_cust_trx_type_id |
36 | p_ctt_class |
37 | p_trx_date |
38 | p_trx_number |
39 | p_row_id |
40 | p_invoicing_rule_id |
41 | p_rev_recog_run_flag |
42 | p_complete_flag |
43 | p_open_receivables_flag |
44 | p_customer_id |
45 | p_site_use_id |
46 | p_gl_date |
47 | p_prev_gl_date |
48 | p_commit_gl_date |
49 | p_batch_gl_date |
50 | p_security_inv_enter_flag |
51 | p_security_cm_enter_flag |
52 | p_security_dm_enter_flag |
53 | p_security_commit_enter_flag |
54 | |
55 | OUT: |
56 | p_default_batch_source_id |
57 | p_default_batch_source_name |
58 | p_auto_trx_numbering_flag |
59 | p_batch_source_type |
60 | p_copy_doc_number_flag |
61 | p_bs_default_cust_trx_type_id |
62 | p_default_cust_trx_type_id |
63 | p_default_type_name |
64 | p_class |
65 | p_open_receivable_flag |
66 | p_post_to_gl_flag |
67 | p_allow_freight_flag |
68 | p_creation_sign |
69 | p_allow_overapplication_flag |
70 | p_natural_app_only_flag |
71 | p_tax_calculation_flag |
72 | p_default_status_code |
73 | p_default_status |
74 | p_default_printing_option_code |
75 | p_default_printing_option |
76 | p_default_term_id |
77 | p_default_term_name |
78 | p_number_of_due_dates |
79 | p_term_due_date |
80 | p_default_gl_date |
81 | |
82 | RETURNS : NONE |
83 | |
84 | NOTES |
85 | |
86 | MODIFICATION HISTORY |
87 | 04-NOV-95 Charlie Tomberg Created |
88 | |
89 +===========================================================================*/
90
91 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
92
93 PROCEDURE get_header_defaults(
94 p_batch_source_id IN
95 ra_batch_sources.batch_source_id%type,
96 p_batch_batch_source_id IN
97 ra_batch_sources.batch_source_id%type,
98 p_profile_batch_source_id IN
99 ra_batch_sources.batch_source_id%type,
100 p_customer_trx_id IN
101 ra_customer_trx.customer_trx_id%type,
102 p_cust_trx_type_id IN
103 ra_cust_trx_types.cust_trx_type_id%type,
104 p_term_id IN
105 ra_terms.term_id%type,
106 p_com_default_cust_trx_type_id IN
107 ra_cust_trx_types.cust_trx_type_id%type,
108 p_ctt_class IN
109 ra_cust_trx_types.type%type,
110 p_trx_date IN
111 ra_customer_trx.trx_date%type,
112 p_trx_number IN
113 ra_customer_trx.trx_number%type,
114 p_row_id IN varchar2,
115 p_invoicing_rule_id IN
116 ra_rules.rule_id%type,
117 p_rev_recog_run_flag IN varchar2,
118 p_complete_flag IN
119 ra_customer_trx.complete_flag%type,
120 p_open_receivables_flag IN
121 ra_cust_trx_types.accounting_affect_flag%type,
122 p_customer_id IN
123 hz_cust_accounts.cust_account_id%type,
124 p_site_use_id IN
125 hz_cust_site_uses.site_use_id%type,
126 p_gl_date IN
127 ra_cust_trx_line_gl_dist.gl_date%type,
128 p_prev_gl_date IN
129 ra_cust_trx_line_gl_dist.gl_date%type,
130 p_commit_gl_date IN
131 ra_cust_trx_line_gl_dist.gl_date%type,
132 p_batch_gl_date IN
133 ra_cust_trx_line_gl_dist.gl_date%type,
134 p_default_batch_source_id OUT NOCOPY
135 ra_batch_sources.batch_source_id%type,
136 p_default_batch_source_name OUT NOCOPY
137 ra_batch_sources.name%type,
138 p_auto_trx_numbering_flag OUT NOCOPY
139 ra_batch_sources.auto_trx_numbering_flag%type,
140 p_batch_source_type OUT NOCOPY
141 ra_batch_sources.batch_source_type%type,
142 p_copy_doc_number_flag OUT NOCOPY
143 ra_batch_sources.copy_doc_number_flag%type,
144 p_bs_default_cust_trx_type_id OUT NOCOPY
145 ra_cust_trx_types.cust_trx_type_id%type,
146 p_default_cust_trx_type_id OUT NOCOPY
147 ra_cust_trx_types.cust_trx_type_id%type,
148 p_default_type_name OUT NOCOPY
149 ra_cust_trx_types.name%type,
150 p_class OUT NOCOPY
151 ra_cust_trx_types.type%type,
152 p_open_receivable_flag OUT NOCOPY
153 ra_cust_trx_types.accounting_affect_flag%type,
154 p_post_to_gl_flag OUT NOCOPY
155 ra_cust_trx_types.post_to_gl%type,
156 p_allow_freight_flag OUT NOCOPY
157 ra_cust_trx_types.allow_freight_flag%type,
158 p_creation_sign OUT NOCOPY
159 ra_cust_trx_types.creation_sign%type,
160 p_allow_overapplication_flag OUT NOCOPY
161 ra_cust_trx_types.allow_overapplication_flag%type,
162 p_natural_app_only_flag OUT NOCOPY
163 ra_cust_trx_types.natural_application_only_flag%type,
164 p_tax_calculation_flag OUT NOCOPY
165 ra_cust_trx_types.tax_calculation_flag%type,
166 p_default_status_code OUT NOCOPY
167 ar_lookups.lookup_code%type,
168 p_default_status OUT NOCOPY
169 ar_lookups.meaning%type,
170 p_default_printing_option_code OUT NOCOPY
171 ar_lookups.lookup_code%type,
172 p_default_printing_option OUT NOCOPY
173 ar_lookups.meaning%type,
174 p_default_term_id OUT NOCOPY
175 ra_terms.term_id%type,
176 p_default_term_name OUT NOCOPY
177 ra_terms.name%type,
178 p_number_of_due_dates OUT NOCOPY number,
179 p_term_due_date OUT NOCOPY
180 ra_customer_trx.term_due_date%type,
181 p_default_gl_date OUT NOCOPY
182 ra_cust_trx_line_gl_dist.gl_date%type,
183 p_security_inv_enter_flag IN
184 varchar2 DEFAULT 'Y',
185 p_security_cm_enter_flag IN
186 varchar2 DEFAULT 'Y',
187 p_security_dm_enter_flag IN
188 varchar2 DEFAULT 'Y',
189 p_security_commit_enter_flag IN
190 varchar2 DEFAULT 'Y'
191 ) IS
192
193 l_batch_source_id ra_batch_sources.batch_source_id%type;
194 l_default_batch_source_name ra_batch_sources.name%type;
195 l_auto_trx_numbering_flag ra_batch_sources.auto_trx_numbering_flag%type;
196 l_batch_source_type ra_batch_sources.batch_source_type%type;
197 l_copy_doc_number_flag ra_batch_sources.copy_doc_number_flag%type;
198 l_bs_default_cust_trx_type_id ra_cust_trx_types.cust_trx_type_id%type;
199 l_default_cust_trx_type_id ra_cust_trx_types.cust_trx_type_id%type;
200 l_default_status_code ar_lookups.lookup_code%type;
201 l_default_printing_option_code ar_lookups.lookup_code%type;
202 l_default_term_id ra_terms.term_id%type;
203 l_default_term_name ra_terms.name%type;
204 l_default_class ra_cust_trx_types.type%type;
205 l_post_to_gl_flag ra_cust_trx_types.post_to_gl%type;
206 l_allow_not_open_flag varchar2(1);
207 l_default_gl_date ra_cust_trx_line_gl_dist.gl_date%type;
208 l_defaulting_rule_used varchar2(128);
209 l_error_message varchar2(128);
210
211 BEGIN
212
213 IF PG_DEBUG in ('Y', 'C') THEN
214 arp_util.debug('arp_trx_defaults.get_header_defaults()+');
215 END IF;
216
217
218 /*-----------------------------------------------------+
219 | Determine the batch source value or default value |
220 +-----------------------------------------------------*/
221
222 /*4091613*/
223 IF p_customer_trx_id is NULL THEN
224 IF ( p_batch_source_id IS NOT NULL)
225 THEN
226
227 arp_trx_defaults_2.get_source_default(
228 p_batch_source_id,
229 p_ctt_class,
230 p_trx_date,
231 p_trx_number,
232 l_batch_source_id,
233 p_default_batch_source_name,
234 p_auto_trx_numbering_flag,
235 p_batch_source_type,
236 p_copy_doc_number_flag,
237 l_bs_default_cust_trx_type_id
238 );
239
240 ELSE
241 l_batch_source_id := p_batch_source_id;
242 END IF;
243
244 IF (
245 l_batch_source_id IS NULL
246 AND
247 p_batch_batch_source_id IS NOT NULL
248 )
249 THEN
250
251 -- Try the current batch
252
253 IF ( p_batch_batch_source_id IS NOT NULL )
254 THEN
255
256 arp_trx_defaults_2.get_source_default(
257 p_batch_batch_source_id,
258 p_ctt_class,
259 p_trx_date,
260 p_trx_number,
261 l_batch_source_id,
262 p_default_batch_source_name,
263 p_auto_trx_numbering_flag,
264 p_batch_source_type,
265 p_copy_doc_number_flag,
266 l_bs_default_cust_trx_type_id
267 );
268 END IF;
269
270 END IF;
271
272 -- Try the profile
273
274 IF (
275 l_batch_source_id IS NULL
276 AND p_profile_batch_source_id IS NOT NULL
277 )
278 THEN
279
280 arp_trx_defaults_2.get_source_default(
281 p_profile_batch_source_id,
282 p_ctt_class,
283 p_trx_date,
284 p_trx_number,
285 l_batch_source_id,
286 p_default_batch_source_name,
287 p_auto_trx_numbering_flag,
288 p_batch_source_type,
289 p_copy_doc_number_flag,
290 l_bs_default_cust_trx_type_id
291 );
292
293 END IF;
294 END IF;
295
296
297 /*-----------------------------------------------------------+
298 | Don't do any more processing if the batch source cannot |
299 | be determined or defaulted. |
300 | Otherwise, get the type default. |
301 +-----------------------------------------------------------*/
302
303 /*4091613*/
304 IF ( l_batch_source_id IS NULL AND p_customer_trx_id IS NULL)
305 THEN RETURN;
306 ELSE
307 p_default_batch_source_id := l_batch_source_id;
308 p_bs_default_cust_trx_type_id := l_bs_default_cust_trx_type_id;
309
310 IF ( p_cust_trx_type_id IS NOT NULL)
311 THEN
312
313 arp_trx_defaults_2.get_type_defaults(
314 p_cust_trx_type_id,
315 p_trx_date,
316 p_ctt_class,
317 p_row_id,
318 p_invoicing_rule_id,
319 p_rev_recog_run_flag,
320 p_complete_flag,
321 p_open_receivables_flag,
322 p_customer_trx_id,
323 l_default_cust_trx_type_id,
324 p_default_type_name,
325 l_default_class,
326 p_open_receivable_flag,
327 l_post_to_gl_flag,
328 p_allow_freight_flag,
329 p_creation_sign,
330 p_allow_overapplication_flag,
331 p_natural_app_only_flag,
332 p_tax_calculation_flag,
333 l_default_status_code,
334 p_default_status,
335 l_default_printing_option_code,
336 p_default_printing_option,
337 l_default_term_id,
338 l_default_term_name,
339 p_number_of_due_dates,
340 p_term_due_date,
341 p_security_inv_enter_flag,
342 p_security_cm_enter_flag,
343 p_security_dm_enter_flag,
344 p_security_commit_enter_flag
345 );
346
347 END IF;
348
349 -- Try to default the type from the commitment
350
351 IF (
352 l_default_cust_trx_type_id IS NULL
353 AND
354 p_com_default_cust_trx_type_id IS NOT NULL
355 )
356 THEN
357
358 arp_trx_defaults_2.get_type_defaults(
359 p_com_default_cust_trx_type_id,
360 p_trx_date,
361 p_ctt_class,
362 p_row_id,
363 p_invoicing_rule_id,
364 p_rev_recog_run_flag,
365 p_complete_flag,
366 p_open_receivables_flag,
367 p_customer_trx_id,
368 l_default_cust_trx_type_id,
369 p_default_type_name,
370 l_default_class,
371 p_open_receivable_flag,
372 l_post_to_gl_flag,
373 p_allow_freight_flag,
374 p_creation_sign,
375 p_allow_overapplication_flag,
376 p_natural_app_only_flag,
377 p_tax_calculation_flag,
378 l_default_status_code,
379 p_default_status,
380 l_default_printing_option_code,
381 p_default_printing_option,
382 l_default_term_id ,
383 l_default_term_name,
384 p_number_of_due_dates,
385 p_term_due_date,
386 p_security_inv_enter_flag,
387 p_security_cm_enter_flag,
388 p_security_dm_enter_flag,
389 p_security_commit_enter_flag
390 );
391
392 END IF;
393
394 -- Try to default the type from the batch source
395
396 IF (
397 l_default_cust_trx_type_id IS NULL
398 AND
399 l_bs_default_cust_trx_type_id IS NOT NULL
400 )
401 THEN
402
403 arp_trx_defaults_2.get_type_defaults(
404 l_bs_default_cust_trx_type_id,
405 p_trx_date,
406 p_ctt_class,
407 p_row_id,
408 p_invoicing_rule_id,
409 p_rev_recog_run_flag,
410 p_complete_flag,
411 p_open_receivables_flag,
412 p_customer_trx_id,
413 l_default_cust_trx_type_id,
414 p_default_type_name,
415 l_default_class,
416 p_open_receivable_flag,
417 l_post_to_gl_flag,
418 p_allow_freight_flag,
419 p_creation_sign,
420 p_allow_overapplication_flag,
421 p_natural_app_only_flag,
422 p_tax_calculation_flag,
423 l_default_status_code,
424 p_default_status,
425 l_default_printing_option_code,
426 p_default_printing_option,
427 l_default_term_id,
428 l_default_term_name,
429 p_number_of_due_dates,
430 p_term_due_date,
431 p_security_inv_enter_flag,
432 p_security_cm_enter_flag,
433 p_security_dm_enter_flag,
434 p_security_commit_enter_flag
435 );
436
437 END IF;
438
439 p_default_cust_trx_type_id := l_default_cust_trx_type_id;
440 p_default_status_code := l_default_status_code;
441 p_default_printing_option_code := l_default_printing_option_code;
442 p_default_term_id := l_default_term_id;
443 p_default_term_name := l_default_term_name;
444 p_class := l_default_class;
445 p_post_to_gl_flag := l_post_to_gl_flag;
446
447 END IF;
448
449 arp_trx_defaults_3.get_term_default(
450 p_term_id,
451 l_default_term_id,
452 l_default_term_name,
453 p_customer_id,
454 p_site_use_id,
455 p_trx_date,
456 NVL(p_ctt_class, l_default_class),
457 l_default_cust_trx_type_id,
458 p_default_term_id,
459 p_default_term_name,
460 p_number_of_due_dates,
461 p_term_due_date );
462
463
464 /*-----------------------------------------------------------------+
465 | Default the status to Open if no other default has been found |
466 +-----------------------------------------------------------------*/
467
468 IF ( l_default_status_code IS NULL)
469 THEN
470
471 BEGIN
472
473 SELECT lookup_code,
474 meaning
475 INTO p_default_status_code,
476 p_default_status
477 FROM ar_lookups arl_status
478 WHERE 'INVOICE_TRX_STATUS' = arl_status.lookup_type
479 AND 'OP' = arl_status.lookup_code
480 AND 'Y' = arl_status.enabled_flag
481 AND NVL(p_trx_date, TRUNC(SYSDATE))
482 BETWEEN arl_status.start_date_active
483 AND NVL(arl_status.end_date_active,
484 NVL( p_trx_date, TRUNC(SYSDATE) ) );
485
486 EXCEPTION
487 WHEN NO_DATA_FOUND THEN NULL;
488 WHEN OTHERS THEN RAISE;
489
490 END;
491
492 END IF;
493
494
495 /*-------------------------------------------------------------------------+
496 | Default the printing option to Print if no other default has been found |
497 +-------------------------------------------------------------------------*/
498
499 IF ( l_default_printing_option_code IS NULL)
500 THEN
501
502 BEGIN
503
504 SELECT lookup_code,
505 meaning
506 INTO p_default_printing_option_code,
507 p_default_printing_option
508 FROM ar_lookups arl_print
509 WHERE 'INVOICE_PRINT_OPTIONS' = arl_print.lookup_type
510 AND 'PRI' = arl_print.lookup_code
511 AND 'Y' = arl_print.enabled_flag
512 AND NVL(p_trx_date, TRUNC(SYSDATE))
513 BETWEEN arl_print.start_date_active
514 AND NVL(arl_print.end_date_active,
515 NVL( p_trx_date, TRUNC(SYSDATE) ) );
516
517 EXCEPTION
518 WHEN NO_DATA_FOUND THEN NULL;
519 WHEN OTHERS THEN RAISE;
520
521 END;
522
523 END IF;
524
525 /*---------------------------+
526 | Get the default gl_date |
527 +---------------------------*/
528
529 IF (l_post_to_gl_flag = 'Y')
530 THEN
531 IF (p_invoicing_rule_id = -3)
532 THEN l_allow_not_open_flag := 'Y';
533 ELSE l_allow_not_open_flag := 'N';
534 END IF;
535
536 IF ( arp_util.validate_and_default_gl_date(
537 p_gl_date,
538 NULL,
539 p_prev_gl_date,
540 p_commit_gl_date ,
541 NULL,
542 p_batch_gl_date,
543 p_trx_date,
544 TRUNC(sysdate),
545 l_allow_not_open_flag,
546 TO_CHAR(p_invoicing_rule_id),
547 pg_set_of_books_id,
548 222,
549 l_default_gl_date,
550 l_defaulting_rule_used,
551 l_error_message
552 ) = FALSE )
553 THEN
554 fnd_message.set_name('AR', 'GENERIC_MESSAGE');
555 fnd_message.set_token('GENERIC_TEXT',
556 l_error_message);
557 app_exception.raise_exception;
558
559 ELSE
560
561 IF PG_DEBUG in ('Y', 'C') THEN
562 arp_util.debug('get_header_defaults: ' || 'default GL Date: ' ||
563 to_char(l_default_gl_date) ||
564 ' Rule: ' || l_defaulting_rule_used);
565 END IF;
566
567 IF (l_default_gl_date IS NOT NULL)
568 THEN
569 p_default_gl_date := l_default_gl_date;
570 END IF;
571 END IF;
572
573 END IF;
574
575 /*---------------------------------------------------------+
576 | Get the default primary salesperson: |
577 | Default from: |
578 | - The salesrep on the customer record |
579 | - No Sales Credit (only if salescredits are required) |
580 +---------------------------------------------------------*/
581 /*
582 SELECT NVL(s.name, s1.name),
583 NVL(s.salesrep_number, s1.salesrep_number),
584 NVL(s.salesrep_id, s1.salesrep_id)
585 INTO p_primary_salesrep_name,
586 p_primary_salesrep_number,
587 p_primary_salesrep_id
588 FROM ra_salesreps s,
589 ra_salesreps s1,
590 hz_cust_accounts cust_acct
591 WHERE cust_acct.primary_salesrep_id = s.salesrep_id(+)
592 AND cust_acct.cust_account_id = p_customer_id
593 AND DECODE(p_salesrep_required_flag,
594 'Y', -3,
595 -100) = s1.salesrep_id(+)
596 AND p_trx_date BETWEEN
597 NVL(s.start_date_active(+), p_trx_date) AND
598 NVL(s.end_date_active(+), p_trx_date)
599 AND p_trx_date BETWEEN
600 NVL(s1.start_date_active(+), p_trx_date) AND
601 NVL(s1.end_date_active(+), p_trx_date);
602 */
603
604 IF PG_DEBUG in ('Y', 'C') THEN
605 arp_util.debug('arp_trx_defaults.get_header_defaults()-');
606 END IF;
607
608 EXCEPTION
609 WHEN OTHERS THEN
610 IF PG_DEBUG in ('Y', 'C') THEN
611 arp_util.debug('EXCEPTION: arp_trx_defaults.get_header_defaults()');
612 END IF;
613 RAISE;
614
615 END get_header_defaults;
616
617
618 /*---------------------------------------------+
619 | Package initialization section. |
620 +---------------------------------------------*/
621
622 BEGIN
623
624 pg_text_dummy := arp_ct_pkg.get_text_dummy;
625 pg_flag_dummy := arp_ct_pkg.get_flag_dummy;
626 pg_number_dummy := arp_ct_pkg.get_number_dummy;
627 pg_date_dummy := arp_ct_pkg.get_date_dummy;
628
629 pg_base_curr_code := arp_global.functional_currency;
630 pg_base_precision := arp_global.base_precision;
631 pg_base_min_acc_unit := arp_global.base_min_acc_unit;
632 pg_set_of_books_id :=
633 arp_trx_global.system_info.system_parameters.set_of_books_id;
634
635 END ARP_TRX_DEFAULTS;