[Home] [Help]
PACKAGE BODY: APPS.AR_CM_API_PUB
Source
4 * Credit Memo APIs allow users to apply/unapply on account credit memo
1 PACKAGE BODY AR_CM_API_PUB AS
2 /* $Header: ARXPCMEB.pls 120.3 2011/09/17 18:13:11 naneja ship $ */
3 /*#
5 * against a debit memo or invoice using simple calls to PL/SQL functions.
6 */
7
8 G_PKG_NAME CONSTANT VARCHAR2(30) := 'AR_CM_API_PUB';
9
10 G_MSG_UERROR CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR;
11 G_MSG_ERROR CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_ERROR;
12 G_MSG_SUCCESS CONSTANT NUMBER := FND_MSG_PUB.G_MSG_LVL_SUCCESS;
13
14 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
15
16 PROCEDURE apply_on_account(
17 p_api_version IN NUMBER,
18 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
19 p_commit IN VARCHAR2 := FND_API.G_FALSE,
20 p_cm_app_rec IN cm_app_rec_type,
21 x_return_status OUT NOCOPY VARCHAR2,
22 x_msg_count OUT NOCOPY NUMBER,
23 x_msg_data OUT NOCOPY VARCHAR2,
24 x_out_rec_application_id OUT NOCOPY NUMBER,
25 x_acctd_amount_applied_from OUT NOCOPY ar_receivable_applications.acctd_amount_applied_from%TYPE,
26 x_acctd_amount_applied_to OUT NOCOPY ar_receivable_applications.acctd_amount_applied_to%TYPE,
27 p_org_id IN NUMBER DEFAULT NULL)
28
29 IS
30
31 l_api_name CONSTANT VARCHAR2(30) := 'Apply_on_account';
32 l_api_version CONSTANT NUMBER := 1.0;
33 l_cm_customer_trx_id NUMBER;
34 l_inv_customer_trx_id NUMBER;
35 l_inv_customer_trx_line_id NUMBER;
36 l_installment NUMBER(15);
37 l_applied_payment_schedule_id NUMBER(15);
38 l_def_ids_return_status VARCHAR(1);
39 l_def_return_status VARCHAR(1);
40 l_val_return_status VARCHAR(1);
41 l_dflex_val_return_status VARCHAR2(1);
42 l_return_status VARCHAR2(1);
43 l_cm_gl_date DATE;
44 l_cm_amount_rem NUMBER;
45 l_cm_trx_date DATE;
46 l_cm_ps_id NUMBER;
47 l_cm_currency_code fnd_currencies.currency_code%TYPE;
48 l_inv_due_date DATE;
49 l_inv_currency_code fnd_currencies.currency_code%TYPE;
50 l_inv_trx_date DATE;
51 l_inv_gl_date DATE;
52 l_allow_overappln_flag VARCHAR2(1);
53 l_natural_appln_only_flag VARCHAR2(1);
54 l_creation_sign VARCHAR2(1);
55 l_inv_line_amount NUMBER;
56 l_inv_amount_rem NUMBER;
57
58 l_apply_date DATE;
59 l_apply_gl_date DATE;
60 l_show_closed_invoices VARCHAR2(1);
61 l_amount_applied NUMBER;
62
63
64 l_rec_application_id NUMBER;
65 l_acctd_amount_applied_from NUMBER;
66 l_acctd_amount_applied_to NUMBER;
67
68 l_attribute_rec ar_receipt_api_pub.attribute_rec_type;
69 l_org_return_status VARCHAR2(1); --bug7641800
73
70 l_org_id NUMBER;
71
72 BEGIN
74
75 IF PG_DEBUG in ('Y', 'C') THEN
76 arp_util.debug('AR_CM_API_PUB.APPLY_ON_ACCOUNT(+)');
77 END IF;
78
79 /*------------------------------------+
80 | Standard start of API savepoint |
81 +------------------------------------*/
82
83 SAVEPOINT Apply_CM;
84
85 /*--------------------------------------------------+
86 | Standard call to check for call compatibility |
87 +--------------------------------------------------*/
88
89 IF NOT FND_API.Compatible_API_Call(
90 l_api_version,
91 p_api_version,
92 l_api_name,
93 G_PKG_NAME
94 )
95 THEN
96 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
97 END IF;
98
99 /*--------------------------------------------------------------+
100 | Initialize message list if p_init_msg_list is set to TRUE |
101 +--------------------------------------------------------------*/
102
103 IF FND_API.to_Boolean( p_init_msg_list )
104 THEN
105 FND_MSG_PUB.initialize;
106 END IF;
107
108 /*-------------------------------------------------+
109 | Initialize SOB/org dependent variables |
110 +-------------------------------------------------*/
111 /* bug7641800, Added parameter to accept org_id from customer and added
112 code to set ORG accordingly. */
113 l_org_id := p_org_id;
114 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
115 ar_mo_cache_utils.set_org_context_in_api
116 (
117 p_org_id =>l_org_id,
118 p_return_status =>l_org_return_status
119 );
120
121 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
122 x_return_status := FND_API.G_RET_STS_ERROR;
123 ELSE
124 -- arp_global.init_global;
125 -- arp_standard.init_standard;
126
127 /*-----------------------------------------+
128 | Initialize return status to SUCCESS |
129 +-----------------------------------------*/
130
131 x_return_status := FND_API.G_RET_STS_SUCCESS;
132
133 /*---------------------------------------------+
134 | ========== Start of API Body ========== |
135 +---------------------------------------------*/
136
137 l_cm_customer_trx_id := p_cm_app_rec.cm_customer_trx_id;
138 l_inv_customer_trx_id := p_cm_app_rec.inv_customer_trx_id;
139 l_inv_customer_trx_line_id := p_cm_app_rec.inv_customer_trx_line_id;
140 l_installment := p_cm_app_rec.installment;
141 l_applied_payment_schedule_id := p_cm_app_rec.applied_payment_schedule_id;
142 l_apply_date := p_cm_app_Rec.apply_date;
143 l_apply_gl_date := p_cm_app_rec.gl_date;
144 l_show_closed_invoices := p_cm_app_rec.show_closed_invoices;
145 l_amount_applied := p_cm_app_rec.amount_applied;
146
147 /*-----------------------+
148 | |
149 |ID TO VALUE CONVERSION |
150 | |
151 +-----------------------*/
152
153 -- Call Defaulting API here to get IDs based on input parameters
154 ar_cm_val_pvt.default_app_ids(
155 l_cm_customer_trx_id,
156 p_cm_app_rec.cm_trx_number,
157 l_inv_customer_trx_id,
158 p_cm_app_rec.inv_trx_number,
159 l_inv_customer_trx_line_id,
160 p_cm_app_rec.inv_line_number,
161 l_installment,
162 l_applied_payment_schedule_id,
163 l_def_ids_return_status);
164
165
166 IF PG_DEBUG in ('Y', 'C') THEN
167 arp_util.debug( 'Defaulting Ids Return_status = '||l_def_ids_return_status);
168 END IF;
169 /*---------------------+
170 | |
171 | DEFAULTING |
172 | |
173 +---------------------*/
174
175 -- Call API for defaulting
176 ar_cm_val_pvt.default_app_info(
177 l_cm_customer_trx_id ,
178 l_inv_customer_trx_id ,
179 l_inv_customer_trx_line_id ,
180 l_show_closed_invoices ,
181 l_installment ,
182 l_apply_date ,
183 l_apply_gl_date ,
184 l_amount_applied ,
185 l_applied_payment_schedule_id ,
186 l_cm_gl_date ,
187 l_cm_trx_date ,
188 l_cm_amount_rem ,
189 l_cm_currency_code ,
190 l_inv_due_date ,
191 l_inv_currency_code ,
192 l_inv_amount_rem ,
193 l_inv_trx_date ,
194 l_inv_gl_date ,
195 l_allow_overappln_flag ,
196 l_natural_appln_only_flag ,
197 l_creation_sign ,
198 l_cm_ps_id ,
199 l_inv_line_amount ,
200 l_def_return_status
201 );
202 IF PG_DEBUG in ('Y', 'C') THEN
203 arp_util.debug( 'Default Info Return_status = '||l_def_return_status);
204 arp_util.debug( 'Applied PS ID = '||l_applied_payment_schedule_id);
208 /*---------------------+
205 END IF;
206
207
209 | |
210 | VALIDATION |
211 | |
212 +---------------------*/
213 -- Call new PVT API for validation
214 IF l_def_return_status = FND_API.G_RET_STS_SUCCESS AND
215 l_def_ids_return_status = FND_API.G_RET_STS_SUCCESS
216 THEN
217 ar_cm_val_pvt.validate_app_info(
218 l_apply_date,
219 l_cm_trx_date,
220 l_inv_trx_date,
221 l_apply_gl_date,
222 l_cm_gl_date,
223 l_inv_gl_date,
224 l_amount_applied,
225 l_applied_payment_schedule_id,
226 l_inv_customer_trx_line_id,
227 l_inv_line_amount,
228 l_creation_sign,
229 l_allow_overappln_flag,
230 l_natural_appln_only_flag,
231 l_cm_amount_rem,
232 l_inv_amount_rem,
233 l_cm_currency_code ,
234 l_inv_currency_code,
235 l_val_return_status
236 );
237 IF PG_DEBUG in ('Y', 'C') THEN
238 arp_util.debug( 'Validation Return_status = '||l_val_return_status);
239 arp_util.debug( 'Applied PS ID = '||l_applied_payment_schedule_id);
240 END IF;
241 END IF;
242
243 -- Validate DFF
244
245 l_attribute_rec.attribute_category := p_cm_app_rec.attribute_category;
246 l_attribute_rec.attribute1 := p_cm_app_rec.attribute1;
247 l_attribute_rec.attribute2 := p_cm_app_rec.attribute2;
248 l_attribute_rec.attribute3 := p_cm_app_rec.attribute3;
249 l_attribute_rec.attribute4 := p_cm_app_rec.attribute4;
250 l_attribute_rec.attribute5 := p_cm_app_rec.attribute5;
251 l_attribute_rec.attribute6 := p_cm_app_rec.attribute6;
252 l_attribute_rec.attribute7 := p_cm_app_rec.attribute7;
253 l_attribute_rec.attribute8 := p_cm_app_rec.attribute8;
254 l_attribute_rec.attribute9 := p_cm_app_rec.attribute9;
255 l_attribute_rec.attribute10 := p_cm_app_rec.attribute10;
256 l_attribute_rec.attribute11 := p_cm_app_rec.attribute11;
257 l_attribute_rec.attribute12 := p_cm_app_rec.attribute12;
258 l_attribute_rec.attribute13 := p_cm_app_rec.attribute13;
259 l_attribute_rec.attribute14 := p_cm_app_rec.attribute14;
260 l_attribute_rec.attribute15 := p_cm_app_rec.attribute15;
261
262 -- Call existing receipt api that does this validation
263 -- for populating RA
264 ar_receipt_lib_pvt.Validate_Desc_Flexfield(
265 l_attribute_rec,
266 'AR_RECEIVABLE_APPLICATIONS',
267 l_dflex_val_return_status
268 );
269
270 IF l_def_ids_return_status <> FND_API.G_RET_STS_SUCCESS OR
271 l_val_return_status <> FND_API.G_RET_STS_SUCCESS OR
272 l_def_return_status <> FND_API.G_RET_STS_SUCCESS OR
273 l_dflex_val_return_status <> FND_API.G_RET_STS_SUCCESS THEN
274 x_return_status := FND_API.G_RET_STS_ERROR;
275 END IF;
276
277
278 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
279 p_count => x_msg_count,
280 p_data => x_msg_data
281 );
282
283 END IF; -- Closing IF for ORG_RET_STATUS
284
285 IF x_return_status <> FND_API.G_RET_STS_SUCCESS
286 THEN
287
288 ROLLBACK TO Apply_CM;
289
290 x_return_status := FND_API.G_RET_STS_ERROR ;
291
292
293 IF PG_DEBUG in ('Y', 'C') THEN
294 arp_util.debug( 'Error(s) occurred. Rolling back and setting status to ERROR');
295 END IF;
296 Return;
297 END IF;
298
299
300 /*---------------------+
301 | |
302 | ENTITY HANDLER |
303 | |
304 +--------------------*/
305
306 -- Display inputs to entity handler
307 IF PG_DEBUG in ('Y', 'C') THEN
308 arp_util.debug( 'CM PS ID = '||l_cm_ps_id ||
309 ' Invoice PS ID = '|| l_applied_payment_schedule_id ||
310 ' AMount applied = '|| l_amount_applied ||
311 ' Apply date = ' || l_apply_date||
312 ' GL date = '|| l_apply_gl_date);
313 END IF;
314
315 -- Lock the PS of the CM transaction
316 arp_ps_pkg.nowaitlock_p (p_ps_id => l_cm_ps_id);
317
318 -- Lock the PS of the transaction to be applied
319 arp_ps_pkg.nowaitlock_p (p_ps_id => l_applied_payment_schedule_id);
320
321 l_return_status := FND_API.G_RET_STS_SUCCESS;
322
323
324 BEGIN
325 --call the entity handler
326 arp_process_application.cm_application(
327 p_cm_ps_id => l_cm_ps_id,
328 p_invoice_ps_id => l_applied_payment_schedule_id,
329 p_amount_applied => l_amount_applied,
330 p_apply_date => l_apply_date,
331 p_gl_date => l_apply_gl_date,
332 p_ussgl_transaction_code => p_cm_app_rec.ussgl_transaction_code,
333 p_attribute_category => p_cm_app_rec.attribute_category,
334 p_attribute1 => p_cm_app_rec.attribute1,
335 p_attribute2 => p_cm_app_rec.attribute2,
339 p_attribute6 => p_cm_app_rec.attribute6,
336 p_attribute3 => p_cm_app_rec.attribute3,
337 p_attribute4 => p_cm_app_rec.attribute4,
338 p_attribute5 => p_cm_app_rec.attribute5,
340 p_attribute7 => p_cm_app_rec.attribute7,
341 p_attribute8 => p_cm_app_rec.attribute8,
342 p_attribute9 => p_cm_app_rec.attribute9,
343 p_attribute10 => p_cm_app_rec.attribute10,
344 p_attribute11 => p_cm_app_rec.attribute11,
345 p_attribute12 => p_cm_app_rec.attribute12,
346 p_attribute13 => p_cm_app_rec.attribute13,
347 p_attribute14 => p_cm_app_rec.attribute14,
348 p_attribute15 => p_cm_app_rec.attribute15,
349 p_global_attribute_category => p_cm_app_rec.global_attribute_category,
350 p_global_attribute1 => p_cm_app_rec.global_attribute1,
351 p_global_attribute2 => p_cm_app_rec.global_attribute2,
352 p_global_attribute3 => p_cm_app_rec.global_attribute3,
353 p_global_attribute4 => p_cm_app_rec.global_attribute4,
354 p_global_attribute5 => p_cm_app_rec.global_attribute5,
355 p_global_attribute6 => p_cm_app_rec.global_attribute6,
356 p_global_attribute7 => p_cm_app_rec.global_attribute7,
357 p_global_attribute8 => p_cm_app_rec.global_attribute8,
358 p_global_attribute9 => p_cm_app_rec.global_attribute9,
359 p_global_attribute10 => p_cm_app_rec.global_attribute10,
360 p_global_attribute11 => p_cm_app_rec.global_attribute11,
361 p_global_attribute12 => p_cm_app_rec.global_attribute12,
362 p_global_attribute13 => p_cm_app_rec.global_attribute13,
363 p_global_attribute14 => p_cm_app_rec.global_attribute14,
364 p_global_attribute15 => p_cm_app_rec.global_attribute15,
365 p_global_attribute16 => p_cm_app_rec.global_attribute16,
366 p_global_attribute17 => p_cm_app_rec.global_attribute17,
367 p_global_attribute18 => p_cm_app_rec.global_attribute18,
368 p_global_attribute19 => p_cm_app_rec.global_attribute19,
369 p_global_attribute20 => p_cm_app_rec.global_attribute20,
370 p_customer_trx_line_id => l_inv_customer_trx_line_id ,
371 p_comments => p_cm_app_rec.comments,
372 p_module_name => 'CMAPI',
373 p_module_version => p_api_version,
374 p_out_rec_application_id => l_rec_application_id,
375 p_acctd_amount_applied_from => l_acctd_amount_applied_from,
376 p_acctd_amount_applied_to => l_acctd_amount_applied_to
377 );
378
379 x_out_rec_application_id := l_rec_application_id;
380 x_acctd_amount_applied_from := l_acctd_amount_applied_from;
381 x_acctd_amount_applied_to := l_acctd_amount_applied_to;
382
383 EXCEPTION
384 WHEN OTHERS THEN
385
386 /*-------------------------------------------------------+
387 | Handle application errors that result from trapable |
388 | error conditions. The error messages have already |
389 | been put on the error stack. |
390 +-------------------------------------------------------*/
391
392 IF (SQLCODE = -20001)
393 THEN
394 ROLLBACK TO Apply_CM;
395
396 -- Display_Parameters;
397 x_return_status := FND_API.G_RET_STS_ERROR ;
398 FND_MESSAGE.SET_NAME ('AR','GENERIC_MESSAGE');
399 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','ARP_PROCESS_APPLICATION.CM_APPLICATION'||SQLERRM);
400 FND_MSG_PUB.Add;
401
402 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
403 p_count => x_msg_count,
404 p_data => x_msg_data
405 );
406 RETURN;
407 ELSE
408 RAISE;
409 END IF;
410 END;
411
412 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
413 RAISE FND_API.G_EXC_ERROR;
414 END IF;
415 IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
416 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
417 END IF;
418
419
420 /*--------------------------------+
421 | Standard check of p_commit |
422 +--------------------------------*/
423
424 IF FND_API.To_Boolean( p_commit )
425 THEN
426 IF PG_DEBUG in ('Y', 'C') THEN
427 arp_util.debug( 'committing');
428 END IF;
429 Commit;
430 END IF;
431 IF PG_DEBUG in ('Y', 'C') THEN
432 arp_util.debug('Apply ()- ');
433 END IF;
434 EXCEPTION
435 WHEN FND_API.G_EXC_ERROR THEN
436
437 IF PG_DEBUG in ('Y', 'C') THEN
438 arp_util.debug( SQLCODE, G_MSG_ERROR);
439 arp_util.debug( SQLERRM, G_MSG_ERROR);
440 END IF;
441
442 ROLLBACK TO Apply_CM;
443 x_return_status := FND_API.G_RET_STS_ERROR ;
444
445 -- Display_Parameters;
446
447 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
448 p_count => x_msg_count,
449 p_data => x_msg_data
450 );
451
452 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
453
454 IF PG_DEBUG in ('Y', 'C') THEN
458 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
455 arp_util.debug( SQLERRM, G_MSG_ERROR);
456 END IF;
457 ROLLBACK TO Apply_CM;
459
460 -- Display_Parameters;
461
462 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
463 p_count => x_msg_count,
464 p_data => x_msg_data
465 );
466
467 WHEN OTHERS THEN
468 /*-------------------------------------------------------+
469 | Handle application errors that result from trapable |
470 | error conditions. The error messages have already |
471 | been put on the error stack. |
472 +-------------------------------------------------------*/
473
474 IF (SQLCODE = -20001)
475 THEN
476
477 ROLLBACK TO Apply_CM;
478
479 --If only one error message on the stack,
480 --retrive it
481
482 x_return_status := FND_API.G_RET_STS_ERROR ;
483 FND_MESSAGE.SET_NAME ('AR','GENERIC_MESSAGE');
484 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','APPLY : '||SQLERRM);
485 FND_MSG_PUB.Add;
486
487 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
488 p_count => x_msg_count,
489 p_data => x_msg_data
490 );
491
492 RETURN;
493
494 ELSE
495 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
496 FND_MESSAGE.SET_NAME ('AR','GENERIC_MESSAGE');
497 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','APPLY : '||SQLERRM);
498 FND_MSG_PUB.Add;
499 END IF;
500
501 IF PG_DEBUG in ('Y', 'C') THEN
502 arp_util.debug( SQLCODE, G_MSG_ERROR);
503 arp_util.debug( SQLERRM, G_MSG_ERROR);
504 END IF;
505
506 ROLLBACK TO Apply_CM;
507
508 IF FND_MSG_PUB.Check_Msg_Level
509 THEN
510 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME,
511 l_api_name
512 );
513 END IF;
514
515 -- Display_Parameters;
516
517 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
518 p_count => x_msg_count,
519 p_data => x_msg_data
520 );
521
522
523 END apply_on_account;
524
525 PROCEDURE unapply_on_account(
526 p_api_version IN NUMBER,
527 p_init_msg_list IN VARCHAR2 := FND_API.G_FALSE,
528 p_commit IN VARCHAR2 := FND_API.G_FALSE,
529 p_cm_unapp_rec IN cm_unapp_rec_type,
530 x_return_status OUT NOCOPY VARCHAR2,
531 x_msg_count OUT NOCOPY NUMBER,
532 x_msg_data OUT NOCOPY VARCHAR2,
533 p_org_id IN NUMBER DEFAULT NULL)
534
535 IS
536
537 l_api_name CONSTANT VARCHAR2(20) := 'Unapply_on_account';
538 l_api_version CONSTANT NUMBER := 1.0;
539
540
541 l_cm_customer_trx_id NUMBER;
542 l_inv_customer_trx_id NUMBER;
543 l_applied_payment_schedule_id NUMBER;
544 l_receivable_application_id NUMBER;
545 l_reversal_gl_date DATE;
546 l_apply_gl_date DATE;
547 l_cm_gl_date DATE;
548
549 l_def_ids_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
550 l_val_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
551
552 l_org_return_status VARCHAR2(1); --bug7641800
553 l_org_id NUMBER;
554
555 /*Bug 12760563*/
556 l_xla_ev_rec arp_xla_events.xla_events_type;
557 Cursor ra_event_rows (p_customer_trx_id in number) IS
558 SELECT ra.receivable_application_id,
559 ra.customer_trx_id,
560 ct.trx_number
561 from ar_receivable_applications ra, ra_customer_trx ct
562 where ra.posting_control_id=-3
563 and ra.application_type = 'CM'
564 and ra.customer_trx_id=p_customer_trx_id
565 and ra.event_id is null
566 and ra.customer_trx_id = ct.customer_trx_id;
567
568 BEGIN
569 IF PG_DEBUG in ('Y', 'C') THEN
570 arp_util.debug('ar_cm_api_pub.Unapply_on_account()+ ');
571 END IF;
572
573 /*------------------------------------+
574 | Standard start of API savepoint |
575 +------------------------------------*/
576
577 SAVEPOINT Unapply_CM;
578
579 /*--------------------------------------------------+
580 | Standard call to check for call compatibility |
581 +--------------------------------------------------*/
582
583 IF NOT FND_API.Compatible_API_Call(
584 l_api_version,
585 p_api_version,
586 l_api_name,
587 G_PKG_NAME
588 )
589 THEN
590 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
591 END IF;
592
593
597
594 /*--------------------------------------------------------------+
595 | Initialize message list if p_init_msg_list is set to TRUE |
596 +--------------------------------------------------------------*/
598 IF FND_API.to_Boolean( p_init_msg_list )
599 THEN
600 FND_MSG_PUB.initialize;
601 END IF;
602
603
604 original_cm_unapp_info.cm_trx_number := p_cm_unapp_rec.cm_trx_number;
605 original_cm_unapp_info.cm_customer_trx_id := p_cm_unapp_rec.cm_customer_trx_id;
606 original_cm_unapp_info.applied_ps_id := p_cm_unapp_rec.applied_payment_schedule_id;
607 original_cm_unapp_info.inv_customer_trx_id:= p_cm_unapp_rec.inv_customer_trx_id;
608 original_cm_unapp_info.inv_trx_number := p_cm_unapp_rec.inv_trx_number;
609 original_cm_unapp_info.receivable_application_id := p_cm_unapp_rec.receivable_application_id;
610
611
612 /*-------------------------------------------------+
613 | Initialize SOB/org dependent variables |
614 +-------------------------------------------------*/
615 /* bug7641800, Added parameter to accept org_id from customer and added
616 code to set ORG accordingly. */
617 l_org_id := p_org_id;
618 l_org_return_status := FND_API.G_RET_STS_SUCCESS;
619 ar_mo_cache_utils.set_org_context_in_api
620 (
621 p_org_id =>l_org_id,
622 p_return_status =>l_org_return_status
623 );
624
625 IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
626 x_return_status := FND_API.G_RET_STS_ERROR;
627 ELSE
628 -- arp_global.init_global;
629 -- arp_standard.init_standard;
630
631 /*-----------------------------------------+
632 | Initialize return status to SUCCESS |
633 +-----------------------------------------*/
634
635 x_return_status := FND_API.G_RET_STS_SUCCESS;
636 /*---------------------------------------------+
637 | ========== Start of API Body ========== |
638 +---------------------------------------------*/
639
640 --Assign IN parameter values to local variables
641 --which are also used as assignment targets.
642
643 l_cm_customer_trx_id := p_cm_unapp_rec.cm_customer_trx_id;
644 l_inv_customer_trx_id := p_cm_unapp_rec.inv_customer_trx_id;
645 l_applied_payment_schedule_id := p_cm_unapp_rec.applied_payment_schedule_id;
646 l_receivable_application_id := p_cm_unapp_rec.receivable_application_id;
647 l_reversal_gl_date := trunc(p_cm_unapp_rec.reversal_gl_date);
648
649
650 --Derive the id's for the entered values and if both the
651 --values and the id's superceed the values
652
653 ar_cm_val_pvt.default_unapp_ids(
654 p_cm_unapp_rec.cm_trx_number ,
655 l_cm_customer_trx_id ,
656 p_cm_unapp_rec.inv_trx_number ,
657 l_inv_customer_trx_id ,
658 l_receivable_application_id,
659 p_cm_unapp_rec.installment ,
660 l_applied_payment_schedule_id ,
661 l_apply_gl_date,
662 l_def_ids_return_status
663 );
664 IF PG_DEBUG in ('Y', 'C') THEN
665 arp_util.debug( 'Cm customer trx id : '|| l_cm_customer_trx_id );
666 arp_util.debug( 'receivable app id : '|| l_receivable_application_id );
667 END IF;
668
669 ar_cm_val_pvt.default_unapp_info(
670 l_receivable_application_id,
671 l_apply_gl_date,
672 l_cm_customer_trx_id,
673 l_reversal_gl_date,
674 l_cm_gl_date);
675
676 IF PG_DEBUG in ('Y', 'C') THEN
677 arp_util.debug( 'Cm customer trx id : '|| l_cm_customer_trx_id );
678 arp_util.debug( 'receivable app id : '|| l_receivable_application_id );
679 arp_util.debug( 'reversal date : '|| l_reversal_gl_date );
680 END IF;
681 ar_cm_val_pvt.validate_unapp_info(
682 l_cm_gl_date,
683 l_receivable_application_id,
684 l_reversal_gl_date,
685 l_apply_gl_date,
686 l_val_return_status);
687
688 IF PG_DEBUG in ('Y', 'C') THEN
689 arp_util.debug( 'validation return status :'||l_val_return_status);
690 END IF;
691
692 IF l_def_ids_return_status <> FND_API.G_RET_STS_SUCCESS OR
693 l_val_return_status <> FND_API.G_RET_STS_SUCCESS THEN
694 x_return_status := FND_API.G_RET_STS_ERROR ;
695 END IF;
696
697 END IF; -- Closing IF for ORG_RET_STATUS
698
699 IF x_return_status <> FND_API.G_RET_STS_SUCCESS
700 THEN
701
702 ROLLBACK TO Unapply_CM;
703
704 x_return_status := FND_API.G_RET_STS_ERROR ;
705
706 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
707 p_count => x_msg_count,
708 p_data => x_msg_data
709 );
710
711 IF PG_DEBUG in ('Y', 'C') THEN
712 arp_util.debug( 'Error(s) occurred. Rolling back and setting status to ERROR');
713 END IF;
714 Return;
715 END IF;
716
717 IF PG_DEBUG in ('Y', 'C') THEN
718 arp_util.debug( '*******DUMP THE INPUT PARAMETERS ********');
722 END IF;
719 arp_util.debug( 'l_receivable_application_id :'||to_char(l_receivable_application_id));
720 arp_util.debug( 'l_applied_payment_schedule_id :'||to_char(l_applied_payment_schedule_id));
721 arp_util.debug( 'l_reversal_gl_date :'||to_char(l_reversal_gl_date,'DD-MON-YY'));
723
724
725 BEGIN
726 --call the entity handler.
727 arp_process_application.reverse_cm_app(
728 l_receivable_application_id,
729 l_applied_payment_schedule_id,
730 l_reversal_gl_date,
731 trunc(sysdate),
732 'CMAPI',
733 p_api_version);
734
735 /*Bug 12760563 As RCA calling Event creation code in last to stamp event in case event_id remains null*/
736 For app_rec in ra_event_rows (l_cm_customer_trx_id)
737 Loop
738
739 l_xla_ev_rec.xla_from_doc_id := app_rec.receivable_application_id;
740 l_xla_ev_rec.xla_to_doc_id := app_rec.receivable_application_id;
741 l_xla_ev_rec.xla_mode := 'O';
742 l_xla_ev_rec.xla_call := 'B';
743 l_xla_ev_rec.xla_doc_table := 'CMAPP';
744 ARP_XLA_EVENTS.create_events(p_xla_ev_rec => l_xla_ev_rec);
745 end loop;
746
747
748 EXCEPTION
749 WHEN OTHERS THEN
750
751
752 /*-------------------------------------------------------+
753 | Handle application errors that result from trapable |
754 | error conditions. The error messages have already |
755 | been put on the error stack. |
756 +-------------------------------------------------------*/
757
758 IF (SQLCODE = -20001)
759 THEN
760 ROLLBACK TO Unapply_CM;
761
762 -- Display_Parameters;
763 x_return_status := FND_API.G_RET_STS_ERROR ;
764 FND_MESSAGE.SET_NAME ('AR','GENERIC_MESSAGE');
765 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','ARP_PROCESS_APPLICATION.REVERSE_CM_APP : '||SQLERRM);
766 FND_MSG_PUB.Add;
767
768 FND_MSG_PUB.Count_And_Get( p_encoded => FND_API.G_FALSE,
769 p_count => x_msg_count,
770 p_data => x_msg_data
771 );
772 RETURN;
773 ELSE
774 RAISE;
775 END IF;
776
777 END;
778
779 /*--------------------------------+
780 | Standard check of p_commit |
781 +--------------------------------*/
782
783 IF FND_API.To_Boolean( p_commit )
784 THEN
785 IF PG_DEBUG in ('Y', 'C') THEN
786 arp_util.debug( 'committing');
787 END IF;
788 Commit;
789 END IF;
790
791 IF PG_DEBUG in ('Y', 'C') THEN
792 arp_util.debug('ar_cm_api.Unapply_on_account ()- ');
793 END IF;
794 EXCEPTION
795 WHEN FND_API.G_EXC_ERROR THEN
796
797 IF PG_DEBUG in ('Y', 'C') THEN
798 arp_util.debug( SQLCODE, G_MSG_ERROR);
799 arp_util.debug( SQLERRM, G_MSG_ERROR);
800 END IF;
801
802 ROLLBACK TO Unapply_CM;
803 x_return_status := FND_API.G_RET_STS_ERROR ;
804
805 -- Display_Parameters;
806
807 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
808 p_count => x_msg_count,
809 p_data => x_msg_data
810 );
811
812 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
813
814 IF PG_DEBUG in ('Y', 'C') THEN
815 arp_util.debug( SQLERRM, G_MSG_ERROR);
816 END IF;
817 ROLLBACK TO Unapply_CM;
818 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
819
820 -- Display_Parameters;
821
822 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
823 p_count => x_msg_count,
824 p_data => x_msg_data
825 );
826
827 WHEN OTHERS THEN
828
829 /*-------------------------------------------------------+
830 | Handle application errors that result from trapable |
831 | error conditions. The error messages have already |
832 | been put on the error stack. |
833 +-------------------------------------------------------*/
834
835 IF (SQLCODE = -20001)
836 THEN
837
838 ROLLBACK TO Unapply_CM;
839
840 x_return_status := FND_API.G_RET_STS_ERROR ;
841 FND_MESSAGE.SET_NAME ('AR','GENERIC_MESSAGE');
842 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','UNAPPLY : '||SQLERRM);
843 FND_MSG_PUB.Add;
844
845 --If only one error message on the stack,
846 --retrive it
847
848 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
849 p_count => x_msg_count,
853 RETURN;
850 p_data => x_msg_data
851 );
852
854
855 ELSE
856 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
857 FND_MESSAGE.SET_NAME ('AR','GENERIC_MESSAGE');
858 FND_MESSAGE.SET_TOKEN('GENERIC_TEXT','UNAPPLY : '||SQLERRM);
859 FND_MSG_PUB.Add;
860 END IF;
861
862 IF PG_DEBUG in ('Y', 'C') THEN
863 arp_util.debug( SQLCODE, G_MSG_ERROR);
864 arp_util.debug( SQLERRM, G_MSG_ERROR);
865 END IF;
866
867 ROLLBACK TO Unapply_CM;
868
869 IF FND_MSG_PUB.Check_Msg_Level
870 THEN
871 FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME,
872 l_api_name
873 );
874 END IF;
875
876 -- Display_Parameters;
877
878 FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
879 p_count => x_msg_count,
880 p_data => x_msg_data
881 );
882
883 END unapply_on_account;
884
885
886 END AR_CM_API_PUB;