1 PACKAGE BODY ar_receipt_lib_pvt AS
2 /* $Header: ARXPRELB.pls 120.78.12010000.7 2009/01/13 20:15:25 mraymond ship $ */
3
4 G_PKG_NAME CONSTANT VARCHAR2(30) := 'AR_RECEIPT_LIB_PVT';
5
6 G_MSG_UERROR CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR;
7 G_MSG_ERROR CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_ERROR;
8 G_MSG_SUCCESS CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_SUCCESS;
9 G_MSG_HIGH CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_DEBUG_HIGH;
10 G_MSG_MEDIUM CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_DEBUG_MEDIUM;
11 G_MSG_LOW CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW;
12
13 G_SITE_USE_CACHE_SIZE BINARY_INTEGER := 1000;
14 G_CUST_NUM_CACHE_SIZE BINARY_INTEGER := 1000;
15 G_CUST_NAME_CACHE_SIZE BINARY_INTEGER := 1000;
16 G_METHOD_CACHE_SIZE BINARY_INTEGER := 1000;
17 G_CUST_BK_AC_NUM_CACHE_SIZE BINARY_INTEGER := 1000;
18 G_CUST_BK_AC_NAME_CACHE_SIZE BINARY_INTEGER := 1000;
19 G_REMIT_BK_AC_NUM_CACHE_SIZE BINARY_INTEGER := 1000;
20 G_REMIT_BK_AC_NAME_CACHE_SIZE BINARY_INTEGER := 1000;
21 G_CURRENCY_CACHE_SIZE BINARY_INTEGER := 1000;
22 G_RATE_TYPE_CACHE_SIZE BINARY_INTEGER := 1000;
23 G_METHOD_INFO_CACHE_SIZE BINARY_INTEGER := 1000;
24 G_EXCHANGE_RATE_CACHE_SIZE BINARY_INTEGER := 1000;
25 G_ACTIVITY_NAME_CACHE_SIZE BINARY_INTEGER := 1000; -- Bugfix 2853738
26 /* Bug fix 2982212 */
27 G_TAX_CODE_CACHE_SIZE BINARY_INTEGER := 1000;
28 G_REF_PAYMENT_CACHE_SIZE BINARY_INTEGER := 1000;
29 G_REF_PAYMENT_BATCH_CACHE_SIZE BINARY_INTEGER := 1000;
30 G_REF_RECEIPT_CACHE_SIZE BINARY_INTEGER := 1000;
31 G_REF_REMITTANCE_CACHE_SIZE BINARY_INTEGER := 1000;
32 G_LEGAL_ENTITY_CACHE_SIZE BINARY_INTEGER := 1000;
33
34 /* modified for tca uptake */
35 TYPE Site_Use_Cache_Rec_Type IS RECORD
36 (id hz_cust_site_uses.site_use_id%TYPE,
37 customer_id hz_cust_acct_sites.cust_account_id%TYPE,
38 site_use_code hz_cust_site_uses.site_use_code%TYPE,
39 location hz_cust_site_uses.location%TYPE,
40 primary_flag VARCHAR2(1)
41 );
42 TYPE Exchange_Rate_Cache_Rec_Type IS RECORD
43 (exchange_rate ar_cash_receipts.exchange_rate%TYPE,
44 currency ar_cash_receipts.currency_code%TYPE,
45 exchange_rate_type ar_cash_receipts.exchange_rate_type%TYPE,
46 exchange_date ar_cash_receipts.exchange_date%TYPE
47 );
48
49 TYPE Method_Info_Cache_Rec_Type IS RECORD
50 (receipt_method_id ar_cash_receipts.receipt_method_id%TYPE,
51 remit_bank_acct_use_id ar_cash_receipts.remit_bank_acct_use_id%TYPE,
52 currency_code ar_cash_receipts.currency_code%TYPE,
53 called_from VARCHAR2(200),
54 state ar_receipt_classes.creation_status%TYPE,
55 creation_method_code ar_receipt_classes.creation_method_code%TYPE,
56 bau_end_date ce_bank_acct_uses.end_date%TYPE,
57 rm_start_date ar_receipt_methods.start_date%TYPE,
58 rm_end_date ar_receipt_methods.end_date%TYPE,
59 rma_start_date ar_receipt_method_accounts.start_date%TYPE,
60 rma_end_date ar_receipt_method_accounts.end_date%TYPE
61 );
62
63 TYPE Id_Cache_Rec_Type IS RECORD
64 ( id VARCHAR2(100),
65 value VARCHAR2(100)
66 );
67
68
69 TYPE Site_Use_Cache_Tbl_Type IS
70 TABLE OF Site_Use_Cache_Rec_Type
71 INDEX BY BINARY_INTEGER;
72
73
74 TYPE Exchange_Rate_Cache_Tbl_Type IS
75 TABLE OF Exchange_Rate_Cache_Rec_Type
76 INDEX BY BINARY_INTEGER;
77
78 TYPE Method_Info_Cache_Tbl_Type IS
79 TABLE OF Method_Info_Cache_Rec_Type
80 INDEX BY BINARY_INTEGER;
81
82 TYPE Id_Cache_Tbl_Type IS
83 TABLE OF Id_Cache_Rec_Type
84 INDEX BY BINARY_INTEGER;
85
86
87 G_Site_Use_Cache_Tbl Site_Use_Cache_Tbl_Type;
88 G_Cust_Num_Cache_Tbl Id_Cache_Tbl_Type;
89 G_Cust_Name_Cache_Tbl Id_Cache_Tbl_Type;
90 G_Method_Cache_Tbl Id_Cache_Tbl_Type;
91 G_Cust_Bank_Ac_Num_Cache_Tbl Id_Cache_Tbl_Type;
92 G_Cust_Bank_Ac_Name_Cache_Tbl Id_Cache_Tbl_Type;
93 G_Remit_Bank_Ac_Num_Cache_Tbl Id_Cache_Tbl_Type;
94 G_Remit_Bank_Ac_Name_Cache_Tbl Id_Cache_Tbl_Type;
95 G_Currency_Cache_Tbl Id_Cache_Tbl_Type;
96 G_Rate_Type_Cache_Tbl Id_Cache_Tbl_Type;
97 Method_Info_Cache_Tbl Method_Info_Cache_Tbl_Type;
98 Exchange_Rate_Cache_Tbl Exchange_Rate_Cache_Tbl_Type;
99 G_Activity_Name_Cache_Tbl Id_Cache_Tbl_Type; -- Bugfix 2853738
100 /* Bug fix 2982212 */
101 G_Tax_Code_Cache_Tbl Id_Cache_Tbl_Type;
102 G_Ref_Payment_Cache_Tbl Id_Cache_Tbl_Type;
103 G_Ref_Payment_Batch_Cache_Tbl Id_Cache_Tbl_Type;
104 G_Ref_Receipt_Cache_Tbl Id_Cache_Tbl_Type;
105 G_Ref_Remittance_Cache_Tbl Id_Cache_Tbl_Type;
106 G_Legal_Entity_Cache_Tbl Id_Cache_Tbl_Type;
107
108 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
109
110 PROCEDURE Configure_Library_Caches(
111 p_site_use_cache IN BINARY_INTEGER DEFAULT 1000,
112 p_cust_number_cache IN BINARY_INTEGER DEFAULT 1000,
113 p_cust_name_cache IN BINARY_INTEGER DEFAULT 1000,
114 p_receipt_method_cache IN BINARY_INTEGER DEFAULT 1000,
115 p_cust_bank_ac_num_cache IN BINARY_INTEGER DEFAULT 1000,
116 p_cust_bank_ac_name_cache IN BINARY_INTEGER DEFAULT 1000,
117 p_remit_bank_ac_num_cache IN BINARY_INTEGER DEFAULT 1000,
118 p_remit_bank_ac_name_cache IN BINARY_INTEGER DEFAULT 1000,
119 p_currency_cache IN BINARY_INTEGER DEFAULT 1000,
120 p_rate_type_cache IN BINARY_INTEGER DEFAULT 1000,
121 p_method_info_cache IN BINARY_INTEGER DEFAULT 1000,
122 p_exchange_rate_cache IN BINARY_INTEGER DEFAULT 1000
123 ) IS
124 BEGIN
125 IF PG_DEBUG in ('Y', 'C') THEN
126 arp_util.debug('Configure_Library_Caches()+ ');
127 END IF;
128
129 G_SITE_USE_CACHE_SIZE := p_site_use_cache;
130 G_CUST_NUM_CACHE_SIZE := p_cust_number_cache;
131 G_CUST_NAME_CACHE_SIZE := p_cust_name_cache;
132 G_METHOD_CACHE_SIZE := p_receipt_method_cache;
133 G_CUST_BK_AC_NUM_CACHE_SIZE := p_cust_bank_ac_num_cache;
134 G_CUST_BK_AC_NAME_CACHE_SIZE := p_cust_bank_ac_name_cache;
135 G_REMIT_BK_AC_NUM_CACHE_SIZE := p_remit_bank_ac_num_cache;
136 G_REMIT_BK_AC_NAME_CACHE_SIZE := p_remit_bank_ac_name_cache;
137 G_CURRENCY_CACHE_SIZE := p_currency_cache;
138 G_RATE_TYPE_CACHE_SIZE := p_rate_type_cache;
139 G_METHOD_INFO_CACHE_SIZE := p_method_info_cache;
140 G_EXCHANGE_RATE_CACHE_SIZE := p_exchange_rate_cache;
141
142 IF PG_DEBUG in ('Y', 'C') THEN
143 arp_util.debug('Configure_Library_Caches()- ');
144 END IF;
145
146 EXCEPTION
147 WHEN OTHERS THEN
148 IF PG_DEBUG in ('Y', 'C') THEN
149 arp_util.debug('EXCEPTION: Configure_Library_Caches() ');
150 END IF;
151 RAISE;
152
153 END Configure_Library_Caches;
154 PROCEDURE Add_Value_To_Cache(p_cache_name IN VARCHAR2,
155 p_value IN VARCHAR2,
156 p_id IN VARCHAR2,
157 p_index IN BINARY_INTEGER
158 ) IS
159
160 BEGIN
161
162 IF PG_DEBUG in ('Y', 'C') THEN
163 arp_util.debug('Add_Value_To_Cache()+ ');
164 END IF;
165
166 IF ( p_cache_name = 'CUSTOMER_NUMBER' )
167 THEN
168 IF ( p_index <= G_CUST_NUM_CACHE_SIZE )
169 THEN
170 G_Cust_Num_Cache_Tbl( p_index ).value := p_value;
171 G_Cust_Num_Cache_Tbl( p_index ).id := p_id;
172 END IF;
173
174 ELSIF ( p_cache_name = 'CUSTOMER_NAME' )
175 THEN
176 IF ( p_index <= G_CUST_NAME_CACHE_SIZE )
177 THEN
178 G_Cust_Name_Cache_Tbl( p_index ).value := p_value;
179 G_Cust_Name_Cache_Tbl( p_index ).id := p_id;
180 END IF;
181 ELSIF ( p_cache_name = 'RECEIPT_METHOD_NAME' )
182 THEN
183 IF ( p_index <= G_METHOD_CACHE_SIZE )
184 THEN
185 G_Method_Cache_Tbl( p_index ).value := p_value;
186 G_Method_Cache_Tbl( p_index ).id := p_id;
187 END IF;
188 ELSIF ( p_cache_name = 'CUST_BANK_ACCOUNT_NUMBER' )
189 THEN
190 IF ( p_index <= G_CUST_BK_AC_NUM_CACHE_SIZE )
191 THEN
192 G_Cust_Bank_Ac_Num_Cache_Tbl( p_index ).value := p_value;
193 G_Cust_Bank_Ac_Num_Cache_Tbl( p_index ).id := p_id;
194 END IF;
195 ELSIF ( p_cache_name = 'CUST_BANK_ACCOUNT_NAME' )
196 THEN
197 IF ( p_index <= G_CUST_BK_AC_NAME_CACHE_SIZE )
198 THEN
199 G_Cust_Bank_Ac_Name_Cache_Tbl( p_index ).value := p_value;
200 G_Cust_Bank_Ac_Name_Cache_Tbl( p_index ).id := p_id;
201 END IF;
202 ELSIF ( p_cache_name = 'REMIT_BANK_ACCOUNT_NUMBER' )
203 THEN
204 IF ( p_index <= G_REMIT_BK_AC_NUM_CACHE_SIZE )
205 THEN
206 G_Remit_Bank_Ac_Num_Cache_Tbl( p_index ).value := p_value;
207 G_Remit_Bank_Ac_Num_Cache_Tbl( p_index ).id := p_id;
208 END IF;
209 ELSIF ( p_cache_name = 'REMIT_BANK_ACCOUNT_NAME' )
210 THEN
211 IF ( p_index <= G_REMIT_BK_AC_NAME_CACHE_SIZE )
212 THEN
213 G_Remit_Bank_Ac_Name_Cache_Tbl( p_index ).value := p_value;
214 G_Remit_Bank_Ac_Name_Cache_Tbl( p_index ).id := p_id;
215 END IF;
216 ELSIF ( p_cache_name = 'CURRENCY_NAME' )
217 THEN
218 IF ( p_index <= G_CURRENCY_CACHE_SIZE )
219 THEN
220 G_Currency_Cache_Tbl( p_index ).value := p_value;
221 G_Currency_Cache_Tbl( p_index ).id := p_id;
222 END IF;
223 ELSIF ( p_cache_name = 'EXCHANGE_RATE_TYPE_NAME' )
224 THEN
225 IF ( p_index <= G_RATE_TYPE_CACHE_SIZE )
226 THEN
227 G_Rate_Type_Cache_Tbl( p_index ).value := p_value;
228 G_Rate_Type_Cache_Tbl( p_index ).id := p_id;
229 END IF;
230 -- Bugfix 2853738
231 ELSIF ( p_cache_name = 'RECEIVABLES_ACTIVITY')
232 THEN
233 IF ( p_index <= G_ACTIVITY_NAME_CACHE_SIZE)
234 THEN
235 G_Activity_Name_Cache_Tbl( p_index ).value := p_value;
236 G_Activity_Name_Cache_Tbl( p_index ).id := p_id;
237 END IF;
238 /* Bug fix 2982212 */
239 ELSIF ( p_cache_name = 'TAX_CODE')
240 THEN
241 IF ( p_index <= G_TAX_CODE_CACHE_SIZE)
242 THEN
243 G_Tax_Code_Cache_Tbl( p_index ).value := p_value;
244 G_Tax_Code_Cache_Tbl( p_index ).id := p_id;
245 END IF;
246 ELSIF ( p_cache_name = 'REF_PAYMENT')
247 THEN
248 IF ( p_index <= G_REF_PAYMENT_CACHE_SIZE)
249 THEN
250 G_Ref_Payment_Cache_Tbl( p_index ).value := p_value;
251 G_Ref_Payment_Cache_Tbl( p_index ).id := p_id;
252 END IF;
253 ELSIF ( p_cache_name = 'REF_PAYMENT_BATCH')
254 THEN
255 IF ( p_index <= G_REF_PAYMENT_BATCH_CACHE_SIZE )
256 THEN
257 G_Ref_Payment_Batch_Cache_Tbl( p_index ).value := p_value;
258 G_Ref_Payment_Batch_Cache_Tbl( p_index ).id := p_id;
259 END IF;
260 ELSIF ( p_cache_name = 'REF_RECEIPT')
261 THEN
262 IF ( p_index <= G_REF_RECEIPT_CACHE_SIZE)
263 THEN
264 G_Ref_Receipt_Cache_Tbl( p_index ).value := p_value;
265 G_Ref_Receipt_Cache_Tbl( p_index ).id := p_id;
266 END IF;
267 ELSIF ( p_cache_name = 'REF_REMITTANCE')
268 THEN
269 IF ( p_index <= G_REF_REMITTANCE_CACHE_SIZE)
270 THEN
271 G_Ref_Remittance_Cache_Tbl( p_index ).value := p_value;
272 G_Ref_Remittance_Cache_Tbl( p_index ).id := p_id;
273 END IF;
274 ELSIF ( p_cache_name = 'LEGAL_ENTITY')
275 THEN
276 IF ( p_index <= G_LEGAL_ENTITY_CACHE_SIZE)
277 THEN
278 G_Legal_Entity_Cache_Tbl( p_index ).value := p_value;
279 G_Legal_Entity_Cache_Tbl( p_index ).id := p_id;
280 END IF;
281 END IF;
282 IF PG_DEBUG in ('Y', 'C') THEN
283 arp_util.debug('Add_Value_To_Cache()- ');
284 END IF;
285
286 EXCEPTION
287 WHEN OTHERS THEN
288 IF PG_DEBUG in ('Y', 'C') THEN
289 arp_util.debug('EXCEPTION: Add_Value_To_Cache. Cache: ' ||
290 p_cache_name || ' ' ||
291 ' Value: ' || p_value);
292 END IF;
293 RAISE;
294
295 END Add_Value_To_Cache;
296
297 FUNCTION Find_Value_In_Cache(
298 p_cache_name IN VARCHAR2,
299 p_value IN VARCHAR2,
300 p_index OUT NOCOPY BINARY_INTEGER
301 ) RETURN VARCHAR2 IS
302
303 l_index BINARY_INTEGER;
304 l_count BINARY_INTEGER;
305
306 BEGIN
307
308 IF PG_DEBUG in ('Y', 'C') THEN
309 arp_util.debug('Find_Value_In_Cache()+ ');
310 END IF;
311
312 IF (p_cache_name = 'CUSTOMER_NUMBER')
313 THEN
314 l_count := G_Cust_Num_Cache_Tbl.count;
315
316 ELSIF (p_cache_name = 'CUSTOMER_NAME')
317 THEN
318 l_count := G_Cust_Name_Cache_Tbl.count;
319
320 ELSIF (p_cache_name = 'RECEIPT_METHOD_NAME')
321 THEN
322 l_count := G_Method_Cache_Tbl.count;
323
324 ELSIF (p_cache_name = 'CUST_BANK_ACCOUNT_NUMBER')
325 THEN
326 l_count := G_Cust_Bank_Ac_Num_Cache_Tbl.count;
327
328 ELSIF (p_cache_name = 'CUST_BANK_ACCOUNT_NAME')
329 THEN
330 l_count := G_Cust_Bank_Ac_Name_Cache_Tbl.count;
331
332 ELSIF (p_cache_name = 'REMIT_BANK_ACCOUNT_NUMBER')
333 THEN
334 l_count := G_Remit_Bank_Ac_Num_Cache_Tbl.count;
335
336 ELSIF (p_cache_name = 'REMIT_BANK_ACCOUNT_NAME')
337 THEN
338 l_count := G_Remit_Bank_Ac_Name_Cache_Tbl.count;
339
340 ELSIF (p_cache_name = 'CURRENCY_NAME')
341 THEN
342 l_count := G_Currency_Cache_Tbl.count;
343
344 ELSIF (p_cache_name = 'EXCHANGE_RATE_TYPE_NAME')
345 THEN
346 l_count := G_Rate_Type_Cache_Tbl.count;
347
348 -- Bugfix 2853738
349 ELSIF (p_cache_name = 'RECEIVABLES_ACTIVITY')
350 THEN
351 l_count := G_Activity_Name_Cache_Tbl.count ;
352
353 /* Bugfix 2982212 */
354 ELSIF (p_cache_name = 'TAX_CODE')
355 THEN
356 l_count := G_Tax_Code_Cache_Tbl.count ;
357
358 ELSIF (p_cache_name = 'REF_PAYMENT')
359 THEN
360 l_count := G_Ref_Payment_Cache_Tbl.count ;
361
362 ELSIF (p_cache_name = 'REF_PAYMENT_BATCH')
363 THEN
364 l_count := G_Ref_Payment_Batch_Cache_Tbl.count ;
365
366 ELSIF (p_cache_name = 'REF_RECEIPT')
367 THEN
368 l_count := G_Ref_Receipt_Cache_Tbl.count ;
369
370 ELSIF (p_cache_name = 'REF_REMITTANCE')
371 THEN
372 l_count := G_Ref_Remittance_Cache_Tbl.count ;
373
374 ELSIF (p_cache_name = 'LEGAL_ENTITY')
375 THEN
376 l_count := G_Legal_Entity_Cache_Tbl.count ;
377 END IF;
378
379
380 FOR l_index IN 1..l_count LOOP
381
382 p_index := l_index;
383
384 IF ( p_cache_name = 'CUSTOMER_NAME'
385 AND G_Cust_Name_Cache_Tbl(l_index).value = p_value)
386 THEN
387 RETURN( G_Cust_Name_Cache_Tbl(l_index).id);
388
389 ELSIF (p_cache_name = 'CUSTOMER_NUMBER' /* Bug 2982212*/
390 AND G_Cust_Num_Cache_Tbl(l_index).value = p_value)
391 THEN
392 RETURN( G_Cust_Num_Cache_Tbl(l_index).id);
393
394 ELSIF (p_cache_name = 'RECEIPT_METHOD_NAME' /* Bug 2982212*/
395 AND G_Method_Cache_Tbl(l_index).value = p_value)
396 THEN
397 RETURN( G_Method_Cache_Tbl(l_index).id);
398
399 ELSIF (p_cache_name = 'CUST_BANK_ACCOUNT_NUMBER'
400 AND G_Cust_Bank_Ac_Num_Cache_Tbl(l_index).value = p_value)
401 THEN
402 RETURN(G_Cust_Bank_Ac_Num_Cache_Tbl(l_index).id);
403
404 ELSIF (p_cache_name = 'CUST_BANK_ACCOUNT_NAME'
405 AND G_Cust_Bank_Ac_Name_Cache_Tbl(l_index).value = p_value)
406 THEN
407 RETURN(G_Cust_Bank_Ac_Name_Cache_Tbl(l_index).id);
408
409 ELSIF (p_cache_name = 'REMIT_BANK_ACCOUNT_NUMBER'
410 AND G_Remit_Bank_Ac_Num_Cache_Tbl(l_index).value = p_value)
411 THEN
412 RETURN(G_Remit_Bank_Ac_Num_Cache_Tbl(l_index).id);
413
414 ELSIF (p_cache_name = 'REMIT_BANK_ACCOUNT_NAME'
415 AND G_Remit_Bank_Ac_Name_Cache_Tbl(l_index).value = p_value)
416 THEN
417 RETURN(G_Remit_Bank_Ac_Name_Cache_Tbl(l_index).id);
418
419 -- bug2680657 : Added p_value condition for CURRENCY_NAME and
420 -- EXCHANGE_RATE_TYPE_NAME
421 ELSIF (p_cache_name = 'CURRENCY_NAME'
422 AND G_Currency_Cache_Tbl(l_index).value = p_value)
423 THEN
424 RETURN(G_Currency_Cache_Tbl(l_index).id);
425
426 ELSIF (p_cache_name = 'EXCHANGE_RATE_TYPE_NAME'
427 AND G_Rate_Type_Cache_Tbl(l_index).value = p_value)
428 THEN
429 RETURN(G_Rate_Type_Cache_Tbl(l_index).id);
430
431 -- Bugfix 2853738
432 ELSIF (p_cache_name = 'RECEIVABLES_ACTIVITY'
433 AND G_Activity_Name_Cache_Tbl(l_index).value = p_value)
434 THEN
435 RETURN( G_Activity_Name_Cache_Tbl(l_index).id);
436
437 /* Bugfix 2982212 */
438 ELSIF (p_cache_name = 'TAX_CODE'
439 AND G_Tax_Code_Cache_Tbl(l_index).value = p_value)
440 THEN
441 RETURN( G_Tax_Code_Cache_Tbl(l_index).id);
442
443 ELSIF (p_cache_name = 'REF_PAYMENT'
444 AND G_Ref_Payment_Cache_Tbl(l_index).value = p_value)
445 THEN
446 RETURN( G_Ref_Payment_Cache_Tbl(l_index).id);
447
448 ELSIF (p_cache_name = 'REF_PAYMENT_BATCH'
449 AND G_Ref_Payment_Batch_Cache_Tbl(l_index).value = p_value)
450 THEN
451 RETURN( G_Ref_Payment_Batch_Cache_Tbl(l_index).id);
452
453 ELSIF (p_cache_name = 'REF_RECEIPT'
454 AND G_Ref_Receipt_Cache_Tbl(l_index).value = p_value)
455 THEN
456 RETURN( G_Ref_Receipt_Cache_Tbl(l_index).id);
457
458 ELSIF (p_cache_name = 'REF_REMITTANCE'
459 AND G_Ref_Remittance_Cache_Tbl(l_index).value = p_value)
460 THEN
461 RETURN( G_Ref_Remittance_Cache_Tbl(l_index).id);
462
463 ELSIF (p_cache_name = 'LEGAL_ENTITY'
464 AND G_Legal_Entity_Cache_Tbl(l_index).value = p_value)
465 THEN
466 RETURN( G_Legal_Entity_Cache_Tbl(l_index).id);
467 END IF;
468
469 END LOOP;
470
471 IF PG_DEBUG in ('Y', 'C') THEN
472 arp_util.debug('Find_Value_In_Cache()- ');
473 END IF;
474
475 RETURN(NULL);
476
477 EXCEPTION
478
479 WHEN OTHERS THEN
480 IF PG_DEBUG in ('Y', 'C') THEN
481 arp_util.debug('EXCEPTION: Find_Value_In_Cache. Cache: ' ||
482 p_cache_name || ' ' ||
483 ' Value: ' || p_value);
484 END IF;
485
486 RAISE;
487
488 END Find_Value_In_Cache;
489
490
491
492 FUNCTION Get_Id(
493 p_entity IN VARCHAR2,
494 p_value IN VARCHAR2,
495 p_return_status OUT NOCOPY VARCHAR2,
496 p_date IN DATE DEFAULT NULL
497 ) RETURN VARCHAR2 IS
498
499 l_cached_id VARCHAR2(100);
500 l_selected_id VARCHAR2(100);
501 l_index BINARY_INTEGER;
502 l_date DATE; -- ETAX: bug 4594101
503
504 BEGIN
505
506 IF PG_DEBUG in ('Y', 'C') THEN
507 arp_util.debug('Get_Id()+ ');
508 END IF;
509
510 IF ( p_value IS NULL )
511 THEN
512
513 RETURN(NULL);
514
515 ELSE
516 l_cached_id := Find_Value_In_Cache( p_entity,
517 p_value,
518 l_index
519 );
520
521 IF ( l_cached_id IS NOT NULL )
522 THEN
523
524 RETURN( l_cached_id );
525
526 ELSE
527 IF ( p_entity = 'CUSTOMER_NUMBER' )
528 THEN
529
530 /* modified for tca uptake */
531 /* fixed bug 1544201: removed customer_prospect_code */
532 SELECT c.cust_account_id
533 INTO l_selected_id
534 FROM hz_cust_accounts c,
535 hz_customer_profiles cp,
536 hz_parties party
537 WHERE c.cust_account_id = cp.cust_account_id (+) and
538 cp.site_use_id is null and
539 c.account_number = p_value
540 AND c.party_id = party.party_id;
541
542 ELSIF ( p_entity = 'CUSTOMER_NAME' )
543 THEN
544
545 /* modified for tca uptake */
546 /* fixed bug 1544201: removed customer_prospect_code */
547 SELECT cust_acct.cust_account_id
548 INTO l_selected_id
549 FROM hz_cust_accounts cust_acct,
550 hz_customer_profiles cp,
551 hz_parties party
552 WHERE cust_acct.cust_account_id = cp.cust_account_id (+)
553 and cust_acct.party_id = party.party_id(+)
554 and cp.site_use_id is null
555 and party.party_name = p_value;
556
557 ELSIF (p_entity = 'RECEIPT_METHOD_NAME' )
558
559 THEN
560
561 SELECT receipt_method_id
562 INTO l_selected_id
563 FROM ar_receipt_methods
564 WHERE name = p_value;
565 /* PAYMENT UPTAKE removed the following
566 a) getting the bank_account_id from CUST_BANK_ACCOUNT_NUMBER.
567 b) getting the bank_account_id from CUST_BANK_ACCOUNT_NAME.
568 */
569
570 ELSIF (p_entity = 'REMIT_BANK_ACCOUNT_NUMBER')
571 THEN
572 SELECT bank_account_id
573 INTO l_selected_id
574 FROM ce_bank_accounts
575 WHERE bank_account_num = p_value;
576
577 ELSIF (p_entity = 'REMIT_BANK_ACCOUNT_NAME')
578 THEN
579 SELECT bank_account_id
580 INTO l_selected_id
581 FROM ce_bank_accounts
582 WHERE bank_account_name = p_value;
583
584 ELSIF (p_entity = 'CURRENCY_NAME')
585 THEN
586 SELECT currency_code
587 INTO l_selected_id
588 FROM fnd_currencies_vl
589 WHERE name = p_value;
590 ELSIF (p_entity = 'EXCHANGE_RATE_TYPE_NAME')
591 THEN
592 SELECT conversion_type
593 INTO l_selected_id
594 FROM gl_daily_conversion_types
595 WHERE user_conversion_type = p_value ;
596
597 ELSIF (p_entity = 'REF_PAYMENT' ) THEN
598 --get from ap_checks.
599 select check_id
600 into l_selected_id
601 from ap_checks
602 where check_number = p_value;
603 ELSIF (p_entity = 'REF_PAYMENT_BATCH' ) THEN
604 --
605 select isc.checkrun_id
606 into l_selected_id
607 from ap_invoice_selection_criteria isc
608 where isc.checkrun_name = p_value;
609 ELSIF (p_entity = 'REF_RECEIPT' ) THEN
610 --
611 select cash_receipt_id
612 into l_selected_id
613 from ar_cash_receipts
614 where receipt_number = p_value;
615 ELSIF (p_entity = 'REF_REMITTANCE' ) THEN
616 --
617 select batch_id
618 into l_selected_id
619 from ar_batches
620 where name = p_value
621 and type = 'REMITTANCE' ;
622 ELSIF (p_entity = 'RECEIVABLES_ACTIVITY' ) THEN
623 --
624 select receivables_trx_id
625 into l_selected_id
626 from ar_receivables_trx
627 where name = p_value;
628 ELSIF (p_entity = 'TAX_CODE' ) THEN
629 --
630 -- ETAX replaced reference of obsoleted ar vat tax
631
632 if (p_date is NULL) THEN
633 l_date := SYSDATE;
634 end if;
635
636 SELECT tax_rate_id
637 INTO l_selected_id
638 from zx_sco_rates
639 WHERE tax_rate_code = p_value
640 AND nvl(active_flag, 'Y') = 'Y' /* 4400063 */
641 AND l_date between
642 nvl(effective_from, l_date)
643 and nvl(effective_to, l_date);
644
645 ELSIF (p_entity = 'LEGAL_ENTITY' ) THEN
646 --
647 SELECT ba.account_owner_org_id
648 INTO l_selected_id
649 FROM ce_bank_accounts ba, ce_bank_acct_uses bau
650 WHERE ba.bank_account_id = bau.bank_account_id
651 AND bau.bank_acct_use_id = p_value;
652 END IF;
653
654
655 Add_Value_To_Cache(
656 p_entity,
657 p_value,
658 l_selected_id,
659 NVL( l_index, 0 ) + 1
660 );
661
662 IF PG_DEBUG in ('Y', 'C') THEN
663 arp_util.debug('Get_Id: ' || 'Value selected. Entity: '||
664 p_entity || ',' ||
665 ' Value: ' || p_value || ',' ||
666 'ID: ' || l_selected_id);
667 arp_util.debug('Get_Id()- ');
668 END IF;
669
670 RETURN( l_selected_id );
671
672
673 END IF; -- end value not found in cache case
674
675 END IF; -- end p_value is not null case
676
677
678 IF PG_DEBUG in ('Y', 'C') THEN
679 arp_util.debug('Get_Id()- ');
680 END IF;
681
682
683 EXCEPTION
684
685 WHEN NO_DATA_FOUND THEN
686 IF PG_DEBUG in ('Y', 'C') THEN
687 arp_util.debug('Get_Id: ' || 'Value not found. Entity: ' ||
688 p_entity ||' Value: ' || p_value);
689 END IF;
690 return(null);
691 IF PG_DEBUG in ('Y', 'C') THEN
692 arp_util.debug('Get_Id()- ');
693 END IF;
694
695 WHEN OTHERS THEN
696 IF PG_DEBUG in ('Y', 'C') THEN
697 arp_util.debug('Get_Id: ' || 'Value not found. Entity: ' ||
698 p_entity ||' Value: ' || p_value);
699 END IF;
700 RAISE;
701
702 END Get_Id;
703
704
705 /* modified for tca uptake */
706 PROCEDURE Add_Site_Use_To_Cache(
707 p_customer_id IN hz_cust_acct_sites.cust_account_id%TYPE,
708 p_location IN hz_cust_site_uses.location%TYPE,
709 p_site_use_code IN hz_cust_site_uses.site_use_code%TYPE,
710 p_id IN hz_cust_site_uses.site_use_id%TYPE,
711 p_index IN BINARY_INTEGER
712 ) IS
713 BEGIN
714
715 IF PG_DEBUG in ('Y', 'C') THEN
716 arp_util.debug('Add_Site_Use_To_Cache()+ ');
717 END IF;
718 IF ( p_index <= G_SITE_USE_CACHE_SIZE )
719 THEN
720 G_Site_Use_Cache_Tbl(p_index).customer_id :=
721 p_customer_id;
722 G_Site_Use_Cache_Tbl(p_index).location :=
723 p_location;
724 G_Site_Use_Cache_Tbl(p_index).site_use_code :=
725 p_site_use_code;
726 G_Site_Use_Cache_Tbl(p_index).id := p_id;
727 END IF;
728 IF PG_DEBUG in ('Y', 'C') THEN
729 arp_util.debug('Add_Site_Use_To_Cache()- ');
730 END IF;
731 EXCEPTION
732 WHEN OTHERS THEN
733 IF PG_DEBUG in ('Y', 'C') THEN
734 arp_util.debug('EXCEPTION: Add_Site_Use_To_Cache');
735 END IF;
736 RAISE;
737 END Add_Site_Use_To_Cache;
738
739 /* modified for tca uptake */
740 FUNCTION Find_Site_Use_In_Cache(
741 p_customer_id IN hz_cust_accounts.cust_account_id%TYPE,
742 p_location IN hz_cust_site_uses.site_use_id%TYPE,
743 p_site_use_code IN hz_cust_site_uses.site_use_code%TYPE,
744 p_index OUT NOCOPY BINARY_INTEGER
745 ) RETURN hz_cust_site_uses.site_use_id%TYPE IS
746
747 l_index BINARY_INTEGER;
748 l_count BINARY_INTEGER;
749
750 BEGIN
751
752 IF PG_DEBUG in ('Y', 'C') THEN
753 arp_util.debug('Find_Site_Use_In_Cache()+ ');
754 END IF;
755
756 l_count := G_Site_Use_Cache_Tbl.count;
757
758 FOR l_index IN 1..l_count LOOP
759
760 p_index := l_index;
761 IF p_location IS NOT NULL THEN
762
763 IF ( G_Site_Use_Cache_Tbl(l_index).customer_id = p_customer_id
764 AND G_Site_Use_Cache_Tbl(l_index).location = p_location
765 AND G_Site_Use_Cache_Tbl(l_index).site_use_code = p_site_use_code)
766 THEN
767 RETURN( G_Site_Use_Cache_Tbl(l_index).id);
768
769 END IF;
770 ELSE
771 IF ( G_Site_Use_Cache_Tbl(l_index).customer_id = p_customer_id
772 AND G_Site_Use_Cache_Tbl(l_index).site_use_code = p_site_use_code
773 AND G_Site_Use_Cache_Tbl(l_index).primary_flag = 'Y')
774 THEN
775 RETURN( G_Site_Use_Cache_Tbl(l_index).id);
776 END IF;
777 END IF;
778
779 END LOOP;
780
781 IF PG_DEBUG in ('Y', 'C') THEN
782 arp_util.debug('Find_Site_Use_In_Cache()- ');
783 END IF;
784
785 RETURN(NULL);
786
787 EXCEPTION
788
789 WHEN OTHERS THEN
790 IF PG_DEBUG in ('Y', 'C') THEN
791 arp_util.debug('EXCEPTION: Find_Site_Use_In_Cache');
792 END IF;
793
794 RAISE;
795
796 END Find_Site_Use_In_Cache;
797
798 /* modified for tca uptake */
799 FUNCTION Get_Site_Use_Id(
800 p_customer_id IN hz_cust_acct_sites.cust_account_id%TYPE,
801 p_location IN hz_cust_site_uses.location%TYPE,
802 p_site_use_code1 IN hz_cust_site_uses.site_use_code%TYPE DEFAULT NULL,
803 p_site_use_code2 IN hz_cust_site_uses.site_use_code%TYPE DEFAULT NULL)
804 RETURN hz_cust_site_uses.site_use_id%type IS
805 l_cached_id hz_cust_site_uses.site_use_id%type;
806 l_selected_id hz_cust_site_uses.site_use_id%type;
807 l_index BINARY_INTEGER;
808 BEGIN
809
810 IF PG_DEBUG in ('Y', 'C') THEN
811 arp_util.debug('Get_Site_Use_Id()+ ');
812 END IF;
813
814 /* IF ( p_customer_id IS NULL ) THEN
815 RETURN(NULL);
816 ELSE
817 l_cached_id := Find_Site_Use_In_Cache(
818 p_customer_id,
819 p_location,
820 p_site_use_code,
821 l_index
822 );
823 IF ( l_cached_id IS NOT NULL ) THEN
824 RETURN( l_cached_id );
825 ELSE
826 */
827 IF p_customer_id IS NOT NULL THEN
828 IF (p_location IS NOT NULL) THEN
829 BEGIN
830 /* modified for tca uptake */
831 SELECT site_use.site_use_id
832 INTO l_selected_id
833 FROM hz_cust_site_uses site_use,
834 hz_cust_acct_sites acct_site
835 WHERE acct_site.cust_account_id = p_customer_id
836 AND acct_site.status = 'A'
837 AND site_use.cust_acct_site_id = acct_site.cust_acct_site_id
838 AND (site_use.site_use_code = nvl(p_site_use_code1,
839 site_use.site_use_code) OR
840 site_use.site_use_code = nvl(p_site_use_code1,
841 site_use.site_use_code))
842 AND site_use.status = 'A'
843 AND site_use.location = p_location;
844 EXCEPTION
845 WHEN no_data_found THEN
846 IF PG_DEBUG in ('Y', 'C') THEN
847 arp_util.debug('Get_Site_Use_Id: ' || 'No data found in the hz_cust_site_uses for the location :'||p_location);
848 END IF;
849 --the error message will be raised in the validation routine.
850 null;
851 END;
852
853 ELSE
854 --the case when no location is specified for the customer.
855 --here we are defaulting the primary bill_to loaction.
856 BEGIN
857 /* modified for tca uptake */
858 SELECT site_use.site_use_id
859 INTO l_selected_id
860 FROM hz_cust_site_uses site_use,
861 hz_cust_acct_sites acct_site
862 WHERE acct_site.cust_account_id = p_customer_id
863 AND acct_site.status = 'A'
864 AND site_use.cust_acct_site_id = acct_site.cust_acct_site_id
865 AND (site_use.site_use_code = nvl(p_site_use_code1,
866 site_use.site_use_code) OR
867 site_use.site_use_code = nvl(p_site_use_code1,
868 site_use.site_use_code))
869 AND site_use.status = 'A'
870 AND site_use.primary_flag = 'Y';
871
872 EXCEPTION
873 WHEN no_data_found THEN
874 IF PG_DEBUG in ('Y', 'C') THEN
875 arp_util.debug('Get_Site_Use_Id: ' || 'No_data_found : Site use id could not be defaulted for customer_id '||to_char(p_customer_id));
876 END IF;
877 --This is the case where customer site use id is null
878 --neither it was supplied by the user nor it could be defaulted
879 --a WARNING message raised in the validation routine to indicate
880 --that the customer site use id could not be defaulted.
881 null;
882 END;
883
884 END IF;
885 END IF;
886 /* Add_Site_Use_To_Cache(
887 p_customer_id,
888 p_location,
889 p_site_use_code,
890 l_selected_id,
891 NVL( l_index, 0 ) + 1
892 );
893 RETURN( l_selected_id );
894
895 END IF;
896 END IF;
897 */
898 RETURN( l_selected_id );
899 EXCEPTION
900 WHEN others THEN
901 IF PG_DEBUG in ('Y', 'C') THEN
902 arp_util.debug('EXCEPTION: Get_Site_Use_Id.');
903 END IF;
904 raise;
905
906 END Get_Site_Use_Id;
907
908 FUNCTION Get_Cross_Validated_Id( p_entity IN VARCHAR2,
909 p_number_value IN VARCHAR2,
910 p_name_value IN VARCHAR2,
911 p_return_status OUT NOCOPY VARCHAR2
912 ) RETURN VARCHAR2 IS
913 l_id_from_name VARCHAR2(100);
914 l_id_from_num VARCHAR2(100);
915 BEGIN
916
917 IF (p_number_value IS NULL) OR
918 (p_name_value IS NULL)
919 THEN
920 RETURN(NULL);
921 END IF;
922
923 p_return_status := FND_API.G_RET_STS_SUCCESS;
924
925 l_id_from_name := Get_Id(p_entity||'_NAME',
926 p_name_value,
927 p_return_status
928 );
929
930 l_id_from_num := Get_Id(p_entity||'_NUMBER',
931 p_number_value,
932 p_return_status
933 );
934
935 IF l_id_from_name = l_id_from_num THEN
936 RETURN(l_id_from_name);
937 ELSE
938 --p_return_status := FND_API.G_RET_STS_ERROR;
939 --FND_MESSAGE.SET_NAME('AR', 'INVALID_VALUE_ERR');
940 --FND_MESSAGE.SET_TOKEN('PARAMETER','Customer Number/Name');
941 --FND_MSG_PUB.Add;
942 RETURN(NULL);
943 END IF;
944
945 EXCEPTION
946 WHEN others THEN
947 IF PG_DEBUG in ('Y', 'C') THEN
948 arp_util.debug('EXCEPTION: Get_Cross_Validated_Id() '||p_entity);
949 END IF;
950 raise;
951 END Get_Cross_Validated_Id;
952
953 PROCEDURE Add_Method_Info_To_Cache( p_method_info_record IN OUT NOCOPY Method_Info_Cache_Rec_Type,
954 p_index BINARY_INTEGER ) IS
955
956 l_index BINARY_INTEGER;
957 BEGIN
958
959 IF PG_DEBUG in ('Y', 'C') THEN
960 arp_util.debug('Add_Method_Info_To_Cache()+ ');
961 END IF;
962 IF p_index IS NULL THEN
963 l_index := nvl(Method_Info_Cache_Tbl.LAST,0) + 1;
964 END IF;
965
966 IF ( l_index <= G_METHOD_INFO_CACHE_SIZE ) THEN
967
968 Method_Info_Cache_Tbl(l_index) := p_method_info_record;
969
970 IF PG_DEBUG in ('Y', 'C') THEN
971 arp_util.debug('Added the record at index '|| l_index);
972 END IF;
973 END IF;
974
975 IF PG_DEBUG in ('Y', 'C') THEN
976 arp_util.debug('Add_Method_Info_To_Cache()- ');
977 END IF;
978
979 EXCEPTION
980
981 WHEN OTHERS THEN
982 IF PG_DEBUG in ('Y', 'C') THEN
983 arp_util.debug('EXCEPTION: Add_Method_Info_To_Cache');
984 END IF;
985 RAISE;
986 END Add_Method_Info_To_Cache;
987
988
989 PROCEDURE Get_Method_Info_From_Cache(
990 p_method_info_record IN OUT NOCOPY Method_Info_Cache_Rec_Type,
991 p_receipt_date IN ar_cash_receipts.receipt_date%TYPE ) IS
992 l_count BINARY_INTEGER;
993 l_index_curr BINARY_INTEGER;
994
995 BEGIN
996 IF PG_DEBUG in ('Y', 'C') THEN
997 arp_util.debug('Get_Method_Info_From_Cache ()+ ');
998 END IF;
999
1000 l_count := Method_Info_Cache_Tbl.count;
1001
1002 IF l_count IS NOT NULL THEN
1003 --If The Record Exists In Cache,Then Set The Values To Out Params And
1004 -- Return From The Procedure
1005 For L_index In 1..L_count Loop
1006
1007 If ( Method_info_cache_tbl(L_index).Receipt_method_id = P_method_info_record.Receipt_method_id And
1008 Method_info_cache_tbl(L_index).Currency_code = Nvl(P_method_info_record.Currency_code,'0') And
1009 Method_info_cache_tbl(L_index).Called_from = P_method_info_record.Called_from And
1010 Nvl(Method_info_cache_tbl(L_index).Bau_end_date,P_receipt_date +1) > P_receipt_date And
1011 ( P_receipt_date Between Method_info_cache_tbl(L_index).Rm_start_date And
1012 Nvl( Method_info_cache_tbl(L_index).Rm_end_date, P_receipt_date)) And
1013 ( P_receipt_date Between Method_info_cache_tbl(L_index).Rma_start_date And
1014 Nvl(Method_info_cache_tbl(L_index).Rma_end_date, P_receipt_date ) ) ) Then
1015 P_method_info_record := Method_info_cache_tbl(L_index);
1016
1017 If Pg_debug In ('y', 'c') Then
1018 Arp_util.Debug('found The Record In Cache ');
1019 End If;
1020 Exit;
1021 End If;
1022 End Loop;
1023 END IF;
1024
1025 IF PG_DEBUG in ('Y', 'C') THEN
1026 arp_util.debug('Get_Method_Info_From_Cache ()- ');
1027 END IF;
1028
1029 EXCEPTION
1030 WHEN others THEN
1031 IF PG_DEBUG in ('Y', 'C') THEN
1032 arp_util.debug('EXCEPTION: Get_Method_Info_From_Cache() ');
1033 END IF;
1034 raise;
1035 END Get_Method_Info_From_Cache;
1036
1037
1038 PROCEDURE Add_Exchange_Rate_To_Cache(
1039 p_currency_code IN ar_cash_receipts.currency_code%TYPE,
1040 p_exchange_rate_date IN ar_cash_receipts.exchange_date%TYPE,
1041 p_exchange_rate_type IN ar_cash_receipts.exchange_rate_type%TYPE,
1042 p_exchange_rate IN ar_cash_receipts.exchange_rate%TYPE,
1043 p_index IN BINARY_INTEGER
1044 ) IS
1045 BEGIN
1046
1047 IF PG_DEBUG in ('Y', 'C') THEN
1048 arp_util.debug('Add_Exchange_Rate_To_Cache()+ ');
1049 END IF;
1050
1051
1052 IF ( p_index <= G_EXCHANGE_RATE_CACHE_SIZE )
1053 THEN
1054 Exchange_Rate_Cache_Tbl(p_index).exchange_rate :=
1055 p_exchange_rate;
1056 Exchange_Rate_Cache_Tbl(p_index).currency :=
1057 p_currency_code;
1058 Exchange_Rate_Cache_Tbl(p_index).exchange_rate_type :=
1059 p_exchange_rate_type;
1060 Exchange_Rate_Cache_Tbl(p_index).exchange_date :=
1061 p_exchange_rate_date;
1062 END IF;
1063
1064 IF PG_DEBUG in ('Y', 'C') THEN
1065 arp_util.debug('Add_Exchange_Rate_To_Cache()- ');
1066 END IF;
1067
1068 EXCEPTION
1069
1070 WHEN OTHERS THEN
1071 IF PG_DEBUG in ('Y', 'C') THEN
1072 arp_util.debug('EXCEPTION: Add_Exchange_Rate_To_Cache');
1073 END IF;
1074
1075 RAISE;
1076
1077 END Add_Exchange_Rate_To_Cache;
1078
1079 PROCEDURE Default_gl_date(p_entered_date IN DATE,
1080 p_gl_date OUT NOCOPY DATE,
1081 p_validation_date IN DATE, /* Bug fix 3547720 */
1082 p_return_status OUT NOCOPY VARCHAR2) IS
1083 l_error_message VARCHAR2(128);
1084 l_defaulting_rule_used VARCHAR2(100);
1085 l_default_gl_date DATE;
1086 BEGIN
1087 p_return_status := FND_API.G_RET_STS_SUCCESS;
1088 IF PG_DEBUG in ('Y', 'C') THEN
1089 arp_util.debug('Default_gl_date ()+');
1090 END IF;
1091 IF p_gl_date IS NULL THEN
1092 IF (arp_util.validate_and_default_gl_date(
1093 p_entered_date,
1094 NULL,
1095 p_validation_date, /* Bug fix 3547720 */
1096 NULL,
1097 NULL,
1098 p_entered_date,
1099 NULL,
1100 NULL,
1101 'N',
1102 NULL,
1103 arp_global.set_of_books_id,
1104 222,
1105 l_default_gl_date,
1106 l_defaulting_rule_used,
1107 l_error_message) = TRUE)
1108 THEN
1109 p_gl_date := l_default_gl_date;
1110 IF PG_DEBUG in ('Y', 'C') THEN
1111 arp_util.debug('Default_gl_date: ' || 'Defaulted GL Date : '||to_char(p_gl_date,'DD-MON-YYYY'));
1112 END IF;
1113 ELSE
1114 IF PG_DEBUG in ('Y', 'C') THEN
1115 arp_util.debug('Default_gl_date: ' || 'GL Date could not be defaulted ');
1116 END IF;
1117 -- Raise error message if failure in defaulting the gl_date
1118 FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
1119 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', l_error_message);
1120 FND_MSG_PUB.Add;
1121 p_return_status := FND_API.G_RET_STS_ERROR;
1122 END IF;
1123 END IF;
1124 IF PG_DEBUG in ('Y', 'C') THEN
1125 arp_util.debug('Default_gl_date ()-');
1126 END IF;
1127 END default_gl_date;
1128
1129
1130 FUNCTION Find_Cached_Exchange_Rate(
1131 p_currency_code IN ar_cash_receipts.currency_code%TYPE,
1132 p_exchange_rate_date IN ar_cash_receipts.exchange_date%TYPE,
1133 p_exchange_rate_type IN ar_cash_receipts.exchange_rate_type%TYPE
1134 ) RETURN NUMBER IS
1135 l_count BINARY_INTEGER;
1136 l_index_curr BINARY_INTEGER;
1137 l_exchange_rate NUMBER;
1138 l_set_of_books_id NUMBER := arp_global.set_of_books_id;
1139 l_functional_currency VARCHAR2(100) := arp_global.functional_currency;
1140 BEGIN
1141 IF PG_DEBUG in ('Y', 'C') THEN
1142 arp_util.debug('Find_Cached_Exchange_Rate ()+');
1143 END IF;
1144 IF (p_currency_code IS NOT NULL) AND
1145 (p_currency_code <> l_functional_currency) AND
1146 (p_exchange_rate_date IS NOT NULL) AND
1147 (p_exchange_rate_type IS NOT NULL) AND
1148 (p_exchange_rate_type <>'User')
1149 THEN
1150 -- This section of code is commented out NOCOPY as the implementation of the
1151 -- of the caching mechanism has been deferred as of now
1152 /*
1153 l_count := Exchange_Rate_Cache_Tbl.count;
1154
1155 FOR l_index IN 1..l_count LOOP
1156
1157 l_index_curr := l_index;
1158
1159 IF (Exchange_Rate_Cache_Tbl(l_index).currency = p_currency_code AND
1160 Exchange_Rate_Cache_Tbl(l_index).exchange_rate_type = p_exchange_rate_type AND
1161 Exchange_Rate_Cache_Tbl(l_index).exchange_date = p_exchange_rate_date)
1162 THEN
1163 RETURN(Exchange_Rate_Cache_Tbl(l_index).exchange_rate);
1164 END IF;
1165
1166 END LOOP;
1167
1168 --the rate is not in the cache so get it from the database.
1169 */
1170 l_exchange_rate := gl_currency_api.get_rate(
1171 l_set_of_books_id,
1172 p_currency_code,
1173 p_exchange_rate_date,
1174 p_exchange_rate_type
1175 );
1176 /*
1177 Add_Exchange_Rate_To_Cache(
1178 p_currency_code,
1179 p_exchange_rate_date,
1180 p_exchange_rate_type,
1181 l_exchange_rate,
1182 NVL( l_index_curr, 0 ) + 1
1183 );
1184 */
1185 END IF;
1186 RETURN( l_exchange_rate );
1187 IF PG_DEBUG in ('Y', 'C') THEN
1188 arp_util.debug('Find_Cached_Exchange_Rate ()-');
1189 END IF;
1190 EXCEPTION
1191 WHEN gl_currency_api.NO_RATE THEN
1192 --rate does not exist set appropriate message.
1193 --p_return_status := FND_API.G_RET_STS_ERROR ;
1194 return(null);
1195 IF PG_DEBUG in ('Y', 'C') THEN
1196 arp_util.debug('Find_Cached_Exchange_Rate: ' || 'Exception : gl_currency_api.NO_RATE ');
1197 END IF;
1198 WHEN gl_currency_api.INVALID_CURRENCY THEN
1199 -- invalid currency set appropriate message.
1200 --p_return_status := FND_API.G_RET_STS_ERROR ;
1201 return(null);
1202 IF PG_DEBUG in ('Y', 'C') THEN
1203 arp_util.debug('Find_Cached_Exchange_Rate: ' || 'Exception: gl_currency_api.INVALID_CURRENCY ');
1204 END IF;
1205 WHEN others THEN
1206 IF PG_DEBUG in ('Y', 'C') THEN
1207 arp_util.debug('EXCEPTION: Find_Cached_Exchange_Rate() ');
1208 END IF;
1209 raise;
1210 END Find_Cached_Exchange_Rate;
1211
1212 PROCEDURE Default_Receipt_Method_Info(
1213 p_receipt_method_id IN ar_cash_receipts.receipt_method_id%TYPE,
1214 p_currency_code IN ar_cash_receipts.currency_code%TYPE,
1215 p_receipt_date IN ar_cash_receipts.receipt_date%TYPE,
1216 p_remittance_bank_account_id IN OUT NOCOPY ar_receipt_method_accounts_all.remit_bank_acct_use_id%TYPE,
1217 p_state OUT NOCOPY ar_receipt_classes.creation_status%TYPE,
1218 p_creation_method_code OUT NOCOPY ar_receipt_classes.creation_method_code%TYPE,
1219 p_called_from IN VARCHAR2,
1220 p_return_status OUT NOCOPY VARCHAR2
1221 ) IS
1222 /*Bug 3518573 changing the logic to pick default remittance bank account */
1223 CURSOR get_remit_bank_acct_id(
1224 p_currency_code ar_cash_receipts.currency_code%TYPE,
1225 p_receipt_date ar_cash_receipts.receipt_date%TYPE,
1226 p_called_from VARCHAR2,
1227 p_receipt_method_id ar_cash_receipts.receipt_method_id%TYPE) is
1228 SELECT ba.bank_acct_use_id,
1229 rc.creation_status,
1230 rc.creation_method_code,
1231 rma.start_date rma_start_date,
1232 rma.end_date rma_end_date,
1233 rm.start_date rm_start_date,
1234 rm.end_date rm_end_date,
1235 ba.end_Date bau_end_date
1236 FROM ar_receipt_methods rm,
1237 ce_bank_accounts cba,
1238 ce_bank_acct_uses ba,
1239 ar_receipt_method_accounts rma ,
1240 ar_receipt_classes rc
1241 WHERE rm.receipt_method_id = p_receipt_method_id
1242 and (p_receipt_date
1243 between
1244 rm.start_date and
1245 nvl(rm.end_date, p_receipt_date))
1246 and ((rc.creation_method_code = DECODE(p_called_from,'BR_REMITTED','BR_REMIT',
1247 'BR_FACTORED_WITH_RECOURSE','BR_REMIT',
1248 'BR_FACTORED_WITHOUT_RECOURSE','BR_REMIT','@*%?&')) or
1249 (rc.creation_method_code = 'MANUAL') or
1250 (rc.creation_method_code = 'AUTOMATIC'
1251 --and rc.remit_flag = 'Y'
1252 -- OSTEINME 2/27/2001: removed remit_flag
1253 -- condition for iReceivables CC functionality.
1254 -- See bug 1659109.
1255 -- bichatte autorecapi.
1256 and rc.confirm_flag = decode(p_called_from, 'AUTORECAPI',rc.confirm_flag,'N')))
1257 and cba.account_classification = 'INTERNAL'
1258 and nvl(ba.end_date, p_receipt_date +1) > p_receipt_date
1259 and p_receipt_date
1260 between
1261 rma.start_date and
1262 nvl(rma.end_date, p_receipt_date)
1263 and cba.currency_code = decode(cba.receipt_multi_currency_flag, 'Y',
1264 cba.currency_code, p_currency_code)
1265 and rc.receipt_class_id = rm.receipt_class_id
1266 and rm.receipt_method_id = rma.receipt_method_id
1267 and rma.remit_bank_acct_use_id = ba.bank_acct_use_id
1268 and ba.bank_account_id = cba.bank_account_id
1269 --APANDIT: changes made for the misc receipt creation api.
1270 and ((nvl(p_called_from,'*$') <> 'MISC')
1271 or
1272 (rm.receipt_class_id not in (
1273 select arc.receipt_class_id
1274 from ar_receipt_classes arc
1275 where arc.notes_receivable='Y'
1276 or arc.bill_of_exchange_flag='Y')))
1277 order by
1278 decode(rma.primary_flag,'Y',1,'N',2,3),
1279 decode(cba.currency_code,p_currency_code,1,2),
1280 cba.bank_branch_id,
1281 cba.bank_account_name,
1282 ba.bank_acct_use_id;
1283
1284 l_method_info_record Method_Info_Cache_Rec_Type;
1285
1286 BEGIN
1287 IF PG_DEBUG in ('Y', 'C') THEN
1288 arp_util.debug('Default_Receipt_Method_Info ()+');
1289 END IF;
1290
1291 p_return_status := FND_API.G_RET_STS_SUCCESS;
1292
1293 IF p_receipt_method_id IS NOT NULL THEN
1294
1295 IF p_remittance_bank_account_id IS NULL THEN
1296
1297 l_method_info_record.receipt_method_id := p_receipt_method_id;
1298 l_method_info_record.currency_code := p_currency_code;
1299 l_method_info_record.called_from := nvl(p_called_from,'@*%?&');
1300
1301 --check if it exists in cache
1302 Get_Method_Info_From_Cache( l_method_info_record,
1303 p_receipt_date );
1304
1305 IF l_method_info_record.remit_bank_acct_use_id IS NULL THEN
1306 OPEN get_remit_bank_acct_id(p_currency_code,p_receipt_date,p_called_from,p_receipt_method_id);
1307
1308 FETCH get_remit_bank_acct_id INTO
1309 l_method_info_record.remit_bank_acct_use_id,
1310 l_method_info_record.state,
1311 l_method_info_record.creation_method_code,
1312 l_method_info_record.rma_start_date,
1313 l_method_info_record.rma_end_date,
1314 l_method_info_record.rm_start_date,
1315 l_method_info_record.rm_end_date,
1316 l_method_info_record.bau_end_date;
1317
1318 IF get_remit_bank_acct_id%NOTFOUND then
1319 null;
1320 END IF;
1321 CLOSE get_remit_bank_acct_id;
1322
1323 --add it to cache
1324 Add_Method_Info_To_Cache( l_method_info_record,null);
1325 END IF;
1326
1327 p_remittance_bank_account_id := l_method_info_record.remit_bank_acct_use_id;
1328 p_state := l_method_info_record.state;
1329 p_creation_method_code := l_method_info_record.creation_method_code;
1330 ELSE
1331 --user has specified the remittance bank account id
1332 --so get the creation_status only.
1333
1334 SELECT rc.creation_status,
1335 rc.creation_method_code
1336 INTO p_state,
1337 p_creation_method_code
1338 FROM ar_receipt_classes rc,
1339 ar_receipt_methods rm
1340 WHERE rc.receipt_class_id = rm.receipt_class_id
1341 AND rm.receipt_method_id = p_receipt_method_id;
1342
1343 --the invalid error message will be raised in the
1344 --validation phase. We will check in the validation
1345 --phase that if p_state is null and method_id is not
1346 --null then method_id is invalid
1347 END IF;
1348 END IF;
1349
1350 IF PG_DEBUG in ('Y', 'C') THEN
1351 arp_util.debug('Default_Receipt_Method_Info ()-');
1352 END IF;
1353
1354 EXCEPTION
1355 WHEN no_data_found THEN
1356 --In the validation phase we will raise the relevant error
1357 --if either the p_state or remittance_bank_id is null
1358 null;
1359 WHEN too_many_rows THEN
1360 --This will happen only if the receipt method was specified
1361 --and we tried to default the remittance bank and the state
1362 p_return_status := FND_API.G_RET_STS_ERROR;
1363 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_ID_NULL');
1364 FND_MSG_PUB.Add;
1365 IF PG_DEBUG in ('Y', 'C') THEN
1366 arp_util.debug('Default_Receipt_Method_Info: ' || 'The remittance bank account could not be defaulted ');
1367 END IF;
1368 WHEN others THEN
1369 IF PG_DEBUG in ('Y', 'C') THEN
1370 arp_util.debug('EXCEPTION: Default_Receipt_Method_info() ');
1371 arp_util.debug('Default_Receipt_Method_Info: ' || 'p_receipt_method_id = '
1372 ||TO_CHAR(p_receipt_method_id));
1373 END IF;
1374 raise;
1375
1376 END Default_Receipt_Method_Info;
1377
1378 /* Bug3315058 */
1379 PROCEDURE validate_cc_segments(
1380 p_code_combination_id IN NUMBER,
1381 p_gl_date IN DATE,
1382 p_message IN VARCHAR2,
1383 p_return_status OUT NOCOPY VARCHAR2
1384 ) IS
1385 l_concat_segs varchar2(2000);
1386 l_value boolean := FALSE;
1387 l_chart_of_accounts_id gl_sets_of_books.chart_of_accounts_id%type;
1388 l_validation_date date ;
1389 BEGIN
1390 IF PG_DEBUG in ('Y', 'C') THEN
1391 arp_util.debug('validate_cc_segments ()+');
1392 END IF;
1393 p_return_status := FND_API.G_RET_STS_SUCCESS;
1394 l_validation_date := p_gl_date;
1395 l_chart_of_accounts_id := arp_global.chart_of_accounts_id;
1396 IF PG_DEBUG in ('Y', 'C') THEN
1397 arp_util.debug('l_chart_of_accounts_id = '||to_char(l_chart_of_accounts_id));
1398 END IF;
1399 l_concat_segs := fnd_flex_ext.get_segs('SQLGL','GL#',
1400 l_chart_of_accounts_id,
1401 p_code_combination_id);
1402 IF PG_DEBUG in ('Y', 'C') THEN
1403 arp_util.debug('l_concat_segs = '||l_concat_segs);
1404 END IF;
1405 l_value := FND_FLEX_KEYVAL.validate_segs('CHECK_SEGMENTS','SQLGL','GL#',
1406 l_chart_of_accounts_id,
1407 l_concat_segs,
1408 'V',l_validation_date);
1409 IF l_value THEN
1410 IF PG_DEBUG in ('Y', 'C') THEN
1411 arp_util.debug('Returning true');
1412 END IF;
1413 ELSE
1414 IF PG_DEBUG in ('Y', 'C') THEN
1415 arp_util.debug('Returning False');
1416 END IF;
1417 END IF;
1418 IF (NOT l_value) THEN
1419 FND_MESSAGE.SET_NAME('AR',p_message);
1420 FND_MSG_PUB.Add;
1421 p_return_status := FND_API.G_RET_STS_ERROR;
1422 END IF;
1423 END validate_cc_segments;
1424
1425 /* Bug fix 3315058
1426 Procedure which checks the validity of the different accounts of a payment method */
1427 PROCEDURE Validate_Receipt_Method_ccid(
1428 p_receipt_method_id IN ar_cash_receipts.receipt_method_id%TYPE ,
1429 p_remittance_bank_account_id IN ar_receipt_method_accounts_all.remit_bank_acct_use_id%TYPE,
1430 p_gl_date IN DATE,
1431 p_return_status OUT NOCOPY VARCHAR2
1432 )IS
1433 l_receipt_method_id ar_receipt_methods.receipt_method_id%type;
1434 l_remit_bank_account_id ar_receipt_method_accounts.remit_bank_acct_use_id%type;
1435 l_cash_ccid gl_code_combinations.code_combination_id%type;
1436 l_earned_ccid gl_code_combinations.code_combination_id%type;
1437 l_on_account_ccid gl_code_combinations.code_combination_id%type;
1438 l_unapplied_ccid gl_code_combinations.code_combination_id%type;
1439 l_unearned_ccid gl_code_combinations.code_combination_id%type;
1440 l_unidentified_ccid gl_code_combinations.code_combination_id%type;
1441 l_bank_charges_ccid gl_code_combinations.code_combination_id%type;
1442 l_factor_ccid gl_code_combinations.code_combination_id%type;
1443 l_remittance_ccid gl_code_combinations.code_combination_id%type;
1444 l_receipt_clearing_ccid gl_code_combinations.code_combination_id%type;
1445 l_short_term_debt_ccid gl_code_combinations.code_combination_id%type;
1446 l_message varchar2(100);
1447 l_gl_date DATE;
1448 l_cc_val_ret_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
1449 BEGIN
1450 IF PG_DEBUG in ('Y', 'C') THEN
1451 arp_util.debug('Validate_Receipt_Method_ccid ()+');
1452 END IF;
1453 p_return_status := FND_API.G_RET_STS_SUCCESS;
1454 l_gl_date := p_gl_date;
1455 IF p_receipt_method_id IS NOT NULL
1456 AND p_remittance_bank_account_id IS NOT NULL THEN
1457 SELECT rma.cash_ccid,art1.code_combination_id,rma.on_account_ccid,
1458 rma.unapplied_ccid,art2.code_combination_id,rma.unidentified_ccid,
1459 rma.bank_charges_ccid,rma.factor_ccid,rma.remittance_ccid,
1460 rma.receipt_clearing_ccid, rma.short_term_debt_ccid
1461 INTO l_cash_ccid,l_earned_ccid,l_on_account_ccid,
1462 l_unapplied_ccid,l_unearned_ccid,l_unidentified_ccid,
1463 l_bank_charges_ccid,l_factor_ccid,l_remittance_ccid,
1464 l_receipt_clearing_ccid,l_short_term_debt_ccid
1465 FROM ar_receipt_method_accounts rma,
1466 ar_receivables_trx art1, ar_receivables_trx art2
1467 WHERE remit_bank_acct_use_id = p_remittance_bank_account_id
1468 AND receipt_method_id = p_receipt_method_id
1469 AND art1.receivables_trx_id = rma.edisc_receivables_trx_id
1470 AND art2.receivables_trx_id = rma.unedisc_receivables_trx_id;
1471 END IF;
1472
1473 IF l_cash_ccid IS NOT NULL THEN
1474 l_message := 'AR_CASH_ACC_ASSGN';
1475 validate_cc_segments(l_cash_ccid,l_gl_date,
1476 l_message,l_cc_val_ret_status);
1477 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1478 p_return_status := FND_API.G_RET_STS_ERROR;
1479 RETURN;
1480 END IF;
1481 END IF;
1482
1483 IF l_earned_ccid IS NOT NULL THEN
1484 l_message := 'AR_EARN_DISC_ACC_ASSGN';
1485 validate_cc_segments(l_earned_ccid,l_gl_date,
1486 l_message,l_cc_val_ret_status);
1487 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1488 p_return_status := FND_API.G_RET_STS_ERROR;
1489 RETURN;
1490 END IF;
1491 END IF;
1492
1493 IF l_on_account_ccid IS NOT NULL THEN
1494 l_message := 'AR_ONACC_ACC_ASSGN';
1495 validate_cc_segments(l_on_account_ccid,l_gl_date,
1496 l_message,l_cc_val_ret_status);
1497 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1498 p_return_status := FND_API.G_RET_STS_ERROR;
1499 RETURN;
1500 END IF;
1501 END IF;
1502 IF l_unapplied_ccid IS NOT NULL THEN
1503 l_message := 'AR_UNAPP_ACC_ASSGN';
1504 validate_cc_segments(l_unapplied_ccid,l_gl_date,
1505 l_message,l_cc_val_ret_status);
1506 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1507 p_return_status := FND_API.G_RET_STS_ERROR;
1508 RETURN;
1509 END IF;
1510 END IF;
1511
1512 IF l_unearned_ccid IS NOT NULL THEN
1513 l_message := 'AR_UNEARN_DISC_ACC_ASSGN';
1514 validate_cc_segments(l_unearned_ccid,l_gl_date,
1515 l_message,l_cc_val_ret_status);
1516 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1517 p_return_status := FND_API.G_RET_STS_ERROR;
1518 RETURN;
1519 END IF;
1520 END IF;
1521 IF l_unidentified_ccid IS NOT NULL THEN
1522 l_message := 'AR_UNIDEN_ACC_ASSGN';
1523 validate_cc_segments(l_unidentified_ccid,l_gl_date,
1524 l_message,l_cc_val_ret_status);
1525 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1526 p_return_status := FND_API.G_RET_STS_ERROR;
1527 RETURN;
1528 END IF;
1529 END IF;
1530 IF l_bank_charges_ccid IS NOT NULL THEN
1531 l_message := 'AR_BANK_CHRG_ACC_ASSGN';
1532 validate_cc_segments(l_bank_charges_ccid,l_gl_date,
1533 l_message,l_cc_val_ret_status);
1534 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1535 p_return_status := FND_API.G_RET_STS_ERROR;
1536 RETURN;
1537 END IF;
1538 END IF;
1539
1540 IF l_factor_ccid IS NOT NULL THEN
1541 l_message := 'AR_FCTR_ACC_ASSGN';
1542 validate_cc_segments(l_factor_ccid,l_gl_date,
1543 l_message,l_cc_val_ret_status);
1544 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1545 p_return_status := FND_API.G_RET_STS_ERROR;
1546 RETURN;
1547 END IF;
1548 END IF;
1549
1550 IF l_remittance_ccid IS NOT NULL THEN
1551 l_message := 'AR_REM_ACC_ASSGN';
1552 validate_cc_segments(l_remittance_ccid,l_gl_date,
1553 l_message,l_cc_val_ret_status);
1554 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1555 p_return_status := FND_API.G_RET_STS_ERROR;
1556 RETURN;
1557 END IF;
1558 END IF;
1559 IF l_receipt_clearing_ccid IS NOT NULL THEN
1560 l_message := 'AR_CLRNCE_ACC_ASSGN';
1561 validate_cc_segments(l_receipt_clearing_ccid,l_gl_date,
1562 l_message,l_cc_val_ret_status);
1563 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1564 p_return_status := FND_API.G_RET_STS_ERROR;
1565 RETURN;
1566 END IF;
1567 END IF;
1568
1569 IF l_short_term_debt_ccid IS NOT NULL THEN
1570 l_message := 'AR_SHRT_TERM_DEBT_ACC_ASSGN';
1571 validate_cc_segments(l_short_term_debt_ccid,l_gl_date,
1572 l_message,l_cc_val_ret_status);
1573 IF l_cc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN
1574 p_return_status := FND_API.G_RET_STS_ERROR;
1575 RETURN;
1576 END IF;
1577 END IF;
1578 END Validate_Receipt_Method_ccid;
1579 /* End bug fix 3315058 */
1580
1581 FUNCTION Get_cross_rate (p_from_currency IN VARCHAR2,
1582 p_to_currency IN VARCHAR2,
1583 p_exchange_rate_date IN DATE,
1584 p_exchange_rate IN NUMBER
1585 ) RETURN NUMBER IS
1586 l_euro_to_emu_rate NUMBER;
1587 l_fixed_rate BOOLEAN;
1588 l_relationship VARCHAR2(50);
1589 euro_code VARCHAR2(15);
1590 l_cross_rate NUMBER;
1591 BEGIN
1592
1593 gl_currency_api.get_relation(
1594 p_from_currency,
1595 p_to_currency,
1596 trunc(p_exchange_rate_date),
1597 l_fixed_rate,
1598 l_relationship);
1599 euro_code := gl_currency_api.get_euro_code;
1600
1601 IF (l_relationship = 'EMU-OTHER') THEN
1602 l_euro_to_emu_rate :=
1603 gl_currency_api.get_rate(
1604 euro_code,
1605 p_from_currency,
1606 trunc(p_exchange_rate_date),
1607 NULL);
1608 ELSIF (l_relationship = 'OTHER-EMU') THEN
1609 l_euro_to_emu_rate :=
1610 gl_currency_api.get_rate(
1611 euro_code,
1612 p_to_currency,
1613 trunc(p_exchange_rate_date),
1614 NULL);
1615 ELSE
1616 RAISE gl_euro_user_rate_api.INVALID_RELATION;
1617 END IF;
1618 l_cross_rate :=
1619 gl_euro_user_rate_api.get_cross_rate(p_from_currency,
1620 p_to_currency,
1621 p_exchange_rate_date,
1622 p_exchange_rate,
1623 l_euro_to_emu_rate);
1624 return(l_cross_rate);
1625 EXCEPTION
1626 WHEN gl_euro_user_rate_api.INVALID_RELATION THEN
1627 null;
1628 WHEN gl_euro_user_rate_api.INVALID_CURRENCY THEN
1629 null;
1630 WHEN others THEN
1631 raise;
1632 END Get_cross_rate;
1633
1634 PROCEDURE Default_Currency_info(
1635 p_currency_code IN OUT NOCOPY ar_cash_receipts.currency_code%TYPE,
1636 p_receipt_date IN OUT NOCOPY ar_cash_receipts.receipt_date%TYPE,
1637 p_exchange_rate_date IN OUT NOCOPY ar_cash_receipts.exchange_date%TYPE,
1638 p_exchange_rate_type IN OUT NOCOPY ar_cash_receipts.exchange_rate_type%TYPE,
1639 p_exchange_rate IN OUT NOCOPY ar_cash_receipts.exchange_rate%TYPE,
1640 p_return_status OUT NOCOPY VARCHAR2
1641 ) IS
1642
1643 l_euro_to_emu_rate NUMBER;
1644 l_euro_to_other_prompt VARCHAR2(30);
1645 l_euro_to_emu_prompt VARCHAR2(30);
1646 l_emu_to_other_prompt VARCHAR2(30);
1647 l_cross_rate NUMBER;
1648 l_conversion_rate NUMBER;
1649 BEGIN
1650 IF PG_DEBUG in ('Y', 'C') THEN
1651 arp_util.debug('Default_Currency_info ()+');
1652 END IF;
1653 p_return_status := FND_API.G_RET_STS_SUCCESS;
1654
1655 IF p_currency_code <> arp_global.functional_currency THEN
1656
1657 --default exchange rate date if null
1658 IF (p_exchange_rate_date IS NULL) THEN
1659 p_exchange_rate_date := p_receipt_date;
1660 END IF;
1661
1662 --default exchange rate type if null
1663 IF p_exchange_rate_type IS NULL THEN
1664 p_exchange_rate_type := pg_profile_def_x_rate_type;
1665 END IF;
1666
1667 IF p_exchange_rate_type IS NOT NULL THEN
1668
1669 IF p_exchange_rate_type <> 'User' THEN
1670 --for any exchange_rate type other than 'User',
1671 --default exchange rate if not entered.
1672 IF p_exchange_rate IS NULL THEN
1673 p_exchange_rate := Find_Cached_Exchange_Rate(
1674 p_currency_code,
1675 p_exchange_rate_date,
1676 p_exchange_rate_type
1677 );
1678 ELSE
1679 --if user has entered exchange rate for type <> User, raise error message
1680 p_return_status := FND_API.G_RET_STS_ERROR;
1681 FND_MESSAGE.SET_NAME('AR','AR_RAPI_X_RATE_INVALID');
1682 FND_MSG_PUB.Add;
1683 END IF;
1684 ELSE
1685 --case where rate_type is 'User'
1686
1687 --if the user entered exchange rate is greater than 0 then
1688 --check for the case of EMU currency
1689 IF p_exchange_rate >0 THEN
1690
1691 --This is the case rate_type is User and exchange_rate exists
1692
1693 -- Returns 'Y' if the current conversion type is User AND
1694 -- they are converting from EMU -> OTHER or OTHER -> EMU AND
1695 -- they are not allowed to enter EMU -> OTHER and
1696 -- OTHER -> EMU rates directly
1697 -- Returns 'N' Otherwise
1698
1699 IF (gl_euro_user_rate_api.is_cross_rate(p_currency_code,
1700 arp_global.functional_currency,
1701 p_exchange_rate_date,
1702 p_exchange_rate_type) = 'Y')
1703 THEN
1704
1705 gl_euro_user_rate_api.get_prompts_and_rate(
1706 p_currency_code,
1707 arp_global.functional_currency,
1708 p_exchange_rate_date,
1709 l_euro_to_other_prompt,
1710 l_euro_to_emu_prompt,
1711 l_emu_to_other_prompt,
1712 l_euro_to_emu_rate);
1713
1714 l_cross_rate :=
1715 gl_euro_user_rate_api.get_cross_rate(
1716 p_currency_code,
1717 p_currency_code,
1718 p_exchange_rate_date,
1719 p_exchange_rate,
1720 l_euro_to_emu_rate);
1721
1722 p_exchange_rate := l_cross_rate;
1723 ELSE
1724 -- case where gl_euro_user_rate_api.is_cross_rate = 'N'
1725 -- here the exchange_rate is directly between the EMU and the non-EMU currency.
1726
1727 p_exchange_rate := round(p_exchange_rate,38);
1728
1729 END IF; --is_cross_rate
1730
1731 END IF; -- exchange_rate >0
1732
1733 END IF; --rate type <> 'User'
1734 END IF; --if echange rate type IS NOT NULL
1735 END IF; --entered_currency <> functional currency
1736
1737 IF PG_DEBUG in ('Y', 'C') THEN
1738 arp_util.debug('Default_Currency_info ()+');
1739 END IF;
1740 EXCEPTION
1741 WHEN others THEN
1742 IF PG_DEBUG in ('Y', 'C') THEN
1743 arp_util.debug('EXCEPTION: Default_Currency_Info() ');
1744 arp_util.debug('Default_Currency_info: ' || 'p_currency_code = '||p_currency_code);
1745 END IF;
1746 raise;
1747 END Default_Currency_Info;
1748
1749 /* modified for tca uptake */
1750 PROCEDURE Default_cash_ids(
1751 p_usr_currency_code IN fnd_currencies_vl.name%TYPE,
1752 p_usr_exchange_rate_type IN gl_daily_conversion_types.user_conversion_type%TYPE,
1753 p_customer_name IN hz_parties.party_name%TYPE,
1754 p_customer_number IN hz_cust_accounts.account_number%TYPE,
1755 p_location IN hz_cust_site_uses.location%type,
1756 p_receipt_method_name IN OUT NOCOPY ar_receipt_methods.name%TYPE,
1757 /* 6612301 */
1758 p_customer_bank_account_name IN iby_ext_bank_accounts_v.bank_account_name%TYPE,
1759 p_customer_bank_account_num IN iby_ext_bank_accounts_v.bank_account_number%TYPE,
1760 p_remittance_bank_account_name IN ce_bank_accounts.bank_account_name%TYPE,
1761 p_remittance_bank_account_num IN ce_bank_accounts.bank_account_num%TYPE,
1762 p_currency_code IN OUT NOCOPY ar_cash_receipts.currency_code%TYPE,
1763 p_exchange_rate_type IN OUT NOCOPY ar_cash_receipts.exchange_rate_type%TYPE,
1764 p_customer_id IN OUT NOCOPY ar_cash_receipts.pay_from_customer%TYPE,
1765 p_customer_site_use_id IN OUT NOCOPY hz_cust_site_uses.site_use_id%TYPE,
1766 p_receipt_method_id IN OUT NOCOPY ar_cash_receipts.receipt_method_id%TYPE,
1767 /* 6612301 */
1768 p_customer_bank_account_id IN OUT NOCOPY ar_cash_receipts.customer_bank_account_id%TYPE,
1769 p_customer_bank_branch_id IN OUT NOCOPY ar_cash_receipts.customer_bank_branch_id%TYPE,
1770 p_remittance_bank_account_id IN OUT NOCOPY ar_cash_receipts.remit_bank_acct_use_id%TYPE,
1771 p_receipt_date IN DATE,
1772 p_return_status OUT NOCOPY VARCHAR2,
1773 p_default_site_use IN VARCHAR2 --4448307-4509459
1774 )
1775 IS
1776 l_remittance_bank_account_id NUMBER;
1777 l_receipt_method_id NUMBER;
1778 l_customer_id NUMBER;
1779 l_return_status VARCHAR2(1);
1780 l_get_id_return_status VARCHAR2(1);
1781 l_get_x_val_return_status VARCHAR2(1);
1782 l_boe_flag VARCHAR2(1);
1783 BEGIN
1784 IF PG_DEBUG in ('Y', 'C') THEN
1785 arp_util.debug('Default_cash_ids_from_values ()+');
1786 END IF;
1787 p_return_status := FND_API.G_RET_STS_SUCCESS;
1788 -- Customer ID/Number/Name
1789 -- If 0 has been entered in as the customer ID, consider it null
1790 IF (NVL(p_customer_id,0) = 0)
1791 THEN
1792 IF(p_customer_name IS NOT NULL) and
1793 (p_customer_number IS NULL)
1794 THEN
1795 p_customer_id := Get_Id('CUSTOMER_NAME',
1796 p_customer_name,
1797 l_get_id_return_status);
1798 IF p_customer_id IS NULL THEN
1799 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_NAME_INVALID');
1800 FND_MSG_PUB.Add;
1801 p_return_status := FND_API.G_RET_STS_ERROR;
1802 END IF;
1803
1804 ELSIF(p_customer_name IS NULL) and
1805 (p_customer_number IS NOT NULL)
1806 THEN
1807 p_customer_id := Get_Id( 'CUSTOMER_NUMBER',
1808 p_customer_number,
1809 l_get_id_return_status);
1810 IF p_customer_id IS NULL THEN
1811 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_NUM_INVALID');
1812 FND_MSG_PUB.Add;
1813 p_return_status := FND_API.G_RET_STS_ERROR;
1814 END IF;
1815
1816 ELSIF(p_customer_name IS NOT NULL) and
1817 (p_customer_number IS NOT NULL)
1818 THEN
1819 p_customer_id := Get_Cross_Validated_Id( 'CUSTOMER',
1820 p_customer_number,
1821 p_customer_name,
1822 l_get_x_val_return_status);
1823 IF p_customer_id IS NULL THEN
1824 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_NAME_NUM_INVALID');
1825 FND_MSG_PUB.Add;
1826 p_return_status := FND_API.G_RET_STS_ERROR;
1827 END IF;
1828 END IF;
1829
1830 ELSE
1831 --In case the ID has been entered by the user
1832 IF (p_customer_name IS NOT NULL) OR
1833 (p_customer_number IS NOT NULL) THEN
1834 --give a warning message to indicate that the customer_number and customer_name
1835 --entered by the user have been ignored.
1836 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
1837 THEN
1838 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_NAME_NUM_IGN');
1839 FND_MSG_PUB.Add;
1840 p_return_status := FND_API.G_RET_STS_ERROR;
1841 END IF;
1842 END IF;
1843
1844
1845 END IF;
1846
1847 --Customer site use id
1848 /*
1849 IF p_customer_id IS NOT NULL THEN
1850 IF p_customer_site_use_id IS NULL THEN
1851
1852 p_customer_site_use_id := Get_Site_Use_Id(p_customer_id,
1853 p_location,
1854 'BILL_TO',
1855 'DRAWEE' --added drawee for bug 1420529
1856 );
1857 ELSE
1858 IF p_location IS NOT NULL THEN
1859 --raise warning that
1860 null;
1861 END IF;
1862 END IF;
1863 END IF;
1864 */
1865
1866
1867 /*bug4448307-4509459*/
1868 IF p_customer_id IS NOT NULL THEN
1869 IF arp_global.sysparam.site_required_flag = 'Y' THEN
1870
1871 IF p_customer_site_use_id IS NULL THEN
1872
1873 p_customer_site_use_id := Get_Site_Use_Id(p_customer_id,
1874 p_location,
1875 'BILL_TO',
1876 'DRAWEE' --added drawee for bug 1420529
1877 );
1878 END IF;
1879 ELSE
1880 IF p_default_site_use = 'Y' THEN
1881 IF p_customer_site_use_id IS NULL THEN
1882
1883 p_customer_site_use_id := Get_Site_Use_Id(p_customer_id,
1884 p_location,
1885 'BILL_TO',
1886 'DRAWEE' --added drawee for bug 1420529
1887 );
1888 END IF;
1889 ELSE
1890 null;
1891 END IF;
1892 END IF;
1893 END IF;
1894 /*bug4448307-4509459*/
1895
1896
1897 --Receipt method ID,Name
1898 IF p_receipt_method_id IS NULL
1899 THEN
1900 IF p_receipt_method_name IS NOT NULL THEN
1901 p_receipt_method_id := Get_Id('RECEIPT_METHOD_NAME',
1902 p_receipt_method_name,
1903 l_get_id_return_status
1904 );
1905 IF p_receipt_method_id IS NULL THEN
1906 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_MD_NAME_INVALID');
1907 FND_MSG_PUB.Add;
1908 p_return_status := FND_API.G_RET_STS_ERROR;
1909 ELSE
1910 l_boe_flag := arpt_sql_func_util.check_BOE_Paymeth(p_receipt_method_id);
1911 if l_boe_flag = 'Y' then
1912 FND_MESSAGE.SET_NAME('AR','AR_BOE_OBSOLETE');
1913 FND_MSG_PUB.Add;
1914 p_return_status := FND_API.G_RET_STS_ERROR;
1915 end if;
1916 END IF;
1917 END IF;
1918 ELSE
1919 IF (p_receipt_method_name IS NOT NULL) THEN
1920 --give a warning message to indicate that the receipt_method_name
1921 --entered by the user has been ignored.
1922 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
1923 THEN
1924 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_MD_NAME_IGN');
1925 FND_MSG_PUB.Add;
1926 END IF;
1927 ELSE
1928 BEGIN
1929 SELECT name
1930 INTO p_receipt_method_name
1931 FROM ar_receipt_methods
1932 WHERE receipt_method_id = p_receipt_method_id;
1933
1934 l_boe_flag := arpt_sql_func_util.check_BOE_Paymeth(p_receipt_method_id);
1935 if l_boe_flag = 'Y' then
1936 FND_MESSAGE.SET_NAME('AR','AR_BOE_OBSOLETE');
1937 FND_MSG_PUB.Add;
1938 p_return_status := FND_API.G_RET_STS_ERROR;
1939 end if;
1940
1941 EXCEPTION
1942 WHEN no_data_found THEN
1943 IF PG_DEBUG in ('Y', 'C') THEN
1944 arp_util.debug('Default_cash_ids: ' || 'Invalid receipt method id');
1945 END IF;
1946 null;
1947 END;
1948
1949 END IF;
1950
1951 END IF;
1952
1953 --Currency code
1954 IF p_currency_code IS NULL THEN
1955 IF p_usr_currency_code IS NOT NULL
1956 THEN
1957 p_currency_code := Get_Id('CURRENCY_NAME',
1958 p_usr_currency_code,
1959 l_get_id_return_status
1960 );
1961 IF p_currency_code IS NULL THEN
1962 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_CURR_CODE_INVALID');
1963 FND_MSG_PUB.Add;
1964 p_return_status := FND_API.G_RET_STS_ERROR;
1965 END IF;
1966 ELSE
1967
1968 p_currency_code := arp_global.functional_currency;
1969 --Raise a warning message saying that currency was defaulted
1970 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
1971 THEN
1972 FND_MESSAGE.SET_NAME('AR','AR_RAPI_FUNC_CURR_DEFAULTED');
1973 FND_MSG_PUB.Add;
1974 END IF;
1975
1976 END IF;
1977
1978 ELSE
1979 IF (p_usr_currency_code IS NOT NULL) THEN
1980
1981 --give a warning message to indicate that the usr_currency_code
1982 -- entered by the user have been ignored.
1983 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
1984 THEN
1985 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_CURR_CODE_IGN');
1986 FND_MSG_PUB.Add;
1987 END IF;
1988
1989 END IF;
1990 END IF;
1991
1992 /* Revert changes done for customer bank ref under payment uptake */
1993
1994 --Customer bank account Number,Name,ID
1995
1996 IF p_customer_bank_account_id IS NULL
1997 THEN
1998 IF(p_customer_bank_account_name IS NOT NULL) and
1999 (p_customer_bank_account_num IS NULL)
2000 THEN
2001 /* p_customer_bank_account_id := Get_Id('CUST_BANK_ACCOUNT_NAME',
2002 p_customer_bank_account_name,
2003 l_get_id_return_status
2004 );
2005 IF p_customer_bank_account_id IS NULL THEN
2006 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_BK_AC_NAME_INVALID');
2007 FND_MSG_PUB.Add;
2008 p_return_status := FND_API.G_RET_STS_ERROR;
2009 END IF; */
2010
2011 begin
2012 select distinct bb.branch_party_id "bank_branch_id",
2013 bb.BANK_ACCOUNT_ID
2014 into p_customer_bank_branch_id
2015 ,p_customer_bank_account_id
2016 from iby_fndcpt_payer_assgn_instr_v a,
2017 iby_ext_bank_accounts_v bb
2018 where a.cust_account_id = p_customer_id
2019 and a.instrument_type = 'BANKACCOUNT'
2020 and ( a.acct_site_use_id = p_customer_site_use_id or a.acct_site_use_id is null)
2021 and a.currency_code = p_currency_code
2022 and bb.ext_bank_account_id = a.instrument_id
2023 and bb.bank_account_name = p_customer_bank_account_name;
2024 exception
2025 when others then
2026 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_BK_AC_NAME_INVALID');
2027 FND_MSG_PUB.Add;
2028 p_return_status := FND_API.G_RET_STS_ERROR;
2029 end;
2030
2031 ELSIF(p_customer_bank_account_name IS NULL) and
2032 (p_customer_bank_account_num IS NOT NULL)
2033 THEN
2034 /* p_customer_bank_account_id := Get_Id('CUST_BANK_ACCOUNT_NUMBER',
2035 p_customer_bank_account_num,
2036 l_get_id_return_status
2037 );
2038 IF p_customer_bank_account_id IS NULL THEN
2039 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_BK_AC_NUM_INVALID');
2040 FND_MSG_PUB.Add;
2041 p_return_status := FND_API.G_RET_STS_ERROR;
2042 END IF; */
2043
2044 begin
2045 select distinct bb.branch_party_id "bank_branch_id",
2046 bb.BANK_ACCOUNT_ID
2047 into p_customer_bank_branch_id,
2048 p_customer_bank_account_id
2049 from iby_fndcpt_payer_assgn_instr_v a,
2050 iby_ext_bank_accounts_v bb
2051 where a.cust_account_id = p_customer_id
2052 and a.instrument_type = 'BANKACCOUNT'
2053 and ( a.acct_site_use_id = p_customer_site_use_id or a.acct_site_use_id is null)
2054 and a.currency_code = p_currency_code
2055 and bb.ext_bank_account_id = a.instrument_id
2056 and bb.bank_account_number = p_customer_bank_account_num;
2057 exception
2058 when others then
2059 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_BK_AC_NUM_INVALID');
2060 FND_MSG_PUB.Add;
2061 p_return_status := FND_API.G_RET_STS_ERROR;
2062 end;
2063
2064 ELSIF(p_customer_bank_account_name IS NOT NULL) and
2065 (p_customer_bank_account_num IS NOT NULL)
2066 THEN
2067 /* p_customer_bank_account_id := Get_Cross_Validated_Id( 'CUST_BANK_ACCOUNT',
2068 p_customer_bank_account_num,
2069 p_customer_bank_account_name,
2070 l_get_id_return_status
2071 );
2072 IF p_customer_bank_account_id IS NULL THEN
2073 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_BK_AC_2_INVALID');
2074 FND_MSG_PUB.Add;
2075 p_return_status := FND_API.G_RET_STS_ERROR;
2076 END IF; */
2077
2078 begin
2079 select distinct bb.branch_party_id "bank_branch_id",
2080 bb.BANK_ACCOUNT_ID
2081 into p_customer_bank_branch_id
2082 ,p_customer_bank_account_id
2083 from iby_fndcpt_payer_assgn_instr_v a,
2084 iby_ext_bank_accounts_v bb
2085 where a.cust_account_id = p_customer_id
2086 and a.instrument_type = 'BANKACCOUNT'
2087 and ( a.acct_site_use_id = p_customer_site_use_id or a.acct_site_use_id is null)
2088 and a.currency_code = p_currency_code
2089 and bb.ext_bank_account_id = a.instrument_id
2090 and bb.bank_account_name = p_customer_bank_account_name
2091 and bb.bank_account_number = p_customer_bank_account_num;
2092 exception
2093 when others then
2094 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_BK_AC_2_INVALID');
2095 FND_MSG_PUB.Add;
2096 p_return_status := FND_API.G_RET_STS_ERROR;
2097 end;
2098
2099 END IF;
2100
2101 ELSE --In case the ID has been entered by the user
2102 IF (p_customer_bank_account_num IS NOT NULL) OR
2103 (p_customer_bank_account_name IS NOT NULL) THEN
2104 --give a warning message to indicate that the customer_bank_account_num and
2105 --p_customer_bank_account_name entered by the user have been ignored.
2106 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
2107 THEN
2108 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_BK_NAME_NUM_IGN');
2109 FND_MSG_PUB.Add;
2110 END IF;
2111 END IF;
2112
2113 END IF;
2114
2115
2116 --Remittance bank account Number,Name,ID
2117
2118
2119 IF p_remittance_bank_account_id IS NULL
2120 THEN
2121 IF(p_remittance_bank_account_name IS NOT NULL) and
2122 (p_remittance_bank_account_num IS NULL)
2123 THEN
2124 p_remittance_bank_account_id := Get_Id('REMIT_BANK_ACCOUNT_NAME',
2125 p_remittance_bank_account_name,
2126 l_get_id_return_status
2127 );
2128 IF p_remittance_bank_account_id IS NULL THEN
2129 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_NAME_INVALID');
2130 FND_MSG_PUB.Add;
2131 p_return_status := FND_API.G_RET_STS_ERROR;
2132 END IF;
2133 ELSIF(p_remittance_bank_account_name IS NULL) and
2134 (p_remittance_bank_account_num IS NOT NULL)
2135 THEN
2136 p_remittance_bank_account_id := Get_Id('REMIT_BANK_ACCOUNT_NUMBER',
2137 p_remittance_bank_account_num,
2138 l_get_id_return_status
2139 );
2140 IF p_remittance_bank_account_id IS NULL THEN
2141 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_NUM_INVALID');
2142 FND_MSG_PUB.Add;
2143 p_return_status := FND_API.G_RET_STS_ERROR;
2144 END IF;
2145 ELSIF(p_remittance_bank_account_name IS NOT NULL) and
2146 (p_remittance_bank_account_num IS NOT NULL)
2147 THEN
2148 p_remittance_bank_account_id := Get_Cross_Validated_Id( 'REMIT_BANK_ACCOUNT',
2149 p_remittance_bank_account_num,
2150 p_remittance_bank_account_name,
2151 l_get_x_val_return_status
2152 );
2153 IF p_remittance_bank_account_id IS NULL THEN
2154 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_2_INVALID');
2155 FND_MSG_PUB.Add;
2156 p_return_status := FND_API.G_RET_STS_ERROR;
2157 END IF;
2158 END IF;
2159
2160 ELSE
2161
2162 IF (p_remittance_bank_account_name IS NOT NULL) OR
2163 (p_remittance_bank_account_num IS NOT NULL)
2164 THEN
2165 --give a warning message to indicate that the remittance_bank_account_num and
2166 --remittance_bank_account_name entered by the user have been ignored.
2167 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
2168 THEN
2169 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_NAME_NUM_IGN');
2170 FND_MSG_PUB.Add;
2171 END IF;
2172 END IF;
2173
2174 END IF;
2175
2176 -- Exchange_rate_type
2177 IF p_exchange_rate_type IS NULL THEN
2178 IF p_usr_exchange_rate_type IS NOT NULL
2179 THEN
2180 p_exchange_rate_type := Get_Id('EXCHANGE_RATE_TYPE_NAME',/* Bug fix 2982212*/
2181 p_usr_exchange_rate_type,
2182 l_get_id_return_status
2183 );
2184 IF p_exchange_rate_type IS NULL THEN
2185 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_X_RATE_TYP_INVALID');
2186 FND_MSG_PUB.Add;
2187 p_return_status := FND_API.G_RET_STS_ERROR;
2188 END IF;
2189 END IF;
2190
2191 ELSE
2192 IF (p_usr_exchange_rate_type IS NOT NULL) THEN
2193 --give a warning message to indicate that the usr_exchange_rate_type
2194 -- entered by the user have been ignored.
2195 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
2196 THEN
2197 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_X_RATE_TYPE_IGN');
2198 FND_MSG_PUB.Add;
2199 END IF;
2200 END IF;
2201
2202 END IF;
2203
2204
2205 IF PG_DEBUG in ('Y', 'C') THEN
2206 arp_util.debug('Default_cash_ids_from_values ()-');
2207 END IF;
2208 EXCEPTION
2209 WHEN others THEN
2210 IF PG_DEBUG in ('Y', 'C') THEN
2211 arp_util.debug('EXCEPTION: Default_cash_ids_from_values() ',
2212 G_MSG_UERROR);
2213 END IF;
2214 raise;
2215
2216 END Default_cash_ids;
2217
2218 PROCEDURE Get_Cash_Defaults(
2219 p_currency_code IN OUT NOCOPY ar_cash_receipts.currency_code%TYPE,
2220 p_exchange_rate_type IN OUT NOCOPY ar_cash_receipts.exchange_rate_type%TYPE,
2221 p_exchange_rate IN OUT NOCOPY ar_cash_receipts.exchange_rate%TYPE,
2222 p_exchange_rate_date IN OUT NOCOPY ar_cash_receipts.exchange_date%TYPE,
2223 p_amount IN OUT NOCOPY ar_cash_receipts.amount%TYPE,
2224 p_factor_discount_amount IN OUT NOCOPY ar_cash_receipts.factor_discount_amount%TYPE,
2225 p_receipt_date IN OUT NOCOPY ar_cash_receipts.receipt_date%TYPE,
2226 p_gl_date IN OUT NOCOPY DATE,
2227 p_maturity_date IN OUT NOCOPY DATE,
2228 p_customer_receipt_reference IN OUT NOCOPY ar_cash_receipts.customer_receipt_reference%TYPE,
2229 p_override_remit_account_flag IN OUT NOCOPY ar_cash_receipts.override_remit_account_flag%TYPE,
2230 p_remittance_bank_account_id IN OUT NOCOPY ar_cash_receipts.remit_bank_acct_use_id%TYPE,
2231 p_deposit_date IN OUT NOCOPY ar_cash_receipts.deposit_date%TYPE,
2232 p_receipt_method_id IN OUT NOCOPY ar_cash_receipts.receipt_method_id%TYPE,
2233 p_state OUT NOCOPY ar_receipt_classes.creation_status%TYPE,
2234 p_anticipated_clearing_date IN OUT NOCOPY ar_cash_receipts.anticipated_clearing_date%TYPE,
2235 p_called_from IN VARCHAR2,
2236 p_creation_method_code OUT NOCOPY ar_receipt_classes.creation_method_code%TYPE,
2237 p_return_status OUT NOCOPY VARCHAR2
2238 )
2239 IS
2240 l_cr CONSTANT char(1) := '';
2241 l_temp_id NUMBER(15);
2242 l_temp_char VARCHAR2(80) ;
2243 l_temp_date DATE ;
2244 l_def_curr_return_status VARCHAR2(1);
2245 l_def_rm_return_status VARCHAR2(1);
2246 l_def_gl_dt_return_status VARCHAR2(1);
2247 /* Bug fix 3315058 */
2248 l_bank_acc_val_ret_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
2249 BEGIN
2250
2251 IF PG_DEBUG in ('Y', 'C') THEN
2252 arp_util.debug('Get_Cash_Defaults()+ ');
2253 END IF;
2254 p_return_status := FND_API.G_RET_STS_SUCCESS;
2255 -- default the receipt date if NULL
2256 IF (p_receipt_date IS NULL)
2257 THEN
2258 Select trunc(sysdate)
2259 into p_receipt_date
2260 from dual;
2261 END IF;
2262
2263 -- default the gl_date
2264 IF p_gl_date IS NULL THEN
2265 Default_gl_date(p_receipt_date,
2266 p_gl_date,
2267 NULL,
2268 l_def_gl_dt_return_status);
2269 IF PG_DEBUG in ('Y', 'C') THEN
2270 arp_util.debug('Get_Cash_Defaults: ' || 'l_default_gl_date_return_status : '||l_def_gl_dt_return_status);
2271 END IF;
2272 END IF;
2273
2274 IF (p_deposit_date IS NULL)
2275 THEN
2276 p_deposit_date := p_receipt_date;
2277 END IF;
2278
2279 IF (p_maturity_date IS NULL) THEN
2280 p_maturity_date := p_deposit_date;
2281 END IF;
2282
2283 -- Default the Currency parameters
2284 Default_Currency_info(p_currency_code,
2285 p_receipt_date,
2286 p_exchange_rate_date,
2287 p_exchange_rate_type,
2288 p_exchange_rate,
2289 l_def_curr_return_status
2290 );
2291
2292 --Set the precision of the receipt amount as per currency
2293 IF p_amount is NOT NULL THEN
2294 p_amount := arp_util.CurrRound( p_amount,
2295 p_currency_code
2296 );
2297 END IF;
2298
2299 --Default the Receipt Method related parameters
2300 Default_Receipt_Method_info(p_receipt_method_id,
2301 p_currency_code,
2302 p_receipt_date,
2303 p_remittance_bank_account_id,
2304 p_state,
2305 p_creation_method_code,
2306 p_called_from,
2307 l_def_rm_return_status
2308 );
2309
2310 /* Bug fix 3315058 */
2311 Validate_Receipt_Method_ccid(p_receipt_method_id,
2312 p_remittance_bank_account_id,
2313 p_gl_date,
2314 l_bank_acc_val_ret_status);
2315
2316 --default the override_remit_bank_account_flag
2317 IF (p_override_remit_account_flag IS NULL) THEN
2318 p_override_remit_account_flag := 'Y';
2319 END IF;
2320
2321 IF l_def_rm_return_status <> FND_API.G_RET_STS_SUCCESS OR
2322 l_def_gl_dt_return_status <> FND_API.G_RET_STS_SUCCESS OR
2323 l_def_curr_return_status <> FND_API.G_RET_STS_SUCCESS OR
2324 l_bank_acc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN /* Bug3315058 */
2325 p_return_status := FND_API.G_RET_STS_ERROR;
2326 END IF;
2327 IF PG_DEBUG in ('Y', 'C') THEN
2328 arp_util.debug('Get_Cash_Defaults: ' || '************Cash Defaults********************');
2329 arp_util.debug('Get_Cash_Defaults: ' || 'p_receipt_date : '||to_char(p_receipt_date,'DD-MON-YYYY'));
2330 arp_util.debug('Get_Cash_Defaults: ' || 'p_gl_date : '||to_char(p_gl_date,'DD-MON-YYYY'));
2331 arp_util.debug('Get_Cash_Defaults: ' || 'p_deposit_date : '||to_char(p_deposit_date,'DD-MON-YYYY'));
2332 arp_util.debug('Get_Cash_Defaults: ' || 'p_maturity_date : '||to_char(p_maturity_date,'DD-MON-YYYY'));
2333 arp_util.debug('Get_Cash_Defaults: ' || 'p_currency_code : '||p_currency_code);
2334 arp_util.debug('Get_Cash_Defaults: ' || 'p_exchange_rate_date : '||to_char(p_exchange_rate_date,'DD-MON-YYYY'));
2335 arp_util.debug('Get_Cash_Defaults: ' || 'p_exchange_rate_type : '||p_exchange_rate_type);
2336 arp_util.debug('Get_Cash_Defaults: ' || 'p_exchange_rate : '||to_char(p_exchange_rate));
2337 arp_util.debug('Get_Cash_Defaults: ' || 'p_receipt_method_id : '||to_char(p_receipt_method_id));
2338 arp_util.debug('Get_Cash_Defaults: ' || 'remit bank acct use id : '||to_char(p_remittance_bank_account_id));
2339 arp_util.debug('Get_Cash_Defaults: ' || 'p_state : '||p_state);
2340 arp_util.debug('Get_Cash_Defaults ()-');
2341 END IF;
2342 END Get_Cash_Defaults;
2343
2344 FUNCTION Get_grace_days(
2345 p_customer_id IN NUMBER,
2346 p_bill_to_site_use_id IN NUMBER) RETURN NUMBER IS
2347
2348 l_grace_days NUMBER;
2349 l_bill_to_site_use_id NUMBER;
2350
2351 BEGIN
2352
2353 l_bill_to_site_use_id := NVL(p_bill_to_site_use_id,-99999);
2354 IF p_customer_id IS NOT NULL THEN
2355
2356 /* modified for tca uptake */
2357 SELECT NVL(NVL(site.discount_grace_days, cust.discount_grace_days),0)
2358 INTO l_grace_days
2359 FROM
2360 hz_customer_profiles cust,
2361 hz_customer_profiles site,
2362 hz_cust_accounts c
2363 WHERE
2364 c.cust_account_id = p_customer_id
2365 AND cust.cust_account_id = c.cust_account_id
2366 AND cust.site_use_id IS NULL
2367 AND site.cust_account_id (+) = c.cust_account_id
2368 AND site.site_use_id (+) = l_bill_to_site_use_id;
2369 END IF;
2370
2371 RETURN l_grace_days;
2372
2373 EXCEPTION
2374 WHEN OTHERS THEN
2375 IF PG_DEBUG in ('Y', 'C') THEN
2376 arp_util.debug('EXCEPTION: Get_grace_days()');
2377 END IF;
2378 raise;
2379 END Get_grace_days;
2380
2381 PROCEDURE Default_trans_to_receipt_rate(p_trx_currency_code IN VARCHAR2,
2382 p_cr_currency_code IN VARCHAR2,
2383 p_receipt_date IN VARCHAR2,
2384 p_trans_to_receipt_rate IN OUT NOCOPY NUMBER,
2385 p_amount_applied IN NUMBER,
2386 p_amount_applied_from IN NUMBER,
2387 p_cr_date IN DATE,
2388 p_return_status OUT NOCOPY VARCHAR2
2389 ) IS
2390 l_exchange_rate_type VARCHAR2(30);
2391 l_temp_rate NUMBER;
2392 l_amount_applied NUMBER;
2393 l_amount_applied_from NUMBER;
2394 BEGIN
2395 IF PG_DEBUG in ('Y', 'C') THEN
2396 arp_util.debug('Default_trans_to_receipt_rate ()+');
2397 END IF;
2398
2399 p_return_status := FND_API.G_RET_STS_SUCCESS;
2400 --if the trx currency and the receipt currency are not same
2401 IF p_cr_currency_code <> p_trx_currency_code THEN
2402
2403 --do the rounding
2404 IF P_trans_to_receipt_rate IS NOT NULL THEN
2405 p_trans_to_receipt_rate := ROUND(p_trans_to_receipt_rate, 38);
2406 END IF;
2407
2408 --get the default only if p_trans_to_receipt_rate has not been entered by
2409 --user
2410 IF p_trans_to_receipt_rate IS NULL AND
2411 (gl_currency_api.is_fixed_rate(
2412 p_cr_currency_code,
2413 p_trx_currency_code,
2414 p_cr_date
2415 ) <> 'Y') THEN
2416
2417 --try to first get the rate from gl if possible
2418
2419 l_exchange_rate_type := pg_profile_cc_rate_type;
2420
2421 IF (l_exchange_rate_type IS NOT NULL)
2422 THEN
2423 --relationship between the two currencies is not fixed
2424 --and the default CROSS_CURRENCY_RATE_TYPE exists
2425 --try to get the rate from gl
2426
2427 BEGIN
2428 l_temp_rate := gl_currency_api.get_rate(
2429 p_trx_currency_code,
2430 p_cr_currency_code,
2431 p_cr_date,
2432 l_exchange_rate_type);
2433 EXCEPTION
2434 WHEN gl_currency_api.NO_RATE THEN
2435 --rate does not exist set appropriate message.
2436 --p_return_status := FND_API.G_RET_STS_ERROR ;
2437 l_temp_rate := NULL;
2438 IF PG_DEBUG in ('Y', 'C') THEN
2439 arp_util.debug('Default_trans_to_receipt_rate: ' || 'Exception : gl_currency_api.NO_RATE ');
2440 END IF;
2441 WHEN gl_currency_api.INVALID_CURRENCY THEN
2442 -- invalid currency set appropriate message.
2443 --p_return_status := FND_API.G_RET_STS_ERROR ;
2444 l_temp_rate := NULL;
2445 IF PG_DEBUG in ('Y', 'C') THEN
2446 arp_util.debug('Default_trans_to_receipt_rate: ' || 'Exception: gl_currency_api.INVALID_CURRENCY ');
2447 END IF;
2448 END;
2449 END IF ;
2450
2451 ELSIF gl_currency_api.is_fixed_rate(
2452 p_cr_currency_code,
2453 p_trx_currency_code,
2454 p_cr_date
2455 ) = 'Y' THEN
2456 --In case of fixed relationship get the fixed rate and return it.
2457
2458 BEGIN
2459 l_temp_rate := gl_currency_api.get_rate(
2460 p_trx_currency_code,
2461 p_cr_currency_code,
2462 p_cr_date,
2463 l_exchange_rate_type
2464 );
2465 EXCEPTION
2466 WHEN gl_currency_api.NO_RATE THEN
2467 --rate does not exist set appropriate message.
2468 --p_return_status := FND_API.G_RET_STS_ERROR ;
2469 l_temp_rate := NULL;
2470 IF PG_DEBUG in ('Y', 'C') THEN
2471 arp_util.debug('Default_trans_to_receipt_rate: ' || 'Exception : gl_currency_api.NO_RATE ');
2472 END IF;
2473 WHEN gl_currency_api.INVALID_CURRENCY THEN
2474 -- invalid currency set appropriate message.
2475 --p_return_status := FND_API.G_RET_STS_ERROR ;
2476 l_temp_rate := NULL;
2477 IF PG_DEBUG in ('Y', 'C') THEN
2478 arp_util.debug('Default_trans_to_receipt_rate: ' || 'Exception: gl_currency_api.INVALID_CURRENCY ');
2479 END IF;
2480 END;
2481
2482 IF p_trans_to_receipt_rate IS NOT NULL THEN
2483 IF l_temp_rate <> p_trans_to_receipt_rate THEN
2484 --raise error as the user specified CC rate is not the same as the
2485 --fixed rate.
2486 p_return_status := FND_API.G_RET_STS_ERROR;
2487 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CC_RATE_INVALID');
2488 FND_MSG_PUB.Add;
2489 return;
2490 END IF;
2491 END IF;
2492
2493 END IF;
2494
2495 --In the case where, neither the fixed rate relationship
2496 --exists between the two currencies nor rate_type is available
2497 --so user needs to enter the value here or the trans_to_receipt_rate
2498 --is to be derived from the amount applied and the amount applied from.
2499
2500 IF l_temp_rate IS NOT NULL THEN
2501 p_trans_to_receipt_rate := l_temp_rate;
2502
2503 ELSE
2504
2505 --rate does not exist in the gl so try to get it from the
2506 --following formula for a CC application:
2507 --p_trans_to_receipt_rate =
2508 -- p_amount_applied_from/p_amount_applied
2509
2510 IF p_amount_applied_from IS NOT NULL AND
2511 p_amount_applied IS NOT NULL
2512 THEN
2513 l_amount_applied_from := arp_util.CurrRound(
2514 p_amount_applied_from,
2515 p_cr_currency_code
2516 );
2517 /* Bugfix 2916389. Use p_trx_currency_code instead of
2518 p_cr_currency_code. */
2519 l_amount_applied := arp_util.CurrRound(
2520 p_amount_applied,
2521 p_trx_currency_code
2522 );
2523 p_trans_to_receipt_rate := ROUND(l_amount_applied_from/l_amount_applied, 38);
2524
2525 END IF;
2526 END IF;
2527
2528 END IF;
2529 IF PG_DEBUG in ('Y', 'C') THEN
2530 arp_util.debug('Default_trans_to_receipt_rate: ' || 'p_trans_to_receipt_rate :'||to_char(p_trans_to_receipt_rate));
2531 arp_util.debug('Default_trans_to_receipt_rate ()-');
2532 END IF;
2533 EXCEPTION
2534 WHEN others THEN
2535 IF PG_DEBUG in ('Y', 'C') THEN
2536 arp_util.debug('EXCEPTION: Default_trans_to_receipt_rate()');
2537 END IF;
2538 raise;
2539 END Default_trans_to_receipt_rate;
2540
2541 PROCEDURE Default_amount_applied_from(
2542 p_amount_applied IN NUMBER,
2543 p_trx_currency_code IN VARCHAR2,
2544 p_trans_to_receipt_rate IN NUMBER,
2545 p_cr_currency_code IN VARCHAR2,
2546 p_amount_applied_from IN OUT NOCOPY NUMBER,
2547 p_return_status OUT NOCOPY VARCHAR2
2548 ) IS
2549
2550 BEGIN
2551 IF PG_DEBUG in ('Y', 'C') THEN
2552 arp_util.debug('Default_amount_applied_from ()+');
2553 END IF;
2554 p_return_status := FND_API.G_RET_STS_SUCCESS;
2555 IF p_amount_applied_from IS NULL THEN
2556 IF p_trx_currency_code <> p_cr_currency_code THEN
2557
2558 --this is the CC application case
2559 IF p_trans_to_receipt_rate IS NOT NULL AND
2560 p_amount_applied IS NOT NULL
2561 THEN
2562
2563 p_amount_applied_from := arp_util.CurrRound(
2564 p_amount_applied * p_trans_to_receipt_rate,
2565 p_cr_currency_code
2566 );
2567 END IF;
2568
2569 END IF;
2570
2571 ELSE
2572 --if user has entered the amount_applied_from then round it.
2573 p_amount_applied_from := arp_util.CurrRound(
2574 p_amount_applied_from,
2575 p_cr_currency_code
2576 );
2577 END IF;
2578 IF PG_DEBUG in ('Y', 'C') THEN
2579 arp_util.debug('Default_amount_applied_from ()+');
2580 END IF;
2581
2582 EXCEPTION
2583 WHEN others THEN
2584 IF PG_DEBUG in ('Y', 'C') THEN
2585 arp_util.debug('Default_amount_applied_from: ' || 'EXCEPTION: Default_applied_amount_from()');
2586 END IF;
2587 raise;
2588
2589 END Default_amount_applied_from;
2590
2591
2592 PROCEDURE Default_val_llca_parameters (
2593 p_llca_type IN VARCHAR2,
2594 p_cash_receipt_id IN NUMBER,
2595 p_customer_trx_id IN NUMBER,
2596 p_customer_trx_line_id IN NUMBER,
2597 p_amount_applied IN OUT NOCOPY NUMBER,
2598 p_line_amount IN OUT NOCOPY NUMBER,
2599 p_tax_amount IN OUT NOCOPY NUMBER,
2600 p_freight_amount IN OUT NOCOPY NUMBER,
2601 p_charges_amount IN OUT NOCOPY NUMBER,
2602 p_line_discount IN OUT NOCOPY NUMBER,
2603 p_tax_discount IN OUT NOCOPY NUMBER,
2604 p_freight_discount IN NUMBER,
2605 p_discount IN OUT NOCOPY NUMBER,
2606 p_receipt_currency_code IN VARCHAR2,
2607 p_invoice_currency_code IN VARCHAR2,
2608 p_cr_date IN DATE,
2609 p_return_status OUT NOCOPY VARCHAR2,
2610 p_msg_count OUT NOCOPY NUMBER,
2611 p_msg_data OUT NOCOPY VARCHAR2
2612 ) IS
2613
2614 cursor gt_lines_cur (p_cust_trx_id in number) is
2615 select * from ar_llca_trx_lines_gt
2616 where customer_trx_id = p_cust_trx_id;
2617
2618 l_gt_count NUMBER;
2619 l_line_amount_remaining NUMBER;
2620 l_line_tax_remaining NUMBER;
2621 l_line_number NUMBER;
2622 l_calc_tot_amount_app NUMBER;
2623 l_calc_line_per NUMBER;
2624 l_calc_line_amount NUMBER;
2625 l_calc_tax_amount NUMBER;
2626 l_calc_freight_amount NUMBER;
2627 l_cum_amount_app NUMBER := 0;
2628 l_cum_line_amount NUMBER := 0;
2629 l_cum_tax_amount NUMBER := 0;
2630 l_cum_line_discount NUMBER := 0;
2631 l_cum_tax_discount NUMBER := 0;
2632
2633
2634 -- Bug 6931978 Cross Currency App
2635 l_def_rate_return_status VARCHAR2(1);
2636 l_receipt_date DATE;
2637 l_trans_to_receipt_rate NUMBER;
2638
2639 BEGIN
2640 IF PG_DEBUG in ('Y', 'C') THEN
2641 arp_util.debug('Default_val_llca_parameters()+');
2642 END IF;
2643 p_return_status := FND_API.G_RET_STS_SUCCESS;
2644
2645
2646 -- Initialize the Sys Parameters /INV PS /REC PS / Copy Trx lines into GT
2647 arp_process_det_pkg.initialization (p_customer_trx_id,
2648 p_cash_receipt_id,
2649 p_return_status,
2650 p_msg_data,
2651 p_msg_count);
2652
2653 IF PG_DEBUG in ('Y', 'C') THEN
2654 arp_util.debug('Default_val_llca_parameters: Initialization Return Status : '||p_return_status);
2655 END IF;
2656
2657 IF p_return_status <> FND_API.G_RET_STS_SUCCESS
2658 THEN
2659 FND_MESSAGE.SET_NAME ('AR','GENERIC_MESSAGE');
2660 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','ARP_PROCESS_DET_PKG.INITIALIZTION '||SQLERRM);
2661 FND_MSG_PUB.Add;
2662 p_return_status := FND_API.G_RET_STS_ERROR ;
2663
2664 IF PG_DEBUG in ('Y', 'C') THEN
2665 arp_util.debug('Apply_In_Detail: ' || 'Error(s) occurred in arp_process_det_pkg.Initialization ');
2666 END IF;
2667 Return;
2668 END IF;
2669
2670 IF p_llca_type = 'S'
2671 THEN
2672 IF PG_DEBUG in ('Y', 'C') THEN
2673 arp_util.debug('Default_val_llca_parameters: Summary Level Application ');
2674 END IF;
2675 IF p_line_amount IS NULL AND p_tax_amount IS NULL
2676 AND p_freight_amount IS NULL AND p_charges_amount is NULL
2677 THEN
2678 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_LTFC_AMT_NULL');
2679 FND_MSG_PUB.ADD;
2680 p_return_status := FND_API.G_RET_STS_ERROR ;
2681 END IF;
2682 IF Nvl(p_amount_applied,0) <>
2683 ( Nvl(p_line_amount,0) + Nvl(p_tax_amount,0)
2684 + Nvl(p_freight_amount,0) + Nvl(p_charges_amount,0))
2685 THEN
2686 p_amount_applied := Nvl(p_line_amount,0)
2687 + Nvl(p_tax_amount,0) + Nvl(p_freight_amount,0)
2688 + Nvl(p_charges_amount,0);
2689
2690 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
2691 THEN
2692 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_AMT_DEFLT_IGN');
2693 FND_MSG_PUB.Add;
2694 END IF;
2695
2696 IF PG_DEBUG in ('Y', 'C') THEN
2697 arp_util.debug('Default_application_info: ' ||
2698 'Amount applied has been defaulted to the sum of
2699 line/tax/freight/charges amount ');
2700 END IF;
2701 END IF;
2702
2703
2704 Elsif P_llca_type = 'L'
2705 Then
2706 IF PG_DEBUG in ('Y', 'C') THEN
2707 arp_util.debug('Default_val_llca_parameters: Line Level Application ');
2708 END IF;
2709 IF ( Nvl(p_line_amount,0) <> 0
2710 and Nvl(p_tax_amount,0) <> 0
2711 and nvl(p_charges_amount,0) <> 0
2712 )
2713 THEN
2714 p_line_amount := NULL;
2715 p_tax_amount := NULL;
2716 p_charges_amount := NULL;
2717 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
2718 THEN
2719 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_LTC_IGN');
2720 FND_MSG_PUB.Add;
2721 END IF;
2722
2723 IF PG_DEBUG in ('Y', 'C') THEN
2724 arp_util.debug('Default_val_llca_parameters: ' || 'Line, Tax,
2725 , Charges amount has been defaulted to Null');
2726 END IF;
2727 END IF;
2728
2729 select count(*) into l_gt_count
2730 from ar_llca_trx_lines_gt
2731 where customer_trx_id = p_customer_trx_id
2732 and rownum = 1;
2733
2734 -- For All Lines, Amount due remaining / line remaining will be defaulted later.
2735 IF nvl(l_gt_count,0) = 0
2736 THEN
2737 If Nvl(p_amount_applied,0) <> 0
2738 THEN
2739 p_amount_applied := NULL;
2740
2741 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
2742 THEN
2743 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_AMT_DEFLT_IGN');
2744 FND_MSG_PUB.Add;
2745 END IF;
2746
2747 IF PG_DEBUG in ('Y', 'C') THEN
2748 arp_util.debug('Default_val_llca_parameters: ' || 'Amount applied
2749 amount has been defaulted to Null');
2750 END IF;
2751 END IF;
2752 Else
2753 -- Specified Lines
2754 IF PG_DEBUG in ('Y', 'C') THEN
2755 arp_util.debug('Specified one or more lines in PLSQL table... ');
2756 END IF;
2757
2758 -- Calculate the line level amounts
2759 For sp_lines_row in gt_lines_cur(p_customer_trx_id)
2760 LOOP
2761 BEGIN
2762
2763 -- Bug 6931978
2764 IF p_invoice_currency_code = p_receipt_currency_code THEN
2765 If sp_lines_row.line_amount IS NULL AND
2766 sp_lines_row.tax_amount IS NULL AND
2767 sp_lines_row.amount_applied is NULL AND
2768 sp_lines_row.customer_trx_line_id is NOT NULL
2769 THEN
2770 ar_receipt_lib_pvt.populate_errors_gt (
2771 p_customer_trx_id => p_customer_trx_id,
2772 p_customer_trx_line_id => sp_lines_row.customer_trx_line_id,
2773 p_error_message =>
2774 arp_standard.fnd_message('AR_RAPI_LTFC_AMT_NULL'),
2775 p_invalid_value => NULL
2776 );
2777 p_return_status := FND_API.G_RET_STS_ERROR ;
2778 EXIT;
2779 END IF;
2780 END IF;
2781 -- Bug 6931978 END
2782 select to_char(line.line_number) apply_to,
2783 nvl(line.amount_due_remaining,0),
2784 nvl(tax.amount_due_remaining,0)
2785 into
2786 l_line_number,
2787 l_line_amount_remaining,
2788 l_line_tax_remaining
2789 from ra_customer_trx_lines line,
2790 (select link_to_cust_trx_line_id,
2791 line_type,
2792 sum(nvl(amount_due_original,0)) amount_due_original,
2793 sum(nvl(amount_due_remaining,0)) amount_due_remaining
2794 from ra_customer_trx_lines
2795 where customer_trx_id = sp_lines_row.customer_trx_id -- Bug 7241703 Added condition
2796 and nvl(line_type,'TAX') = 'TAX'
2797 group by link_to_cust_trx_line_id,line_type
2798 ) tax
2799 where line.customer_Trx_id = sp_lines_row.customer_trx_id
2800 and line.customer_trx_line_id = sp_lines_row.customer_trx_line_id
2801 and line.line_type = 'LINE'
2802 and line.customer_trx_line_id = tax.link_to_cust_trx_line_id (+);
2803 EXCEPTION
2804 WHEN NO_DATA_FOUND THEN
2805 IF PG_DEBUG in ('Y', 'C') THEN
2806 arp_util.debug('' || 'EXCEPTION: Default_val_llca_parameters()');
2807 END IF;
2808 p_return_status := FND_API.G_RET_STS_ERROR ;
2809 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_TRX_LINE_ID_INVALID');
2810 FND_MSG_PUB.ADD;
2811 RAISE;
2812 WHEN others THEN
2813 IF PG_DEBUG in ('Y', 'C') THEN
2814 arp_util.debug('' || 'EXCEPTION: Default_val_llca_parameters()');
2815 END IF;
2816 RAISE;
2817 END;
2818 IF PG_DEBUG in ('Y', 'C') THEN
2819 arp_util.debug('Customer_trx_line_id =>'||to_char(sp_lines_row.customer_trx_line_id));
2820 END IF;
2821 Select decode ( ( Nvl(l_line_amount_remaining,0)
2822 / ( Nvl(l_line_amount_remaining,0)
2823 + Nvl(l_line_tax_remaining,0)
2824 )
2825 ),0,1,
2826 ( Nvl(l_line_amount_remaining,0)
2827 / ( Nvl(l_line_amount_remaining,0)
2828 + Nvl(l_line_tax_remaining,0)
2829 )
2830 )
2831 )
2832 into l_calc_line_per
2833 from dual;
2834
2835 -- Bug 6931978 Cross Currency App
2836 IF p_invoice_currency_code <> p_receipt_currency_code THEN
2837 IF Nvl(sp_lines_row.amount_applied_from,0) <> 0
2838 Then
2839
2840 Default_trans_to_receipt_rate(
2841 p_invoice_currency_code ,
2842 p_receipt_currency_code ,
2843 l_receipt_date ,
2844 l_trans_to_receipt_rate ,
2845 sp_lines_row.amount_applied,
2846 sp_lines_row.amount_applied_from,
2847 p_cr_date,
2848 l_def_rate_return_status
2849 );
2850 sp_lines_row.amount_applied := arp_util.CurrRound(
2851 sp_lines_row.amount_applied_from / l_trans_to_receipt_rate,
2852 p_invoice_currency_code);
2853 sp_lines_row.tax_amount := NULL;
2854 sp_lines_row.line_amount := NULL;
2855
2856
2857 IF PG_DEBUG in ('Y', 'C') THEN
2858 arp_util.debug('Default_val_llca_parameters: ' || 'Default trans_to_receipt_rate status: '||l_def_rate_return_status);
2859 arp_util.debug('Default_val_llca_parameters: ' || 'l_trans_to_receipt_rate: '||l_trans_to_receipt_rate);
2860 arp_util.debug('Default_val_llca_parameters: ' || 'sp_lines_row.amount_applied: '||sp_lines_row.amount_applied);
2861 END IF;
2862
2863 END IF;
2864 END IF;
2865
2866 -- Bug 6931978 End
2867
2868
2869 -- First Priority Line Amount
2870 If Nvl(sp_lines_row.line_amount,0) <> 0
2871 Then
2872 IF PG_DEBUG in ('Y', 'C') THEN
2873 arp_util.debug('First priority : Line Amount ');
2874 arp_util.debug('Line Amount has taken precedence over the amount applied ');
2875 END IF;
2876 l_calc_tot_amount_app := arp_util.CurrRound(
2877 ( nvl(sp_lines_row.line_amount,0)
2878 / nvl(l_calc_line_per,1)
2879 )
2880 ,p_invoice_currency_code);
2881 l_calc_line_amount := arp_util.CurrRound(sp_lines_row.line_amount
2882 ,p_invoice_currency_code);
2883
2884 -- Calculate Line amount based on the Amount Applied.
2885 Elsif Nvl(sp_lines_row.amount_applied,0) <> 0
2886 Then
2887 IF PG_DEBUG in ('Y', 'C') THEN
2888 arp_util.debug('Considered the Amount Applied value ');
2889 End If;
2890
2891 l_calc_tot_amount_app := arp_util.CurrRound(sp_lines_row.amount_applied
2892 ,p_invoice_currency_code);
2893 l_calc_line_amount := arp_util.CurrRound((l_calc_tot_amount_app
2894 * l_calc_line_per),p_invoice_currency_code);
2895 End If;
2896
2897 IF PG_DEBUG in ('Y', 'C') THEN
2898 arp_util.debug('l_calc_tot_amount_app -> '||to_char(l_calc_tot_amount_app));
2899 arp_util.debug('l_calc_line_amount -> '||to_char(l_calc_line_amount));
2900 END IF;
2901
2902
2903 -- Tax amount has taken precedence over the Line / amount applied
2904 If NVL(sp_lines_row.tax_amount,0) <> 0
2905 THEN
2906 IF PG_DEBUG in ('Y', 'C') THEN
2907 arp_util.debug('Tax Amount has taken precedence over the amount applied ');
2908 End If;
2909 l_calc_tax_amount := arp_util.CurrRound(sp_lines_row.tax_amount
2910 ,p_invoice_currency_code);
2911
2912 l_calc_tot_amount_app := l_calc_line_amount +
2913 l_calc_tax_amount;
2914 Else
2915 IF PG_DEBUG in ('Y', 'C') THEN
2916 arp_util.debug('Amount Applied has taken precedence over the Tax Amount');
2917 End If;
2918 -- Amount applied has taken precedence over the tax amount
2919 l_calc_tax_amount := arp_util.CurrRound((Nvl(l_calc_tot_amount_app,0)
2920 - Nvl(l_calc_line_amount,0))
2921 ,p_invoice_currency_code);
2922 End If;
2923
2924
2925 If Nvl(sp_lines_row.amount_applied,0) <> Nvl(l_calc_tot_amount_app,0)
2926 Then
2927 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
2928 THEN
2929 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_AMT_DEFLT_IGN');
2930 FND_MSG_PUB.Add;
2931 END IF;
2932 END If;
2933
2934
2935 IF PG_DEBUG in ('Y', 'C') THEN
2936 arp_util.debug('l_calc_tot_amount_app -> '||to_char(l_calc_tot_amount_app));
2937 arp_util.debug('l_calc_line_amount -> '||to_char(l_calc_line_amount));
2938 arp_util.debug('l_calc_tax_amount -> '||to_char(l_calc_tax_amount));
2939 END IF;
2940
2941 -- Update the GT table with calculated values
2942
2943 Update ar_llca_trx_lines_gt
2944 set amount_applied = Nvl(l_calc_tot_amount_app,0),
2945 line_amount = Nvl(l_calc_line_amount,0),
2946 tax_amount = Nvl(l_calc_tax_amount,0)
2947 where customer_trx_id = p_customer_trx_id
2948 and customer_trx_line_id = sp_lines_row.customer_trx_line_id;
2949
2950 -- Running totals
2951 l_cum_amount_app := Nvl(l_cum_amount_app,0) + Nvl(l_calc_tot_amount_app,0);
2952 l_cum_line_amount := Nvl(l_cum_line_amount,0)+ Nvl(l_calc_line_amount,0);
2953 l_cum_tax_amount := Nvl(l_cum_tax_amount,0) + Nvl(l_calc_tax_amount,0);
2954 l_cum_line_discount := Nvl(l_cum_line_discount,0) + Nvl(sp_lines_row.line_discount,0);
2955 l_cum_tax_discount := Nvl(l_cum_tax_discount,0) + Nvl(sp_lines_row.tax_discount,0);
2956
2957 IF PG_DEBUG in ('Y', 'C') THEN
2958 arp_util.debug('l_cum_tot_amount_app -> '||to_char(l_cum_amount_app));
2959 arp_util.debug('l_cum_line_amount -> '||to_char(l_cum_line_amount));
2960 arp_util.debug('l_cum_tax_amount -> '||to_char(l_cum_tax_amount));
2961 arp_util.debug('l_cum_line_discount -> '||to_char(l_cum_line_discount));
2962 arp_util.debug('l_cum_tax_discount -> '||to_char(l_cum_tax_discount));
2963 END IF;
2964 End Loop;
2965 p_amount_applied := nvl(l_cum_amount_app,0) + nvl(p_freight_amount,0);
2966 p_line_amount := nvl(l_cum_line_amount,0);
2967 p_tax_amount := nvl(l_cum_tax_amount,0);
2968 p_line_discount := nvl(l_cum_line_discount,0);
2969 p_tax_discount := nvl(l_cum_tax_discount,0);
2970 p_discount := nvl(p_line_discount,0) + nvl(p_tax_discount,0)
2971 + nvl(p_freight_discount,0);
2972 IF PG_DEBUG in ('Y', 'C') THEN
2973 arp_util.debug('p_amount_applied => '||to_char(p_amount_applied) );
2974 arp_util.debug('p_line_amount => '||to_char(l_cum_line_amount));
2975 arp_util.debug('p_tax_amount => '||to_char(l_cum_tax_amount));
2976 arp_util.debug('p_freight_amount => '||to_char(p_freight_amount));
2977 arp_util.debug('p_line_discount => '||to_char(p_line_discount));
2978 arp_util.debug('p_tax_discount => '||to_char(p_tax_discount));
2979 arp_util.debug('p_freight_discount => '||to_char(p_freight_discount));
2980 arp_util.debug('p_discount (Total) => '||to_char(p_discount));
2981 END IF;
2982
2983 END IF; /* GT COUNT END IF */
2984 END IF; /* P_llca_type ENDIF */
2985
2986
2987 IF PG_DEBUG in ('Y', 'C') THEN
2988 arp_util.debug('Default_val_llca_parameters()-');
2989 END IF;
2990 EXCEPTION
2991 WHEN others THEN
2992 IF PG_DEBUG in ('Y', 'C') THEN
2993 arp_util.debug('EXCEPTION: Default_val_llca_parameters: ()');
2994 END IF;
2995 raise;
2996 END;
2997
2998 PROCEDURE Default_disc_and_amt_applied(
2999 p_customer_id IN NUMBER,
3000 p_bill_to_site_use_id IN NUMBER,
3001 p_applied_payment_schedule_id IN NUMBER,
3002 p_amount_applied IN OUT NOCOPY NUMBER,
3003 p_discount IN OUT NOCOPY NUMBER,
3004 p_term_id IN NUMBER,
3005 p_installment IN NUMBER,
3006 p_trx_date IN DATE,
3007 p_cr_date IN DATE,
3008 p_cr_currency_code IN VARCHAR2,
3009 p_trx_currency_code IN VARCHAR2,
3010 p_cr_exchange_rate IN NUMBER,
3011 p_trx_exchange_rate IN NUMBER,--corresponds to app_folder.exchange_rate
3012 p_apply_date IN DATE,
3013 p_amount_due_original IN NUMBER,
3014 p_amount_due_remaining IN NUMBER,
3015 p_cr_unapp_amount IN NUMBER,
3016 p_allow_overappln_flag IN VARCHAR2,
3017 p_calc_discount_on_lines_flag IN VARCHAR2,
3018 p_partial_discount_flag IN VARCHAR2,
3019 p_amount_line_items_original IN NUMBER,
3020 p_discount_taken_unearned IN NUMBER,
3021 p_discount_taken_earned IN NUMBER,
3022 p_customer_trx_line_id IN NUMBER,
3023 p_trx_line_amount IN NUMBER,
3024 p_llca_type IN VARCHAR2,
3025 p_discount_max_allowed OUT NOCOPY NUMBER,
3026 p_discount_earned_allowed OUT NOCOPY NUMBER,
3027 p_discount_earned OUT NOCOPY NUMBER,
3028 p_discount_unearned OUT NOCOPY NUMBER,
3029 p_new_amount_due_remaining OUT NOCOPY NUMBER,
3030 p_return_status OUT NOCOPY VARCHAR2
3031 )
3032 IS
3033
3034 l_grace_days NUMBER;
3035 l_applied_in_amount NUMBER;
3036 l_earned_disc_pct NUMBER;
3037 l_best_disc_pct NUMBER;
3038 l_out_discount_date DATE;
3039 l_out_earned_discount NUMBER;
3040 l_out_unearned_discount NUMBER;
3041 l_out_amount_to_apply NUMBER;
3042 l_out_discount_to_take NUMBER;
3043 l_discount_date DATE;
3044 l_discount NUMBER;
3045 l_discount_mode VARCHAR2(1);
3046 l_exchange_rate_type VARCHAR2(30);
3047 tmp_rate NUMBER;
3048 l_default_amount_applied_flag VARCHAR2(30);
3049 l_convert_amount_inv NUMBER;
3050 l_convert_amount_cr NUMBER;
3051 l_allow_discount VARCHAR2(1) DEFAULT 'Y'; /* Bug fix 3450317 */
3052
3053 BEGIN
3054 IF PG_DEBUG in ('Y', 'C') THEN
3055 arp_util.debug('Default_disc_and_amt_applied ()+');
3056 END IF;
3057 p_return_status := FND_API.G_RET_STS_SUCCESS;
3058 IF PG_DEBUG in ('Y', 'C') THEN
3059 arp_util.debug('Default_disc_and_amt_applied: ' || 'p_discount = '||p_discount);
3060 END IF;
3061 IF p_amount_applied IS NULL THEN
3062 IF PG_DEBUG in ('Y', 'C') THEN
3063 arp_util.debug('Default_disc_and_amt_applied: ' || 'The p_amount_applied is NULL ');
3064 END IF;
3065 IF p_trx_currency_code <> p_cr_currency_code --The cross-currency case
3066 THEN
3067 l_exchange_rate_type := pg_profile_cc_rate_type;
3068 IF PG_DEBUG in ('Y', 'C') THEN
3069 arp_util.debug('Default_disc_and_amt_applied: ' || 'default cross currency exchange rate type :'||l_exchange_rate_type);
3070 END IF;
3071 IF ( (gl_currency_api.is_fixed_rate(
3072 p_cr_currency_code,
3073 p_trx_currency_code,
3074 p_cr_date
3075 ) = 'Y' ) OR
3076 l_exchange_rate_type IS NOT NULL)
3077 THEN
3078 IF PG_DEBUG in ('Y', 'C') THEN
3079 arp_util.debug('Default_disc_and_amt_applied: ' || 'p_trx_currency_code :'||p_trx_currency_code);
3080 arp_util.debug('Default_disc_and_amt_applied: ' || 'p_cr_currency_code :'||p_cr_currency_code);
3081 arp_util.debug('Default_disc_and_amt_applied: ' || 'p_cr_date :'||p_cr_date);
3082 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_exchange_rate_type :'||l_exchange_rate_type);
3083 arp_util.debug('Default_disc_and_amt_applied: ' || 'p_amount_due_remaining :'||to_char(p_amount_due_remaining));
3084 arp_util.debug('Default_disc_and_amt_applied: ' || 'p_cr_unapp_amount :'||to_char(p_cr_unapp_amount));
3085 END IF;
3086
3087 BEGIN
3088
3089 /* bug 2174978 : cross currency applications are unable to do partial applications
3090
3091 define converted amounts for
3092 a) transaction amount in receipt currency
3093 b) receipt amount in transaction currency
3094 and assign the appropriate converted amount to l_applied_in_amount below */
3095
3096 -- invoice amount in receipt currency
3097 l_convert_amount_inv := gl_currency_api.convert_amount(
3098 p_trx_currency_code,
3099 p_cr_currency_code,
3100 p_cr_date,
3101 l_exchange_rate_type,
3102 p_amount_due_remaining);
3103
3104 -- receipt amount in invoice currency
3105 l_convert_amount_cr := gl_currency_api.convert_amount(
3106 p_cr_currency_code,
3107 p_trx_currency_code,
3108 p_cr_date,
3109 l_exchange_rate_type,
3110 p_cr_unapp_amount);
3111
3112 IF PG_DEBUG in ('Y', 'C') THEN
3113 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_convert_amount_inv:'||to_char(l_convert_amount_inv));
3114 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_convert_amount_cr :'||to_char(l_convert_amount_cr));
3115 END IF;
3116
3117
3118 EXCEPTION
3119 WHEN gl_currency_api.NO_RATE THEN
3120 l_convert_amount_inv := NULL;
3121 l_convert_amount_cr := NULL;
3122 IF PG_DEBUG in ('Y', 'C') THEN
3123 arp_util.debug('Default_disc_and_amt_applied: ' || 'No rate exists in the GL for the cross currency conversion ');
3124 END IF;
3125 WHEN gl_currency_api.INVALID_CURRENCY THEN
3126 IF PG_DEBUG in ('Y', 'C') THEN
3127 arp_util.debug('Default_disc_and_amt_applied: ' || 'The Receipt/Invoice currency is Invalid ');
3128 END IF;
3129 raise;
3130 END;
3131
3132 -- l_applied_in_amount is in terms of transaction currency
3133 -- because we need discounts in that currency
3134
3135 IF (l_convert_amount_inv = p_cr_unapp_amount) THEN
3136 /* if invoice amount in receipt currency matches receipt's unapplied amount
3137 pass the invoice amount in invoice currency */
3138
3139 l_applied_in_amount := p_amount_due_remaining;
3140 IF PG_DEBUG in ('Y', 'C') THEN
3141 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_convert_amount_inv = p_cr_unapp_amount, l_applied_in_amount = ' || to_char(l_applied_in_amount));
3142 END IF;
3143 ELSE
3144 /* bug 2174978 : if invoice amount in receipt currency <> receipt's unapplied amount
3145 pass the receipt amount in invoice currency */
3146
3147 l_applied_in_amount := l_convert_amount_cr;
3148 IF PG_DEBUG in ('Y', 'C') THEN
3149 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_convert_amount_inv <> p_cr_unapp_amount, l_applied_in_amount :'||to_char(l_applied_in_amount));
3150 END IF;
3151 END IF;
3152
3153 /* if exchange rate type was ok, but no rate in GL, the value returned is
3154 NULL so we have to set the value as though no fixed rate existed */
3155 IF (l_applied_in_amount IS NULL) THEN
3156 l_applied_in_amount := p_amount_due_remaining;
3157 END IF;
3158
3159 ELSE
3160 -- No fixed rate exists then amount_due_remaining on the inv
3161 --is used as the amount for discount calculation
3162
3163 l_applied_in_amount := p_amount_due_remaining;
3164 END IF;
3165 ELSE -- Same currency application
3166 /* Bug fix 3539657
3167 Set the l_applied_in_amount based on the value of ADR and the Unapplied amount */
3168 IF p_amount_due_remaining > p_cr_unapp_amount THEN
3169 l_applied_in_amount := p_cr_unapp_amount;
3170 ELSE
3171 l_applied_in_amount := p_amount_due_remaining;
3172 END IF;
3173 END IF;
3174
3175 /* Bug fix 3539657
3176 If the p_customer_trx_line_id is specified, limit the amount applied to
3177 the line amount if the line amount is less than the defaulted amount applied */
3178 IF p_customer_trx_line_id IS NOT NULL
3179 AND p_llca_type is NULL
3180 AND p_trx_line_amount < l_applied_in_amount THEN
3181 l_applied_in_amount := p_trx_line_amount;
3182 --give a warning message here to let the user know that the
3183 --transaction line amount has been used as the default amount applied.
3184 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS) THEN
3185 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_LINE_AMT_DEFLT');
3186 FND_MSG_PUB.Add;
3187 END IF;
3188 END IF;
3189
3190 -- Defaulting mode for disount routine.
3191 l_discount_mode := '3';
3192 l_default_amount_applied_flag := pg_profile_amt_applied_def;
3193 ELSE --user has entered the amount applied.
3194 If p_llca_type is NOT NULL
3195 THEN
3196 l_applied_in_amount := Nvl(p_amount_applied,0);
3197 -- Direct mode for discount routine.
3198 l_discount_mode := '3';
3199 l_default_amount_applied_flag := pg_profile_amt_applied_def;
3200 Else
3201 l_applied_in_amount := p_amount_applied;
3202 -- Direct mode for discount routine.
3203 l_discount_mode := '2';
3204 l_default_amount_applied_flag := '';
3205 End IF;
3206 END IF;
3207
3208 -- Get discount grace days.
3209 l_grace_days := Get_grace_days( p_customer_id,
3210 p_bill_to_site_use_id );
3211
3212 /* Bug fix 3450317
3213 See if discounts are allowed for this customer */
3214 SELECT NVL(NVL(site.discount_terms, cust.discount_terms),'Y')
3215 INTO l_allow_discount
3216 FROM
3217 hz_customer_profiles cust
3218 , hz_customer_profiles site
3219 WHERE
3220 cust.cust_account_id = p_customer_id
3221 AND cust.site_use_id IS NULL
3222 AND site.cust_account_id (+) = cust.cust_account_id
3223 AND site.site_use_id (+) = p_bill_to_site_use_id;
3224
3225 IF p_applied_payment_schedule_id > 0 AND
3226 l_grace_days IS NOT NULL THEN
3227 IF PG_DEBUG in ('Y', 'C') THEN
3228 arp_util.debug('Default_disc_and_amt_applied: ' || 'Before calling the discounts routine ..');
3229 END IF;
3230
3231 arp_calculate_discount.discounts_cover(
3232 -- IN PARAMETERS
3233 p_mode => l_discount_mode,
3234 p_invoice_currency_code => p_trx_currency_code,
3235 p_ps_id => p_applied_payment_schedule_id,
3236 p_term_id => p_term_id,
3237 p_terms_sequence_number => p_installment,
3238 p_trx_date => p_trx_date,
3239 p_apply_date => p_apply_date,
3240 p_grace_days => l_grace_days,
3241 p_default_amt_apply_flag => l_default_amount_applied_flag,
3242 p_partial_discount_flag => p_partial_discount_flag,
3243 p_calc_discount_on_lines_flag=> p_calc_discount_on_lines_flag,
3244 p_allow_overapp_flag => p_allow_overappln_flag,
3245 p_close_invoice_flag => 'N',
3246 p_input_amount => NVL(l_applied_in_amount,0),
3247 p_amount_due_original => p_amount_due_original,
3248 p_amount_due_remaining => p_amount_due_remaining,
3249 p_discount_taken_earned => NVL(p_discount_taken_earned,0),
3250 p_discount_taken_unearned => NVL(p_discount_taken_unearned,0),
3251 p_amount_line_items_original=> p_amount_line_items_original,
3252 p_module_name => 'RECEIPTAPI',
3253 p_module_version => '1.0',
3254 p_allow_discount => l_allow_discount , /* Bug fix 3450317 */
3255 --*** OUT NOCOPY
3256 p_earned_disc_pct => l_earned_disc_pct,
3257 p_best_disc_pct => l_best_disc_pct,
3258 p_out_discount_date => l_discount_date,
3259 p_out_earned_discount => l_out_earned_discount,
3260 p_out_unearned_discount => l_out_unearned_discount,
3261 p_out_amount_to_apply => l_out_amount_to_apply,
3262 p_out_discount_to_take => l_discount
3263 );
3264 IF PG_DEBUG in ('Y', 'C') THEN
3265 arp_util.debug('Default_disc_and_amt_applied: ' || 'After calling the discounts routine ..');
3266 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_out_earned_discount = '||l_out_earned_discount);
3267 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_out_unearned_discount = '||l_out_unearned_discount);
3268 arp_util.debug('Default_disc_and_amt_applied: ' || 'l_discount = '||l_discount);
3269 arp_util.debug('Default_disc_and_amt_applied: ' || 'p_discount = '||p_discount);
3270 END IF;
3271 l_earned_disc_pct := ROUND(l_earned_disc_pct,6);
3272
3273 -- Store the maximum allowed discount, to be used later while validating
3274 p_discount_max_allowed :=arp_util.CurrRound( l_out_earned_discount+
3275 l_out_unearned_discount,
3276 p_trx_currency_code);
3277 p_discount_earned_allowed := l_out_earned_discount;
3278
3279 IF p_discount IS NULL THEN
3280 p_discount := l_discount;
3281 END IF;
3282
3283 --earned discounts
3284 -- Bug 3527600: Allow for negative discount
3285 IF (ABS(p_discount) > ABS(p_discount_earned_allowed))
3286 THEN
3287 p_discount_earned := p_discount_earned_allowed;
3288 ELSE
3289 p_discount_earned := p_discount;
3290 END IF;
3291
3292 -- unearned discounts
3293 /* Bug 2535663 - p_discount, the discount passed in, should be used, not
3294 l_discount which is the discount_earned */
3295 -- Bug 3527600: Allow for negative discount
3296 IF (((p_discount > 0) AND ( p_discount - p_discount_earned_allowed > 0)) OR
3297 ((p_discount < 0) AND ( p_discount - p_discount_earned_allowed < 0)))
3298 THEN
3299 p_discount_unearned := p_discount - p_discount_earned_allowed;
3300 ELSE
3301 p_discount_unearned := 0;
3302 END IF;
3303
3304 -- Populate Amount Applied if user has not entered any value for it.
3305 -- if the line number has not been entered by the user or is NULL then
3306 -- default the amount_applied to the l_out_amount_to_apply obtained
3307 -- from the discounts routine above else default it to the inv_line_amount
3308
3309 IF p_amount_applied IS NULL THEN
3310 /* Bug fix 3539657 */
3311 /* IF p_customer_trx_line_id IS NULL
3312 THEN
3313 p_amount_applied := l_out_amount_to_apply;
3314 ELSE
3315
3316 IF p_trx_line_amount IS NOT NULL AND
3317 p_trx_line_amount < l_out_amount_to_apply
3318 THEN
3319 p_amount_applied := p_trx_line_amount;
3320 --give a warning message here to let the user know that the
3321 --transaction line amount has been used as the default amount applied.
3322 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS) THEN
3323 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_LINE_AMT_DEFLT');
3324 FND_MSG_PUB.Add;
3325 END IF;
3326 END IF;
3327
3328 END IF; */
3329
3330 p_amount_applied := l_out_amount_to_apply;
3331 END IF;
3332
3333 END IF;
3334
3335 p_amount_applied := arp_util.CurrRound(p_amount_applied,
3336 p_trx_currency_code);
3337 p_discount := arp_util.CurrRound(p_discount,
3338 p_trx_currency_code);
3339 IF PG_DEBUG in ('Y', 'C') THEN
3340 arp_util.debug('Default_disc_and_amt_applied ()-');
3341 END IF;
3342 EXCEPTION
3343 WHEN others THEN
3344 IF PG_DEBUG in ('Y', 'C') THEN
3345 arp_util.debug('Default_disc_and_amt_applied: ' || 'EXCEPTION: Default_discount_and_amount_applied()');
3346 END IF;
3347 raise;
3348 END Default_disc_and_amt_applied;
3349
3350 FUNCTION Get_trx_Line_amount(
3351 p_customer_trx_id IN ra_customer_trx.customer_trx_id%TYPE,
3352 p_payment_schedule_id IN ar_payment_schedules.payment_schedule_id%TYPE,
3353 p_customer_trx_line_id IN ra_customer_trx_lines.customer_trx_line_id%TYPE,
3354 p_return_status OUT NOCOPY VARCHAR2
3355 ) RETURN NUMBER IS
3356
3357 l_trx_line_amount NUMBER;
3358 BEGIN
3359 IF p_customer_trx_id IS NOT NULL AND
3360 p_customer_trx_line_id IS NOT NULL
3361 THEN
3362
3363 SELECT ctl.extended_amount *
3364 nvl(tl.relative_amount,1)/ nvl(t.base_amount,1)
3365 INTO l_trx_line_amount
3366 FROM ra_customer_trx_lines ctl ,
3367 ra_terms t ,
3368 ra_terms_lines tl ,
3369 ar_payment_schedules ps
3370 WHERE ps.payment_schedule_id = p_payment_schedule_id and
3371 ctl.customer_trx_id = p_customer_trx_id and
3372 ctl.line_type = 'LINE' and
3373 tl.term_id(+) = ps.term_id and
3374 tl.sequence_num(+) = ps.terms_sequence_number and
3375 t.term_id(+) = tl.term_id and
3376 ctl.customer_trx_line_id = p_customer_trx_line_id;
3377
3378 RETURN(l_trx_line_amount);
3379 END IF;
3380
3381 EXCEPTION
3382 WHEN no_data_found THEN
3383 p_return_status := FND_API.G_RET_STS_ERROR ;
3384 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_TRX_LINE_ID_INVALID');
3385 FND_MSG_PUB.ADD;
3386 return(null);
3387
3388 WHEN others THEN
3389 IF PG_DEBUG in ('Y', 'C') THEN
3390 arp_util.debug('Get_trx_Line_amount: ' || 'EXCEPTION: Default_Trx_Line_Amount()');
3391 END IF;
3392 raise;
3393 END Get_trx_Line_amount;
3394
3395
3396 PROCEDURE Default_Trx_Info(
3397 p_customer_trx_id IN ra_customer_trx.customer_trx_id%TYPE,
3398 p_customer_trx_line_id IN NUMBER,
3399 p_show_closed_invoices IN VARCHAR2,
3400 p_cr_gl_date IN DATE,
3401 p_cr_customer_id IN ar_cash_receipts.pay_from_customer%TYPE,
3402 p_cr_currency_code IN VARCHAR2,
3403 p_cr_payment_schedule_id IN NUMBER,
3404 p_cr_date IN DATE,
3405 p_called_from IN VARCHAR2,
3406 p_customer_id OUT NOCOPY NUMBER, --customer on transaction
3407 p_cust_trx_type_id OUT NOCOPY ra_customer_trx.cust_trx_type_id%TYPE ,
3408 p_trx_due_date OUT NOCOPY DATE,
3409 p_trx_currency_code OUT NOCOPY VARCHAR2,
3410 p_trx_exchange_rate OUT NOCOPY NUMBER,
3411 p_trx_date OUT NOCOPY DATE,
3412 p_trx_gl_date OUT NOCOPY DATE,
3413 p_calc_discount_on_lines_flag OUT NOCOPY VARCHAR2,
3414 p_partial_discount_flag OUT NOCOPY VARCHAR2,
3415 p_allow_overappln_flag OUT NOCOPY VARCHAR2,
3416 p_natural_appln_only_flag OUT NOCOPY VARCHAR2,
3417 p_creation_sign OUT NOCOPY VARCHAR2,
3418 p_applied_payment_schedule_id IN OUT NOCOPY NUMBER,
3419 p_gl_date OUT NOCOPY DATE, --this is the application gl_date
3420 p_term_id OUT NOCOPY NUMBER,
3421 p_amount_due_original OUT NOCOPY NUMBER,
3422 p_amount_line_items_original OUT NOCOPY NUMBER,
3423 p_amount_due_remaining OUT NOCOPY NUMBER,
3424 p_discount_taken_earned OUT NOCOPY NUMBER,
3425 p_discount_taken_unearned OUT NOCOPY NUMBER,
3426 p_trx_line_amount OUT NOCOPY NUMBER,
3427 p_installment IN OUT NOCOPY NUMBER,
3428 p_bill_to_site_use_id OUT NOCOPY NUMBER,
3429 p_llca_type IN VARCHAR2,
3430 p_line_items_original OUT NOCOPY NUMBER,
3431 p_line_items_remaining OUT NOCOPY NUMBER,
3432 p_tax_original OUT NOCOPY NUMBER,
3433 p_tax_remaining OUT NOCOPY NUMBER,
3434 p_freight_original OUT NOCOPY NUMBER,
3435 p_freight_remaining OUT NOCOPY NUMBER,
3436 p_rec_charges_charged OUT NOCOPY NUMBER,
3437 p_rec_charges_remaining OUT NOCOPY NUMBER,
3438 p_return_status OUT NOCOPY VARCHAR2
3439 ) IS
3440 l_location VARCHAR2(50);
3441 l_found VARCHAR2(1);
3442 l_applied_payment_schedule_id NUMBER;
3443 l_line_amt_return_status VARCHAR2(1);
3444
3445 /* modified for tca uptake */
3446 CURSOR get_site_use_id IS
3447 SELECT site_use_id
3448 FROM hz_cust_site_uses site_use,
3449 hz_cust_acct_sites acct_site
3450 WHERE acct_site.cust_acct_site_id = site_use.cust_acct_site_id
3451 AND acct_site.cust_account_id = p_customer_id
3452 AND site_use.location = l_location
3453 AND site_use.site_use_code IN ('BILL_TO','DRAWEE');
3454
3455 BEGIN
3456 IF PG_DEBUG in ('Y', 'C') THEN
3457 arp_util.debug('Default_Trx_Info ()+');
3458 END IF;
3459 p_return_status := FND_API.G_RET_STS_SUCCESS;
3460 --this is only for regular application, not for on-account
3461
3462
3463 IF p_customer_trx_id IS NOT NULL AND
3464 p_installment IS NOT NULL THEN
3465
3466 IF p_called_from IN ('BR_REMITTED',
3467 'BR_FACTORED_WITH_RECOURSE',
3468 'BR_FACTORED_WITHOUT_RECOURSE') THEN
3469 --called from the BR Remittance program
3470
3471 -- To handle the case where the apply routine is called from the
3472 -- BR Remittance program, we refer to the underlying tables directly
3473 -- instead of accessing the view ar_open_trx_v. This is because
3474 -- as per the view definition of ar_open_trx_v it will not return the
3475 -- 'reserved'(having reserved_type and reserved_value not null)
3476 -- transactions(Bill).
3477
3478 IF arp_global.sysparam.pay_unrelated_invoices_flag = 'Y' THEN
3479
3480 /* modified for tca uptake */
3481 SELECT
3482 ps.customer_id
3483 , ps.cust_trx_type_id
3484 , decode(ps.customer_id ,-1,NULL ,ps.due_date)
3485 , ps.invoice_currency_code
3486 , ps.exchange_rate
3487 , ct.trx_date
3488 , ps.gl_date
3489 , t.calc_discount_on_lines_flag
3490 , t.partial_discount_flag
3491 , ctt.allow_overapplication_flag
3492 , ctt.natural_application_only_flag
3493 , ctt.creation_sign
3494 , ps.payment_schedule_id
3495 , greatest(p_cr_gl_date,ps.gl_date,
3496 decode(pg_profile_appln_gl_date_def,
3497 'INV_REC_SYS_DT', sysdate, 'INV_REC_DT', ps.gl_date,
3498 ps.gl_date)) gl_date
3499 , ps.term_id
3500 , ps.amount_due_original
3501 , ps.amount_line_items_original
3502 , arp_util.CurrRound(ps.amount_due_remaining,
3503 ps.invoice_currency_code)
3504 , ps.discount_taken_earned
3505 , ps.discount_taken_unearned
3506 , ps.amount_line_items_original
3507 , ps.amount_line_items_remaining
3508 , ps.tax_original
3509 , ps.tax_remaining
3510 , ps.freight_original
3511 , ps.freight_remaining
3512 , ps.receivables_charges_charged
3513 , ps.receivables_charges_remaining
3514 , su.location
3515 INTO
3516 p_customer_id ,
3517 p_cust_trx_type_id ,
3518 p_trx_due_date ,
3519 p_trx_currency_code,
3520 p_trx_exchange_rate,
3521 p_trx_date,
3522 p_trx_gl_date ,
3523 p_calc_discount_on_lines_flag ,
3524 p_partial_discount_flag ,
3525 p_allow_overappln_flag ,
3526 p_natural_appln_only_flag ,
3527 p_creation_sign ,
3528 l_applied_payment_schedule_id ,
3529 p_gl_date, --this is the application gl_date
3530 p_term_id ,
3531 p_amount_due_original,
3532 p_amount_line_items_original ,
3533 p_amount_due_remaining ,
3534 p_discount_taken_earned,
3535 p_discount_taken_unearned,
3536 p_line_items_original,
3537 p_line_items_remaining,
3538 p_tax_original,
3539 p_tax_remaining,
3540 p_freight_original,
3541 p_freight_remaining,
3542 p_rec_charges_charged,
3543 p_rec_charges_remaining,
3544 l_location
3545 FROM
3546 ra_customer_trx ct
3547 , ra_cust_trx_types ctt
3548 , hz_cust_site_uses su
3549 , ra_batch_sources bs
3550 , ar_lookups lu
3551 , hz_cust_accounts cust
3552 , ra_terms t
3553 , ar_payment_schedules ps
3554 , ar_cons_inv ci
3555 WHERE
3556 ps.class in ('CB','CM','DEP','DM','INV','BR')
3557 AND ps.selected_for_receipt_batch_id is null
3558 AND t.term_id(+) = ps.term_id
3559 AND ct.customer_trx_id(+) = ps.customer_trx_id
3560 AND bs.batch_source_id (+) = ct.batch_source_id
3561 AND ctt.cust_trx_type_id(+) = ps.cust_trx_type_id
3562 AND cust.cust_account_id(+) = ps.customer_id
3563 AND su.site_use_id(+) = ps.customer_site_use_id
3564 AND ps.class = lu.lookup_code
3565 AND ct.previous_customer_trx_id is null
3566 AND lu.lookup_type = 'INV/CM'
3567 AND ci.cons_inv_id(+) = ps.cons_inv_id
3568 AND ct.customer_trx_id = p_customer_trx_id
3569 AND ps.invoice_currency_code =
3570 decode(nvl(pg_profile_enable_cc,'N'),
3571 'Y',ps.invoice_currency_code,p_cr_currency_code)
3572 AND ps.status=decode(p_show_closed_invoices,'Y',ps.status,'OP')
3573 AND ps.terms_sequence_number = p_installment
3574 ;
3575 ELSE --This is the case where pay_unrelated_invoices_flag is 'N'
3576
3577 /* modified for tca uptake */
3578 SELECT
3579 ps.customer_id
3580 , ps.cust_trx_type_id
3581 , decode(ps.customer_id ,-1,NULL,ps.due_date)
3582 , ps.invoice_currency_code
3583 , ps.exchange_rate
3584 , ct.trx_date
3585 , ps.gl_date
3586 , t.calc_discount_on_lines_flag
3587 , t.partial_discount_flag
3588 , ctt.allow_overapplication_flag
3589 , ctt.natural_application_only_flag
3590 , ctt.creation_sign
3591 , ps.payment_schedule_id
3592 , greatest(p_cr_gl_date,ps.gl_date,
3593 decode(pg_profile_appln_gl_date_def,
3594 'INV_REC_SYS_DT', sysdate, 'INV_REC_DT', ps.gl_date,
3595 ps.gl_date)) gl_date
3596 , ps.term_id
3597 , ps.amount_due_original
3598 , ps.amount_line_items_original
3599 , arp_util.CurrRound(ps.amount_due_remaining,
3600 ps.invoice_currency_code)
3601 , ps.discount_taken_earned
3602 , ps.discount_taken_unearned
3603 , ps.amount_line_items_original
3604 , ps.amount_line_items_remaining
3605 , ps.tax_original
3606 , ps.tax_remaining
3607 , ps.freight_original
3608 , ps.freight_remaining
3609 , ps.receivables_charges_charged
3610 , ps.receivables_charges_remaining
3611 , su.location
3612 INTO
3613 p_customer_id ,
3614 p_cust_trx_type_id ,
3615 p_trx_due_date ,
3616 p_trx_currency_code,
3617 p_trx_exchange_rate,
3618 p_trx_date,
3619 p_trx_gl_date ,
3620 p_calc_discount_on_lines_flag ,
3621 p_partial_discount_flag ,
3622 p_allow_overappln_flag ,
3623 p_natural_appln_only_flag ,
3624 p_creation_sign ,
3625 l_applied_payment_schedule_id ,
3626 p_gl_date, --this is the application gl_date
3627 p_term_id ,
3628 p_amount_due_original,
3629 p_amount_line_items_original ,
3630 p_amount_due_remaining ,
3631 p_discount_taken_earned,
3632 p_discount_taken_unearned,
3633 p_line_items_original,
3634 p_line_items_remaining,
3635 p_tax_original,
3636 p_tax_remaining,
3637 p_freight_original,
3638 p_freight_remaining,
3639 p_rec_charges_charged,
3640 p_rec_charges_remaining,
3641 l_location
3642 FROM
3643 ra_customer_trx ct
3644 , ra_cust_trx_types ctt
3645 , hz_cust_site_uses su
3646 , ra_batch_sources bs
3647 , ar_lookups lu
3648 , hz_cust_accounts cst
3649 , ra_terms t
3650 , ar_payment_schedules ps
3651 , ar_cons_inv ci
3652 WHERE
3653 ps.class in ('CB','CM','DEP','DM','INV','BR')
3654 AND ps.selected_for_receipt_batch_id is null
3655 AND t.term_id(+) = ps.term_id
3656 AND ct.customer_trx_id(+) = ps.customer_trx_id
3657 AND bs.batch_source_id (+) = ct.batch_source_id
3658 AND ctt.cust_trx_type_id(+) = ps.cust_trx_type_id
3659 AND cst.cust_account_id(+) = ps.customer_id
3660 AND su.site_use_id(+) = ps.customer_site_use_id
3661 AND ps.class = lu.lookup_code
3662 AND ct.previous_customer_trx_id is null
3663 AND lu.lookup_type = 'INV/CM'
3664 AND ci.cons_inv_id(+) = ps.cons_inv_id
3665 AND ct.customer_trx_id = p_customer_trx_id
3666 AND ps.invoice_currency_code =
3667 decode(nvl(pg_profile_enable_cc,'N'),
3668 'Y',ps.invoice_currency_code,p_cr_currency_code)
3669 AND ps.status=decode(p_show_closed_invoices,'Y',ps.status,'OP')
3670 AND ps.terms_sequence_number = p_installment
3671 AND ps.customer_id IN (
3672 SELECT rcr.related_cust_account_id
3673 FROM hz_cust_acct_relate rcr
3674 WHERE rcr.status='A' and
3675 rcr.cust_account_id= p_cr_customer_id
3676 and rcr.bill_to_flag = 'Y'
3677 UNION
3678 SELECT p_cr_customer_id
3679 FROM dual
3680 UNION
3681 SELECT rel.related_cust_account_id
3682 FROM ar_paying_relationships_v rel,
3683 hz_cust_accounts acc
3684 WHERE rel.party_id = acc.party_id
3685 AND acc.cust_account_id = p_cr_customer_id
3686 AND p_cr_date BETWEEN effective_start_date
3687 AND effective_end_date
3688 );
3689
3690 END IF;
3691
3692 ELSE
3693
3694 IF arp_global.sysparam.pay_unrelated_invoices_flag = 'Y' THEN
3695 /* modified for tca uptake */
3696 SELECT
3697 ot.customer_id ,
3698 ot.cust_trx_type_id ,
3699 ot.trx_due_date ,
3700 ot.invoice_currency_code,
3701 ot.trx_exchange_rate,
3702 ot.trx_date,
3703 ot.trx_gl_date ,
3704 ot.calc_discount_on_lines_flag ,
3705 ot.partial_discount_flag ,
3706 ot.allow_overapplication_flag ,
3707 ot.natural_application_only_flag ,
3708 ot.creation_sign ,
3709 ot.payment_schedule_id ,
3710 greatest(p_cr_gl_date,ot.trx_gl_date,
3711 decode(pg_profile_appln_gl_date_def,
3712 'INV_REC_SYS_DT', sysdate, 'INV_REC_DT', ot.trx_gl_date,
3713 ot.trx_gl_date)) gl_date,
3714 ot.term_id ,
3715 ot.amount_due_original,
3716 ot.amount_line_items_original ,
3717 arp_util.CurrRound(ot.balance_due_curr_unformatted,
3718 ot.invoice_currency_code) ,
3719 ot.discount_taken_earned,
3720 ot.discount_taken_unearned,
3721 ot.amount_line_items_original,
3722 ot.amount_line_items_remaining,
3723 ot.tax_original,
3724 ot.tax_remaining,
3725 ot.freight_original,
3726 ot.freight_remaining,
3727 Null receivables_charges_charged,
3728 ot.receivables_charges_remaining,
3729 ot.location
3730 INTO
3731 p_customer_id ,
3732 p_cust_trx_type_id ,
3733 p_trx_due_date ,
3734 p_trx_currency_code,
3735 p_trx_exchange_rate,
3736 p_trx_date,
3737 p_trx_gl_date ,
3738 p_calc_discount_on_lines_flag ,
3739 p_partial_discount_flag ,
3740 p_allow_overappln_flag ,
3741 p_natural_appln_only_flag ,
3742 p_creation_sign ,
3743 l_applied_payment_schedule_id ,
3744 p_gl_date, --this is the application gl_date
3745 p_term_id ,
3746 p_amount_due_original,
3747 p_amount_line_items_original ,
3748 p_amount_due_remaining ,
3749 p_discount_taken_earned,
3750 p_discount_taken_unearned,
3751 p_line_items_original,
3752 p_line_items_remaining,
3753 p_tax_original,
3754 p_tax_remaining,
3755 p_freight_original,
3756 p_freight_remaining,
3757 p_rec_charges_charged,
3758 p_rec_charges_remaining,
3759 l_location
3760 FROM
3761 ar_open_trx_v ot
3762 WHERE
3763 ot.customer_trx_id = p_customer_trx_id and
3764 ot.invoice_currency_code =
3765 DECODE(NVL(pg_profile_enable_cc,'N'),
3766 'Y',ot.invoice_currency_code,p_cr_currency_code) and
3767 ot.status=decode(p_show_closed_invoices,'Y',ot.status,'OP') and
3768 ot.terms_sequence_number = p_installment;
3769
3770 ELSE
3771 --This is the case where pay_unrelated_invoices_flag is 'N'
3772 /* modified for tca uptake */
3773 SELECT
3774 ot.customer_id ,
3775 ot.cust_trx_type_id ,
3776 ot.trx_due_date ,
3777 ot.invoice_currency_code,
3778 ot.trx_exchange_rate,
3779 ot.trx_date,
3780 ot.trx_gl_date ,
3781 ot.calc_discount_on_lines_flag ,
3782 ot.partial_discount_flag ,
3783 ot.allow_overapplication_flag ,
3784 ot.natural_application_only_flag ,
3785 ot.creation_sign ,
3786 ot.payment_schedule_id ,
3787 greatest(p_cr_gl_date,ot.trx_gl_date,
3788 decode(pg_profile_appln_gl_date_def,
3789 'INV_REC_SYS_DT', sysdate, 'INV_REC_DT', ot.trx_gl_date,
3790 ot.trx_gl_date)) gl_date,
3791 ot.term_id ,
3792 ot.amount_due_original,
3793 ot.amount_line_items_original ,
3794 arp_util.CurrRound(ot.balance_due_curr_unformatted,
3795 ot.invoice_currency_code) ,
3796 ot.discount_taken_earned,
3797 ot.discount_taken_unearned,
3798 ot.amount_line_items_original,
3799 ot.amount_line_items_remaining,
3800 ot.tax_original,
3801 ot.tax_remaining,
3802 ot.freight_original,
3803 ot.freight_remaining,
3804 Null receivables_charges_charged,
3805 ot.receivables_charges_remaining,
3806 ot.location
3807 INTO
3808 p_customer_id ,
3809 p_cust_trx_type_id ,
3810 p_trx_due_date ,
3811 p_trx_currency_code,
3812 p_trx_exchange_rate,
3813 p_trx_date,
3814 p_trx_gl_date ,
3815 p_calc_discount_on_lines_flag ,
3816 p_partial_discount_flag,
3817 p_allow_overappln_flag,
3818 p_natural_appln_only_flag,
3819 p_creation_sign,
3820 l_applied_payment_schedule_id,
3821 p_gl_date, --this is the defaulted application gl_date
3822 p_term_id,
3823 p_amount_due_original,
3824 p_amount_line_items_original,
3825 p_amount_due_remaining,
3826 p_discount_taken_earned,
3827 p_discount_taken_unearned,
3828 p_line_items_original,
3829 p_line_items_remaining,
3830 p_tax_original,
3831 p_tax_remaining,
3832 p_freight_original,
3833 p_freight_remaining,
3834 p_rec_charges_charged,
3835 p_rec_charges_remaining,
3836 l_location
3837 FROM
3838 ar_open_trx_v ot
3839 WHERE
3840 ot.customer_trx_id = p_customer_trx_id and
3841 ot.invoice_currency_code =
3842 DECODE(NVL(pg_profile_enable_cc,'N'),
3843 'Y',ot.invoice_currency_code,p_cr_currency_code) and
3844 ot.status=decode(p_show_closed_invoices,'Y',ot.status,'OP') and
3845 ot.terms_sequence_number = p_installment and
3846 ot.customer_id IN (
3847 SELECT rcr.related_cust_account_id
3848 FROM hz_cust_acct_relate rcr
3849 WHERE rcr.status='A' and
3850 rcr.cust_account_id= p_cr_customer_id
3851 and rcr.bill_to_flag = 'Y'
3852 UNION
3853 SELECT p_cr_customer_id
3854 FROM dual
3855 UNION
3856 SELECT rel.related_cust_account_id
3857 FROM ar_paying_relationships_v rel,
3858 hz_cust_accounts acc
3859 WHERE rel.party_id = acc.party_id
3860 AND acc.cust_account_id = p_cr_customer_id
3861 AND p_cr_date BETWEEN effective_start_date
3862 AND effective_end_date
3863 );
3864
3865 END IF;
3866
3867 END IF;
3868
3869 --If the defaulted payment_schedule_id does not match the
3870 --applied_ps_id entered by the user, then raise error.
3871 IF p_applied_payment_schedule_id IS NOT NULL THEN
3872 IF l_applied_payment_schedule_id <>
3873 p_applied_payment_schedule_id THEN
3874 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_PS_ID_X_INVALID');
3875 FND_MSG_PUB.Add;
3876 p_return_status := FND_API.G_RET_STS_ERROR ;
3877 END IF;
3878 ELSE
3879 p_applied_payment_schedule_id := l_applied_payment_schedule_id;
3880 END IF;
3881
3882 --Derive site_use_id from the Location
3883 --this could be a DRAWEE or BILL_TO site_use_id
3884 OPEN get_site_use_id;
3885 FETCH get_site_use_id INTO p_bill_to_site_use_id;
3886 CLOSE get_site_use_id;
3887
3888
3889 --If line number has been specified and you have a customer_trx_id,(defaulted or entered)
3890 --then get the Line information
3891 --If the customer_trx_id enterd by the user was invalid then this section of the code
3892 --will not get executed as the control goes directly to the no_data_found exception
3893
3894 --we check for the return status so that we are sure that the payment schedule id is valid
3895 IF p_return_status = FND_API.G_RET_STS_SUCCESS AND
3896 p_customer_trx_id IS NOT NULL AND
3897 p_llca_type IS NULL AND
3898 p_customer_trx_line_id IS NOT NULL THEN
3899
3900 p_trx_line_amount :=
3901 Get_trx_Line_amount(p_customer_trx_id,
3902 p_applied_payment_schedule_id,
3903 p_customer_trx_line_id,
3904 l_line_amt_return_status
3905 );
3906 IF l_line_amt_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3907 p_return_status := FND_API.G_RET_STS_ERROR;
3908 END IF;
3909 p_trx_line_amount := arp_util.CurrRound(p_trx_line_amount,
3910 p_trx_currency_code);
3911 END IF;
3912 --Also check if the payment_schedule of the transaction has already been
3913 --applied once to the current_receipt, if yes then raise error
3914 BEGIN
3915 IF p_customer_trx_line_id IS NULL THEN
3916 select 'Y'
3917 into l_found
3918 from ar_receivable_applications rap
3919 where rap.payment_schedule_id = p_cr_payment_schedule_id
3920 and rap.applied_payment_schedule_id = p_applied_payment_schedule_id
3921 and applied_customer_trx_line_id is NULL
3922 and rap.display = 'Y'
3923 and rap.status = 'APP';
3924 ELSE
3925 select 'Y'
3926 into l_found
3927 from ar_receivable_applications rap
3928 where rap.payment_schedule_id = p_cr_payment_schedule_id
3929 and rap.applied_payment_schedule_id = p_applied_payment_schedule_id
3930 and rap.applied_customer_trx_line_id = p_customer_trx_line_id
3931 and rap.display = 'Y'
3932 and rap.status = 'APP';
3933 END IF;
3934 if l_found = 'Y' then
3935 raise too_many_rows;
3936 end if;
3937
3938 EXCEPTION
3939 when no_data_found then
3940 null;
3941 when too_many_rows then
3942 FND_MESSAGE.SET_NAME('AR', 'AR_RW_PAID_INVOICE_TWICE' );
3943 FND_MSG_PUB.Add;
3944 p_return_status := FND_API.G_RET_STS_ERROR ;
3945 END;
3946
3947 ELSE --case when p_customer_trx_id is null
3948 --no further validation done in the validation routines for customer_trx_id
3949 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUST_TRX_ID_NULL');
3950 FND_MSG_PUB.Add;
3951 p_return_status := FND_API.G_RET_STS_ERROR ;
3952
3953 END IF;
3954
3955 IF PG_DEBUG in ('Y', 'C') THEN
3956 arp_util.debug('Default_Trx_Info: ' || 'p_applied_payment_schedule_id : '||to_char(p_applied_payment_schedule_id));
3957 arp_util.debug('Default_Trx_Info: ' || 'p_bill_to_site_use_id : '||to_char(p_bill_to_site_use_id));
3958 arp_util.debug('Default_Trx_Info: ' || 'p_calc_discount_on_lines_flag : '||p_calc_discount_on_lines_flag);
3959 arp_util.debug('Default_Trx_Info: ' || 'p_partial_discount_flag : '||p_partial_discount_flag );
3960 arp_util.debug('Default_Trx_Info: ' || 'p_allow_overappln_flag : '||p_allow_overappln_flag);
3961 arp_util.debug('Default_Trx_Info: ' || 'p_natural_appln_only_flag : '||p_natural_appln_only_flag);
3962 arp_util.debug('Default_Trx_Info: ' || 'p_creation_sign : '||p_creation_sign);
3963 arp_util.debug('Default_Trx_Info ()-');
3964 END IF;
3965 EXCEPTION
3966 WHEN no_data_found THEN
3967 IF PG_DEBUG in ('Y', 'C') THEN
3968 arp_util.debug('Default_Trx_Info : No data found ');
3969 END IF;
3970 IF ar_receipt_api_pub.Original_application_info.customer_trx_id IS NOT NULL THEN
3971
3972 IF ar_receipt_api_pub.Original_application_info.installment IS NOT NULL THEN
3973 p_return_status := FND_API.G_RET_STS_ERROR ;
3974 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_ID_INST_INVALID');
3975 FND_MSG_PUB.ADD;
3976 ELSE
3977 p_return_status := FND_API.G_RET_STS_ERROR ;
3978 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUST_TRX_ID_INVALID');
3979 FND_MSG_PUB.ADD;
3980 END IF;
3981
3982 ELSIF ar_receipt_api_pub.Original_application_info.trx_number IS NOT NULL THEN
3983
3984 IF ar_receipt_api_pub.Original_application_info.installment IS NOT NULL THEN
3985 p_return_status := FND_API.G_RET_STS_ERROR ;
3986 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_NUM_INST_INVALID');
3987 FND_MSG_PUB.ADD;
3988 ELSE
3989 p_return_status := FND_API.G_RET_STS_ERROR ;
3990 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_NUM_INVALID');
3991 FND_MSG_PUB.ADD;
3992 END IF;
3993
3994 ELSIF ar_receipt_api_pub.Original_application_info.applied_payment_schedule_id IS NOT NULL THEN
3995 p_return_status := FND_API.G_RET_STS_ERROR ;
3996 FND_MESSAGE.SET_NAME('AR','AR_RAPI_APP_PS_ID_INVALID');
3997 FND_MSG_PUB.ADD;
3998 END IF;
3999 WHEN others THEN
4000 IF PG_DEBUG in ('Y', 'C') THEN
4001 arp_util.debug('EXCEPTION: Default_Trx_Info()');
4002 END IF;
4003 raise;
4004 END Default_Trx_Info;
4005
4006 PROCEDURE Default_Receipt_Info(
4007 p_cash_receipt_id IN ar_cash_receipts.cash_receipt_id%TYPE,
4008 p_cr_gl_date OUT NOCOPY DATE,
4009 p_cr_customer_id OUT NOCOPY ar_cash_receipts.pay_from_customer%TYPE,
4010 p_cr_amount OUT NOCOPY ar_cash_receipts.amount%TYPE,
4011 p_cr_currency_code OUT NOCOPY VARCHAR2,
4012 p_cr_exchange_rate OUT NOCOPY NUMBER,
4013 p_cr_cust_site_use_id OUT NOCOPY ar_cash_receipts.customer_site_use_id%TYPE,
4014 p_cr_date OUT NOCOPY ar_cash_receipts.receipt_date%TYPE,
4015 p_cr_unapp_amount OUT NOCOPY NUMBER,
4016 p_cr_payment_schedule_id OUT NOCOPY NUMBER,
4017 p_remittance_bank_account_id OUT NOCOPY NUMBER,
4018 p_receipt_method_id OUT NOCOPY NUMBER,
4019 p_return_status OUT NOCOPY VARCHAR2
4020 ) IS
4021
4022 BEGIN
4023 p_return_status := FND_API.G_RET_STS_SUCCESS;
4024 IF PG_DEBUG in ('Y', 'C') THEN
4025 arp_util.debug('Default_Receipt_Info ()+');
4026 END IF;
4027 IF p_cash_receipt_id IS NOT NULL THEN
4028 BEGIN
4029 SELECT cr.pay_from_customer,
4030 crh.gl_date,
4031 cr.amount,
4032 cr.customer_site_use_id,
4033 cr.receipt_date,
4034 cr.currency_code,
4035 cr.exchange_rate,
4036 ps.payment_schedule_id,
4037 ba.bank_acct_use_id,
4038 cr.receipt_method_id
4039 INTO p_cr_customer_id,
4040 p_cr_gl_date,
4041 p_cr_amount,
4042 p_cr_cust_site_use_id,
4043 p_cr_date,
4044 p_cr_currency_code,
4045 p_cr_exchange_rate,
4046 p_cr_payment_schedule_id,
4047 p_remittance_bank_account_id,
4048 p_receipt_method_id
4049 FROM ar_cash_receipts cr,
4050 ar_cash_receipt_history crh,
4051 ar_payment_schedules ps,
4052 ce_bank_acct_uses ba
4053 WHERE cr.remit_bank_acct_use_id = ba.bank_acct_use_id and
4054 cr.cash_receipt_id = crh.cash_receipt_id and
4055 crh.first_posted_record_flag = 'Y' and /* bug 3333680 */
4056 cr.cash_receipt_id = p_cash_receipt_id and
4057 cr.cash_receipt_id = ps.cash_receipt_id and
4058 crh.status IN ('CONFIRMED','CLEARED', 'REMITTED','APPROVED',
4059 decode(crh.factor_flag,'Y','RISK_ELIMINATED')); /* Risk Eliminated condition added
4060 for bug 2215047*/
4061 EXCEPTION
4062 WHEN NO_DATA_FOUND THEN
4063 BEGIN
4064 SELECT cr.pay_from_customer,
4065 crh.gl_date,
4066 cr.amount,
4067 cr.customer_site_use_id,
4068 cr.receipt_date,
4069 cr.currency_code,
4070 cr.exchange_rate,
4071 ps.payment_schedule_id,
4072 ba.bank_acct_use_id,
4073 cr.receipt_method_id
4074 INTO p_cr_customer_id,
4075 p_cr_gl_date,
4076 p_cr_amount,
4077 p_cr_cust_site_use_id,
4078 p_cr_date,
4079 p_cr_currency_code,
4080 p_cr_exchange_rate,
4081 p_cr_payment_schedule_id,
4082 p_remittance_bank_account_id,
4083 p_receipt_method_id
4084 FROM ar_cash_receipts cr,
4085 ar_cash_receipt_history crh,
4086 ar_payment_schedules ps,
4087 ce_bank_acct_uses ba
4088 WHERE cr.remit_bank_acct_use_id = ba.bank_acct_use_id and
4089 cr.cash_receipt_id = crh.cash_receipt_id and
4090 crh.first_posted_record_flag = 'N' and
4091 cr.cash_receipt_id = p_cash_receipt_id and
4092 cr.cash_receipt_id = ps.cash_receipt_id and
4093 crh.status = 'APPROVED';
4094 EXCEPTION
4095 WHEN no_data_found THEN
4096 IF ar_receipt_api_pub.Original_application_info.cash_receipt_id IS NOT NULL THEN
4097 p_return_status := FND_API.G_RET_STS_ERROR ;
4098 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_CASH_RCPT_ID_INVALID');
4099 FND_MSG_PUB.ADD;
4100 ELSIF ar_receipt_api_pub.Original_application_info.receipt_number IS NOT NULL THEN
4101 p_return_status := FND_API.G_RET_STS_ERROR ;
4102 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_RCPT_NUM_INVALID');
4103 FND_MSG_PUB.ADD;
4104 END IF;
4105 WHEN others THEN
4106 IF PG_DEBUG in ('Y', 'C') THEN
4107 arp_util.debug('EXCEPTION: Default_Receipt_Info()');
4108 END IF;
4109 raise;
4110 END;
4111 WHEN others THEN
4112 IF PG_DEBUG in ('Y', 'C') THEN
4113 arp_util.debug('EXCEPTION: Default_Receipt_Info()');
4114 END IF;
4115 raise;
4116 END;
4117
4118 SELECT SUM(NVL(ra.amount_applied,0))
4119 INTO p_cr_unapp_amount
4120 FROM ar_receivable_applications ra
4121 WHERE ra.status = 'UNAPP'
4122 AND ra.cash_receipt_id = p_cash_receipt_id;
4123
4124 ELSE
4125 --if the receipt number is also null raise error here
4126 --otherwise the error would have been raised while defaulting the cash receipt id from the
4127 --receipt number
4128 IF ar_receipt_api_pub.Original_application_info.receipt_number IS NULL THEN
4129 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_CASH_RCPT_ID_NULL');
4130 FND_MSG_PUB.ADD;
4131 p_return_status := FND_API.G_RET_STS_ERROR ;
4132 END IF;
4133
4134 END IF;
4135 IF PG_DEBUG in ('Y', 'C') THEN
4136 arp_util.debug('Default_Receipt_Info: ' || ' p_return_status :'||p_return_status);
4137 arp_util.debug('Default_Receipt_Info ()-');
4138 END IF;
4139 EXCEPTION
4140 WHEN no_data_found THEN
4141 IF ar_receipt_api_pub.Original_application_info.cash_receipt_id IS NOT NULL THEN
4142 p_return_status := FND_API.G_RET_STS_ERROR ;
4143 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_CASH_RCPT_ID_INVALID');
4144 FND_MSG_PUB.ADD;
4145 ELSIF ar_receipt_api_pub.Original_application_info.receipt_number IS NOT NULL THEN
4146 p_return_status := FND_API.G_RET_STS_ERROR ;
4147 FND_MESSAGE.SET_NAME( 'AR','AR_RAPI_RCPT_NUM_INVALID');
4148 FND_MSG_PUB.ADD;
4149 END IF;
4150 WHEN others THEN
4151 IF PG_DEBUG in ('Y', 'C') THEN
4152 arp_util.debug('EXCEPTION: Default_Receipt_Info()');
4153 END IF;
4154 raise;
4155
4156 END Default_Receipt_Info;
4157
4158 PROCEDURE Default_apply_date(p_receipt_date IN DATE,
4159 p_trx_date IN DATE,
4160 p_apply_date IN OUT NOCOPY DATE) IS
4161 BEGIN
4162
4163 --
4164 --The apply_date should be deafaulted to the greatest of the
4165 --sysdate,receipt_date and trx_date.
4166
4167 /* 7693172 - trunc'd return value to insure that timestamp
4168 is not recorded in RA table. This could cause problems
4169 with discount calculations */
4170 IF p_apply_date IS NULL THEN
4171 p_apply_date := TRUNC(GREATEST(sysdate,
4172 GREATEST(NVL(p_receipt_date,sysdate),
4173 NVL(p_trx_date,sysdate))));
4174 END IF;
4175
4176
4177 END Default_apply_date;
4178
4179 PROCEDURE Default_customer_trx_id(
4180 p_customer_trx_id IN OUT NOCOPY NUMBER,
4181 p_trx_number IN VARCHAR,
4182 p_return_status OUT NOCOPY VARCHAR2
4183 ) IS
4184 BEGIN
4185 IF PG_DEBUG in ('Y', 'C') THEN
4186 arp_util.debug('Default_customer_trx_id ()+');
4187 END IF;
4188 p_return_status := FND_API.G_RET_STS_SUCCESS;
4189 IF p_customer_trx_id IS NULL THEN
4190 IF p_trx_number IS NOT NULL THEN
4191 BEGIN
4192 SELECT customer_trx_id
4193 INTO p_customer_trx_id
4194 FROM ra_customer_trx
4195 WHERE trx_number = p_trx_number;
4196 EXCEPTION
4197 WHEN no_data_found THEN
4198 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_NUM_INVALID');
4199 FND_MSG_PUB.Add;
4200 p_return_status := FND_API.G_RET_STS_ERROR ;
4201 END;
4202 END IF;
4203
4204 ELSE
4205
4206 IF p_trx_number IS NOT NULL
4207 THEN
4208 --give a warning message to indicate that the trx number
4209 --entered by the user has been ignored.
4210 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
4211 THEN
4212 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_NUM_IGN');
4213 FND_MSG_PUB.Add;
4214 END IF;
4215 END IF;
4216 END IF;
4217 IF PG_DEBUG in ('Y', 'C') THEN
4218 arp_util.debug('Default_customer_trx_id ()-');
4219 END IF;
4220 EXCEPTION
4221 WHEN others THEN
4222 IF PG_DEBUG in ('Y', 'C') THEN
4223 arp_util.debug('EXCEPTION: Default_customer_trx_id()', G_MSG_UERROR);
4224 END IF;
4225 END Default_customer_trx_id;
4226 /* Bug 5284890 */
4227 PROCEDURE Default_group_id( p_customer_trx_id IN NUMBER,
4228 p_group_id IN VARCHAR2,
4229 p_llca_type IN VARCHAR2,
4230 p_return_status OUT NOCOPY VARCHAR2
4231 ) IS
4232 l_count Number;
4233 BEGIN
4234 IF PG_DEBUG in ('Y', 'C') THEN
4235 arp_util.debug('Default_group_id ()+');
4236 END IF;
4237 p_return_status := FND_API.G_RET_STS_SUCCESS;
4238
4239 select count(1)
4240 into l_count
4241 from ra_customer_trx_lines line
4242 where line.customer_Trx_id = p_customer_trx_id
4243 and line.line_type = 'LINE'
4244 and line.source_data_key4 = p_group_id
4245 and rownum = 1;
4246
4247 If nvl(l_count,0) = 0 AND
4248 nvl(p_llca_type,'S') = 'G'
4249 THEN
4250 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_GROUP_ID_INVALID');
4251 FND_MSG_PUB.Add;
4252 p_return_status := FND_API.G_RET_STS_ERROR ;
4253 END IF;
4254
4255 IF PG_DEBUG in ('Y', 'C') THEN
4256 arp_util.debug('Default_group_id ()+');
4257 END IF;
4258 END ;
4259 /* Bug fix 3435834
4260 New procedure created for defaulting customer_trx_line_id */
4261 PROCEDURE Default_customer_trx_line_id(
4262 p_customer_trx_id IN OUT NOCOPY NUMBER,
4263 p_customer_trx_line_id IN OUT NOCOPY NUMBER,
4264 p_line_number IN NUMBER,
4265 p_llca_type IN VARCHAR2,
4266 p_return_status OUT NOCOPY VARCHAR2
4267 ) IS
4268 cursor c1 (p_cust_trx_id in number) is
4269 select * from ar_llca_trx_lines_gt
4270 where customer_trx_id = p_cust_trx_id;
4271 l_cust_trx_line_id Number;
4272 BEGIN
4273 IF PG_DEBUG in ('Y', 'C') THEN
4274 arp_util.debug('Default_customer_trx_line_id ()+');
4275 END IF;
4276 p_return_status := FND_API.G_RET_STS_SUCCESS;
4277
4278 IF p_customer_trx_line_id IS NOT NULL AND
4279 p_line_number IS NOT NULL
4280 THEN
4281 --give a warning message to indicate that the line number
4282 --entered by the user has been ignored.
4283 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
4284 THEN
4285 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_LINE_NUM_IGN');
4286 FND_MSG_PUB.Add;
4287 END IF;
4288 END IF;
4289
4290 If p_llca_type IS NULL THEN
4291 IF p_customer_trx_id IS NOT NULL THEN
4292 IF p_customer_trx_line_id IS NULL THEN
4293 IF p_line_number IS NOT NULL THEN
4294 BEGIN
4295 SELECT customer_trx_line_id
4296 INTO p_customer_trx_line_id
4297 FROM ra_customer_trx_lines
4298 WHERE customer_trx_id = p_customer_trx_id
4299 AND line_number = p_line_number
4300 AND line_type = 'LINE';
4301 EXCEPTION
4302 WHEN no_data_found THEN
4303 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_LINE_NO_INVALID');
4304 FND_MSG_PUB.Add;
4305 p_return_status := FND_API.G_RET_STS_ERROR ;
4306 END;
4307 END IF;
4308 END IF;
4309 ELSE
4310 /* If the customer_trx_id is not provided and customer_trx_line_id is
4311 provided, derive the customer_trx_id */
4312 IF p_customer_trx_line_id IS NOT NULL THEN
4313 BEGIN
4314 SELECT customer_trx_id
4315 INTO p_customer_trx_id
4316 FROM ra_customer_trx_lines
4317 WHERE customer_trx_line_id = p_customer_trx_line_id
4318 AND line_type = 'LINE';
4319 EXCEPTION
4320 WHEN no_data_found THEN
4321 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_LINE_ID_INVALID');
4322 FND_MSG_PUB.Add;
4323 p_return_status := FND_API.G_RET_STS_ERROR ;
4324 END;
4325 END IF;
4326 END IF;
4327 Else --LLCA
4328
4329 If p_llca_type not in ('S','L','G')
4330 Then
4331 FND_MESSAGE.SET_NAME('AR','AR_RAPI_INVALID_LLCA_TYPE');
4332 FND_MSG_PUB.Add;
4333 p_return_status := FND_API.G_RET_STS_ERROR ;
4334 END IF;
4335
4336 If p_llca_type = 'L'
4337 Then
4338 For i in C1(p_customer_trx_id)
4339 Loop
4340 IF i.customer_trx_line_id IS NULL Then
4341 If i.line_number is not null
4342 Then
4343 BEGIN
4344 SELECT customer_trx_line_id
4345 INTO l_cust_trx_line_id
4346 FROM ra_customer_trx_lines
4347 WHERE customer_trx_id = p_customer_trx_id
4348 AND line_number = i.line_number
4349 AND line_type = 'LINE';
4350
4351 Update ar_llca_trx_lines_gt
4352 set customer_trx_line_id = l_cust_trx_line_id
4353 where customer_trx_id = p_customer_trx_id
4354 and line_number = i.line_number;
4355 EXCEPTION
4356 WHEN no_data_found THEN
4357 ar_receipt_lib_pvt.populate_errors_gt (
4358 p_customer_trx_id => p_customer_trx_id,
4359 p_customer_trx_line_id => i.customer_trx_line_id,
4360 p_error_message =>
4361 arp_standard.fnd_message('AR_RAPI_TRX_LINE_NO_INVALID'),
4362 p_invalid_value => i.line_number
4363 );
4364 p_return_status := FND_API.G_RET_STS_ERROR ;
4365 END;
4366 End If; /* LINE_NUMBER */
4367 Else
4368 BEGIN
4369 SELECT customer_trx_line_id
4370 INTO l_cust_trx_line_id
4371 FROM ra_customer_trx_lines
4372 WHERE customer_trx_id = p_customer_trx_id
4373 AND customer_trx_line_id = i.customer_trx_line_id
4374 AND line_type = 'LINE';
4375 EXCEPTION
4376 WHEN no_data_found THEN
4377 ar_receipt_lib_pvt.populate_errors_gt (
4378 p_customer_trx_id => p_customer_trx_id,
4379 p_customer_trx_line_id => i.customer_trx_line_id,
4380 p_error_message =>
4381 arp_standard.fnd_message('AR_RAPI_TRX_LINE_ID_INVALID'),
4382 p_invalid_value =>i.customer_trx_line_id
4383 );
4384 p_return_status := FND_API.G_RET_STS_ERROR ;
4385 END;
4386 END IF;
4387
4388 If i.line_amount IS NULL AND
4389 i.tax_amount IS NULL AND
4390 i.amount_applied is NULL AND
4391 i.amount_applied_from is NULL AND -- Bug 6931978 - Cross Currency App
4392 i.customer_trx_line_id is NOT NULL
4393 THEN
4394 ar_receipt_lib_pvt.populate_errors_gt (
4395 p_customer_trx_id => p_customer_trx_id,
4396 p_customer_trx_line_id => i.customer_trx_line_id,
4397 p_error_message =>
4398 arp_standard.fnd_message('AR_RAPI_LTFC_AMT_NULL'),
4399 p_invalid_value => NULL
4400 );
4401 p_return_status := FND_API.G_RET_STS_ERROR ;
4402 END IF;
4403 End Loop;
4404 END IF;
4405 END If;
4406 IF PG_DEBUG in ('Y', 'C') THEN
4407 arp_util.debug('Default_customer_trx_line_id ()-');
4408 END IF;
4409 EXCEPTION
4410 WHEN others THEN
4411 IF PG_DEBUG in ('Y', 'C') THEN
4412 arp_util.debug('EXCEPTION: Default_customer_trx_line_id()', G_MSG_UERROR);
4413 END IF;
4414 END Default_customer_trx_line_id;
4415
4416
4417 PROCEDURE Default_cash_receipt_id(
4418 p_cash_receipt_id IN OUT NOCOPY NUMBER,
4419 p_receipt_number IN VARCHAR2,
4420 p_return_status OUT NOCOPY VARCHAR2
4421 ) IS
4422 BEGIN
4423 IF PG_DEBUG in ('Y', 'C') THEN
4424 arp_util.debug('Default_cash_receipt_id ()+');
4425 END IF;
4426 p_return_status := FND_API.G_RET_STS_SUCCESS;
4427 arp_util.debug('Default_appln_ids:CHECK 2' || 'p_receipt_number :'||to_char(p_receipt_number));
4428 IF p_cash_receipt_id IS NULL
4429 THEN
4430 BEGIN
4431 SELECT cash_receipt_id
4432 INTO p_cash_receipt_id
4433 FROM ar_cash_receipts
4434 WHERE receipt_number = p_receipt_number;
4435 EXCEPTION
4436 WHEN no_data_found THEN
4437 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_NUM_INVALID');
4438 FND_MSG_PUB.Add;
4439 p_return_status := FND_API.G_RET_STS_ERROR ;
4440 WHEN too_many_rows THEN
4441 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_NUM_INVALID');
4442 FND_MSG_PUB.Add;
4443 p_return_status := FND_API.G_RET_STS_ERROR ;
4444 END;
4445
4446 ELSE
4447 IF p_receipt_number IS NOT NULL
4448 THEN
4449 --give a warning message to indicate that the receipt number
4450 --entered by the user has been ignored.
4451 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
4452 THEN
4453 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_NUM_IGN');
4454 FND_MSG_PUB.Add;
4455 END IF;
4456 END IF;
4457 END IF;
4458 IF PG_DEBUG in ('Y', 'C') THEN
4459 arp_util.debug('Default_cash_receipt_id ()-');
4460 END IF;
4461 EXCEPTION
4462 WHEN others THEN
4463 IF PG_DEBUG in ('Y', 'C') THEN
4464 arp_util.debug('EXCEPTION: Default_cash_receipt_id()');
4465 END IF;
4466 END Default_cash_receipt_id;
4467
4468 PROCEDURE Default_appln_ids(
4469 p_cash_receipt_id IN OUT NOCOPY NUMBER,
4470 p_receipt_number IN VARCHAR2,
4471 p_customer_trx_id IN OUT NOCOPY NUMBER,
4472 p_trx_number IN VARCHAR2,
4473 p_customer_trx_line_id IN OUT NOCOPY NUMBER, /* Bug fix 3435834 */
4474 p_line_number IN NUMBER,
4475 p_installment IN OUT NOCOPY NUMBER,
4476 p_applied_payment_schedule_id IN NUMBER,
4477 p_llca_type IN VARCHAR2,
4478 p_group_id IN VARCHAR2, /* Bug 5284890 */
4479 p_return_status OUT NOCOPY VARCHAR2 ) IS
4480 CURSOR payment_schedule IS
4481 SELECT customer_trx_id,terms_sequence_number
4482 FROM ar_payment_schedules
4483 WHERE payment_schedule_id = p_applied_payment_schedule_id and
4484 payment_schedule_id >0 and
4485 class in ('INV','DM','DEP','CB','CM','BR');
4486 CURSOR install_number IS
4487 SELECT terms_sequence_number
4488 FROM ar_payment_schedules
4489 WHERE customer_trx_id = p_customer_trx_id;
4490 l_customer_trx_id NUMBER;
4491 l_installment NUMBER;
4492 p_return_status_lines VARCHAR2(100); /* Bug fix 3435834 */
4493 p_return_status_group VARCHAR2(100); /* Bug 5284890 */
4494
4495 BEGIN
4496 IF PG_DEBUG in ('Y', 'C') THEN
4497 arp_util.debug('Default_appln_ids ()+ ');
4498 END IF;
4499 p_return_status := FND_API.G_RET_STS_SUCCESS;
4500
4501 -- First get a valid value for the customer_trx_id
4502 IF p_trx_number IS NOT NULL THEN
4503 Default_customer_trx_id(p_customer_trx_id ,
4504 p_trx_number ,
4505 p_return_status);
4506 END IF;
4507
4508 /* Bug fix 3435834 */
4509 /* Default the customer_trx_line_id and customer_trx_id*/
4510 Default_Customer_trx_line_id(p_customer_trx_id,
4511 p_customer_trx_line_id,
4512 p_line_number,
4513 p_llca_type,
4514 p_return_status_lines);
4515
4516 /* Group logic will be implement via bug 5440167
4517 IF Nvl(p_llca_type,'S') = 'G'
4518 THEN
4519 Default_group_id (p_customer_trx_id,
4520 p_group_id,
4521 p_llca_type,
4522 p_return_status_group);
4523 END If; */
4524
4525 --If the customer_trx_id id is null, use the entered aplied_payment_schedule_id
4526 --for deriving the customer_trx_id and installment.
4527 IF p_applied_payment_schedule_id IS NOT NULL THEN
4528 OPEN payment_schedule;
4529 FETCH payment_schedule INTO l_customer_trx_id, l_installment;
4530 IF payment_schedule%NOTFOUND THEN
4531 FND_MESSAGE.SET_NAME('AR','AR_RAPI_APP_PS_ID_INVALID');
4532 FND_MSG_PUB.Add;
4533 p_return_status := FND_API.G_RET_STS_ERROR ;
4534 END IF;
4535 CLOSE payment_schedule;
4536
4537 IF p_return_status = FND_API.G_RET_STS_SUCCESS THEN
4538
4539 IF nvl(p_customer_trx_id,nvl(l_customer_trx_id,-99)) = nvl(l_customer_trx_id,-99) THEN
4540 p_customer_trx_id := l_customer_trx_id;
4541 END IF;
4542
4543 IF nvl(p_installment,nvl(l_installment,-99)) = nvl(l_installment,-99) THEN
4544 p_installment := l_installment;
4545 END IF;
4546
4547 END IF;
4548 ELSE
4549 --default the installment from the customer_trx_id if not entered
4550 IF p_customer_trx_id IS NOT NULL THEN
4551 IF p_installment IS NULL THEN
4552 BEGIN
4553 SELECT terms_sequence_number
4554 INTO p_installment
4555 FROM ar_payment_schedules
4556 WHERE customer_trx_id = p_customer_trx_id;
4557 EXCEPTION
4558 WHEN no_data_found THEN
4559 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUST_TRX_ID_INVALID');
4560 FND_MSG_PUB.Add;
4561 p_return_status := FND_API.G_RET_STS_ERROR;
4562 WHEN too_many_rows THEN
4563 If p_llca_type is Null
4564 THEN
4565 FND_MESSAGE.SET_NAME('AR','AR_RAPI_INSTALL_NULL');
4566 FND_MSG_PUB.Add;
4567 Else
4568 FND_MESSAGE.SET_NAME('AR','AR_LL_INSTALL_NOT_ALLOWED');
4569 FND_MSG_PUB.Add;
4570 End If;
4571 p_return_status := FND_API.G_RET_STS_ERROR;
4572 END;
4573 END IF;
4574 END IF;
4575 END IF;
4576
4577 -- You cannot apply a receipt to the installment transactions at line-level.
4578 If p_applied_payment_schedule_id IS NOT NULL and
4579 p_llca_type is NOT NULL
4580 Then
4581 Begin
4582 select terms_sequence_number into l_installment
4583 from ar_payment_schedules
4584 where customer_trx_id = p_customer_trx_id;
4585 Exception
4586 WHEN no_data_found THEN
4587 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUST_TRX_ID_INVALID');
4588 FND_MSG_PUB.Add;
4589 p_return_status := FND_API.G_RET_STS_ERROR;
4590 WHEN too_many_rows THEN
4591 FND_MESSAGE.SET_NAME('AR','AR_LL_INSTALL_NOT_ALLOWED');
4592 FND_MSG_PUB.Add;
4593 p_return_status := FND_API.G_RET_STS_ERROR;
4594 END;
4595 End If;
4596
4597 --Derive cash_receipt_id from receipt_number
4598 Default_cash_receipt_id(
4599 p_cash_receipt_id ,
4600 p_receipt_number ,
4601 p_return_status
4602 );
4603
4604 /* Bug fix 3435834 */
4605 IF p_return_status_lines = FND_API.G_RET_STS_ERROR OR
4606 p_return_status_group = FND_API.G_RET_STS_ERROR OR
4607 p_return_status = FND_API.G_RET_STS_ERROR THEN
4608 p_return_status := FND_API.G_RET_STS_ERROR;
4609 END IF;
4610
4611 IF PG_DEBUG in ('Y', 'C') THEN
4612 arp_util.debug('Default_appln_ids: ' || '****Defaulted Value for the application ids****');
4613 arp_util.debug('Default_appln_ids: ' || 'p_cash_receipt_id :'||to_char(p_cash_receipt_id));
4614 arp_util.debug('Default_appln_ids: ' || 'p_customer_trx_id :'||to_char(p_customer_trx_id));
4615 arp_util.debug('Default_appln_ids: ' || 'p_installment :'||to_char(p_installment));
4616 arp_util.debug('Default_appln_ids: ' || 'p_applied_payment_schedule_id :'||to_char(p_applied_payment_schedule_id));
4617 arp_util.debug('Default_appln_ids ()- ');
4618 END IF;
4619 EXCEPTION
4620 WHEN others THEN
4621 IF PG_DEBUG in ('Y', 'C') THEN
4622 arp_util.debug('EXCEPTION: Default_appln_ids()');
4623 END IF;
4624 raise;
4625 END Default_appln_ids;
4626
4627 PROCEDURE Default_application_info(
4628 p_cash_receipt_id IN ar_cash_receipts.cash_receipt_id%TYPE,
4629 p_cr_gl_date OUT NOCOPY DATE,
4630 p_cr_date OUT NOCOPY DATE,
4631 p_cr_amount OUT NOCOPY ar_cash_receipts.amount%TYPE,
4632 p_cr_unapp_amount OUT NOCOPY NUMBER,
4633 p_cr_currency_code OUT NOCOPY VARCHAR2,
4634 p_customer_trx_id IN ra_customer_trx.customer_trx_id%TYPE,
4635 p_installment IN OUT NOCOPY NUMBER,
4636 p_show_closed_invoices IN VARCHAR2,
4637 p_customer_trx_line_id IN NUMBER,
4638 p_trx_due_date OUT NOCOPY DATE,
4639 p_trx_currency_code OUT NOCOPY VARCHAR2,
4640 p_trx_date OUT NOCOPY DATE,
4641 p_trx_gl_date OUT NOCOPY DATE,
4642 p_apply_gl_date IN OUT NOCOPY DATE,
4643 p_calc_discount_on_lines_flag OUT NOCOPY VARCHAR2,
4644 p_partial_discount_flag OUT NOCOPY VARCHAR2,
4645 p_allow_overappln_flag OUT NOCOPY VARCHAR2,
4646 p_natural_appln_only_flag OUT NOCOPY VARCHAR2,
4647 p_creation_sign OUT NOCOPY VARCHAR2,
4648 p_cr_payment_schedule_id OUT NOCOPY NUMBER,
4649 p_applied_payment_schedule_id IN OUT NOCOPY NUMBER,
4650 p_term_id OUT NOCOPY NUMBER,
4651 p_amount_due_original OUT NOCOPY NUMBER,
4652 p_amount_due_remaining OUT NOCOPY NUMBER,
4653 p_trx_line_amount OUT NOCOPY NUMBER,
4654 p_discount IN OUT NOCOPY NUMBER,
4655 p_apply_date IN OUT NOCOPY DATE,
4656 p_discount_max_allowed OUT NOCOPY NUMBER,
4657 p_discount_earned_allowed OUT NOCOPY NUMBER,
4658 p_discount_earned OUT NOCOPY NUMBER,
4659 p_discount_unearned OUT NOCOPY NUMBER,
4660 p_new_amount_due_remaining OUT NOCOPY NUMBER,
4661 p_remittance_bank_account_id OUT NOCOPY NUMBER,
4662 p_receipt_method_id OUT NOCOPY NUMBER,
4663 p_amount_applied IN OUT NOCOPY NUMBER,
4664 p_amount_applied_from IN OUT NOCOPY NUMBER,
4665 p_trans_to_receipt_rate IN OUT NOCOPY NUMBER,
4666 p_llca_type IN VARCHAR2,
4667 p_line_amount IN OUT NOCOPY NUMBER,
4668 p_tax_amount IN OUT NOCOPY NUMBER,
4669 p_freight_amount IN OUT NOCOPY NUMBER,
4670 p_charges_amount IN OUT NOCOPY NUMBER,
4671 p_line_discount IN OUT NOCOPY NUMBER,
4672 p_tax_discount IN OUT NOCOPY NUMBER,
4673 p_freight_discount IN OUT NOCOPY NUMBER,
4674 p_line_items_original OUT NOCOPY NUMBER,
4675 p_line_items_remaining OUT NOCOPY NUMBER,
4676 p_tax_original OUT NOCOPY NUMBER,
4677 p_tax_remaining OUT NOCOPY NUMBER,
4678 p_freight_original OUT NOCOPY NUMBER,
4679 p_freight_remaining OUT NOCOPY NUMBER,
4680 p_rec_charges_charged OUT NOCOPY NUMBER,
4681 p_rec_charges_remaining OUT NOCOPY NUMBER,
4682 p_called_from IN VARCHAR2,
4683 p_return_status OUT NOCOPY VARCHAR2
4684 ) IS
4685
4686 l_cr_customer_id NUMBER;
4687 l_customer_id NUMBER;
4688 l_acct_amount_due_remaining NUMBER;
4689 l_trx_exchange_rate NUMBER;
4690 l_cr_exchange_rate NUMBER;
4691 l_receipt_date DATE;
4692 l_trx_date DATE;
4693 l_discount_taken_earned NUMBER;
4694 l_discount_taken_unearned NUMBER;
4695 l_amount_line_items_original NUMBER;
4696 l_bill_to_site_use_id NUMBER;--this is to store the bill_to_site_use_id on trx.
4697 l_cr_cust_site_use_id NUMBER;--this is to store the site_use_id on the receipt
4698 l_cust_trx_type_id NUMBER;
4699 l_def_cr_return_status VARCHAR2(1);
4700 l_def_trx_return_status VARCHAR2(1);
4701 l_def_amt_return_status VARCHAR2(1);
4702 l_def_rate_return_status VARCHAR2(1);
4703 l_def_aaf_return_status VARCHAR2(1);
4704 --local variables used for OUT NOCOPY parameters
4705 l_calc_discount_on_lines_flag VARCHAR2(1);
4706 l_partial_discount_flag VARCHAR2(1);
4707 l_allow_overappln_flag VARCHAR2(1);
4708 l_natural_appln_only_flag VARCHAR2(1);
4709 l_creation_sign VARCHAR2(1);
4710 l_amount_due_original NUMBER;
4711 l_amount_due_remaining NUMBER;
4712 l_term_id NUMBER;
4713 l_trx_line_amount NUMBER;
4714 l_cr_unapp_amount NUMBER;
4715 l_cr_gl_date DATE;
4716 l_trx_gl_date DATE;
4717 l_applied_payment_schedule_id NUMBER;
4718 l_cr_date DATE;
4719 l_cr_currency_code VARCHAR2(15);
4720 l_trx_currency_code VARCHAR2(15);
4721 l_gl_date DATE;
4722 --bug 3172587
4723 l_return BOOLEAN;
4724 l_default_gl_date DATE;
4725 l_defaulting_rule_used VARCHAR2(100);
4726 l_error_message VARCHAR2(200);
4727
4728 --LLCA
4729 l_line_items_original NUMBER;
4730 l_line_items_remaining NUMBER;
4731 l_tax_original NUMBER;
4732 l_tax_remaining NUMBER;
4733 l_freight_original NUMBER;
4734 l_freight_remaining NUMBER;
4735 l_rec_charges_charged NUMBER;
4736 l_rec_charges_remaining NUMBER;
4737 l_val_llca_return_status VARCHAR2(1);
4738 l_val_llca_msg_data VARCHAR2(2000);
4739 l_val_llca_msg_count NUMBER;
4740 BEGIN
4741 IF PG_DEBUG in ('Y', 'C') THEN
4742 arp_util.debug('Default_application_info ()+');
4743 arp_util.debug('Default_application_info: ' || 'p_discount = '||p_discount );
4744 END IF;
4745
4746 p_return_status := FND_API.G_RET_STS_SUCCESS;
4747 Default_Receipt_Info(
4748 p_cash_receipt_id ,
4749 l_cr_gl_date ,
4750 l_cr_customer_id ,
4751 p_cr_amount ,
4752 l_cr_currency_code,
4753 l_cr_exchange_rate,
4754 l_cr_cust_site_use_id ,
4755 l_cr_date ,
4756 l_cr_unapp_amount ,
4757 p_cr_payment_schedule_id ,
4758 p_remittance_bank_account_id,
4759 p_receipt_method_id,
4760 l_def_cr_return_status );
4761 IF PG_DEBUG in ('Y', 'C') THEN
4762 arp_util.debug('Default_application_info: ' || 'Default_Receipt_Info return status = '||l_def_cr_return_status);
4763 END IF;
4764
4765 /* Bug 4038708 */
4766 IF(l_cr_customer_id is NULL) THEN
4767 FND_MESSAGE.SET_NAME( 'AR','AR_RW_REC_NO_CT');
4768 FND_MSG_PUB.ADD;
4769 p_return_status := FND_API.G_RET_STS_ERROR ;
4770 END IF;
4771
4772 --call the transaction defaulting routine only if the return status of the
4773 --cash defaulting routine was success
4774 IF l_def_cr_return_status = FND_API.G_RET_STS_SUCCESS THEN
4775 Default_Trx_Info(
4776 p_customer_trx_id ,
4777 p_customer_trx_line_id ,
4778 p_show_closed_invoices ,
4779 l_cr_gl_date ,
4780 l_cr_customer_id ,
4781 l_cr_currency_code ,
4782 p_cr_payment_schedule_id,
4783 l_cr_date,
4784 p_called_from,
4785 l_customer_id ,
4786 l_cust_trx_type_id ,
4787 p_trx_due_date ,
4788 l_trx_currency_code ,
4789 l_trx_exchange_rate ,
4790 l_trx_date ,
4791 l_trx_gl_date ,
4792 l_calc_discount_on_lines_flag ,
4793 l_partial_discount_flag ,
4794 l_allow_overappln_flag ,
4795 l_natural_appln_only_flag ,
4796 l_creation_sign ,
4797 p_applied_payment_schedule_id ,
4798 l_gl_date , --this is the defaulted application gl_date
4799 l_term_id ,
4800 l_amount_due_original ,
4801 l_amount_line_items_original ,
4802 l_amount_due_remaining ,
4803 l_discount_taken_earned ,
4804 l_discount_taken_unearned ,
4805 l_trx_line_amount ,
4806 p_installment ,
4807 l_bill_to_site_use_id ,
4808 p_llca_type,
4809 l_line_items_original,
4810 l_line_items_remaining,
4811 l_tax_original,
4812 l_tax_remaining,
4813 l_freight_original,
4814 l_freight_remaining,
4815 l_rec_charges_charged,
4816 l_rec_charges_remaining,
4817 l_def_trx_return_status );
4818
4819 IF PG_DEBUG in ('Y', 'C') THEN
4820 arp_util.debug('Default_application_info: ' || 'Default trx info return status = '||l_def_trx_return_status);
4821 END IF;
4822 END IF;
4823
4824 Default_apply_date(l_cr_date ,
4825 l_trx_date,
4826 p_apply_date);
4827
4828 --If user has not entered the apply_gl_date default it
4829 --to gl_date defaulted by the Default_trx_info()
4830 IF p_apply_gl_date IS NULL THEN
4831 /*apandit : bug 3172587
4832 In case the apply_gl_date is defaulted we need to additionally validate this
4833 defaulted gl_date and in case it is incorrect, then we get the appropriate
4834 gl_date and use it as default.
4835 */
4836 l_return :=
4837 arp_util.validate_and_default_gl_date(
4838 gl_date => l_gl_date,
4839 trx_date => null,
4840 validation_date1 => null,
4841 validation_date2 => null,
4842 validation_date3 => null,
4843 default_date1 => l_gl_date,
4844 default_date2 => null,
4845 default_date3 => null,
4846 p_allow_not_open_flag => 'N',
4847 p_invoicing_rule_id => null,
4848 p_set_of_books_id => arp_global.set_of_books_id,
4849 p_application_id => 222,
4850 default_gl_date => l_default_gl_date ,
4851 defaulting_rule_used => l_defaulting_rule_used,
4852 error_message => l_error_message);
4853
4854 IF l_return = TRUE THEN
4855 p_apply_gl_date := l_default_gl_date;
4856 END IF;
4857
4858 END IF;
4859
4860 -- Default LLCA
4861 If P_llca_type is NOT NULL
4862 THEN
4863
4864 Default_val_llca_parameters(
4865 p_llca_type ,
4866 p_cash_receipt_id ,
4867 p_customer_trx_id ,
4868 p_customer_trx_line_id,
4869 p_amount_applied ,
4870 p_line_amount ,
4871 p_tax_amount ,
4872 p_freight_amount ,
4873 p_charges_amount ,
4874 p_line_discount ,
4875 p_tax_discount ,
4876 p_freight_discount ,
4877 p_discount ,
4878 l_cr_currency_code ,
4879 l_trx_currency_code ,
4880 l_cr_date, -- Bug 6931978 Cross Currency App
4881 l_val_llca_return_status ,
4882 l_val_llca_msg_data ,
4883 l_val_llca_msg_count
4884 );
4885
4886 END IF;
4887
4888 --arp_util.debug('p_apply_gl_date '||p_apply_gl_date);
4889 Default_disc_and_amt_applied(
4890 l_customer_id ,
4891 l_bill_to_site_use_id ,
4892 p_applied_payment_schedule_id ,
4893 p_amount_applied ,
4894 p_discount ,
4895 l_term_id ,
4896 p_installment ,
4897 l_trx_date,
4898 l_cr_date ,
4899 l_cr_currency_code ,
4900 l_trx_currency_code ,
4901 l_cr_exchange_rate ,
4902 l_trx_exchange_rate ,--corresponds to app_folder.exchange_rate
4903 p_apply_date ,
4904 l_amount_due_original ,
4905 l_amount_due_remaining ,
4906 l_cr_unapp_amount ,
4907 l_allow_overappln_flag ,
4908 l_calc_discount_on_lines_flag ,
4909 l_partial_discount_flag ,
4910 l_amount_line_items_original ,
4911 l_discount_taken_unearned ,
4912 l_discount_taken_earned ,
4913 p_customer_trx_line_id ,
4914 l_trx_line_amount ,
4915 p_llca_type,
4916 p_discount_max_allowed ,
4917 p_discount_earned_allowed ,
4918 p_discount_earned ,
4919 p_discount_unearned ,
4920 p_new_amount_due_remaining ,
4921 l_def_amt_return_status);
4922
4923
4924 IF PG_DEBUG in ('Y', 'C') THEN
4925 arp_util.debug('Default_application_info: ' || 'l_calc_discount_on_lines_flag : '||l_calc_discount_on_lines_flag);
4926 arp_util.debug('Default_application_info: ' || 'l_partial_discount_flag : '||l_partial_discount_flag );
4927 arp_util.debug('Default_application_info: ' || 'l_allow_overappln_flag : '||l_allow_overappln_flag);
4928 arp_util.debug('Default_application_info: ' || 'l_natural_appln_only_flag : '||l_natural_appln_only_flag);
4929 arp_util.debug('Default_application_info: ' || 'l_creation_sign : '||l_creation_sign);
4930 arp_util.debug('Default_application_info: ' || 'Default amount return status :'||l_def_amt_return_status );
4931 END IF;
4932
4933 Default_trans_to_receipt_rate(
4934 l_trx_currency_code ,
4935 l_cr_currency_code ,
4936 l_receipt_date ,
4937 p_trans_to_receipt_rate ,
4938 p_amount_applied,
4939 p_amount_applied_from,
4940 l_cr_date,
4941 l_def_rate_return_status
4942 );
4943 IF PG_DEBUG in ('Y', 'C') THEN
4944 arp_util.debug('Default_application_info: ' || 'Default trans_to_receipt_rate status :'||l_def_rate_return_status);
4945 END IF;
4946 Default_amount_applied_from(
4947 p_amount_applied ,
4948 l_trx_currency_code ,
4949 p_trans_to_receipt_rate ,
4950 l_cr_currency_code ,
4951 p_amount_applied_from ,
4952 l_def_aaf_return_status
4953 );
4954 IF PG_DEBUG in ('Y', 'C') THEN
4955 arp_util.debug('Default_application_info: ' || 'Default amount applied from return status :'||l_def_aaf_return_status);
4956 END IF;
4957
4958
4959 --populate the parameters with the values in the local variables
4960
4961 p_term_id := l_term_id;
4962 p_calc_discount_on_lines_flag := l_calc_discount_on_lines_flag;
4963 p_partial_discount_flag := l_partial_discount_flag;
4964 p_allow_overappln_flag := l_allow_overappln_flag;
4965 p_natural_appln_only_flag := l_natural_appln_only_flag;
4966 p_creation_sign := l_creation_sign;
4967 p_cr_unapp_amount := l_cr_unapp_amount;
4968 p_amount_due_original := l_amount_due_original;
4969 p_amount_due_remaining := l_amount_due_remaining;
4970 p_trx_line_amount := l_trx_line_amount;
4971 p_cr_currency_code := l_cr_currency_code;
4972 p_trx_currency_code := l_trx_currency_code;
4973 p_cr_gl_date := l_cr_gl_date;
4974 p_trx_gl_date := l_trx_gl_date;
4975 p_cr_date := l_cr_date;
4976 p_trx_date := l_trx_date;
4977
4978 -- llca
4979 p_line_items_original := l_line_items_original;
4980 p_line_items_remaining := l_line_items_remaining;
4981 p_tax_original := l_tax_original;
4982 p_tax_remaining := l_tax_remaining;
4983 p_freight_original := l_freight_original;
4984 p_freight_remaining := l_freight_remaining;
4985 p_rec_charges_charged := l_rec_charges_charged;
4986 p_rec_charges_remaining := l_rec_charges_remaining;
4987
4988 IF l_def_cr_return_status = FND_API.G_RET_STS_ERROR OR
4989 l_def_trx_return_status = FND_API.G_RET_STS_ERROR OR
4990 l_def_rate_return_status = FND_API.G_RET_STS_ERROR OR
4991 l_val_llca_return_status = FND_API.G_RET_STS_ERROR
4992 THEN
4993 p_return_status := FND_API.G_RET_STS_ERROR;
4994 END IF;
4995
4996 IF PG_DEBUG in ('Y', 'C') THEN
4997 arp_util.debug('Default_application_info: ' || '*****************Application Defaults***************');
4998 arp_util.debug('Default_application_info: ' || 'p_cash_receipt_id : '||to_char(p_cash_receipt_id));
4999 arp_util.debug('Default_application_info: ' || 'p_cr_gl_date : '||to_char(p_cr_gl_date,'DD-MON-YYYY'));
5000 arp_util.debug('Default_application_info: ' || 'p_cr_date : '||to_char(p_cr_date,'DD-MON-YYYY'));
5001 arp_util.debug('Default_application_info: ' || 'p_cr_amount : '||to_char(p_cr_amount));
5002 arp_util.debug('Default_application_info: ' || 'p_cr_unapp_amount : '||to_char(p_cr_unapp_amount));
5003 arp_util.debug('Default_application_info: ' || 'p_cr_currency_code : '||p_cr_currency_code);
5004 arp_util.debug('Default_application_info: ' || 'p_customer_trx_id : '||to_char(p_customer_trx_id));
5005 arp_util.debug('Default_application_info: ' || 'p_installment : '||to_char(p_installment));
5006 arp_util.debug('Default_application_info: ' || 'p_show_closed_invoices : '||p_show_closed_invoices);
5007 arp_util.debug('Default_application_info: ' || 'p_customer_trx_line_id : '||to_char(p_customer_trx_line_id));
5008 arp_util.debug('Default_application_info: ' || 'p_trx_due_date : '||to_char(p_trx_due_date,'DD-MON-YYYY'));
5009 arp_util.debug('Default_application_info: ' || 'p_trx_currency_code : '||p_trx_currency_code);
5010 arp_util.debug('Default_application_info: ' || 'p_trx_gl_date : '||to_char(p_trx_due_date,'DD-MON-YYYY'));
5011 arp_util.debug('Default_application_info: ' || 'p_apply_gl_date : '||to_char(p_apply_gl_date,'DD-MON-YYYY'));
5012 arp_util.debug('Default_application_info: ' || 'p_calc_discount_on_lines_flag : '||p_calc_discount_on_lines_flag);
5013 arp_util.debug('Default_application_info: ' || 'p_partial_discount_flag : '||p_partial_discount_flag);
5014 arp_util.debug('Default_application_info: ' || 'p_allow_overappln_flag : '||p_allow_overappln_flag);
5015 arp_util.debug('Default_application_info: ' || 'p_natural_appln_only_flag : '||p_natural_appln_only_flag);
5016 arp_util.debug('Default_application_info: ' || 'p_creation_sign : '||p_creation_sign);
5017 arp_util.debug('Default_application_info: ' || 'p_cr_payment_schedule_id : '||to_char(p_cr_payment_schedule_id));
5018 arp_util.debug('Default_application_info: ' || 'p_applied_payment_schedule_id : '||to_char(p_applied_payment_schedule_id));
5019 arp_util.debug('Default_application_info: ' || 'p_term_id : '||to_char(p_term_id));
5020 arp_util.debug('Default_application_info: ' || 'p_amount_due_original : '||to_char(p_amount_due_original));
5021 arp_util.debug('Default_application_info: ' || 'p_amount_due_remaining : '||to_char(p_amount_due_remaining));
5022 arp_util.debug('Default_application_info: ' || 'p_trx_line_amount : '||to_char(p_trx_line_amount));
5023 arp_util.debug('Default_application_info: ' || 'p_discount : '||to_char(p_discount));
5024 arp_util.debug('Default_application_info: ' || 'p_apply_date : '||to_char(p_apply_date,'DD-MON-YYYY'));
5025 arp_util.debug('Default_application_info: ' || 'p_discount_max_allowed : '||to_char(p_discount_max_allowed));
5026 arp_util.debug('Default_application_info: ' || 'p_discount_earned_allowed : '||to_char(p_discount_earned_allowed));
5027 arp_util.debug('Default_application_info: ' || 'p_discount_earned : '||to_char(p_discount_earned));
5028 arp_util.debug('Default_application_info: ' || 'p_discount_unearned : '||to_char(p_discount_unearned));
5029 arp_util.debug('Default_application_info: ' || 'p_new_amount_due_remaining : '||to_char(p_new_amount_due_remaining));
5030 arp_util.debug('Default_application_info: ' || 'p_amount_applied : '||to_char(p_amount_applied));
5031 arp_util.debug('Default_application_info: ' || 'p_amount_applied_from : '||to_char(p_amount_applied_from));
5032 arp_util.debug('Default_application_info: ' || 'p_trans_to_receipt_rate : '||to_char(p_trans_to_receipt_rate));
5033 arp_util.debug('Default_application_info: ' || '**********************************************************');
5034 arp_util.debug('Default_application_info ()-');
5035 END IF;
5036 END Default_application_info;
5037
5038 FUNCTION Get_trx_ps_id(p_customer_trx_id IN OUT NOCOPY NUMBER,
5039 p_installment IN NUMBER,
5040 p_called_from IN VARCHAR2,
5041 p_return_status OUT NOCOPY VARCHAR2
5042 ) RETURN NUMBER IS
5043 l_trx_ps_id NUMBER;
5044 BEGIN
5045 IF PG_DEBUG in ('Y', 'C') THEN
5046 arp_util.debug('Get_trx_ps_id ()+');
5047 END IF;
5048 p_return_status := FND_API.G_RET_STS_SUCCESS;
5049
5050 IF p_called_from IN ('BR_REMITTED',
5051 'BR_FACTORED_WITH_RECOURSE',
5052 'BR_FACTORED_WITHOUT_RECOURSE') THEN
5053 --called from the BR Remittance program
5054 IF p_installment IS NOT NULL THEN
5055 BEGIN
5056 SELECT ps.payment_schedule_id
5057 INTO l_trx_ps_id
5058 FROM ra_customer_trx ct,
5059 ar_payment_schedules ps
5060 WHERE ct.customer_trx_id = p_customer_trx_id
5061 AND ct.customer_trx_id = ps.customer_trx_id
5062 AND ps.class IN ('CB','CM','DEP','DM','INV','BR')
5063 AND ps.terms_sequence_number = p_installment
5064 ;
5065 EXCEPTION
5066 WHEN no_data_found THEN
5067
5068 IF ar_receipt_api_pub.Original_unapp_info.customer_trx_id IS NOT NULL THEN
5069 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_ID_INST_INVALID');
5070 FND_MSG_PUB.Add;
5071 p_return_status := FND_API.G_RET_STS_ERROR;
5072 ELSIF ar_receipt_api_pub.Original_unapp_info.trx_number IS NOT NULL THEN
5073 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_NUM_INST_INVALID');
5074 FND_MSG_PUB.Add;
5075 p_return_status := FND_API.G_RET_STS_ERROR;
5076 END IF;
5077
5078 END;
5079
5080 ELSE
5081 --if the user has not entered the installment then if the transaction
5082 --has only one installment, get the ps_id for that installment
5083 BEGIN
5084 SELECT ps.payment_schedule_id
5085 INTO l_trx_ps_id
5086 FROM ra_customer_trx ct,
5087 ar_payment_schedules ps
5088 WHERE ct.customer_trx_id = p_customer_trx_id
5089 AND ct.customer_trx_id = ps.customer_trx_id
5090 AND ps.class IN ('CB','CM','DEP','DM','INV','BR')
5091 ;
5092 EXCEPTION
5093 WHEN no_data_found THEN
5094 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUST_TRX_ID_INVALID');
5095 FND_MSG_PUB.Add;
5096 p_return_status := FND_API.G_RET_STS_ERROR;
5097 WHEN too_many_rows THEN
5098 FND_MESSAGE.SET_NAME('AR','AR_RAPI_INSTALL_NULL');
5099 FND_MSG_PUB.Add;
5100 p_return_status := FND_API.G_RET_STS_ERROR;
5101 END;
5102
5103 END IF;
5104
5105 ELSE --not called from the BR Remittance program
5106
5107 IF p_installment IS NOT NULL THEN
5108 BEGIN
5109 SELECT ps.payment_schedule_id
5110 INTO l_trx_ps_id
5111 FROM ra_customer_trx ct,
5112 ar_payment_schedules ps
5113 WHERE ct.customer_trx_id = p_customer_trx_id
5114 AND ct.customer_trx_id = ps.customer_trx_id
5115 AND ps.class IN ('CB','CM','DEP','DM','INV','BR')
5116 AND ps.terms_sequence_number = p_installment
5117 --these two conditions are to ensure that the trx(bill) is not in remit process
5118 AND ps.reserved_type IS NULL
5119 AND ps.reserved_value IS NULL;
5120 EXCEPTION
5121 WHEN no_data_found THEN
5122
5123 IF ar_receipt_api_pub.Original_unapp_info.customer_trx_id IS NOT NULL THEN
5124 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_ID_INST_INVALID');
5125 FND_MSG_PUB.Add;
5126 p_return_status := FND_API.G_RET_STS_ERROR;
5127 ELSIF ar_receipt_api_pub.Original_unapp_info.trx_number IS NOT NULL THEN
5128 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_NUM_INST_INVALID');
5129 FND_MSG_PUB.Add;
5130 p_return_status := FND_API.G_RET_STS_ERROR;
5131 END IF;
5132 END;
5133
5134 ELSE
5135 --if the user has not entered the installment then if the transaction
5136 --has only one installment, get the ps_id for that installment
5137 BEGIN
5138 SELECT ps.payment_schedule_id
5139 INTO l_trx_ps_id
5140 FROM ra_customer_trx ct,
5141 ar_payment_schedules ps
5142 WHERE ct.customer_trx_id = p_customer_trx_id
5143 AND ct.customer_trx_id = ps.customer_trx_id
5144 AND ps.class IN ('CB','CM','DEP','DM','INV','BR')
5145 --these two conditions are to ensure that the trx(bill) is not in remit process
5146 AND ps.reserved_type IS NULL
5147 AND ps.reserved_value IS NULL
5148 ;
5149 EXCEPTION
5150 WHEN no_data_found THEN
5151 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUST_TRX_ID_INVALID');
5152 FND_MSG_PUB.Add;
5153 p_return_status := FND_API.G_RET_STS_ERROR;
5154 WHEN too_many_rows THEN
5155 FND_MESSAGE.SET_NAME('AR','AR_RAPI_INSTALL_NULL');
5156 FND_MSG_PUB.Add;
5157 p_return_status := FND_API.G_RET_STS_ERROR;
5158 END;
5159
5160 END IF;
5161
5162 END IF;
5163
5164 RETURN(l_trx_ps_id);
5165 IF PG_DEBUG in ('Y', 'C') THEN
5166 arp_util.debug('Get_trx_ps_id ()-');
5167 END IF;
5168 EXCEPTION
5169 WHEN others THEN
5170 IF PG_DEBUG in ('Y', 'C') THEN
5171 arp_util.debug('EXCEPTION: Get_trx_ps_id()');
5172 END IF;
5173 raise;
5174 END Get_trx_ps_id;
5175
5176 PROCEDURE Derive_receivable_appln_id(
5177 p_cash_receipt_id IN NUMBER,
5178 p_applied_payment_schedule_id IN NUMBER,
5179 p_apply_gl_date OUT NOCOPY DATE,
5180 p_receivable_application_id OUT NOCOPY NUMBER,
5181 p_customer_trx_id OUT NOCOPY NUMBER,
5182 p_return_status OUT NOCOPY VARCHAR2
5183 ) IS
5184
5185 BEGIN
5186 IF PG_DEBUG in ('Y', 'C') THEN
5187 arp_util.debug('Derive_receivable_appln_id ()+');
5188 END IF;
5189 p_return_status := FND_API.G_RET_STS_SUCCESS;
5190 IF p_cash_receipt_id IS NOT NULL AND
5191 p_applied_payment_schedule_id IS NOT NULL
5192 THEN
5193 SELECT receivable_application_id, gl_date
5194 ,applied_customer_trx_id
5195 INTO p_receivable_application_id, p_apply_gl_date
5196 ,p_customer_trx_id
5197 FROM ar_receivable_applications ra
5198 WHERE ra.cash_receipt_id = p_cash_receipt_id
5199 AND ra.applied_payment_schedule_id = p_applied_payment_schedule_id
5200 AND ra.display = 'Y'
5201 AND ra.status = 'APP'
5202 AND ra.application_type = 'CASH';
5203
5204 END IF;
5205 IF PG_DEBUG in ('Y', 'C') THEN
5206 arp_util.debug('Derive_receivable_appln_id ()+');
5207 END IF;
5208 EXCEPTION
5209 WHEN no_data_found THEN
5210 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_NOT_APP_TO_INV');
5211 FND_MSG_PUB.Add;
5212 p_return_status := FND_API.G_RET_STS_ERROR;
5213 WHEN others THEN
5214 IF PG_DEBUG in ('Y', 'C') THEN
5215 arp_util.debug('Derive_receivable_appln_id: ' || 'EXCEPTION: Get_receivable_application_id()');
5216 END IF;
5217 raise;
5218 END Derive_receivable_appln_id;
5219
5220 PROCEDURE Get_payment_schedule_info(
5221 p_ps_id IN NUMBER,
5222 p_customer_trx_id OUT NOCOPY VARCHAR2,
5223 p_installment OUT NOCOPY NUMBER,
5224 p_called_from IN VARCHAR2,
5225 p_return_status OUT NOCOPY VARCHAR2 ) IS
5226 CURSOR payment_schedule IS
5227 SELECT ps.customer_trx_id, ps.terms_sequence_number
5228 FROM ar_payment_schedules ps
5229 WHERE ps.payment_schedule_id = p_ps_id
5230 AND ps.class IN ('CB','CM','DEP','DM','INV','BR')
5231 --these two conditions are to ensure that the trx(bill) is not in remit process
5232 AND ps.reserved_type is null
5233 AND ps.reserved_value is null;
5234
5235 CURSOR payment_schedule_br_remit IS
5236 SELECT ps.customer_trx_id, ps.terms_sequence_number
5237 FROM ar_payment_schedules ps
5238 WHERE ps.payment_schedule_id = p_ps_id
5239 AND ps.class IN ('CB','CM','DEP','DM','INV','BR');
5240
5241 BEGIN
5242 IF PG_DEBUG in ('Y', 'C') THEN
5243 arp_util.debug('Get_payment_schedule_info ()+');
5244 END IF;
5245 p_return_status := FND_API.G_RET_STS_SUCCESS;
5246
5247 IF p_called_from IN ('BR_REMITTED',
5248 'BR_FACTORED_WITH_RECOURSE',
5249 'BR_FACTORED_WITHOUT_RECOURSE') THEN
5250 OPEN payment_schedule_br_remit;
5251
5252 FETCH payment_schedule_br_remit INTO p_customer_trx_id, p_installment;
5253 IF payment_schedule_br_remit%NOTFOUND THEN
5254 --raise error message
5255 FND_MESSAGE.SET_NAME('AR','AR_RAPI_APP_PS_ID_INVALID');
5256 FND_MSG_PUB.Add;
5257 p_return_status := FND_API.G_RET_STS_ERROR;
5258 END IF;
5259 CLOSE payment_schedule_br_remit;
5260
5261 ELSE
5262
5263 OPEN payment_schedule;
5264 FETCH payment_schedule INTO p_customer_trx_id, p_installment;
5265 IF payment_schedule%NOTFOUND THEN
5266 --raise error message
5267 FND_MESSAGE.SET_NAME('AR','AR_RAPI_APP_PS_ID_INVALID');
5268 FND_MSG_PUB.Add;
5269 p_return_status := FND_API.G_RET_STS_ERROR;
5270 END IF;
5271 CLOSE payment_schedule;
5272
5273 END IF;
5274
5275 IF PG_DEBUG in ('Y', 'C') THEN
5276 arp_util.debug('Get_payment_schedule_info ()-');
5277 END IF;
5278 END Get_payment_schedule_info;
5279
5280 PROCEDURE Get_receivable_appln_info(
5281 p_ra_id IN NUMBER,
5282 p_ra_app_ps_id OUT NOCOPY NUMBER,
5283 p_cash_receipt_id OUT NOCOPY NUMBER,
5284 p_apply_gl_date OUT NOCOPY DATE, /* Bug fix 3451241 */
5285 p_customer_trx_id OUT NOCOPY NUMBER, /* LLCA */
5286 p_called_from IN VARCHAR2,
5287 p_return_status OUT NOCOPY VARCHAR2
5288 ) IS
5289 CURSOR rec_apppln IS
5290 SELECT ra.cash_receipt_id, ra.applied_payment_schedule_id, ra.gl_date /* Bug fix 3451241 */
5291 , ra.applied_customer_trx_id
5292 FROM ar_receivable_applications ra,
5293 ar_payment_schedules ps
5294 WHERE ra.applied_payment_schedule_id = ps.payment_schedule_id
5295 AND ra.receivable_application_id = p_ra_id
5296 AND ra.display = 'Y'
5297 AND ra.status = 'APP'
5298 AND ps.reserved_value IS NULL
5299 AND ps.reserved_type IS NULL;
5300
5301 CURSOR rec_apppln_br_remit IS
5302 SELECT ra.cash_receipt_id, ra.applied_payment_schedule_id, ra.gl_date /* Bug fix 3451241 */
5303 , ra.applied_customer_trx_id
5304 FROM ar_receivable_applications ra
5305 WHERE ra.receivable_application_id = p_ra_id
5306 AND ra.display = 'Y'
5307 AND ra.status = 'APP';
5308
5309 BEGIN
5310 IF PG_DEBUG in ('Y', 'C') THEN
5311 arp_util.debug('Get_receivable_appln_info ()+');
5312 END IF;
5313
5314 p_return_status := FND_API.G_RET_STS_SUCCESS;
5315
5316 IF p_called_from IN ('BR_REMITTED',
5317 'BR_FACTORED_WITH_RECOURSE',
5318 'BR_FACTORED_WITHOUT_RECOURSE') THEN
5319 OPEN rec_apppln_br_remit;
5320 FETCH rec_apppln_br_remit INTO p_cash_receipt_id, p_ra_app_ps_id, p_apply_gl_date, p_customer_trx_id; /* Bug fix 3451241 */
5321 IF rec_apppln_br_remit%NOTFOUND THEN
5322 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REC_APP_ID_INVALID');
5323 FND_MSG_PUB.Add;
5324 p_return_status := FND_API.G_RET_STS_ERROR;
5325 END IF;
5326 CLOSE rec_apppln_br_remit;
5327
5328 ELSE
5329
5330 OPEN rec_apppln;
5331 FETCH rec_apppln INTO p_cash_receipt_id, p_ra_app_ps_id, p_apply_gl_date,p_customer_trx_id; /* Bug fix 3451241 */
5332 IF rec_apppln%NOTFOUND THEN
5333 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REC_APP_ID_INVALID');
5334 FND_MSG_PUB.Add;
5335 p_return_status := FND_API.G_RET_STS_ERROR;
5336 END IF;
5337 CLOSE rec_apppln;
5338
5339 END IF;
5340
5341 IF PG_DEBUG in ('Y', 'C') THEN
5342 arp_util.debug('Get_receivable_appln_info ()-');
5343 END IF;
5344 END Get_receivable_appln_info;
5345
5346 PROCEDURE Derive_unapp_ids(
5347 p_trx_number IN VARCHAR2,
5348 p_customer_trx_id IN OUT NOCOPY NUMBER,
5349 p_installment IN NUMBER,
5350 p_applied_payment_schedule_id IN OUT NOCOPY NUMBER,
5351 p_receipt_number IN VARCHAR2,
5352 p_cash_receipt_id IN OUT NOCOPY NUMBER,
5353 p_receivable_application_id IN OUT NOCOPY NUMBER,
5354 p_called_from IN VARCHAR2,
5355 p_apply_gl_date OUT NOCOPY DATE,
5356 p_return_status OUT NOCOPY VARCHAR2
5357 ) IS
5358 l_customer_trx_id NUMBER;
5359 l_ra_customer_trx_id NUMBER;
5360 l_installment NUMBER(15);
5361 l_ra_app_ps_id NUMBER;
5362 l_applied_payment_schedule_id NUMBER;
5363 l_receivable_application_id NUMBER;
5364 l_return_status VARCHAR2(1);
5365 l_cash_receipt_id NUMBER(15);
5366 l_cust_trx_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5367 l_ps_id_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5368 l_ra_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5369 l_cr_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5370 BEGIN
5371 IF PG_DEBUG in ('Y', 'C') THEN
5372 arp_util.debug('Derive_unapp_ids ()+');
5373 END IF;
5374 p_return_status := FND_API.G_RET_STS_SUCCESS ;
5375
5376 -- First get a valid value for the customer_trx_id
5377 IF p_trx_number IS NOT NULL THEN
5378 Default_customer_trx_id(p_customer_trx_id ,
5379 p_trx_number ,
5380 l_cust_trx_return_status);
5381 END IF;
5382
5383 --if error is raised in deriving the customer_trx_id from the trx_number,
5384 --do not process the applied_payment_schedule_id any further.
5385 IF l_cust_trx_return_status= FND_API.G_RET_STS_SUCCESS THEN
5386
5387 IF p_applied_payment_schedule_id IS NOT NULL THEN
5388 Get_payment_schedule_info( p_applied_payment_schedule_id,
5389 l_customer_trx_id,
5390 l_installment,
5391 p_called_from,
5392 l_ps_id_return_status
5393 );
5394 IF l_cust_trx_return_status= FND_API.G_RET_STS_SUCCESS AND
5395 l_ps_id_return_status = FND_API.G_RET_STS_SUCCESS
5396 THEN
5397 --Compare the two customer_trx_ids
5398 IF (nvl(p_customer_trx_id,l_customer_trx_id) <> l_customer_trx_id OR
5399 nvl(p_installment,l_installment) <> l_installment) THEN
5400 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_PS_ID_X_INVALID');
5401 FND_MSG_PUB.Add;
5402 p_return_status := FND_API.G_RET_STS_ERROR;
5403 ELSE
5404 p_customer_trx_id := l_customer_trx_id;
5405 END IF;
5406 END IF;
5407
5408 ELSE --the user has not entered the applied_ps_id
5409
5410 IF p_customer_trx_id IS NOT NULL THEN
5411 l_applied_payment_schedule_id :=
5412 Get_trx_ps_id(p_customer_trx_id,
5413 p_installment,
5414 p_called_from,
5415 l_ps_id_return_status);
5416 p_applied_payment_schedule_id
5417 :=l_applied_payment_schedule_id;
5418 END IF;
5419
5420 END IF;
5421 END IF;
5422
5423 --derive the cash_receipt_id from the receipt_number
5424 IF p_receipt_number IS NOT NULL THEN
5425 Default_cash_receipt_id(p_cash_receipt_id,
5426 p_receipt_number,
5427 l_cr_return_status);
5428 END IF;
5429
5430 --If user has entered the receivable_application_id, get the related info
5431 IF p_receivable_application_id IS NOT NULL THEN
5432 Get_receivable_appln_info( p_receivable_application_id,
5433 l_ra_app_ps_id,
5434 l_cash_receipt_id,
5435 p_apply_gl_date, /* Bug fix 3451241 */
5436 l_customer_trx_id, /* LLCA */
5437 p_called_from,
5438 l_ra_return_status
5439 );
5440 IF nvl( l_ra_app_ps_id,-99) <> nvl(p_applied_payment_schedule_id,
5441 nvl( l_ra_app_ps_id,-99))
5442 THEN
5443 IF ar_receipt_api_pub.Original_unapp_info.customer_trx_id IS NOT NULL OR
5444 ar_receipt_api_pub.Original_unapp_info.trx_number IS NOT NULL THEN
5445 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_RA_ID_X_INVALID');
5446 FND_MSG_PUB.Add;
5447 p_return_status := FND_API.G_RET_STS_ERROR;
5448 ELSIF ar_receipt_api_pub.Original_unapp_info.applied_ps_id IS NOT NULL THEN
5449 FND_MESSAGE.SET_NAME('AR','AR_RAPI_APP_PS_RA_ID_X_INVALID');
5450 FND_MSG_PUB.Add;
5451 p_return_status := FND_API.G_RET_STS_ERROR;
5452 END IF;
5453 ELSE
5454 p_applied_payment_schedule_id := l_ra_app_ps_id;
5455 END IF;
5456
5457 IF nvl(l_cash_receipt_id,-99) <> nvl(p_cash_receipt_id,nvl(l_cash_receipt_id,-99)) THEN
5458 --Invalid receivable application identifier for the entered cash receipt
5459 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_RA_ID_X_INVALID');
5460 FND_MSG_PUB.Add;
5461 p_return_status := FND_API.G_RET_STS_ERROR;
5462 ELSE
5463 p_cash_receipt_id := l_cash_receipt_id;
5464 END IF;
5465
5466 /* LLCA */
5467 IF nvl(l_customer_trx_id,-99) <> nvl(p_customer_trx_id,nvl(l_customer_trx_id,-99)) THEN
5468 --Invalid receivable application identifier for the entered customer trx id receipt
5469 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_RA_ID_X_INVALID');
5470 FND_MSG_PUB.Add;
5471 p_return_status := FND_API.G_RET_STS_ERROR;
5472 ELSE
5473 p_customer_trx_id := l_customer_trx_id;
5474 END IF;
5475
5476
5477 ELSE --the user has not passed in the receivable application id
5478 --
5479 -- derive receivable_application_id
5480 --
5481 --If app_ps_id and the cash_receipt_id are not null then
5482 --get the default receivable_application_id which will be
5483 --used for defaulting or cross-validation
5484 IF p_cash_receipt_id IS NOT NULL AND
5485 p_applied_payment_schedule_id IS NOT NULL
5486 THEN
5487 --derive the receivable application id using the cash receipt id and
5488 --the applied payment schedule id
5489 Derive_receivable_appln_id(
5490 p_cash_receipt_id,
5491 p_applied_payment_schedule_id,
5492 p_apply_gl_date,
5493 l_receivable_application_id,
5494 l_customer_trx_id,
5495 l_ra_return_status);
5496 p_receivable_application_id := l_receivable_application_id;
5497 /* LLCA */
5498 If p_customer_trx_id is NULL
5499 THEN
5500 p_customer_trx_id := l_customer_trx_id;
5501 END IF;
5502
5503 END IF; --in other cases we can't derive the receivable application id so it cannot be defaulted
5504
5505 END IF;
5506
5507 IF l_cust_trx_return_status <> FND_API.G_RET_STS_SUCCESS OR
5508 l_ps_id_return_status <> FND_API.G_RET_STS_SUCCESS OR
5509 l_ra_return_status <> FND_API.G_RET_STS_SUCCESS OR
5510 l_cr_return_status <> FND_API.G_RET_STS_SUCCESS OR
5511 p_return_status <> FND_API.G_RET_STS_SUCCESS
5512 THEN
5513 p_return_status := FND_API.G_RET_STS_ERROR;
5514 END IF;
5515 IF PG_DEBUG in ('Y', 'C') THEN
5516 arp_util.debug('Derive_unapp_ids: ' || '****Defaulted Value for the unapplication ids****');
5517 arp_util.debug('Derive_unapp_ids: ' || 'p_cash_receipt_id :'||to_char(p_cash_receipt_id));
5518 arp_util.debug('Derive_unapp_ids: ' || 'p_customer_trx_id :'||to_char(p_customer_trx_id));
5519 arp_util.debug('Derive_unapp_ids: ' || 'p_installment :'||to_char(p_installment));
5520 arp_util.debug('Derive_unapp_ids: ' || 'p_applied_payment_schedule_id :'||to_char(p_applied_payment_schedule_id));
5521 arp_util.debug('Derive_unapp_ids: ' || 'p_receivable_application_id :'||to_char(p_receivable_application_id));
5522 arp_util.debug('Derive_unapp_ids: ' || 'Return Status :'||p_return_status);
5523 arp_util.debug('Derive_unapp_ids ()-');
5524 END IF;
5525 EXCEPTION
5526 WHEN others THEN
5527 IF PG_DEBUG in ('Y', 'C') THEN
5528 arp_util.debug('EXCEPTION: Derive_unapp_ids()');
5529 END IF;
5530 raise;
5531 END Derive_unapp_ids;
5532
5533 /* This is a routine to get the reversal_gl_date for the unapplication */
5534 PROCEDURE Default_reversal_gl_date(
5535 p_receivable_application_id IN NUMBER,
5536 p_reversal_gl_date IN OUT NOCOPY DATE,
5537 p_apply_gl_date IN OUT NOCOPY DATE,
5538 p_cash_receipt_id IN OUT NOCOPY NUMBER
5539 ) IS
5540 l_apply_gl_date DATE;
5541 l_default_gl_date DATE;
5542 l_defaulting_rule_used VARCHAR2(100);
5543 l_error_message VARCHAR2(240);
5544 BEGIN
5545 IF PG_DEBUG in ('Y', 'C') THEN
5546 arp_util.debug('Default_reversal_gl_date ()+');
5547 END IF;
5548 l_apply_gl_date := p_apply_gl_date; /* Bug fix 3503167 */
5549
5550 IF p_receivable_application_id IS NOT NULL THEN
5551 IF p_apply_gl_date IS NULL THEN
5552 --get the gl_date for the application
5553 SELECT gl_date, cash_receipt_id
5554 INTO l_apply_gl_date, p_cash_receipt_id
5555 FROM ar_receivable_applications
5556 WHERE receivable_application_id =
5557 p_receivable_application_id;
5558 END IF;
5559 /* Bug fix 3503167 : We need to pass the apply_gl_date as the candidate gl_date and
5560 as the validation date */
5561 IF p_reversal_gl_date is null THEN
5562 IF (arp_util.validate_and_default_gl_date(
5563 nvl(l_apply_gl_date,trunc(sysdate)),
5564 NULL,
5565 l_apply_gl_date,
5566 NULL,
5567 NULL,
5568 NULL,
5569 NULL,
5570 NULL,
5571 'N',
5572 NULL,
5573 arp_global.set_of_books_id,
5574 222,
5575 l_default_gl_date,
5576 l_defaulting_rule_used,
5577 l_error_message) = TRUE) THEN
5578
5579 p_reversal_gl_date := l_default_gl_date;
5580 ELSE
5581 --we were not able to default the gl_date put the message
5582 --here on the stack, but the return status will be set
5583 --to FND_API.G_RET_STS_ERROR in the validation phase.
5584 FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
5585 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', l_error_message);
5586 FND_MSG_PUB.Add;
5587 END IF;
5588 END IF;
5589 END IF;
5590 IF PG_DEBUG in ('Y', 'C') THEN
5591 arp_util.debug('Default_reversal_gl_date ()-');
5592 END IF;
5593 EXCEPTION
5594 When others THEN
5595 IF PG_DEBUG in ('Y', 'C') THEN
5596 arp_util.debug('EXCEPTION: Default_reversal_gl_date()');
5597 END IF;
5598 raise;
5599 END Default_reversal_gl_date;
5600
5601 /*Added parameter p_cr_unapp_amount for bug 3119391 */
5602 PROCEDURE Default_unapp_info(
5603 p_receivable_application_id IN NUMBER,
5604 p_apply_gl_date IN DATE,
5605 p_cash_receipt_id IN NUMBER,
5606 p_reversal_gl_date IN OUT NOCOPY DATE,
5607 p_receipt_gl_date OUT NOCOPY DATE,
5608 p_cr_unapp_amount OUT NOCOPY NUMBER
5609 ) IS
5610 l_cash_receipt_id NUMBER(15);
5611 l_apply_gl_date DATE;
5612 BEGIN
5613 IF PG_DEBUG in ('Y', 'C') THEN
5614 arp_util.debug('Default_unapp_info ()+');
5615 END IF;
5616 l_apply_gl_date := p_apply_gl_date;
5617 l_cash_receipt_id := p_cash_receipt_id;
5618
5619 Default_reversal_gl_date(p_receivable_application_id,
5620 p_reversal_gl_date,
5621 l_apply_gl_date,
5622 l_cash_receipt_id );
5623 /* Default p_cr_unapp_amount for 3119391 */
5624
5625 SELECT SUM(NVL(ra.amount_applied,0))
5626 INTO p_cr_unapp_amount
5627 FROM ar_receivable_applications ra
5628 WHERE ra.status = 'UNAPP'
5629 AND ra.cash_receipt_id = l_cash_receipt_id;
5630
5631 --default the receipt gl date which is to be used later
5632 --in the validation of the reversal gl date.
5633 IF p_receipt_gl_date IS NULL AND
5634 l_cash_receipt_id IS NOT NULL
5635 THEN
5636 BEGIN
5637 SELECT gl_date
5638 INTO p_receipt_gl_date
5639 FROM ar_cash_receipt_history crh
5640 WHERE crh.cash_receipt_id = l_cash_receipt_id
5641 and crh.FIRST_POSTED_RECORD_FLAG = 'Y';
5642 -- Bug 3074658, Inconsistent bahaviour between UI/API
5643 -- AND crh.current_record_flag = 'Y';
5644 EXCEPTION
5645 WHEN no_data_found THEN
5646 null;
5647 IF PG_DEBUG in ('Y', 'C') THEN
5648 arp_util.debug('Default_unapp_info: ' || 'Could not get the receipt_gl_date. ');
5649 END IF;
5650 END;
5651 END IF;
5652 IF PG_DEBUG in ('Y', 'C') THEN
5653 arp_util.debug('Default_unapp_info ()-');
5654 END IF;
5655 END Default_unapp_info;
5656
5657 PROCEDURE Default_rev_catg_code(p_reversal_category_code IN OUT NOCOPY VARCHAR2,
5658 p_reversal_category_name IN VARCHAR2,
5659 p_return_status OUT NOCOPY VARCHAR2
5660 ) IS
5661
5662 BEGIN
5663 IF PG_DEBUG in ('Y', 'C') THEN
5664 arp_util.debug('Default_rev_catg_code ()+');
5665 END IF;
5666
5667 p_return_status := FND_API.G_RET_STS_SUCCESS;
5668
5669 IF p_reversal_category_code IS NULL THEN
5670 BEGIN
5671 SELECT lookup_code
5672 INTO p_reversal_category_code
5673 FROM ar_lookups
5674 WHERE lookup_type = 'REVERSAL_CATEGORY_TYPE'
5675 AND enabled_flag = 'Y'
5676 AND meaning = p_reversal_category_name;
5677 EXCEPTION
5678 WHEN no_data_found THEN
5679 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REV_CAT_NAME_INVALID');
5680 FND_MSG_PUB.Add;
5681 p_return_status := FND_API.G_RET_STS_ERROR ;
5682 null;
5683 END;
5684 ELSE
5685 IF p_reversal_category_name IS NOT NULL THEN
5686 --give a warning message to indicate that the reversal category name
5687 --entered by the user has been ignored.
5688 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
5689 THEN
5690 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REV_CAT_NAME_IGN');
5691 FND_MSG_PUB.Add;
5692 END IF;
5693 END IF;
5694 END IF;
5695 IF PG_DEBUG in ('Y', 'C') THEN
5696 arp_util.debug('Default_rev_catg_code ()-');
5697 END IF;
5698 EXCEPTION
5699 WHEN others THEN
5700 IF PG_DEBUG in ('Y', 'C') THEN
5701 arp_util.debug('EXCEPTION: Default_rev_catg_code()');
5702 END IF;
5703 raise;
5704 END Default_rev_catg_code;
5705
5706 PROCEDURE Default_rev_reason_code(
5707 p_reversal_reason_code IN OUT NOCOPY VARCHAR2,
5708 p_reversal_reason_name IN VARCHAR2,
5709 p_return_status OUT NOCOPY VARCHAR2
5710 ) IS
5711
5712 BEGIN
5713 IF PG_DEBUG in ('Y', 'C') THEN
5714 arp_util.debug('Default_rev_reason_code ()+');
5715 END IF;
5716
5717 p_return_status := FND_API.G_RET_STS_SUCCESS;
5718
5719 IF p_reversal_reason_code IS NULL THEN
5720 BEGIN
5721 SELECT lookup_code
5722 INTO p_reversal_reason_code
5723 FROM ar_lookups
5724 WHERE lookup_type = 'CKAJST_REASON'
5725 AND enabled_flag = 'Y'
5726 AND meaning = p_reversal_reason_name;
5727 EXCEPTION
5728 WHEN no_data_found THEN
5729 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REV_REAS_NAME_INVALID');
5730 FND_MSG_PUB.Add;
5731 p_return_status := FND_API.G_RET_STS_ERROR ;
5732 null;
5733 END;
5734 ELSE
5735 IF p_reversal_reason_name IS NOT NULL THEN
5736 --give a warning message to indicate that the reversal category name
5737 --entered by the user has been ignored.
5738 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
5739 THEN
5740 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REV_REAS_NAME_IGN');
5741 FND_MSG_PUB.Add;
5742 END IF;
5743 END IF;
5744 END IF;
5745 IF PG_DEBUG in ('Y', 'C') THEN
5746 arp_util.debug('Default_rev_reason_code ()-');
5747 END IF;
5748 EXCEPTION
5749 WHEN others THEN
5750 IF PG_DEBUG in ('Y', 'C') THEN
5751 arp_util.debug('EXCEPTION: Default_rev_reason_code()');
5752 END IF;
5753 raise;
5754 END Default_rev_reason_code;
5755
5756 PROCEDURE Derive_reverse_ids(
5757 p_receipt_number IN VARCHAR2,
5758 p_cash_receipt_id IN OUT NOCOPY NUMBER,
5759 p_reversal_category_name IN VARCHAR2,
5760 p_reversal_category_code IN OUT NOCOPY VARCHAR2,
5761 p_reversal_reason_name IN VARCHAR2,
5762 p_reversal_reason_code IN OUT NOCOPY VARCHAR2,
5763 p_return_status OUT NOCOPY VARCHAR2
5764 ) IS
5765 l_cr_def_return_status VARCHAR2(1);
5766 l_rev_cat_return_status VARCHAR2(1);
5767 l_rev_res_return_status VARCHAR2(1);
5768 BEGIN
5769 IF PG_DEBUG in ('Y', 'C') THEN
5770 arp_util.debug('Derive_reverse_ids ()+ ');
5771 END IF;
5772 p_return_status := FND_API.G_RET_STS_SUCCESS ;
5773
5774
5775 --cash_receipt_id
5776 Default_cash_receipt_id(p_cash_receipt_id ,
5777 p_receipt_number ,
5778 l_cr_def_return_status);
5779 IF PG_DEBUG in ('Y', 'C') THEN
5780 arp_util.debug('Derive_reverse_ids: ' || 'l_cr_def__return_status :'||l_cr_def_return_status);
5781 END IF;
5782
5783 --reversal category
5784 Default_rev_catg_code(p_reversal_category_code,
5785 p_reversal_category_name,
5786 l_rev_cat_return_status
5787 );
5788 IF PG_DEBUG in ('Y', 'C') THEN
5789 arp_util.debug('Derive_reverse_ids: ' || 'l_rev_cat_return_status :'||l_rev_cat_return_status);
5790 END IF;
5791
5792 --reversal reason code
5793 Default_rev_reason_code(p_reversal_reason_code,
5794 p_reversal_reason_name,
5795 l_rev_res_return_status
5796 );
5797
5798 IF l_rev_res_return_status <> FND_API.G_RET_STS_SUCCESS OR
5799 l_rev_cat_return_status <> FND_API.G_RET_STS_SUCCESS OR
5800 l_cr_def_return_status <> FND_API.G_RET_STS_SUCCESS
5801 THEN
5802 p_return_status := FND_API.G_RET_STS_ERROR ;
5803 END IF;
5804
5805 IF PG_DEBUG in ('Y', 'C') THEN
5806 arp_util.debug('Derive_reverse_ids ()- ');
5807 END IF;
5808 EXCEPTION
5809 When others THEN
5810 IF PG_DEBUG in ('Y', 'C') THEN
5811 arp_util.debug('EXCEPTION: Derive_reverse_ids()');
5812 END IF;
5813 END Derive_reverse_ids;
5814
5815 PROCEDURE Default_reverse_info(p_cash_receipt_id IN NUMBER,
5816 p_reversal_gl_date IN OUT NOCOPY DATE,
5817 p_reversal_date IN OUT NOCOPY DATE,
5818 p_receipt_state OUT NOCOPY VARCHAR2,
5819 p_receipt_gl_date OUT NOCOPY DATE,
5820 p_type OUT NOCOPY VARCHAR2
5821 ) IS
5822 l_receipt_date DATE;
5823 l_return_status VARCHAR2(1);
5824 BEGIN
5825 IF PG_DEBUG in ('Y', 'C') THEN
5826 arp_util.debug('Default_reverse_info ()+');
5827 END IF;
5828 /*Get the receipt date and the status */
5829
5830 SELECT cr.receipt_date, crh.status, cr.type
5831 INTO l_receipt_date, p_receipt_state, p_type
5832 FROM ar_cash_receipts cr,
5833 ar_cash_receipt_history crh
5834 WHERE cr.cash_receipt_id = crh.cash_receipt_id
5835 AND crh.current_record_flag = 'Y'
5836 AND cr.cash_receipt_id = p_cash_receipt_id;
5837
5838 /* Bug fix 3547720
5839 p_receipt_gl_date should be populated as the max(gl_date) from CRH */
5840
5841 SELECT max(crh.gl_date)
5842 INTO p_receipt_gl_date
5843 FROM ar_cash_receipt_history crh
5844 WHERE crh.cash_receipt_id = p_cash_receipt_id;
5845
5846 /*Default reversal_date */
5847 IF p_reversal_date IS NULL THEN
5848 IF l_receipt_date > trunc(SYSDATE) THEN
5849 p_reversal_date := l_receipt_date;
5850 ELSE
5851 p_reversal_date := trunc(SYSDATE);
5852 END IF;
5853 END IF;
5854
5855 /* default the reversal_gl_date */
5856 IF p_reversal_gl_date IS NULL THEN
5857 /* Bug fix 3547720 : Changed the call */
5858 /* Bug fix 3922062. Reversal_gl_date should be the maximum of (sysdate and the
5859 maximum of CRH gl_date) */
5860
5861 Default_gl_date(greatest(p_receipt_gl_date, sysdate),
5862 p_reversal_gl_date,
5863 p_receipt_gl_date,
5864 l_return_status);
5865 END IF;
5866
5867 IF PG_DEBUG in ('Y', 'C') THEN
5868 arp_util.debug('Default_reverse_info: ' || '**************Defaulted Variables ************');
5869 arp_util.debug('Default_reverse_info: ' || 'p_reversal_gl_date : '||to_char(p_reversal_gl_date,'DD-MON-YYYY'));
5870 arp_util.debug('Default_reverse_info: ' || 'p_reversal_date : '||to_char(p_reversal_date,'DD-MON-YYYY'));
5871 arp_util.debug('Default_reverse_info: ' || 'p_receipt_state : '||p_receipt_state);
5872 arp_util.debug('Default_reverse_info: ' || 'p_receipt_gl_date : '||to_char(p_receipt_gl_date,'DD-MON-YYYY'));
5873 arp_util.debug('Default_reverse_info ()-');
5874 END IF;
5875 EXCEPTION
5876 WHEN no_data_found THEN
5877 --this may happen because of the invalid cash_receipt_id
5878 --do not raise any message here, it shall be raised in the
5879 --validation phase.
5880 IF PG_DEBUG in ('Y', 'C') THEN
5881 arp_util.debug('Default_reverse_info: ' || 'Could not default info :Cash Receipt Id is invalid');
5882 END IF;
5883 WHEN others THEN
5884 IF PG_DEBUG in ('Y', 'C') THEN
5885 arp_util.debug('EXCEPTION: Default_reverse_info() ');
5886 END IF;
5887 raise;
5888 END Default_reverse_info;
5889
5890 PROCEDURE Default_on_ac_app_info(
5891 p_cash_receipt_id IN NUMBER,
5892 p_cr_gl_date OUT NOCOPY DATE,
5893 p_cr_unapp_amount OUT NOCOPY NUMBER,
5894 p_receipt_date OUT NOCOPY DATE,
5895 p_cr_payment_schedule_id OUT NOCOPY NUMBER,
5896 p_amount_applied IN OUT NOCOPY NUMBER,
5897 p_apply_gl_date IN OUT NOCOPY DATE,
5898 p_apply_date IN OUT NOCOPY DATE,
5899 p_cr_currency_code OUT NOCOPY VARCHAR2,
5900 p_return_status OUT NOCOPY VARCHAR2
5901 ) IS
5902 l_cr_customer_id NUMBER;
5903 l_cr_currency_code VARCHAR2(30);
5904 l_cr_exchange_rate NUMBER;
5905 l_cr_cust_site_use_id NUMBER;
5906 l_return_status VARCHAR2(1);
5907 l_cr_amount NUMBER;
5908 l_receipt_return_status VARCHAR2(1);
5909 l_gl_date_return_status VARCHAR2(1);
5910 l_receipt_date DATE;
5911 l_cr_unapp_amount NUMBER;
5912 l_remit_bank_acct_use_id NUMBER;
5913 l_receipt_method_id NUMBER;
5914 BEGIN
5915 IF PG_DEBUG in ('Y', 'C') THEN
5916 arp_util.debug('Default_on_ac_app_info ()+');
5917 END IF;
5918 p_return_status := FND_API.G_RET_STS_SUCCESS;
5919
5920 Default_Receipt_Info(
5921 p_cash_receipt_id ,
5922 p_cr_gl_date,
5923 l_cr_customer_id,
5924 l_cr_amount,
5925 l_cr_currency_code,
5926 l_cr_exchange_rate,
5927 l_cr_cust_site_use_id,
5928 l_receipt_date,
5929 l_cr_unapp_amount,
5930 p_cr_payment_schedule_id,
5931 l_remit_bank_acct_use_id,
5932 l_receipt_method_id,
5933 l_receipt_return_status
5934 );
5935 IF PG_DEBUG in ('Y', 'C') THEN
5936 arp_util.debug('Default_on_ac_app_info: ' || 'Receipt defaulting return status :'||l_receipt_return_status);
5937 END IF;
5938 Default_apply_date(l_receipt_date ,
5939 null,
5940 p_apply_date);
5941
5942 IF p_apply_gl_date IS NULL THEN
5943 Default_gl_date(p_cr_gl_date,
5944 p_apply_gl_date,
5945 NULL,
5946 l_gl_date_return_status);
5947 END IF;
5948 IF PG_DEBUG in ('Y', 'C') THEN
5949 arp_util.debug('Default_on_ac_app_info: ' || 'Defaulting apply gl date return status :'|| l_gl_date_return_status);
5950 END IF;
5951
5952 --default the amount applied
5953 IF p_amount_applied IS NULL THEN
5954 p_amount_applied := l_cr_unapp_amount;
5955 END IF;
5956 --do the precision
5957 p_amount_applied := arp_util.CurrRound(
5958 p_amount_applied,
5959 l_cr_currency_code
5960 );
5961
5962 p_receipt_date := l_receipt_date ;
5963 p_cr_unapp_amount := l_cr_unapp_amount;
5964
5965 IF l_receipt_return_status <> FND_API.G_RET_STS_SUCCESS OR
5966 l_receipt_return_status <> l_receipt_return_status THEN
5967
5968 p_return_status := FND_API.G_RET_STS_ERROR ;
5969 END IF;
5970
5971 p_cr_currency_code := l_cr_currency_code;
5972
5973 IF PG_DEBUG in ('Y', 'C') THEN
5974 arp_util.debug('Default_on_ac_app_info: ' || '***************Default Values *****************');
5975 arp_util.debug('Default_on_ac_app_info: ' || 'p_cash_receipt_id : '||to_char(p_cash_receipt_id));
5976 arp_util.debug('Default_on_ac_app_info: ' || 'p_cr_gl_date : '||to_char(p_cr_gl_date,'DD-MON-YYYY'));
5977 arp_util.debug('Default_on_ac_app_info: ' || 'p_amount_applied : '||to_char(p_amount_applied));
5978 arp_util.debug('Default_on_ac_app_info: ' || 'p_apply_gl_date : '||to_char(p_apply_gl_date,'DD-MON-YYYY'));
5979 arp_util.debug('Default_on_ac_app_info: ' || 'p_apply_date : '||to_char(p_apply_date,'DD-MON-YYYY'));
5980 arp_util.debug('Default_on_ac_app_info ()-');
5981 END IF;
5982 EXCEPTION
5983 WHEN others THEN
5984 IF PG_DEBUG in ('Y', 'C') THEN
5985 arp_util.debug('EXCEPTION: Default_on_ac_app_info() ');
5986 END IF;
5987 raise;
5988 END Default_on_ac_app_info;
5989
5990 PROCEDURE Derive_unapp_on_ac_ids(
5991 p_receipt_number IN VARCHAR2,
5992 p_cash_receipt_id IN OUT NOCOPY NUMBER,
5993 p_receivable_application_id IN OUT NOCOPY NUMBER,
5994 p_apply_gl_date OUT NOCOPY DATE,
5995 p_return_status OUT NOCOPY VARCHAR2
5996 ) IS
5997 l_rec_appln_id NUMBER ;
5998 l_apply_gl_date DATE;
5999 l_cash_receipt_id NUMBER;
6000 BEGIN
6001 p_return_status := FND_API.G_RET_STS_SUCCESS;
6002 IF PG_DEBUG in ('Y', 'C') THEN
6003 arp_util.debug('Derive_unapp_on_ac_ids ()+');
6004 END IF;
6005 --derive the cash_receipt_id from the receipt_number
6006 IF p_receipt_number IS NOT NULL THEN
6007 Default_cash_receipt_id(p_cash_receipt_id ,
6008 p_receipt_number ,
6009 p_return_status);
6010 END IF;
6011
6012 --get the receivable application id for the on account application
6013 --on this cash receipt. If more than one on-account application exists
6014 --for the receipt, raise error.
6015 IF p_cash_receipt_id IS NOT NULL THEN
6016
6017 BEGIN
6018 SELECT receivable_application_id, gl_date
6019 INTO l_rec_appln_id , p_apply_gl_date
6020 FROM ar_receivable_applications
6021 WHERE cash_receipt_id = p_cash_receipt_id
6022 AND display = 'Y'
6023 AND status = 'ACC';
6024 EXCEPTION
6025 WHEN no_data_found THEN
6026 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CASH_RCPT_ID_INVALID');
6027 FND_MSG_PUB.Add;
6028 p_return_status := FND_API.G_RET_STS_ERROR ;
6029 WHEN too_many_rows THEN
6030 IF p_receivable_application_id IS NULL THEN
6031 FND_MESSAGE.SET_NAME('AR','AR_RAPI_MULTIPLE_ON_AC_APP');
6032 FND_MSG_PUB.Add;
6033 p_return_status := FND_API.G_RET_STS_ERROR ;
6034 END IF;
6035
6036 END;
6037
6038 END IF;
6039
6040 IF p_receivable_application_id IS NOT NULL THEN
6041
6042 BEGIN
6043 SELECT cash_receipt_id, gl_date
6044 INTO l_cash_receipt_id , p_apply_gl_date
6045 FROM ar_receivable_applications
6046 WHERE receivable_application_id = p_receivable_application_id
6047 and display = 'Y'
6048 and status = 'ACC';
6049 EXCEPTION
6050 WHEN no_data_found THEN
6051 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REC_APP_ID_INVALID');
6052 FND_MSG_PUB.Add;
6053 p_return_status := FND_API.G_RET_STS_ERROR ;
6054 END;
6055
6056 --Compare the two cash_receipt_ids
6057 IF p_cash_receipt_id IS NOT NULL THEN
6058 IF p_cash_receipt_id <> NVL(l_cash_receipt_id,p_cash_receipt_id) THEN
6059 --raise error X validation failed
6060 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_RA_ID_X_INVALID');
6061 FND_MSG_PUB.Add;
6062 p_return_status := FND_API.G_RET_STS_ERROR ;
6063 END IF;
6064 END IF;
6065
6066 ELSE
6067 p_receivable_application_id := l_rec_appln_id ;
6068 END IF;
6069
6070 IF p_cash_receipt_id IS NULL THEN
6071 p_cash_receipt_id := l_cash_receipt_id;
6072 END IF;
6073
6074 IF PG_DEBUG in ('Y', 'C') THEN
6075 arp_util.debug('Derive_unapp_on_ac_ids ()+');
6076 END IF;
6077 END Derive_unapp_on_ac_ids;
6078
6079 PROCEDURE Derive_otheraccount_ids(
6080 p_receipt_number IN VARCHAR2,
6081 p_cash_receipt_id IN OUT NOCOPY NUMBER,
6082 p_applied_ps_id IN NUMBER,
6083 p_receivable_application_id IN OUT NOCOPY NUMBER,
6084 p_apply_gl_date OUT NOCOPY DATE,
6085 p_cr_unapp_amt OUT NOCOPY NUMBER, /* Bug fix 3569640 */
6086 p_return_status OUT NOCOPY VARCHAR2
6087 ) IS
6088 l_rec_appln_id NUMBER ;
6089 l_apply_gl_date DATE;
6090 l_cash_receipt_id NUMBER;
6091 l_applied_ps_id NUMBER;
6092
6093 BEGIN
6094 p_return_status := FND_API.G_RET_STS_SUCCESS;
6095 IF PG_DEBUG in ('Y', 'C') THEN
6096 arp_util.debug('Derive_otheraccount_ids ()+');
6097 END IF;
6098 --derive the cash_receipt_id from the receipt_number
6099 IF p_receipt_number IS NOT NULL THEN
6100 Default_cash_receipt_id(p_cash_receipt_id ,
6101 p_receipt_number ,
6102 p_return_status);
6103 END IF;
6104
6105 --get the receivable application id for the prepayment application
6106 --on this cash receipt. If more than one prepayment application exists
6107 --for the receipt, raise error.
6108 -- Bug 2751910 - restrict validation to prepayments
6109 IF (p_cash_receipt_id IS NOT NULL AND p_applied_ps_id = -7) THEN
6110
6111 BEGIN
6112 SELECT receivable_application_id, gl_date
6113 INTO l_rec_appln_id , p_apply_gl_date
6114 FROM ar_receivable_applications
6115 WHERE cash_receipt_id = p_cash_receipt_id
6116 AND applied_payment_schedule_id = p_applied_ps_id
6117 AND display = 'Y'
6118 AND status = 'OTHER ACC';
6119 EXCEPTION
6120 WHEN no_data_found THEN
6121 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CASH_RCPT_ID_INVALID');
6122 FND_MSG_PUB.Add;
6123 p_return_status := FND_API.G_RET_STS_ERROR ;
6124 WHEN too_many_rows THEN
6125 IF p_receivable_application_id IS NULL THEN
6126 FND_MESSAGE.SET_NAME('AR','AR_RAPI_MULTIPLE_PREPAY');
6127 FND_MSG_PUB.Add;
6128 p_return_status := FND_API.G_RET_STS_ERROR ;
6129 END IF;
6130
6131 END;
6132
6133 END IF;
6134
6135 IF p_receivable_application_id IS NOT NULL THEN
6136
6137 BEGIN
6138 SELECT cash_receipt_id, gl_date
6139 INTO l_cash_receipt_id , p_apply_gl_date
6140 FROM ar_receivable_applications
6141 WHERE receivable_application_id = p_receivable_application_id
6142 and display = 'Y'
6143 and applied_payment_schedule_id = p_applied_ps_id
6144 and status = 'OTHER ACC';
6145 EXCEPTION
6146 WHEN no_data_found THEN
6147 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REC_APP_ID_INVALID');
6148 FND_MSG_PUB.Add;
6149 p_return_status := FND_API.G_RET_STS_ERROR ;
6150 END;
6151
6152 --Compare the two cash_receipt_ids
6153 IF p_cash_receipt_id IS NOT NULL THEN
6154 IF p_cash_receipt_id <> NVL(l_cash_receipt_id,p_cash_receipt_id) THEN
6155 --raise error X validation failed
6156 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_RA_ID_X_INVALID');
6157 FND_MSG_PUB.Add;
6158 p_return_status := FND_API.G_RET_STS_ERROR ;
6159 END IF;
6160 END IF;
6161
6162 ELSE
6163 p_receivable_application_id := l_rec_appln_id ;
6164 END IF;
6165
6166 IF p_cash_receipt_id IS NULL THEN
6167 p_cash_receipt_id := l_cash_receipt_id;
6168 END IF;
6169
6170 /* Bug fix 3569640 */
6171 IF p_cash_receipt_id IS NOT NULL THEN
6172 SELECT SUM(NVL(ra.amount_applied,0))
6173 INTO p_cr_unapp_amt
6174 FROM ar_receivable_applications ra
6175 WHERE ra.cash_receipt_id = p_cash_receipt_id
6176 AND ra.status = 'UNAPP'
6177 AND nvl(ra.confirmed_flag,'Y') = 'Y';
6178 END IF;
6179 IF PG_DEBUG in ('Y', 'C') THEN
6180 arp_util.debug('Derive_otheraccount_ids: ' || 'Derive_unapp_on_ac_ids ()+');
6181 END IF;
6182 END Derive_otheraccount_ids;
6183
6184 PROCEDURE Default_unapp_on_ac_act_info(
6185 p_receivable_application_id IN NUMBER,
6186 p_apply_gl_date IN DATE,
6187 p_cash_receipt_id IN NUMBER,
6188 p_reversal_gl_date IN OUT NOCOPY DATE,
6189 p_receipt_gl_date OUT NOCOPY DATE
6190 ) IS
6191 l_apply_date DATE;
6192 l_apply_gl_date DATE;
6193 l_cash_receipt_id NUMBER;
6194 l_default_gl_date DATE;
6195 l_defaulting_rule_used VARCHAR2(100);
6196 l_error_message VARCHAR2(240);
6197 BEGIN
6198 IF PG_DEBUG in ('Y', 'C') THEN
6199 arp_util.debug('Default_unapp_on_ac_act_info: ' || 'Default_unapp_on_acc_act_info ()+');
6200 END IF;
6201 l_apply_gl_date := p_apply_gl_date;
6202
6203 /* Bug fix 3503167 : We need to pass the apply_gl_date as the candidate gl_date and
6204 as the validation date */
6205 IF p_reversal_gl_date is null THEN
6206 IF (arp_util.validate_and_default_gl_date(
6207 nvl(l_apply_gl_date,trunc(sysdate)),
6208 NULL,
6209 l_apply_gl_date,
6210 NULL,
6211 NULL,
6212 NULL,
6213 NULL,
6214 NULL,
6215 'N',
6216 NULL,
6217 arp_global.set_of_books_id,
6218 222,
6219 l_default_gl_date,
6220 l_defaulting_rule_used,
6221 l_error_message) = TRUE) THEN
6222
6223 p_reversal_gl_date := l_default_gl_date;
6224 ELSE
6225 --we were not able to default the gl_date put the message
6226 --here on the stack, but the return status will be set
6227 --to FND_API.G_RET_STS_ERROR in the validation phase.
6228 FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
6229 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', l_error_message);
6230 FND_MSG_PUB.Add;
6231 END IF;
6232 END IF;
6233
6234 --derive the receipt_gl_date which is to be used
6235 --in the validation of the reversal gl date.
6236 IF p_receipt_gl_date IS NULL AND
6237 l_cash_receipt_id IS NOT NULL
6238 THEN
6239 BEGIN
6240 SELECT gl_date
6241 INTO p_receipt_gl_date
6242 FROM ar_cash_receipt_history crh
6243 WHERE crh.cash_receipt_id = l_cash_receipt_id
6244 and crh.current_record_flag = 'Y';
6245 EXCEPTION
6246 WHEN no_data_found THEN
6247 null;
6248 IF PG_DEBUG in ('Y', 'C') THEN
6249 arp_util.debug('Default_unapp_on_ac_act_info: ' || 'Could not get the receipt_gl_date. ');
6250 END IF;
6251 END;
6252 END IF;
6253 IF PG_DEBUG in ('Y', 'C') THEN
6254 arp_util.debug('Default_unapp_on_ac_act_info: ' || '*****Defaulted Values *********');
6255 arp_util.debug('Default_unapp_on_ac_act_info: ' || 'p_cash_receipt_id : '||to_char(p_cash_receipt_id));
6256 arp_util.debug('Default_unapp_on_ac_act_info: ' || 'p_receivable_application_id : '||to_char(p_receivable_application_id));
6257 arp_util.debug('Default_unapp_on_ac_act_info: ' || 'p_apply_gl_date : '||to_char(p_apply_gl_date,'DD-MON-YYYY'));
6258 arp_util.debug('Default_unapp_on_ac_act_info: ' || 'p_reversal_gl_date : '||to_char(p_reversal_gl_date,'DD-MON-YYYY'));
6259 arp_util.debug('Default_unapp_on_ac_act_info: ' || 'Default_unapp_on_acc_act_info ()-');
6260 END IF;
6261
6262 END Default_unapp_on_ac_act_info;
6263
6264 PROCEDURE Derive_activity_unapp_ids(
6265 p_receipt_number IN VARCHAR2,
6266 p_cash_receipt_id IN OUT NOCOPY NUMBER,
6267 p_receivable_application_id IN OUT NOCOPY NUMBER,
6268 p_called_from IN VARCHAR2,
6269 p_apply_gl_date OUT NOCOPY DATE,
6270 p_cr_unapp_amount OUT NOCOPY NUMBER, /* Bug fix 3569640 */
6271 p_return_status OUT NOCOPY VARCHAR2
6272 ) IS
6273 l_rec_appln_id NUMBER ;
6274 l_apply_gl_date DATE;
6275 l_cash_receipt_id NUMBER;
6276 BEGIN
6277 p_return_status := FND_API.G_RET_STS_SUCCESS;
6278 IF PG_DEBUG in ('Y', 'C') THEN
6279 arp_util.debug('Derive_activity_unapp_ids ()+');
6280 END IF;
6281 --derive the cash_receipt_id from the receipt_number
6282 IF p_receipt_number IS NOT NULL THEN
6283 Default_cash_receipt_id(p_cash_receipt_id ,
6284 p_receipt_number ,
6285 p_return_status);
6286 END IF;
6287
6288 --get the receivable application id for the on account application
6289 --on this cash receipt. If more than one activity application exists
6290 --for the receipt, raise error.
6291 /* Bug fix 2512907
6292 If the receivable_application_id is also passed by the user, do not
6293 do a generic select. Also receipt write-off unapplication requires
6294 that applied_payment_schedule_id should be compared with -3 */
6295 /* Bug 3840287 - credit card refund included */
6296 IF p_cash_receipt_id IS NOT NULL
6297 AND p_receivable_application_id IS NULL THEN
6298
6299 BEGIN
6300 SELECT receivable_application_id, gl_date
6301 INTO l_rec_appln_id , p_apply_gl_date
6302 FROM ar_receivable_applications
6303 WHERE cash_receipt_id = p_cash_receipt_id
6304 and ((NVL(p_called_from,'RAPI') = 'BR_FACTORED_WITH_RECOURSE' AND
6305 applied_payment_schedule_id = -2)
6306 or applied_payment_schedule_id IN (-3,-6,-8)
6307 or receivables_trx_id = -16)
6308 and display = 'Y' and
6309 status = 'ACTIVITY';
6310 EXCEPTION
6311 WHEN no_data_found THEN
6312 IF ar_receipt_api_pub.original_activity_unapp_info.cash_receipt_id IS NOT NULL THEN
6313 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CASH_RCPT_ID_INVALID');
6314 FND_MSG_PUB.Add;
6315 p_return_status := FND_API.G_RET_STS_ERROR ;
6316 ELSIF ar_receipt_api_pub.original_activity_unapp_info.receipt_number IS NOT NULL THEN
6317 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_NUM_INVALID');
6318 FND_MSG_PUB.Add;
6319 p_return_status := FND_API.G_RET_STS_ERROR ;
6320 END IF;
6321 WHEN too_many_rows THEN
6322 IF p_receivable_application_id IS NULL THEN
6323 FND_MESSAGE.SET_NAME('AR','AR_RAPI_MULTIPLE_ACTIVITY_APP');
6324 FND_MSG_PUB.Add;
6325 p_return_status := FND_API.G_RET_STS_ERROR ;
6326 END IF;
6327
6328 END;
6329
6330 END IF;
6331
6332 IF p_receivable_application_id IS NOT NULL THEN
6333
6334 /* bug fix 2512907
6335 When a receipt write-off application is unapplied, the applied_payment_schedue_id
6336 should be compared with -3 */
6337 /* Bug 2751910 - or its a netting application with receivable_trx_id
6338 of -16 */
6339 /* Bug 3840287 - credit card refund included */
6340 BEGIN
6341 SELECT cash_receipt_id, gl_date
6342 INTO l_cash_receipt_id , p_apply_gl_date
6343 FROM ar_receivable_applications
6344 WHERE receivable_application_id = p_receivable_application_id
6345 and ((NVL(p_called_from,'RAPI') = 'BR_FACTORED_WITH_RECOURSE' AND
6346 applied_payment_schedule_id = -2)
6347 or applied_payment_schedule_id IN (-3,-6,-8)
6348 or receivables_trx_id = -16)
6349 and display = 'Y'
6350 and status = 'ACTIVITY';
6351 EXCEPTION
6352 WHEN no_data_found THEN
6353 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REC_APP_ID_INVALID');
6354 FND_MSG_PUB.Add;
6355 p_return_status := FND_API.G_RET_STS_ERROR ;
6356 END;
6357
6358 --Compare the two cash_receipt_ids
6359 IF p_cash_receipt_id IS NOT NULL THEN
6360 IF p_cash_receipt_id <> NVL(l_cash_receipt_id,p_cash_receipt_id) THEN
6361 --raise error X validation failed
6362 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_RA_ID_X_INVALID');
6363 FND_MSG_PUB.Add;
6364 p_return_status := FND_API.G_RET_STS_ERROR ;
6365 END IF;
6366 END IF;
6367
6368 ELSE
6369 p_receivable_application_id := l_rec_appln_id ;
6370 END IF;
6371
6372 IF p_cash_receipt_id IS NULL THEN
6373 p_cash_receipt_id := l_cash_receipt_id;
6374 END IF;
6375
6376 /* Bug fix 3569640 */
6377 IF p_cash_receipt_id IS NOT NULL THEN
6378 SELECT SUM(NVL(ra.amount_applied,0))
6379 INTO p_cr_unapp_amount
6380 FROM ar_receivable_applications ra
6381 WHERE ra.cash_receipt_id = p_cash_receipt_id
6382 AND ra.status = 'UNAPP'
6383 AND nvl(ra.confirmed_flag,'Y') = 'Y';
6384 END IF;
6385
6386 IF PG_DEBUG in ('Y', 'C') THEN
6387 arp_util.debug('Derive_activity_unapp_ids ()+');
6388 END IF;
6389 END Derive_activity_unapp_ids;
6390
6391 PROCEDURE get_doc_seq(p_application_id IN NUMBER,
6392 p_document_name IN VARCHAR2,
6393 p_sob_id IN NUMBER,
6394 p_met_code IN VARCHAR2,
6395 p_trx_date IN DATE,
6396 p_doc_sequence_value IN OUT NOCOPY NUMBER,
6397 p_doc_sequence_id OUT NOCOPY NUMBER,
6398 p_return_status OUT NOCOPY VARCHAR2
6399 ) AS
6400 l_doc_seq_ret_stat NUMBER;
6401 l_doc_sequence_name VARCHAR2(50);
6402 l_doc_sequence_type VARCHAR2(50);
6403 l_doc_sequence_value NUMBER;
6404 l_db_sequence_name VARCHAR2(50);
6405 l_seq_ass_id NUMBER;
6406 l_prd_tab_name VARCHAR2(50);
6407 l_aud_tab_name VARCHAR2(50);
6408 l_msg_flag VARCHAR2(1);
6409 BEGIN
6410 IF PG_DEBUG in ('Y', 'C') THEN
6411 arp_util.debug('get_doc_seq ()+');
6412 arp_util.debug('get_doc_seq: ' || 'SEQ : '||NVL( pg_profile_doc_seq, 'N'));
6413 arp_util.debug('get_doc_seq: ' || 'p_document_name :'||p_document_name);
6414 arp_util.debug('get_doc_seq: ' || 'p_application_id :'||to_char(p_application_id));
6415 arp_util.debug('get_doc_seq: ' || 'p_sob_id :'||to_char(p_sob_id));
6416 END IF;
6417 p_return_status := FND_API.G_RET_STS_SUCCESS;
6418 IF ( NVL( pg_profile_doc_seq, 'N') <> 'N' )
6419 THEN
6420 BEGIN
6421 /*------------------------------+
6422 | Get the document sequence. |
6423 +------------------------------*/
6424 l_doc_seq_ret_stat:=
6425 fnd_seqnum.get_seq_info (
6426 p_application_id,
6427 p_document_name,
6428 p_sob_id,
6429 p_met_code,
6430 trunc(p_trx_date),
6431 p_doc_sequence_id,
6432 l_doc_sequence_type,
6433 l_doc_sequence_name,
6434 l_db_sequence_name,
6435 l_seq_ass_id,
6436 l_prd_tab_name,
6437 l_aud_tab_name,
6438 l_msg_flag,
6439 'Y',
6440 'Y');
6441 arp_util.debug('Doc sequence return status :'||to_char(nvl(l_doc_seq_ret_stat,-99)));
6442 IF PG_DEBUG in ('Y', 'C') THEN
6443 arp_util.debug('get_doc_seq: ' || 'l_doc_sequence_name :'||l_doc_sequence_name);
6444 END IF;
6445 arp_util.debug('l_doc_sequence_id :'||to_char(nvl(p_doc_sequence_id,-99)));
6446
6447 IF l_doc_seq_ret_stat = -8 THEN
6448 --this is the case of Always Used
6449 IF PG_DEBUG in ('Y', 'C') THEN
6450 arp_util.debug('get_doc_seq: ' || 'The doc sequence does not exist for the current document');
6451 END IF;
6452 p_return_status := FND_API.G_RET_STS_ERROR;
6453 --Error message
6454 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_DOC_SEQ_NOT_EXIST_A');
6455 FND_MSG_PUB.Add;
6456 ELSIF l_doc_seq_ret_stat = -2 THEN
6457 --this is the case of Partially Used
6458 IF PG_DEBUG in ('Y', 'C') THEN
6459 arp_util.debug('get_doc_seq: ' || 'The doc sequence does not exist for the current document');
6460 END IF;
6461 --Warning
6462 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
6463 THEN
6464 FND_MESSAGE.SET_NAME('AR','AR_RAPI_DOC_SEQ_NOT_EXIST_P');
6465 FND_MSG_PUB.Add;
6466 END IF;
6467 END IF;
6468 /* Added SUBSTRB(l_doc_sequence_type,1,1) = 'A' in IF
6469 for Bug 2667348 */
6470 /* Bug 3038259: Above fix did not consider gapless as
6471 Automatic type */
6472 IF ( l_doc_sequence_name IS NOT NULL
6473 AND p_doc_sequence_id IS NOT NULL
6474 AND SUBSTRB(l_doc_sequence_type,1,1) in ( 'A', 'G'))
6475 THEN
6476 /*------------------------------------+
6477 | Automatic Document Numbering case |
6478 +------------------------------------*/
6479 IF PG_DEBUG in ('Y', 'C') THEN
6480 arp_util.debug('get_doc_seq: ' || 'Automatic Document Numbering case ');
6481 END IF;
6482 l_doc_seq_ret_stat :=
6483 fnd_seqnum.get_seq_val (
6484 p_application_id,
6485 p_document_name,
6486 p_sob_id,
6487 p_met_code,
6488 TRUNC(p_trx_date),
6489 l_doc_sequence_value,
6490 p_doc_sequence_id);
6491 IF p_doc_sequence_value IS NOT NULL THEN
6492 --raise an error message because the user is not supposed to pass
6493 --in a value for the document sequence number in this case.
6494 p_return_status := FND_API.G_RET_STS_ERROR;
6495 FND_MESSAGE.Set_Name('AR', 'AR_RAPI_DOC_SEQ_AUTOMATIC');
6496 FND_MSG_PUB.Add;
6497 END IF;
6498 p_doc_sequence_value := l_doc_sequence_value;
6499 arp_util.debug('l_doc_sequence_value :'||to_char(nvl(p_doc_sequence_value,-99)));
6500 ELSIF (
6501 p_doc_sequence_id IS NOT NULL
6502 AND p_doc_sequence_value IS NOT NULL
6503 )
6504 THEN
6505 /*-------------------------------------+
6506 | Manual Document Numbering case |
6507 | with the document value specified. |
6508 | Use the specified value. |
6509 +-------------------------------------*/
6510
6511 NULL;
6512
6513 ELSIF (
6514 p_doc_sequence_id IS NOT NULL
6515 AND p_doc_sequence_value IS NULL
6516 )
6517 THEN
6518 /*-----------------------------------------+
6519 | Manual Document Numbering case |
6520 | with the document value not specified. |
6521 | Generate a document value mandatory |
6522 | error. |
6523 +-----------------------------------------*/
6524 IF NVL(pg_profile_doc_seq,'N') = 'A' THEN
6525 p_return_status := FND_API.G_RET_STS_ERROR;
6526 FND_MESSAGE.Set_Name('AR', 'AR_RAPI_DOC_SEQ_VALUE_NULL_A');
6527 FND_MESSAGE.Set_Token('SEQUENCE', l_doc_sequence_name);
6528 FND_MSG_PUB.Add;
6529 ELSIF NVL(pg_profile_doc_seq,'N') = 'P' THEN
6530 --Warning
6531 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS) THEN
6532 FND_MESSAGE.SET_NAME('AR','AR_RAPI_DOC_SEQ_VALUE_NULL_P');
6533 FND_MSG_PUB.Add;
6534 END IF;
6535 END IF;
6536
6537
6538 END IF;
6539
6540 EXCEPTION
6541 WHEN NO_DATA_FOUND THEN
6542 /*------------------------------------------+
6543 | No document assignment was found. |
6544 | Generate an error if document numbering |
6545 | is mandatory. |
6546 +------------------------------------------*/
6547 IF PG_DEBUG in ('Y', 'C') THEN
6548 arp_util.debug('get_doc_seq: ' || 'no_data_found raised');
6549 END IF;
6550 IF (pg_profile_doc_seq = 'A' ) THEN
6551 p_return_status := FND_API.G_RET_STS_ERROR;
6552 FND_MESSAGE.Set_Name( 'FND','UNIQUE-ALWAYS USED');
6553 FND_MSG_PUB.Add;
6554 ELSE
6555 p_doc_sequence_id := NULL;
6556 p_doc_sequence_value := NULL;
6557 END IF;
6558
6559 WHEN OTHERS THEN
6560 IF PG_DEBUG in ('Y', 'C') THEN
6561 arp_util.debug('get_doc_seq: ' || 'Unhandled exception in doc sequence assignment');
6562 END IF;
6563 raise;
6564
6565 END;
6566
6567 END IF;
6568 IF PG_DEBUG in ('Y', 'C') THEN
6569 arp_util.debug('get_doc_seq ()+');
6570 END IF;
6571 END get_doc_seq;
6572
6573 /* modified for tca uptake */
6574 PROCEDURE Derive_cust_info_from_trx(
6575 p_customer_trx_id IN ar_payment_schedules.customer_trx_id%TYPE,
6576 p_trx_number IN ra_customer_trx.trx_number%TYPE,
6577 p_installment IN ar_payment_schedules.terms_sequence_number%TYPE,
6578 p_applied_payment_schedule_id IN ar_payment_schedules.payment_schedule_id%TYPE,
6579 p_currency_code IN ar_cash_receipts.currency_code%TYPE,
6580 p_customer_id OUT NOCOPY ar_payment_schedules.customer_id%TYPE,
6581 p_customer_site_use_id OUT NOCOPY hz_cust_site_uses.site_use_id%TYPE,
6582 p_return_status OUT NOCOPY VARCHAR2
6583 )IS
6584 /* modified for tca uptake */
6585 -- Variables addition for Bug 1907635
6586 l_sel_stmt long;
6587 trx_customer INTEGER;
6588 l_rows_processed INTEGER;
6589 -- End of variables addition for Bug 1907635
6590 l_customer_trx_id NUMBER;
6591 BEGIN
6592 -- Bug 1907635
6593 -- Build the query dynamically based on the input parameters
6594 l_sel_stmt := '
6595 SELECT ps.customer_id,
6596 ps.customer_site_use_id
6597 FROM hz_cust_site_uses su,
6598 hz_cust_accounts cust_acct,
6599 ra_cust_trx_types ctt,
6600 ar_payment_schedules ps
6601 WHERE su.site_use_id = ps.customer_site_use_id
6602 and cust_acct.cust_account_id = ps.customer_id
6603 and ctt.cust_trx_type_id = ps.cust_trx_type_id
6604 and ps.selected_for_receipt_batch_id is null
6605 and ps.class in (''BR'',''CB'',''CM'',''DEP'',''DM'',''INV'')
6606 and ps.invoice_currency_code = decode(nvl(:pg_profile_enable_cc, ''N''), ''Y'',
6607 decode(ps.class, ''CM'', :p_currency_code, ps.invoice_currency_code), :p_currency_code)
6608 and ps.status = ''OP'' ';
6609
6610 IF p_applied_payment_schedule_id IS NOT NULL THEN
6611 l_sel_stmt := l_sel_stmt || ' and ps.payment_schedule_id = :applied_ps_id ';
6612 END IF;
6613 IF p_customer_trx_id IS NOT NULL THEN
6614 l_sel_stmt := l_sel_stmt || ' and ps.customer_trx_id = :cust_trx_id ';
6615 END IF;
6616 IF p_installment IS NOT NULL THEN
6617 l_sel_stmt := l_sel_stmt || ' and ps.terms_sequence_number = :inst ';
6618 END IF;
6619
6620 trx_customer := dbms_sql.open_cursor;
6621 dbms_sql.parse(trx_customer, l_sel_stmt, dbms_sql.v7);
6622 /* Bugfix 2605347 */
6623 dbms_sql.bind_variable(trx_customer,':pg_profile_enable_cc', pg_profile_enable_cc);
6624 dbms_sql.bind_variable(trx_customer,':p_currency_code', p_currency_code);
6625 IF p_applied_payment_schedule_id IS NOT NULL THEN
6626 dbms_sql.bind_variable(trx_customer,':applied_ps_id',p_applied_payment_schedule_id);
6627 END IF;
6628 IF p_customer_trx_id IS NOT NULL THEN
6629 dbms_sql.bind_variable(trx_customer, ':cust_trx_id', p_customer_trx_id);
6630 END IF;
6631 IF p_installment IS NOT NULL THEN
6632 dbms_sql.bind_variable(trx_customer, ':inst', p_installment);
6633 END IF;
6634 dbms_sql.define_column(trx_customer,1,p_customer_id);
6635 dbms_sql.define_column(trx_customer,2,p_customer_site_use_id);
6636 -- End of bug 1907635
6637
6638 p_return_status := FND_API.G_RET_STS_SUCCESS;
6639 l_customer_trx_id := p_customer_trx_id;
6640 IF p_trx_number IS NOT NULL THEN
6641 Default_customer_trx_id(l_customer_trx_id ,
6642 p_trx_number ,
6643 p_return_status);
6644 END IF;
6645
6646 IF p_return_status = FND_API.G_RET_STS_SUCCESS THEN
6647 IF p_applied_payment_schedule_id IS NOT NULL AND
6648 l_customer_trx_id IS NULL AND
6649 p_installment IS NULL THEN
6650 -- Bug 1907635
6651 l_rows_processed := dbms_sql.execute(trx_customer);
6652 IF dbms_sql.fetch_rows(trx_customer) > 0 then
6653 dbms_sql.column_value(trx_customer, 1, p_customer_id);
6654 dbms_sql.column_value(trx_customer, 2, p_customer_site_use_id);
6655 ELSE
6656 p_return_status := FND_API.G_RET_STS_ERROR;
6657 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_PSID_NOT_DEF_CUS');
6658 FND_MSG_PUB.Add;
6659 END IF;
6660 dbms_sql.close_cursor(trx_customer);
6661 -- End Bug 1907635
6662 ELSIF p_applied_payment_schedule_id IS NOT NULL AND
6663 l_customer_trx_id IS NOT NULL AND
6664 p_installment IS NOT NULL THEN
6665 -- Bug 1907635
6666 l_rows_processed := dbms_sql.execute(trx_customer);
6667 IF dbms_sql.fetch_rows(trx_customer) > 0 then
6668 dbms_sql.column_value(trx_customer, 1, p_customer_id);
6669 dbms_sql.column_value(trx_customer, 2, p_customer_site_use_id);
6670 ELSE
6671 p_return_status := FND_API.G_RET_STS_ERROR;
6672 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_TRX_INS_PS_NOT_DEF_CUS');
6673 FND_MSG_PUB.Add;
6674 END IF;
6675 dbms_sql.close_cursor(trx_customer);
6676 -- End Bug 1907635
6677 ELSIF p_applied_payment_schedule_id IS NOT NULL AND
6678 l_customer_trx_id IS NOT NULL AND
6679 p_installment IS NULL THEN
6680 -- Bug 1907635
6681 l_rows_processed := dbms_sql.execute(trx_customer);
6682 IF dbms_sql.fetch_rows(trx_customer) > 0 then
6683 dbms_sql.column_value(trx_customer, 1, p_customer_id);
6684 dbms_sql.column_value(trx_customer, 2, p_customer_site_use_id);
6685 ELSE
6686 p_return_status := FND_API.G_RET_STS_ERROR;
6687 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_TRX_PS_NOT_DEF_CUS');
6688 FND_MSG_PUB.Add;
6689 END IF;
6690 dbms_sql.close_cursor(trx_customer);
6691 -- End Bug 1907635
6692 ELSIF p_applied_payment_schedule_id IS NOT NULL AND
6693 l_customer_trx_id IS NULL AND
6694 p_installment IS NOT NULL THEN
6695 -- Bug 1907635
6696 l_rows_processed := dbms_sql.execute(trx_customer);
6697 IF dbms_sql.fetch_rows(trx_customer) > 0 then
6698 dbms_sql.column_value(trx_customer, 1, p_customer_id);
6699 dbms_sql.column_value(trx_customer, 2, p_customer_site_use_id);
6700 ELSE
6701 p_return_status := FND_API.G_RET_STS_ERROR;
6702 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_INS_PS_NOT_DEF_CUS');
6703 FND_MSG_PUB.Add;
6704 END IF;
6705 dbms_sql.close_cursor(trx_customer);
6706 -- End Bug 1907635
6707 ELSIF p_applied_payment_schedule_id IS NULL AND
6708 l_customer_trx_id IS NOT NULL AND
6709 p_installment IS NOT NULL THEN
6710 -- Bug 1907635
6711 l_rows_processed := dbms_sql.execute(trx_customer);
6712 IF dbms_sql.fetch_rows(trx_customer) > 0 then
6713 dbms_sql.column_value(trx_customer, 1, p_customer_id);
6714 dbms_sql.column_value(trx_customer, 2, p_customer_site_use_id);
6715 ELSE
6716 p_return_status := FND_API.G_RET_STS_ERROR;
6717 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_TRX_INS_NOT_DEF_CUS');
6718 FND_MSG_PUB.Add;
6719 END IF;
6720 dbms_sql.close_cursor(trx_customer);
6721 -- End Bug 1907635
6722 ELSIF p_applied_payment_schedule_id IS NULL AND
6723 l_customer_trx_id IS NOT NULL AND
6724 p_installment IS NULL THEN
6725 -- Bug 1907635
6726 l_rows_processed := dbms_sql.execute(trx_customer);
6727 IF dbms_sql.fetch_rows(trx_customer) > 0 then
6728 dbms_sql.column_value(trx_customer, 1, p_customer_id);
6729 dbms_sql.column_value(trx_customer, 2, p_customer_site_use_id);
6730 ELSE
6731 p_return_status := FND_API.G_RET_STS_ERROR;
6732 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_PSID_NOT_DEF_CUS');
6733 FND_MSG_PUB.Add;
6734 END IF;
6735 dbms_sql.close_cursor(trx_customer);
6736 -- End Bug 1907635
6737 ELSE
6738 -- Bug 1907635
6739 dbms_sql.close_cursor(trx_customer);
6740 -- End Bug 1907635
6741 p_customer_id := NULL;
6742 p_customer_site_use_id := NULL;
6743 END IF;
6744 END IF;
6745
6746 IF p_customer_id IS NULL THEN
6747 --raise error because application cant be done against an unidentified receipt
6748 p_return_status := FND_API.G_RET_STS_ERROR;
6749 FND_MESSAGE.Set_Name( 'AR','AR_RAPI_CUST_ID_NULL');
6750 FND_MSG_PUB.Add;
6751 END IF;
6752
6753 pg_cust_derived_from := 'TRANSACTION';
6754
6755 END Derive_cust_info_from_trx;
6756
6757 PROCEDURE Default_misc_ids(
6758 p_usr_currency_code IN VARCHAR2,
6759 p_usr_exchange_rate_type IN VARCHAR2,
6760 p_activity IN VARCHAR2,
6761 p_reference_type IN VARCHAR2,
6762 p_reference_num IN VARCHAR2,
6763 p_tax_code IN VARCHAR2,
6764 p_receipt_method_name IN OUT NOCOPY VARCHAR2,
6765 p_remittance_bank_account_name IN VARCHAR2,
6766 p_remittance_bank_account_num IN VARCHAR2,
6767 p_currency_code IN OUT NOCOPY VARCHAR2,
6768 p_exchange_rate_type IN OUT NOCOPY VARCHAR2,
6769 p_receivables_trx_id IN OUT NOCOPY NUMBER,
6770 p_reference_id IN OUT NOCOPY NUMBER,
6771 p_vat_tax_id IN OUT NOCOPY NUMBER,
6772 p_receipt_method_id IN OUT NOCOPY NUMBER,
6773 p_remittance_bank_account_id IN OUT NOCOPY NUMBER,
6774 p_return_status OUT NOCOPY VARCHAR2,
6775 p_receipt_date IN DATE DEFAULT NULL
6776 )
6777 IS
6778 l_remittance_bank_account_id NUMBER;
6779 l_receipt_method_id NUMBER;
6780 l_return_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
6781 l_get_id_return_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
6782 l_get_x_val_return_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
6783 l_le_id NUMBER;
6784 BEGIN
6785 p_return_status := FND_API.G_RET_STS_SUCCESS;
6786
6787 --Receivable Activity Name /Id.
6788 IF p_receivables_trx_id IS NULL THEN
6789 IF p_activity IS NOT NULL THEN
6790 p_receivables_trx_id:= Get_Id('RECEIVABLES_ACTIVITY',
6791 p_activity,
6792 l_get_id_return_status
6793 );
6794 IF p_receivables_trx_id IS NULL THEN
6795 FND_MESSAGE.SET_NAME('AR','AR_RAPI_ACTIVITY_INVALID');
6796 FND_MSG_PUB.Add;
6797 p_return_status := FND_API.G_RET_STS_ERROR;
6798 END IF;
6799
6800 END IF;
6801
6802 ELSE
6803 IF (p_activity IS NOT NULL) THEN
6804 --give a warning message to indicate that the activity name
6805 --entered by the user has been ignored.
6806 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
6807 THEN
6808 FND_MESSAGE.SET_NAME('AR','AR_RAPI_ACTIVITY_IGN');
6809 FND_MSG_PUB.Add;
6810 END IF;
6811 END IF;
6812
6813 END IF;
6814
6815 --Receipt method ID,Name
6816 IF p_receipt_method_id IS NULL
6817 THEN
6818 IF p_receipt_method_name IS NOT NULL THEN
6819 p_receipt_method_id := Get_Id('RECEIPT_METHOD_NAME',
6820 p_receipt_method_name,
6821 l_get_id_return_status
6822 );
6823 IF p_receipt_method_id IS NULL THEN
6824 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_MD_NAME_INVALID');
6825 FND_MSG_PUB.Add;
6826 p_return_status := FND_API.G_RET_STS_ERROR;
6827 END IF;
6828 END IF;
6829
6830 ELSE
6831 IF (p_receipt_method_name IS NOT NULL) THEN
6832 --give a warning message to indicate that the receipt_method_name
6833 --entered by the user has been ignored.
6834 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
6835 THEN
6836 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_MD_NAME_IGN');
6837 FND_MSG_PUB.Add;
6838 END IF;
6839 ELSE
6840 BEGIN
6841 SELECT name
6842 INTO p_receipt_method_name
6843 FROM ar_receipt_methods
6844 WHERE receipt_method_id = p_receipt_method_id;
6845 EXCEPTION
6846 WHEN no_data_found THEN
6847 IF PG_DEBUG in ('Y', 'C') THEN
6848 arp_util.debug('Default_misc_ids: ' || 'Invalid receipt method id');
6849 END IF;
6850 null;
6851 END;
6852
6853 END IF;
6854 END IF;
6855
6856 --Remittance bank account Number,Name,ID
6857
6858 IF p_remittance_bank_account_id IS NULL
6859 THEN
6860 IF(p_remittance_bank_account_name IS NOT NULL) and
6861 (p_remittance_bank_account_num IS NULL)
6862 THEN
6863 p_remittance_bank_account_id := Get_Id('REMIT_BANK_ACCOUNT_NAME',
6864 p_remittance_bank_account_name,
6865 l_get_id_return_status
6866 );
6867 IF p_remittance_bank_account_id IS NULL THEN
6868 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_NAME_INVALID');
6869 FND_MSG_PUB.Add;
6870 p_return_status := FND_API.G_RET_STS_ERROR;
6871 END IF;
6872 ELSIF(p_remittance_bank_account_name IS NULL) and
6873 (p_remittance_bank_account_num IS NOT NULL)
6874 THEN
6875 p_remittance_bank_account_id := Get_Id('REMIT_BANK_ACCOUNT_NUMBER',
6876 p_remittance_bank_account_num,
6877 l_get_id_return_status
6878 );
6879 IF p_remittance_bank_account_id IS NULL THEN
6880 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_NUM_INVALID');
6881 FND_MSG_PUB.Add;
6882 p_return_status := FND_API.G_RET_STS_ERROR;
6883 END IF;
6884 ELSIF(p_remittance_bank_account_name IS NOT NULL) and
6885 (p_remittance_bank_account_num IS NOT NULL)
6886 THEN
6887 p_remittance_bank_account_id := Get_Cross_Validated_Id( 'REMIT_BANK_ACCOUNT',
6888 p_remittance_bank_account_num,
6889 p_remittance_bank_account_name,
6890 l_get_x_val_return_status
6891 );
6892 IF p_remittance_bank_account_id IS NULL THEN
6893 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_2_INVALID');
6894 FND_MSG_PUB.Add;
6895 p_return_status := FND_API.G_RET_STS_ERROR;
6896 END IF;
6897 END IF;
6898
6899 ELSE
6900
6901 IF (p_remittance_bank_account_name IS NOT NULL) OR
6902 (p_remittance_bank_account_num IS NOT NULL)
6903 THEN
6904 --give a warning message to indicate that the remittance_bank_account_num and
6905 --remittance_bank_account_name entered by the user have been ignored.
6906 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
6907 THEN
6908 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REM_BK_AC_NAME_NUM_IGN');
6909 FND_MSG_PUB.Add;
6910 END IF;
6911 END IF;
6912
6913 END IF;
6914
6915 /* Initialize ZX */
6916 l_le_id :=
6917 ar_receipt_lib_pvt.get_legal_entity(p_remittance_bank_account_id);
6918
6919 -- Exchange_rate_type
6920 IF p_exchange_rate_type IS NULL THEN
6921 IF p_usr_exchange_rate_type IS NOT NULL
6922 THEN
6923 p_exchange_rate_type := Get_Id('EXCHANGE_RATE_TYPE_NAME', /* Bug fix 2982212*/
6924 p_usr_exchange_rate_type,
6925 l_get_id_return_status
6926 );
6927 IF p_exchange_rate_type IS NULL THEN
6928 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_X_RATE_TYP_INVALID');
6929 FND_MSG_PUB.Add;
6930 p_return_status := FND_API.G_RET_STS_ERROR;
6931 END IF;
6932 END IF;
6933
6934 ELSE
6935 IF (p_usr_exchange_rate_type IS NOT NULL) THEN
6936 --give a warning message to indicate that the usr_exchange_rate_type
6937 -- entered by the user have been ignored.
6938 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
6939 THEN
6940 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_X_RATE_TYPE_IGN');
6941 FND_MSG_PUB.Add;
6942 END IF;
6943 END IF;
6944
6945 END IF;
6946
6947 --Currency code
6948 IF p_currency_code IS NULL THEN
6949 IF p_usr_currency_code IS NOT NULL
6950 THEN
6951 p_currency_code := Get_Id('CURRENCY_NAME',
6952 p_usr_currency_code,
6953 l_get_id_return_status
6954 );
6955 IF p_currency_code IS NULL THEN
6956 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_CURR_CODE_INVALID');
6957 FND_MSG_PUB.Add;
6958 p_return_status := FND_API.G_RET_STS_ERROR;
6959 END IF;
6960 ELSE
6961
6962 p_currency_code := arp_global.functional_currency;
6963 --Raise a warning message saying that currency was defaulted
6964 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
6965 THEN
6966 FND_MESSAGE.SET_NAME('AR','AR_RAPI_FUNC_CURR_DEFAULTED');
6967 FND_MSG_PUB.Add;
6968 END IF;
6969
6970 END IF;
6971
6972 ELSE
6973 IF (p_usr_currency_code IS NOT NULL) THEN
6974
6975 --give a warning message to indicate that the usr_currency_code
6976 -- entered by the user have been ignored.
6977 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
6978 THEN
6979 FND_MESSAGE.SET_NAME('AR','AR_RAPI_USR_CURR_CODE_IGN');
6980 FND_MSG_PUB.Add;
6981 END IF;
6982
6983 END IF;
6984 END IF;
6985
6986 --Reference Number, ID
6987 --Based on the reference type, the corresponding reference id
6988 --will be derived from the reference number.
6989 IF p_reference_id IS NULL THEN
6990 IF p_reference_num IS NOT NULL THEN
6991
6992 IF p_reference_type = 'PAYMENT' THEN
6993 p_reference_id := to_number(Get_Id('REF_PAYMENT',
6994 p_reference_num,
6995 l_get_id_return_status)
6996 );
6997 ELSIF p_reference_type = 'PAYMENT_BATCH' THEN
6998 --
6999 p_reference_id := to_number(Get_Id('REF_PAYMENT_BATCH',
7000 p_reference_num,
7001 l_get_id_return_status)
7002 );
7003 ELSIF p_reference_type = 'RECEIPT' THEN
7004 --
7005 p_reference_id := to_number(Get_Id('REF_RECEIPT',
7006 p_reference_num,
7007 l_get_id_return_status
7008 ));
7009 ELSIF p_reference_type = 'REMITTANCE' THEN
7010 --
7011 p_reference_id := to_number(Get_Id('REF_REMITTANCE',
7012 p_reference_num,
7013 l_get_id_return_status
7014 ));
7015 END IF;
7016
7017 IF p_reference_id IS NULL THEN
7018 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REF_NUM_INVALID');
7019 FND_MSG_PUB.Add;
7020 p_return_status := FND_API.G_RET_STS_ERROR;
7021 END IF;
7022
7023 END IF;
7024
7025 ELSE
7026 IF (p_reference_num IS NOT NULL) THEN
7027
7028 --give a warning message to indicate that the reference number
7029 -- entered by the user have been ignored.
7030 -- This warning message is coming as an error in the form. So commenting out NOCOPY
7031
7032 /* IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
7033 THEN
7034 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REF_NUM_IGN');
7035 FND_MSG_PUB.Add;
7036 END IF;
7037 */
7038 null;
7039
7040 END IF;
7041 END IF;
7042
7043
7044 END Default_misc_ids;
7045
7046 PROCEDURE Get_misc_defaults(
7047 p_currency_code IN OUT NOCOPY VARCHAR2,
7048 p_exchange_rate_type IN OUT NOCOPY VARCHAR2,
7049 p_exchange_rate IN OUT NOCOPY NUMBER,
7050 p_exchange_date IN OUT NOCOPY DATE,
7051 p_amount IN OUT NOCOPY NUMBER,
7052 p_receipt_date IN OUT NOCOPY DATE,
7053 p_gl_date IN OUT NOCOPY DATE,
7054 p_remittance_bank_account_id IN OUT NOCOPY NUMBER,
7055 p_deposit_date IN OUT NOCOPY DATE,
7056 p_state IN OUT NOCOPY VARCHAR2,
7057 p_distribution_set_id IN OUT NOCOPY NUMBER,
7058 p_vat_tax_id IN OUT NOCOPY NUMBER,
7059 p_tax_rate IN OUT NOCOPY NUMBER,
7060 p_receipt_method_id IN NUMBER,
7061 p_receivables_trx_id IN NUMBER,
7062 p_tax_code IN VARCHAR2,
7063 p_tax_amount IN NUMBER,
7064 p_creation_method_code OUT NOCOPY VARCHAR2,
7065 p_return_status OUT NOCOPY VARCHAR2
7066 )
7067 IS
7068 l_def_curr_return_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7069 l_def_rm_return_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7070 l_def_gl_dt_return_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7071 l_tax_rt_amt_x_ret_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7072 l_tax_amount NUMBER;
7073 /* Bug fix 3315058 */
7074 l_bank_acc_val_ret_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7075 l_misc_activity_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7076 l_misc_tax_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7077 l_code_combination_id NUMBER;
7078 l_message VARCHAR2(100);
7079 l_le_id NUMBER; /* bug 4594101 */
7080 l_get_id_return_status VARCHAR2(1) DEFAULT FND_API.G_RET_STS_SUCCESS;
7081 l_zx_msg_count NUMBER;
7082 l_zx_msg_data VARCHAR2(1024);
7083 l_zx_effective_date DATE;
7084 l_zx_return_status VARCHAR2(10);
7085
7086 /*Bug 5598297 */
7087 l_source_code ar_receivables_trx.gl_account_source%type;
7088 l_dist_set_id ar_receivables_trx.default_acctg_distribution_set%type;
7089
7090 CURSOR get_dist_ccid(p_dist_id NUMBER) IS
7091 SELECT dist_code_combination_id
7092 FROM ar_distribution_set_lines
7093 WHERE distribution_set_id = p_distribution_set_id;
7094 BEGIN
7095 IF PG_DEBUG in ('Y', 'C') THEN
7096 arp_util.debug('Get_misc_Defaults()+ ');
7097 END IF;
7098 p_return_status := FND_API.G_RET_STS_SUCCESS;
7099 -- default the receipt date if NULL
7100 IF (p_receipt_date IS NULL)
7101 THEN
7102 Select trunc(sysdate)
7103 into p_receipt_date
7104 from dual;
7105 END IF;
7106
7107 -- default the gl_date
7108 IF p_gl_date IS NULL THEN
7109 Default_gl_date(p_receipt_date,
7110 p_gl_date,
7111 NULL,
7112 l_def_gl_dt_return_status);
7113 IF PG_DEBUG in ('Y', 'C') THEN
7114 arp_util.debug('Get_misc_defaults: ' || 'l_default_gl_date_return_status : '||l_def_gl_dt_return_status);
7115 END IF;
7116 END IF;
7117
7118 IF (p_deposit_date IS NULL)
7119 THEN
7120 p_deposit_date := p_receipt_date;
7121 END IF;
7122
7123
7124 -- Default the Currency parameters
7125 Default_Currency_info(p_currency_code,
7126 p_receipt_date,
7127 p_exchange_date,
7128 p_exchange_rate_type,
7129 p_exchange_rate,
7130 l_def_curr_return_status
7131 );
7132
7133 --Set the precision of the receipt amount as per currency
7134 IF p_amount is NOT NULL THEN
7135 p_amount := arp_util.CurrRound( p_amount,
7136 p_currency_code
7137 );
7138 END IF;
7139
7140 --Default the Receipt Method related parameters
7141 Default_Receipt_Method_info(p_receipt_method_id,
7142 p_currency_code,
7143 p_receipt_date,
7144 p_remittance_bank_account_id,
7145 p_state,
7146 p_creation_method_code,
7147 'MISC',
7148 l_def_rm_return_status
7149 );
7150
7151 /* Bug fix 3315058 */
7152 Validate_Receipt_Method_ccid(p_receipt_method_id,
7153 p_remittance_bank_account_id,
7154 p_gl_date,
7155 l_bank_acc_val_ret_status);
7156
7157 /*------------------------------------------+
7158 | Get legal_entity_id |
7159 +------------------------------------------*/
7160 l_le_id :=
7161 ar_receipt_lib_pvt.get_legal_entity(p_remittance_bank_account_id);
7162
7163 /* 5955921 Remittance_bank_account info is not passed by the user then the system will not default
7164 the vat_tax_id based on the user tax_code. Hence moving the below set_tax_security_context
7165 from Default_misc_ids to Get_misc_defaults procedure. */
7166 zx_api_pub.set_tax_security_context(
7167 p_api_version => 1.0,
7168 p_init_msg_list => 'T',
7169 p_commit => 'F',
7170 p_validation_level => NULL,
7171 x_return_status => l_zx_return_status,
7172 x_msg_count => l_zx_msg_count,
7173 x_msg_data => l_zx_msg_data,
7174 p_internal_org_id => arp_standard.sysparm.org_id,
7175 p_legal_entity_id => l_le_id,
7176 p_transaction_date => p_receipt_date,
7177 p_related_doc_date => NULL,
7178 p_adjusted_doc_date=> NULL,
7179 x_effective_date => l_zx_effective_date);
7180 /* End - init */
7181
7182 -- Moved tax default below remittance bank account
7183 -- so we could have LE and init ZX beforehand
7184 -- ETAX: Bug 4594101: Added p_receipt_date to call.
7185 --Vat Tax Id, Tax code
7186 IF p_vat_tax_id IS NULL THEN
7187 IF p_tax_code IS NOT NULL THEN
7188 p_vat_tax_id := Get_Id('TAX_CODE',
7189 p_tax_code,
7190 l_get_id_return_status,
7191 p_receipt_date
7192 );
7193 IF p_vat_tax_id IS NULL THEN
7194 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TAX_CODE_INVALID');
7195 FND_MSG_PUB.Add;
7196 p_return_status := FND_API.G_RET_STS_ERROR;
7197 END IF;
7198 END IF;
7199 ELSE
7200 IF (p_tax_code IS NOT NULL) THEN
7201 --give a warning message to indicate that the tax_code
7202 --entered by the user has been ignored.
7203 IF FND_MSG_PUB.Check_Msg_Level(G_MSG_SUCCESS)
7204 THEN
7205 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TAX_CODE_IGN');
7206 FND_MSG_PUB.Add;
7207 END IF;
7208 END IF;
7209
7210 END IF;
7211
7212 --Default the vat_tax_id from the receivable_trx_id.
7213
7214 IF ( p_receivables_trx_id IS NOT NULL AND p_vat_tax_id IS NULL AND
7215 p_tax_code IS NULL) THEN --the second condition reflects that the
7216 --user had not entered any tax code
7217
7218 IF (arp_legal_entity_util.Is_LE_Subscriber) THEN
7219 BEGIN
7220 /* 5236782 - made details not required for misc receipts */
7221 SELECT vat.tax_rate_id
7222 INTO p_vat_tax_id
7223 FROM ar_receivables_trx rt,
7224 ar_rec_trx_le_details details,
7225 zx_sco_rates vat
7226 WHERE rt.receivables_trx_id = p_receivables_trx_id
7227 AND rt.receivables_trx_id = details.receivables_trx_id (+)
7228 AND details.legal_entity_id (+) = l_le_id
7229 AND rt.type in ('MISCCASH', 'BANK_ERROR')
7230 AND nvl(rt.status, 'A') = 'A'
7231 AND vat.tax_rate_code = decode(sign(p_amount),
7232 1, nvl(details.asset_tax_code,
7233 rt.asset_tax_code),
7234 0, nvl(details.asset_tax_code,
7235 rt.asset_tax_code),
7236 -1, nvl(details.liability_tax_code,
7237 rt.liability_tax_code))
7238 AND nvl(vat.active_flag, 'Y') = 'Y' /* 4400063 */
7239 AND p_receipt_date between
7240 nvl(vat.effective_from, p_receipt_date)
7241 and nvl(vat.effective_to, p_receipt_date);
7242
7243 EXCEPTION
7244 WHEN no_data_found THEN
7245 null;
7246 WHEN others THEN
7247 raise;
7248 END;
7249 ELSE
7250 BEGIN
7251 SELECT vat.tax_rate_id
7252 INTO p_vat_tax_id
7253 FROM ar_receivables_trx rt,
7254 zx_sco_rates vat
7255 WHERE rt.receivables_trx_id = p_receivables_trx_id
7256 AND rt.type in ('MISCCASH', 'BANK_ERROR')
7257 AND nvl(rt.status, 'A') = 'A'
7258 AND vat.tax_rate_code(+) = decode(sign(p_amount),
7259 1, rt.asset_tax_code,
7260 0, rt.asset_tax_code,
7261 -1, rt.liability_tax_code)
7262 AND p_receipt_date between
7263 nvl(vat.effective_from, p_receipt_date)
7264 and nvl(vat.effective_to, p_receipt_date);
7265
7266 EXCEPTION
7267 WHEN no_data_found THEN
7268 null;
7269 WHEN others THEN
7270 raise;
7271 END;
7272 END IF;
7273
7274 END IF;
7275
7276 /*Bug3315058 After getting vat tax id and receivables trx id */
7277
7278 /*Bug 5598297 distribution set id was never initialized */
7279 IF p_distribution_set_id is NULL THEN
7280 Begin
7281 select gl_account_source,default_acctg_distribution_set into
7282 l_source_code, l_dist_set_id
7283 from ar_receivables_trx
7284 where receivables_trx_id = nvl(p_receivables_trx_id,-99);
7285 IF l_source_code = 'DISTRIBUTION_SET' THEN
7286 p_distribution_set_id := l_dist_set_id;
7287 ELSE
7288 p_distribution_set_id := NULL;
7289 END IF;
7290 Exception
7291 when others then
7292 null;
7293 END;
7294 END IF;
7295 IF p_receivables_trx_id IS NOT NULL THEN
7296 IF p_distribution_set_id IS NULL THEN
7297 BEGIN
7298 select code_combination_id
7299 into l_code_combination_id
7300 from ar_receivables_trx
7301 where receivables_trx_id=p_receivables_trx_id;
7302
7303 l_message := 'AR_ACT_GL_ACC_ASSGN';
7304 validate_cc_segments(l_code_combination_id,
7305 p_gl_date,
7306 l_message,
7307 l_misc_activity_status);
7308 EXCEPTION
7309 WHEN OTHERS THEN
7310 l_code_combination_id:=NULL;
7311 l_misc_activity_status:=FND_API.G_RET_STS_ERROR;
7312 END;
7313 ELSE
7314 l_message := 'AR_GL_ACC_ASSGN_DISB_SET';
7315 OPEN get_dist_ccid(p_distribution_set_id);
7316 IF get_dist_ccid%NOTFOUND THEN
7317 l_misc_activity_status:=FND_API.G_RET_STS_ERROR;
7318 l_code_combination_id:=NULL;
7319 ELSE
7320 LOOP
7321 FETCH get_dist_ccid INTO l_code_combination_id;
7322 EXIT WHEN get_dist_ccid%NOTFOUND;
7323 validate_cc_segments(l_code_combination_id,
7324 p_gl_date,
7325 l_message,
7326 l_misc_activity_status);
7327 IF l_misc_activity_status <> FND_API.G_RET_STS_SUCCESS THEN
7328 l_misc_activity_status:=FND_API.G_RET_STS_ERROR;
7329 EXIT;
7330 END IF;
7331 END LOOP;
7332 END IF;
7333 CLOSE get_dist_ccid;
7334 END IF;
7335 IF p_vat_tax_id IS NOT NULL THEN
7336 BEGIN
7337
7338 l_code_combination_id := arp_etax_util.get_tax_account(
7339 p_subject_id => p_vat_tax_id,
7340 p_gl_date => p_gl_date,
7341 p_desired_account => 'TAX',
7342 p_subject_table => 'TAX_RATE');
7343
7344 l_message := 'AR_TAX_ACC_ASSGN';
7345 validate_cc_segments(l_code_combination_id,
7346 p_gl_date,
7347 l_message,
7348 l_misc_tax_status);
7349 EXCEPTION
7350 WHEN OTHERS THEN
7351 l_code_combination_id := NULL;
7352 l_misc_tax_status:=FND_API.G_RET_STS_ERROR;
7353 END;
7354 END IF;
7355 END IF;
7356 /* End of Bug3315058*/
7357 IF p_tax_amount IS NOT NULL THEN
7358
7359 l_tax_amount := arp_util.CurrRound( p_tax_amount,
7360 p_currency_code
7361 );
7362 END IF;
7363
7364 --Derive the tax rate from the tax_amount and the total receipt amount
7365 --also do the cross validation between the tax_amount,tax_rate and amount.
7366
7367 IF p_tax_rate IS NULL and
7368 l_tax_amount IS NOT NULL and
7369 p_amount IS NOT NULL THEN
7370
7371 p_tax_rate := Round(
7372 (100 * (l_tax_amount/p_amount)) / ( 1 - (l_tax_amount/p_amount)),
7373 3);
7374 ELSIF p_tax_rate IS NOT NULL and
7375 l_tax_amount IS NOT NULL and
7376 p_amount IS NOT NULL THEN
7377
7378 IF round(p_tax_rate*p_amount,3) <> p_tax_amount THEN
7379 l_tax_rt_amt_x_ret_status := FND_API.G_RET_STS_ERROR;
7380 FND_MESSAGE.SET_NAME('AR','AR_RAPI_TAX_RATE_AMT_X_INVALID');
7381 FND_MSG_PUB.Add;
7382 END IF;
7383 END IF;
7384
7385
7386 IF l_def_rm_return_status <> FND_API.G_RET_STS_SUCCESS OR
7387 l_def_gl_dt_return_status <> FND_API.G_RET_STS_SUCCESS OR
7388 l_def_curr_return_status <> FND_API.G_RET_STS_SUCCESS OR
7389 l_tax_rt_amt_x_ret_status <> FND_API.G_RET_STS_SUCCESS OR
7390 l_misc_activity_status <> FND_API.G_RET_STS_SUCCESS OR /* Bug fix 3315058 */
7391 l_misc_tax_status <> FND_API.G_RET_STS_SUCCESS OR
7392 l_bank_acc_val_ret_status <> FND_API.G_RET_STS_SUCCESS THEN /* Bug fix 3315058 */
7393 p_return_status := FND_API.G_RET_STS_ERROR;
7394 END IF;
7395 IF PG_DEBUG in ('Y', 'C') THEN
7396 arp_util.debug('Get_misc_defaults: ' || '************Cash Defaults********************');
7397 arp_util.debug('Get_misc_defaults: ' || 'p_receipt_date : '||to_char(p_receipt_date,'DD-MON-YYYY'));
7398 arp_util.debug('Get_misc_defaults: ' || 'p_gl_date : '||to_char(p_gl_date,'DD-MON-YYYY'));
7399 arp_util.debug('Get_misc_defaults: ' || 'p_deposit_date : '||to_char(p_deposit_date,'DD-MON-YYYY'));
7400 arp_util.debug('Get_misc_defaults: ' || 'p_currency_code : '||p_currency_code);
7401 arp_util.debug('Get_misc_defaults: ' || 'p_exchange_rate_date : '||to_char(p_exchange_date,'DD-MON-YYYY'));
7402 arp_util.debug('Get_misc_defaults: ' || 'p_exchange_rate_type : '||p_exchange_rate_type);
7403 arp_util.debug('Get_misc_defaults: ' || 'p_exchange_rate : '||to_char(p_exchange_rate));
7404 arp_util.debug('Get_misc_defaults: ' || 'p_receipt_method_id : '||to_char(p_receipt_method_id));
7405 arp_util.debug('Get_misc_defaults: ' || 'p_remittance_bank_account_id : '||to_char(p_remittance_bank_account_id));
7406 arp_util.debug('Get_misc_defaults: ' || 'p_state : '||p_state);
7407 arp_util.debug('Get_misc_Defaults ()-');
7408 END IF;
7409
7410 END Get_misc_defaults;
7411
7412 PROCEDURE Validate_Desc_Flexfield(
7413 p_desc_flex_rec IN OUT NOCOPY ar_receipt_api_pub.attribute_rec_type,
7414 p_desc_flex_name IN VARCHAR2,
7415 p_return_status IN OUT NOCOPY varchar2
7416 ) IS
7417
7418 l_flex_name fnd_descriptive_flexs.descriptive_flexfield_name%type;
7419 l_count NUMBER;
7420 l_col_name VARCHAR2(50);
7421 l_flex_exists VARCHAR2(1);
7422 CURSOR desc_flex_exists IS
7423 SELECT 'Y'
7424 FROM fnd_descriptive_flexs
7425 WHERE application_id = 222
7426 and descriptive_flexfield_name = p_desc_flex_name;
7427 BEGIN
7428 IF PG_DEBUG in ('Y', 'C') THEN
7429 arp_util.debug('Validate_Desc_Flexfield ()+');
7430 END IF;
7431 p_return_status := FND_API.G_RET_STS_SUCCESS;
7432
7433 OPEN desc_flex_exists;
7434 FETCH desc_flex_exists INTO l_flex_exists;
7435 IF desc_flex_exists%NOTFOUND THEN
7436 CLOSE desc_flex_exists;
7437 FND_MESSAGE.SET_NAME('AR', 'AR_RAPI_DESC_FLEX_INVALID');
7438 FND_MESSAGE.SET_TOKEN('DFF_NAME',p_desc_flex_name);
7439 FND_MSG_PUB.ADD ;
7440 p_return_status := FND_API.G_RET_STS_ERROR;
7441 return;
7442 END IF;
7443 CLOSE desc_flex_exists;
7444
7445
7446 fnd_flex_descval.set_context_value(p_desc_flex_rec.attribute_category);
7447
7448 fnd_flex_descval.set_column_value('ATTRIBUTE1', p_desc_flex_rec.attribute1);
7449 fnd_flex_descval.set_column_value('ATTRIBUTE2', p_desc_flex_rec.attribute2);
7450 fnd_flex_descval.set_column_value('ATTRIBUTE3', p_desc_flex_rec.attribute3);
7451 fnd_flex_descval.set_column_value('ATTRIBUTE4', p_desc_flex_rec.attribute4);
7452 fnd_flex_descval.set_column_value('ATTRIBUTE5', p_desc_flex_rec.attribute5);
7453 fnd_flex_descval.set_column_value('ATTRIBUTE6', p_desc_flex_rec.attribute6);
7454 fnd_flex_descval.set_column_value('ATTRIBUTE7', p_desc_flex_rec.attribute7);
7455 fnd_flex_descval.set_column_value('ATTRIBUTE8', p_desc_flex_rec.attribute8);
7456 fnd_flex_descval.set_column_value('ATTRIBUTE9', p_desc_flex_rec.attribute9);
7457 fnd_flex_descval.set_column_value('ATTRIBUTE10', p_desc_flex_rec.attribute10);
7458 fnd_flex_descval.set_column_value('ATTRIBUTE11',p_desc_flex_rec.attribute11);
7459 fnd_flex_descval.set_column_value('ATTRIBUTE12', p_desc_flex_rec.attribute12);
7460 fnd_flex_descval.set_column_value('ATTRIBUTE13', p_desc_flex_rec.attribute13);
7461 fnd_flex_descval.set_column_value('ATTRIBUTE14', p_desc_flex_rec.attribute14);
7462 fnd_flex_descval.set_column_value('ATTRIBUTE15', p_desc_flex_rec.attribute15);
7463 /* Bugfix 2531340 */
7464 IF ( NOT fnd_flex_descval.validate_desccols('AR',p_desc_flex_name,'I') )
7465 THEN
7466
7467 FND_MESSAGE.SET_NAME('AR', 'AR_RAPI_DESC_FLEX_INVALID');
7468 FND_MESSAGE.SET_TOKEN('DFF_NAME',p_desc_flex_name);
7469 FND_MSG_PUB.ADD ;
7470 p_return_status := FND_API.G_RET_STS_ERROR;
7471 END IF;
7472
7473 l_count := fnd_flex_descval.segment_count;
7474
7475 FOR i in 1..l_count LOOP
7476 l_col_name := fnd_flex_descval.segment_column_name(i);
7477
7478 /* Bug fix 3184559
7479 The calls to fnd_flex_descval.segment_value(i) are replaced with
7480 fnd_flex_descval.segment_id(i)*/
7481 IF l_col_name = 'ATTRIBUTE1' THEN
7482 p_desc_flex_rec.attribute1 := fnd_flex_descval.segment_id(i);
7483 ELSIF l_col_name = 'ATTRIBUTE_CATEGORY' THEN
7484 /* Bugfix 2531340 */
7485 p_desc_flex_rec.attribute_category := fnd_flex_descval.segment_id(i);
7486 ELSIF l_col_name = 'ATTRIBUTE2' THEN
7487 p_desc_flex_rec.attribute2 := fnd_flex_descval.segment_id(i);
7488 ELSIF l_col_name = 'ATTRIBUTE3' THEN
7489 p_desc_flex_rec.attribute3 := fnd_flex_descval.segment_id(i);
7490 ELSIF l_col_name = 'ATTRIBUTE4' THEN
7491 p_desc_flex_rec.attribute4 := fnd_flex_descval.segment_id(i);
7492 ELSIF l_col_name = 'ATTRIBUTE5' THEN
7493 p_desc_flex_rec.attribute5 := fnd_flex_descval.segment_id(i);
7494 ELSIF l_col_name = 'ATTRIBUTE6' THEN
7495 p_desc_flex_rec.attribute6 := fnd_flex_descval.segment_id(i);
7496 ELSIF l_col_name = 'ATTRIBUTE7' THEN
7497 p_desc_flex_rec.attribute7 := fnd_flex_descval.segment_id(i);
7498 ELSIF l_col_name = 'ATTRIBUTE8' THEN
7499 p_desc_flex_rec.attribute8 := fnd_flex_descval.segment_id(i);
7500 ELSIF l_col_name = 'ATTRIBUTE9' THEN
7501 p_desc_flex_rec.attribute9 := fnd_flex_descval.segment_id(i);
7502 ELSIF l_col_name = 'ATTRIBUTE10' THEN
7503 p_desc_flex_rec.attribute10 := fnd_flex_descval.segment_id(i);
7504 ELSIF l_col_name = 'ATTRIBUTE11' THEN
7505 p_desc_flex_rec.attribute11 := fnd_flex_descval.segment_id(i);
7506 ELSIF l_col_name = 'ATTRIBUTE12' THEN
7507 p_desc_flex_rec.attribute12 := fnd_flex_descval.segment_id(i);
7508 ELSIF l_col_name = 'ATTRIBUTE13' THEN
7509 p_desc_flex_rec.attribute13 := fnd_flex_descval.segment_id(i);
7510 ELSIF l_col_name = 'ATTRIBUTE14' THEN
7511 p_desc_flex_rec.attribute14 := fnd_flex_descval.segment_id(i);
7512 ELSIF l_col_name = 'ATTRIBUTE15' THEN
7513 p_desc_flex_rec.attribute15 := fnd_flex_descval.segment_id(i);
7514 END IF;
7515
7516 IF i > l_count THEN
7517 EXIT;
7518 END IF;
7519 END LOOP;
7520
7521 IF PG_DEBUG in ('Y', 'C') THEN
7522 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute_category : '||p_desc_flex_rec.attribute_category);
7523 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute1 : '||p_desc_flex_rec.attribute1);
7524 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute2 : '||p_desc_flex_rec.attribute2);
7525 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute3 : '||p_desc_flex_rec.attribute3);
7526 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute4 : '||p_desc_flex_rec.attribute4);
7527 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute5 : '||p_desc_flex_rec.attribute5);
7528 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute6 : '||p_desc_flex_rec.attribute6);
7529 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute7 : '||p_desc_flex_rec.attribute7);
7530 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute8 : '||p_desc_flex_rec.attribute8);
7531 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute9 : '||p_desc_flex_rec.attribute9);
7532 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute10 : '||p_desc_flex_rec.attribute10);
7533 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute11 : '||p_desc_flex_rec.attribute11);
7534 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute12 : '||p_desc_flex_rec.attribute12);
7535 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute13 : '||p_desc_flex_rec.attribute13);
7536 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute14 : '||p_desc_flex_rec.attribute14);
7537 arp_util.debug('Validate_Desc_Flexfield: ' || 'attribute15 : '||p_desc_flex_rec.attribute15);
7538 arp_util.debug('Validate_Desc_Flexfield ()-');
7539 END IF;
7540 END Validate_Desc_Flexfield;
7541
7542 /* Bug fix 3539008 */
7543 PROCEDURE Default_Desc_Flexfield(
7544 p_desc_flex_rec OUT NOCOPY ar_receipt_api_pub.attribute_rec_type,
7545 p_cash_receipt_id IN NUMBER,
7546 p_return_status IN OUT NOCOPY VARCHAR2
7547 ) IS
7548 BEGIN
7549 IF PG_DEBUG in ('Y', 'C') THEN
7550 arp_util.debug('ar_receipt_lib_pvt.Default_Desc_Flexfield(+)');
7551 END IF;
7552 p_return_status := FND_API.G_RET_STS_SUCCESS;
7553 IF p_cash_receipt_id IS NOT NULL THEN
7554 SELECT attribute_category,
7555 attribute1, attribute2,
7556 attribute3, attribute4,
7557 attribute5, attribute6,
7558 attribute7, attribute8,
7559 attribute9, attribute10,
7560 attribute11, attribute12,
7561 attribute13, attribute14,
7562 attribute15
7563 INTO p_desc_flex_rec.attribute_category,
7564 p_desc_flex_rec.attribute1, p_desc_flex_rec.attribute2,
7565 p_desc_flex_rec.attribute3, p_desc_flex_rec.attribute4,
7566 p_desc_flex_rec.attribute5, p_desc_flex_rec.attribute6,
7567 p_desc_flex_rec.attribute7, p_desc_flex_rec.attribute8,
7568 p_desc_flex_rec.attribute9, p_desc_flex_rec.attribute10,
7569 p_desc_flex_rec.attribute11, p_desc_flex_rec.attribute12,
7570 p_desc_flex_rec.attribute13, p_desc_flex_rec.attribute14,
7571 p_desc_flex_rec.attribute15
7572 FROM ar_cash_receipts
7573 WHERE cash_receipt_id = p_cash_receipt_id;
7574 END IF;
7575 IF PG_DEBUG in ('Y', 'C') THEN
7576 arp_util.debug('ar_receipt_lib_pvt.Default_Desc_Flexfield(-)');
7577 END IF;
7578
7579 EXCEPTION WHEN OTHERS THEN
7580 FND_MESSAGE.SET_NAME('AR','AR_RAPI_CASH_RCPT_ID_INVALID');
7581 FND_MSG_PUB.Add;
7582 p_return_status := FND_API.G_RET_STS_ERROR;
7583 End Default_Desc_Flexfield;
7584 /* End bug fix 3539008 */
7585
7586 PROCEDURE Default_prepay_cc_activity(
7587 p_appl_type IN VARCHAR2,
7588 p_receivable_trx_id IN OUT NOCOPY NUMBER,
7589 p_return_status OUT NOCOPY VARCHAR2
7590 ) IS
7591 BEGIN
7592 IF PG_DEBUG in ('Y', 'C') THEN
7593 arp_util.debug('ar_receipt_lib_pvt.Default_prepay_cc_activity(+)');
7594 END IF;
7595
7596 p_return_status := FND_API.G_RET_STS_SUCCESS;
7597
7598 IF p_receivable_trx_id is null THEN
7599
7600 BEGIN
7601 SELECT rt.receivables_trx_id
7602 INTO p_receivable_trx_id
7603 FROM ar_receivables_trx rt
7604 WHERE nvl(rt.status,'A') = 'A'
7605 AND trunc(sysdate) between nvl(rt.start_date_active,trunc(sysdate))
7606 and nvl(rt.end_date_active,trunc(sysdate))
7607 AND rt.type = p_appl_type
7608 AND ROWNUM = 1;
7609
7610 EXCEPTION
7611 WHEN others THEN
7612 fnd_message.set_name('AR', 'AR_NO_ACTIVITY_FOUND');
7613 p_return_status := FND_API.G_RET_STS_ERROR;
7614 END;
7615 END IF;
7616
7617 IF PG_DEBUG in ('Y', 'C') THEN
7618 arp_util.debug('ar_receipt_lib_pvt.Default_prepay_cc_activity(+)');
7619 END IF;
7620
7621 END Default_prepay_cc_activity;
7622
7623 PROCEDURE default_open_receipt(
7624 p_cash_receipt_id IN OUT NOCOPY NUMBER
7625 , p_receipt_number IN OUT NOCOPY VARCHAR2
7626 , p_applied_ps_id IN OUT NOCOPY NUMBER
7627 , p_open_cash_receipt_id IN OUT NOCOPY NUMBER
7628 , p_open_receipt_number IN OUT NOCOPY VARCHAR2
7629 , p_apply_gl_date IN OUT NOCOPY DATE
7630 , p_open_rec_app_id IN NUMBER
7631 , x_cr_payment_schedule_id OUT NOCOPY NUMBER
7632 , x_last_receipt_date OUT NOCOPY DATE
7633 , x_open_applied_ps_id OUT NOCOPY NUMBER
7634 , x_unapplied_cash OUT NOCOPY NUMBER
7635 , x_open_amount_applied OUT NOCOPY NUMBER
7636 , x_claim_rec_trx_id OUT NOCOPY NUMBER
7637 , x_application_ref_num OUT NOCOPY VARCHAR2
7638 , x_secondary_app_ref_id OUT NOCOPY NUMBER
7639 , x_application_ref_reason OUT NOCOPY VARCHAR2
7640 , x_customer_reference OUT NOCOPY VARCHAR2
7641 , x_customer_reason OUT NOCOPY VARCHAR2
7642 , x_cr_gl_date OUT NOCOPY DATE
7643 , x_open_cr_gl_date OUT NOCOPY DATE
7644 , x_receipt_currency OUT NOCOPY VARCHAR2
7645 , x_open_receipt_currency OUT NOCOPY VARCHAR2
7646 , x_cr_customer_id OUT NOCOPY NUMBER
7647 , x_open_cr_customer_id OUT NOCOPY NUMBER
7648 , x_return_status OUT NOCOPY VARCHAR2
7649 ) IS
7650
7651 l_open_cash_receipt_id NUMBER;
7652 l_receipt_date DATE;
7653 l_open_receipt_date DATE;
7654 l_app_gl_date_prof VARCHAR2(240);
7655
7656 l_cr_amount NUMBER;
7657 l_cr_exchange_rate NUMBER;
7658 l_cr_cust_site_use_id NUMBER;
7659 l_cr_unapp_amount NUMBER;
7660 l_cr_payment_schedule_id NUMBER;
7661 l_remit_bank_acct_use_id NUMBER;
7662 l_receipt_method_id NUMBER;
7663 l_status ar_receivable_applications.status%TYPE;
7664 l_display ar_receivable_applications.display%TYPE;
7665
7666 BEGIN
7667
7668 IF PG_DEBUG in ('Y', 'C') THEN
7669 arp_util.debug('ar_receipt_lib_pvt.Default_open_receipt(+)');
7670 END IF;
7671
7672 x_return_status := FND_API.G_RET_STS_SUCCESS ;
7673 x_open_applied_ps_id := NULL;
7674 x_application_ref_num := NULL;
7675 x_secondary_app_ref_id := NULL;
7676
7677 default_cash_receipt_id
7678 (p_cash_receipt_id,
7679 p_receipt_number,
7680 x_return_status);
7681
7682 IF p_applied_ps_id IS NOT NULL
7683 THEN
7684 BEGIN
7685 SELECT cash_receipt_id INTO p_open_cash_receipt_id
7686 FROM ar_payment_schedules
7687 WHERE payment_schedule_id = p_applied_ps_id;
7688 EXCEPTION when others then
7689 --raise error message
7690 FND_MESSAGE.SET_NAME('AR','AR_RAPI_APP_PS_ID_INVALID');
7691 FND_MSG_PUB.Add;
7692 x_return_status := FND_API.G_RET_STS_ERROR;
7693 END;
7694 END IF;
7695
7696 IF p_open_rec_app_id IS NOT NULL THEN
7697
7698 BEGIN
7699 SELECT applied_payment_schedule_id,
7700 amount_applied,
7701 cash_receipt_id,
7702 receivables_trx_id,
7703 secondary_application_ref_id,
7704 application_ref_num,
7705 application_ref_reason,
7706 customer_reference,
7707 customer_reason,
7708 status,
7709 NVL(display,'N')
7710 INTO x_open_applied_ps_id,
7711 x_open_amount_applied,
7712 p_open_cash_receipt_id ,
7713 x_claim_rec_trx_id,
7714 x_secondary_app_ref_id,
7715 x_application_ref_num,
7716 x_application_ref_reason,
7717 x_customer_reference,
7718 x_customer_reason,
7719 l_status,
7720 l_display
7721 FROM ar_receivable_applications
7722 WHERE receivable_application_id = p_open_rec_app_id ;
7723 EXCEPTION
7724 WHEN no_data_found THEN
7725 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REC_APP_ID_INVALID');
7726 FND_MSG_PUB.Add;
7727 x_return_status := FND_API.G_RET_STS_ERROR ;
7728 END;
7729
7730 default_cash_receipt_id
7731 (p_open_cash_receipt_id,
7732 p_open_receipt_number,
7733 x_return_status);
7734
7735 /* Bug 3018366 - check for current open receipt separated from logic above */
7736 IF (l_display <> 'Y' OR l_status NOT IN ('OTHER ACC','ACC')) THEN
7737 FND_MESSAGE.SET_NAME('AR','AR_RW_NET_OPEN_RCT_ONLY');
7738 FND_MSG_PUB.Add;
7739 x_return_status := FND_API.G_RET_STS_ERROR ;
7740 END IF;
7741
7742 --Compare the two cash_receipt_ids
7743 IF p_open_cash_receipt_id IS NOT NULL THEN
7744 IF p_open_cash_receipt_id <> l_open_cash_receipt_id THEN
7745 --raise error X validation failed
7746 FND_MESSAGE.SET_NAME('AR','AR_RAPI_RCPT_RA_ID_X_INVALID');
7747 FND_MSG_PUB.Add;
7748 x_return_status := FND_API.G_RET_STS_ERROR ;
7749 END IF;
7750 END IF;
7751 END IF;
7752
7753 IF x_return_status <> FND_API.G_RET_STS_ERROR THEN
7754 default_cash_receipt_id
7755 (p_open_cash_receipt_id,
7756 p_open_receipt_number,
7757 x_return_status);
7758 END IF;
7759
7760 SELECT SUM(amount_applied)
7761 INTO x_unapplied_cash
7762 FROM ar_receivable_applications
7763 WHERE cash_receipt_id = p_cash_receipt_id
7764 AND status = 'UNAPP';
7765
7766 IF p_open_rec_app_id IS NULL
7767 THEN
7768 SELECT SUM(amount_applied)
7769 INTO x_open_amount_applied
7770 FROM ar_receivable_applications
7771 WHERE cash_receipt_id = p_open_cash_receipt_id
7772 AND status = 'UNAPP';
7773 END IF;
7774
7775 --
7776 -- Default receipt info
7777 --
7778 Default_Receipt_Info(
7779 p_cash_receipt_id ,
7780 x_cr_gl_date,
7781 x_cr_customer_id,
7782 l_cr_amount,
7783 x_receipt_currency,
7784 l_cr_exchange_rate,
7785 l_cr_cust_site_use_id,
7786 l_receipt_date,
7787 l_cr_unapp_amount,
7788 x_cr_payment_schedule_id,
7789 l_remit_bank_acct_use_id,
7790 l_receipt_method_id,
7791 x_return_status
7792 );
7793
7794 Default_Receipt_Info(
7795 p_open_cash_receipt_id ,
7796 x_open_cr_gl_date,
7797 x_open_cr_customer_id,
7798 l_cr_amount,
7799 x_open_receipt_currency,
7800 l_cr_exchange_rate,
7801 l_cr_cust_site_use_id,
7802 l_open_receipt_date, /* Bug fix 3286069 */
7803 l_cr_unapp_amount,
7804 p_applied_ps_id,
7805 l_remit_bank_acct_use_id,
7806 l_receipt_method_id,
7807 x_return_status
7808 );
7809
7810
7811 IF p_apply_gl_date IS NULL
7812 THEN
7813 p_apply_gl_date := (GREATEST(x_cr_gl_date,x_open_cr_gl_date));
7814 l_app_gl_date_prof :=
7815 NVL(ar_receipt_lib_pvt.pg_profile_appln_gl_date_def,'INV_REC_DT');
7816 IF (l_app_gl_date_prof = 'INV_REC_DT') THEN
7817 NULL;
7818 ELSIF (l_app_gl_date_prof = 'INV_REC_SYS_DT') THEN
7819 IF p_apply_gl_date > SYSDATE THEN
7820 NULL;
7821 ELSE
7822 p_apply_gl_date := SYSDATE;
7823 END IF;
7824 ELSE
7825 p_apply_gl_date := SYSDATE;
7826 END IF;
7827 END IF;
7828
7829 x_last_receipt_date := GREATEST(l_receipt_date,l_open_receipt_date);
7830
7831 IF PG_DEBUG in ('Y', 'C') THEN
7832 arp_util.debug('ar_receipt_lib_pvt.Default_open_receipt(-)');
7833 END IF;
7834 END default_open_receipt;
7835
7836 PROCEDURE default_unapp_open_receipt(
7837 p_receivable_application_id IN NUMBER
7838 , x_applied_cash_receipt_id OUT NOCOPY NUMBER
7839 , x_applied_rec_app_id OUT NOCOPY NUMBER
7840 , x_amount_applied OUT NOCOPY NUMBER
7841 , x_return_status OUT NOCOPY VARCHAR2
7842 ) IS
7843
7844 BEGIN
7845
7846 x_return_status := FND_API.G_RET_STS_SUCCESS;
7847 IF PG_DEBUG in ('Y', 'C') THEN
7848 arp_util.debug('ar_receipt_lib_pvt.Default_unapp_open_receipt(+)');
7849 END IF;
7850
7851 SELECT app.applied_rec_app_id,
7852 applied_app.cash_receipt_id,
7853 app.amount_applied
7854 INTO x_applied_rec_app_id,
7855 x_applied_cash_receipt_id,
7856 x_amount_applied
7857 FROM ar_receivable_applications app,
7858 ar_receivable_applications applied_app
7859 WHERE app.applied_rec_app_id = applied_app.receivable_application_id
7860 AND app.receivable_application_id = p_receivable_application_id;
7861
7862 IF PG_DEBUG in ('Y', 'C') THEN
7863 arp_util.debug('ar_receipt_lib_pvt.Default_unapp_open_receipt(-)');
7864 END IF;
7865
7866 EXCEPTION
7867 WHEN no_data_found THEN
7868 FND_MESSAGE.SET_NAME('AR','AR_RAPI_REC_APP_ID_INVALID');
7869 FND_MSG_PUB.Add;
7870 x_return_status := FND_API.G_RET_STS_ERROR ;
7871 END default_unapp_open_receipt;
7872
7873 FUNCTION get_legal_entity (p_remit_bank_acct_use_id IN NUMBER)
7874 RETURN NUMBER
7875 IS
7876 l_legal_entity_id NUMBER;
7877 l_return_status VARCHAR2(1);
7878 BEGIN
7879 IF PG_DEBUG in ('Y', 'C') THEN
7880 arp_util.debug('ar_receipt_lib_pvt.get_legal_entity(+)');
7881 END IF;
7882
7883 l_legal_entity_id := TO_NUMBER(Get_Id('LEGAL_ENTITY',
7884 p_remit_bank_acct_use_id,
7885 l_return_status
7886 ));
7887 RETURN l_legal_entity_id;
7888
7889 IF PG_DEBUG in ('Y', 'C') THEN
7890 arp_util.debug('ar_receipt_lib_pvt.get_legal_entity(-)');
7891 END IF;
7892 EXCEPTION
7893 WHEN OTHERS THEN
7894 RETURN NULL;
7895 END get_legal_entity;
7896
7897 PROCEDURE default_refund_attributes (
7898 p_cash_receipt_id IN ar_cash_receipts.cash_receipt_id%TYPE
7899 ,p_customer_trx_id IN ra_customer_trx.customer_trx_id%TYPE
7900 ,p_currency_code IN fnd_currencies.currency_code%TYPE
7901 ,p_amount IN NUMBER
7902 ,p_party_id IN OUT NOCOPY hz_parties.party_id%TYPE
7903 ,p_party_site_id IN OUT NOCOPY hz_party_sites.party_site_id%TYPE
7904 ,x_party_name OUT NOCOPY hz_parties.party_name%TYPE
7905 ,x_party_number OUT NOCOPY hz_parties.party_number%TYPE
7906 ,x_party_address OUT NOCOPY VARCHAR2
7907 ,x_exchange_rate OUT NOCOPY ar_cash_receipts.exchange_rate%TYPE
7908 ,x_exchange_rate_type OUT NOCOPY ar_cash_receipts.exchange_rate_type%TYPE
7909 ,x_exchange_date OUT NOCOPY ar_cash_receipts.exchange_date%TYPE
7910 ,x_legal_entity_id OUT NOCOPY ar_cash_receipts.legal_entity_id%TYPE
7911 ,x_payment_method_code OUT NOCOPY ap_invoices.payment_method_code%TYPE
7912 ,x_payment_method_name OUT NOCOPY VARCHAR2
7913 ,x_bank_account_id OUT NOCOPY ar_cash_receipts.customer_bank_account_id%TYPE
7914
7915 ,x_bank_account_num OUT NOCOPY VARCHAR2
7916 ,x_payment_reason_code OUT NOCOPY ap_invoices.payment_reason_code%TYPE
7917 ,x_payment_reason_name OUT NOCOPY VARCHAR2
7918 ,x_delivery_channel_code OUT NOCOPY ap_invoices.delivery_channel_code%TYPE
7919 ,x_delivery_channel_name OUT NOCOPY VARCHAR2
7920 ,x_pay_alone_flag OUT NOCOPY VARCHAR2
7921 ,x_return_status OUT NOCOPY VARCHAR2
7922 ,x_msg_count OUT NOCOPY NUMBER
7923 ,x_msg_data OUT NOCOPY VARCHAR2
7924 )
7925 IS
7926 l_trxn_attributes_rec iby_disbursement_comp_pub.trxn_attributes_rec_type;
7927 l_legal_entity_id ar_cash_receipts.legal_entity_id%TYPE;
7928 l_org_id ar_cash_receipts.org_id%TYPE;
7929 l_cust_acct_id hz_cust_accounts.cust_account_id%TYPE;
7930 l_site_use_id hz_cust_site_uses.site_use_id%TYPE;
7931 l_party_id hz_parties.party_id%TYPE;
7932 l_party_site_id hz_parties.party_id%TYPE;
7933 l_pmt_attr_rec iby_disbursement_comp_pub.default_pmt_attrs_rec_type;
7934 BEGIN
7935 IF PG_DEBUG in ('Y', 'C') THEN
7936 arp_util.debug('ar_receipt_lib_pvt.default_refund_attributes(+)');
7937 END IF;
7938 l_trxn_attributes_rec.application_id := 222;
7939
7940 IF p_cash_receipt_id IS NOT NULL THEN
7941 begin
7942 SELECT legal_entity_id,
7943 exchange_rate,
7944 exchange_rate_type,
7945 exchange_date,
7946 org_id,
7947 pay_from_customer,
7948 customer_site_use_id
7949 INTO x_legal_entity_id,
7950 x_exchange_rate,
7951 x_exchange_rate_type,
7952 x_exchange_date,
7953 l_org_id,
7954 l_cust_acct_id,
7955 l_site_use_id
7956 FROM ar_cash_receipts_all
7957 WHERE cash_receipt_id = p_cash_receipt_id;
7958 exception when others then null;
7959 end;
7960 ELSE
7961 SELECT legal_entity_id,
7962 exchange_rate,
7963 exchange_rate_type,
7964 exchange_date,
7965 org_id,
7966 bill_to_customer_id,
7967 bill_to_site_use_id
7968 INTO x_legal_entity_id,
7969 x_exchange_rate,
7970 x_exchange_rate_type,
7971 x_exchange_date,
7972 l_org_id,
7973 l_cust_acct_id,
7974 l_site_use_id
7975 FROM ra_customer_trx
7976 WHERE customer_trx_id = p_customer_trx_id;
7977 END IF;
7978 IF p_party_id IS NULL THEN
7979 BEGIN
7980 SELECT p.party_id
7981 ,p.party_name
7982 ,p.party_number
7983 INTO p_party_id
7984 ,x_party_name
7985 ,x_party_number
7986 FROM hz_cust_accounts ca
7987 ,hz_parties p
7988 WHERE p.party_id = ca.party_id
7989 AND ca.cust_account_id = l_cust_acct_id;
7990 EXCEPTION
7991 WHEN OTHERS THEN
7992 p_party_id := NULL;
7993 x_party_name := NULL;
7994 x_party_number := NULL;
7995 END;
7996 END IF;
7997 IF p_party_site_id IS NULL and p_party_id IS NOT NULL THEN
7998 begin
7999 SELECT cas.party_site_id
8000 /* , arh_addr_pkg.format_address(loc.address_style,loc.address1,
8001 loc.address2, loc.address3,
8002 loc.address4, loc.city,
8003 loc.county, loc.state,
8004 loc.province, loc.postal_code,
8005 null)*/
8006 , loc.address1
8007 INTO p_party_site_id
8008 ,x_party_address
8009 FROM hz_cust_acct_sites_all cas,
8010 hz_cust_site_uses_all csu,
8011 hz_party_sites ps,
8012 hz_locations loc
8013 WHERE cas.cust_acct_site_id = csu.cust_acct_site_id
8014 AND csu.site_use_id = l_site_use_id
8015 AND cas.party_site_id = ps.party_site_id
8016 AND ps.location_id = loc.location_id;
8017 exception when others then null;
8018 end;
8019 END IF;
8020 IF p_party_id IS NULL THEN
8021 RETURN;
8022 END IF;
8023 l_trxn_attributes_rec.payer_legal_entity_id := x_legal_entity_id;
8024 l_trxn_attributes_rec.payer_org_type := 'OPERATING_UNIT';
8025 l_trxn_attributes_rec.payer_org_id := l_org_id;
8026 l_trxn_attributes_rec.payee_party_id := p_party_id;
8027 l_trxn_attributes_rec.payee_party_site_id := p_party_site_id;
8028 l_trxn_attributes_rec.pay_proc_trxn_type_code := 'AR_CUSTOMER_REFUND';
8029 l_trxn_attributes_rec.payment_currency := p_currency_code;
8030 l_trxn_attributes_rec.payment_amount := p_amount;
8031 l_trxn_attributes_rec.payment_function := 'AR_CUSTOMER_REFUNDS';
8032
8033 IF PG_DEBUG in ('Y', 'C') THEN
8034 arp_util.debug('Calling get_default_payment_attributes .......: ');
8035 END IF;
8036
8037 /* Bug 5056865 p_ignore_payee_pref should be passed as 'Y' as discussed in
8038 Related Bug 5115632 */
8039 begin
8040 iby_disbursement_comp_pub.get_default_payment_attributes(
8041 p_api_version => 1.0
8042 ,p_init_msg_list => FND_API.G_FALSE
8043 ,p_ignore_payee_pref => 'Y'
8044 ,p_trxn_attributes_rec => l_trxn_attributes_rec
8045 ,x_return_status => x_return_status
8046 ,x_msg_count => x_msg_count
8047 ,x_msg_data => x_msg_data
8048 ,x_default_pmt_attrs_rec=> l_pmt_attr_rec);
8049 exception when others then null;
8050 end;
8051
8052 IF PG_DEBUG in ('Y', 'C') THEN
8053 arp_util.debug('get_default_payment_attributes return status: '||x_return_status);
8054 END IF;
8055
8056 x_payment_method_code := l_pmt_attr_rec.payment_method.payment_method_code;
8057 x_payment_method_name := l_pmt_attr_rec.payment_method.payment_method_name;
8058 x_bank_account_id := l_pmt_attr_rec.payee_bankaccount.payee_bankaccount_id;
8059 x_bank_account_num := l_pmt_attr_rec.payee_bankaccount.payee_bankaccount_num;
8060 x_payment_reason_code := l_pmt_attr_rec.payment_reason.code;
8061 x_payment_reason_name := l_pmt_attr_rec.payment_reason.meaning;
8062 x_delivery_channel_code := l_pmt_attr_rec.delivery_channel.code;
8063 x_delivery_channel_name := l_pmt_attr_rec.delivery_channel.meaning;
8064 x_pay_alone_flag := l_pmt_attr_rec.pay_alone;
8065 IF PG_DEBUG in ('Y', 'C') THEN
8066 arp_util.debug('ar_receipt_lib_pvt.default_refund_attributes(-)');
8067 END IF;
8068 END default_refund_attributes;
8069
8070
8071 PROCEDURE populate_llca_gt (
8072 p_customer_trx_id IN NUMBER,
8073 p_llca_type IN VARCHAR2,
8074 p_llca_trx_lines_tbl IN ar_receipt_api_pub.llca_trx_lines_tbl_type,
8075 p_line_amount IN NUMBER,
8076 p_tax_amount IN NUMBER,
8077 p_freight_amount IN NUMBER,
8078 p_charges_amount IN NUMBER,
8079 p_line_discount IN NUMBER,
8080 p_tax_discount IN NUMBER,
8081 p_freight_discount IN NUMBER,
8082 p_amount_applied IN NUMBER,
8083 p_amount_applied_from IN NUMBER,
8084 p_return_status OUT NOCOPY VARCHAR2)
8085 IS
8086 BEGIN
8087 IF PG_DEBUG in ('Y', 'C') THEN
8088 arp_util.debug('Populate_llca_gt ()+ ');
8089 END IF;
8090
8091 p_return_status := FND_API.G_RET_STS_SUCCESS;
8092
8093 -- Clean the GT Table first.
8094 delete from ar_llca_trx_lines_gt
8095 where customer_trx_id = p_customer_trx_id;
8096
8097 delete from ar_llca_trx_errors_gt
8098 where customer_trx_id = p_customer_trx_id;
8099
8100 If p_llca_type = 'S'
8101 Then
8102 If p_llca_trx_lines_tbl.count <> 0 Then
8103 IF PG_DEBUG in ('Y', 'C') THEN
8104 arp_util.debug('Apply_In_Detail: ' || 'Table must be empty for
8105 Summary Level application ');
8106 END IF;
8107 End If;
8108 END IF;
8109
8110 If p_llca_type = 'L'
8111 Then
8112 If p_llca_trx_lines_tbl.count = 0 Then
8113 IF PG_DEBUG in ('Y', 'C') THEN
8114 arp_util.debug('=======================================================');
8115 arp_util.debug(' PL SQL TABLE ( INPUT PARAMETERS ........)+ ');
8116 arp_util.debug('=======================================================');
8117 arp_util.debug('Apply_In_Detail: ' || 'Pl Sql Table is empty ..
8118 All Lines ');
8119 END IF;
8120 Else
8121 IF PG_DEBUG in ('Y', 'C') THEN
8122 arp_util.debug('No of records in PLSQL Table
8123 =>'||to_char(p_llca_trx_lines_tbl.count));
8124 END IF;
8125
8126 --bug7311231, Populating the GT table with flexfield information of each line.
8127 For i in p_llca_trx_lines_tbl.FIRST..p_llca_trx_lines_tbl.LAST
8128 Loop
8129 Insert into ar_llca_trx_lines_gt
8130 ( customer_trx_id,
8131 customer_trx_line_id,
8132 line_number,
8133 line_amount,
8134 tax_amount,
8135 freight_amount,
8136 charges_amount,
8137 amount_applied,
8138 amount_applied_from,
8139 line_discount,
8140 tax_discount,
8141 freight_discount,
8142 attribute_category,
8143 attribute1,
8144 attribute2,
8145 attribute3,
8146 attribute4,
8147 attribute5,
8148 attribute6,
8149 attribute7,
8150 attribute8,
8151 attribute9,
8152 attribute10,
8153 attribute11,
8154 attribute12,
8155 attribute13,
8156 attribute14,
8157 attribute15
8158 )
8159 values
8160 (
8161 p_customer_trx_id,
8162 p_llca_trx_lines_tbl(i).customer_trx_line_id,
8163 p_llca_trx_lines_tbl(i).line_number,
8164 p_llca_trx_lines_tbl(i).line_amount,
8165 p_llca_trx_lines_tbl(i).tax_amount,
8166 Null,
8167 Null,
8168 p_llca_trx_lines_tbl(i).amount_applied,
8169 p_llca_trx_lines_tbl(i).amount_applied_from,
8170 p_llca_trx_lines_tbl(i).line_discount,
8171 p_llca_trx_lines_tbl(i).tax_discount,
8172 Null,
8173 p_llca_trx_lines_tbl(i).attribute_category,
8174 p_llca_trx_lines_tbl(i).attribute1,
8175 p_llca_trx_lines_tbl(i).attribute2,
8176 p_llca_trx_lines_tbl(i).attribute3,
8177 p_llca_trx_lines_tbl(i).attribute4,
8178 p_llca_trx_lines_tbl(i).attribute5,
8179 p_llca_trx_lines_tbl(i).attribute6,
8180 p_llca_trx_lines_tbl(i).attribute7,
8181 p_llca_trx_lines_tbl(i).attribute8,
8182 p_llca_trx_lines_tbl(i).attribute9,
8183 p_llca_trx_lines_tbl(i).attribute10,
8184 p_llca_trx_lines_tbl(i).attribute11,
8185 p_llca_trx_lines_tbl(i).attribute12,
8186 p_llca_trx_lines_tbl(i).attribute13,
8187 p_llca_trx_lines_tbl(i).attribute14,
8188 p_llca_trx_lines_tbl(i).attribute15
8189 );
8190
8191 IF PG_DEBUG in ('Y', 'C') THEN
8192 arp_util.debug('=======================================================');
8193 arp_util.debug(' Line .............=>'||to_char(i));
8194 arp_util.debug('p_customer_trx_id =>'||to_char(p_customer_trx_id));
8195 arp_util.debug('p_customer_trx_line_id =>'||to_char(p_llca_trx_lines_tbl(i).customer_trx_line_id));
8196 arp_util.debug('p_line_number =>'||to_char(p_llca_trx_lines_tbl(i).line_number));
8197 arp_util.debug('p_line_amount =>'||to_char(p_llca_trx_lines_tbl(i).line_amount));
8198 arp_util.debug('p_tax_amount =>'||to_char(p_llca_trx_lines_tbl(i).tax_amount));
8199 -- arp_util.debug('p_freight_amount =>'||to_char(p_llca_trx_lines_tbl(i).freight_amount));
8200 -- arp_util.debug('p_charges_amount =>'||to_char(p_llca_trx_lines_tbl(i).charges_amount));
8201 arp_util.debug('p_amount_applied =>'||to_char(p_llca_trx_lines_tbl(i).amount_applied));
8202 arp_util.debug('p_amount_applied_from =>'||to_char(p_llca_trx_lines_tbl(i).amount_applied_from));
8203 arp_util.debug('p_line_discount =>'||to_char(p_llca_trx_lines_tbl(i).line_discount));
8204 arp_util.debug('p_tax_discount =>'||to_char(p_llca_trx_lines_tbl(i).tax_discount));
8205 -- arp_util.debug('p_freight_discount =>'||to_char(p_llca_trx_lines_tbl(i).freight_amount));
8206 arp_util.debug('=======================================================');
8207 END IF;
8208 End Loop;
8209 End If;
8210 End If;
8211 IF PG_DEBUG in ('Y', 'C') THEN
8212 arp_util.debug('Populate_llca_gt ()- ');
8213 END IF;
8214
8215 EXCEPTION
8216 WHEN others THEN
8217 IF PG_DEBUG in ('Y', 'C') THEN
8218 arp_util.debug('EXCEPTION: (pouplate_llca_gt)');
8219 END IF;
8220 p_return_status := FND_API.G_RET_STS_ERROR;
8221 raise;
8222 End populate_llca_gt;
8223
8224 PROCEDURE populate_errors_gt (
8225 p_customer_trx_id IN NUMBER,
8226 p_customer_trx_line_id IN NUMBER,
8227 p_error_message IN VARCHAR2,
8228 p_invalid_value IN VARCHAR2
8229 ) IS
8230 Begin
8231 IF PG_DEBUG in ('Y', 'C') THEN
8232 arp_util.debug('Populate_errors_gt ()+ ');
8233 END IF;
8234
8235 Insert into ar_llca_trx_errors_gt
8236 ( customer_trx_id,
8237 customer_trx_line_id,
8238 error_message,
8239 invalid_value
8240 )
8241 values
8242 ( p_customer_trx_id,
8243 p_customer_trx_line_id,
8244 p_error_message,
8245 p_invalid_value
8246 );
8247
8248 IF PG_DEBUG in ('Y', 'C') THEN
8249 arp_util.debug('Populate_errors_gt ()- ');
8250 END IF;
8251
8252 EXCEPTION
8253 WHEN others THEN
8254 IF PG_DEBUG in ('Y', 'C') THEN
8255 arp_util.debug('EXCEPTION: (pouplate_errors_gt)');
8256 END IF;
8257 raise;
8258 End populate_errors_gt;
8259
8260 END ar_receipt_lib_pvt;