1 PACKAGE BODY ARP_BALANCE_CHECK AS
2 /* $Header: ARBALCHB.pls 120.4.12010000.1 2008/07/24 16:19:50 appldev ship $ */
3
4 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
5 PG_BAL_CHECK_ENABLED varchar2(1) := NVL(FND_PROFILE.value('AR_ENABLE_JOURNAL_BAL_CHECK'),'Y');
6
7 /* =======================================================================
8 | PROCEDURE Check_Transaction_Balance
9 |
10 | DESCRIPTION
11 | This procedure takes sum of debits and credits for transactions
12 | and tallies that debits equal credits, if not then it sets a
13 | message on the message stack indicating that items are out of
14 | balance.
15 |
16 | PARAMETERS
17 | p_customer_trx_id IN Cash receipt id
18 | p_called_from_api IN Y-api call out
19 * ======================================================================*/
20 PROCEDURE CHECK_TRANSACTION_BALANCE(p_customer_trx_id IN VARCHAR2,
21 p_called_from_api IN VARCHAR2 default 'N') IS
22
23 CURSOR C1(p_cust_trx_id NUMBER) IS
24 SELECT sum(decode(ctlgd.account_class,
25 'REC', nvl(amount,0) * -1,
26 nvl(amount,0))) net_amount,
27 sum(decode(ctlgd.account_class,
28 'REC', nvl(acctd_amount,0) * -1,
29 nvl(acctd_amount,0))) net_acctd_amount,
30 gl_date
31 from ra_cust_trx_line_gl_dist ctlgd
32 where ctlgd.customer_trx_id = p_cust_trx_id
33 and ctlgd.account_set_flag = 'N'
34 and ctlgd.posting_control_id = -3
35 and not exists (select 'x'
36 from ra_customer_trx_lines ctl
37 where ctl.customer_trx_id = p_customer_trx_id
38 and ctl.autorule_complete_flag||'' = 'N'
39 group by ctl.customer_trx_id)
40 group by customer_trx_id, gl_date;
41
42 l_amount NUMBER;
43 l_acctd_amount NUMBER;
44 l_no_balance VARCHAR2(1):= 'N';
45 -- OKL LLCA Bug 6125678
46 l_return_status VARCHAR2(1) := fnd_api.g_ret_sts_success;
47 l_msg_data VARCHAR2(2000);
48 l_msg_count NUMBER;
49 l_customer_rec ra_customer_trx%ROWTYPE;
50 l_gen_line_level_bal_flag VARCHAR(1) := 'N';
51 excep_set_org_rem_amt_r12 EXCEPTION;
52
53
54 BEGIN
55
56 IF PG_DEBUG in ('Y', 'C') THEN
57 arp_standard.debug('ARP_BALANCE_CHK.Check_Transaction_Balance (+)' );
58 END IF;
59
60 IF p_customer_trx_id IS NOT NULL THEN
61
62 --- OKL LLCA Bug 6125678
63 l_customer_rec.customer_trx_id := p_customer_trx_id;
64 -- Check the batch source flag
65
66 SELECT NVL(gen_line_level_bal_flag,'N')
67 INTO l_gen_line_level_bal_flag
68 FROM ra_batch_sources ra, ra_customer_trx rt
69 WHERE ra.batch_source_id = rt.batch_source_id
70 AND rt.customer_trx_id = p_customer_trx_id;
71
72 IF l_gen_line_level_bal_flag = 'Y' THEN
73 ARP_DET_DIST_PKG.set_original_rem_amt_r12
74 ( p_customer_trx => l_customer_rec,
75 x_return_status => l_return_status,
76 x_msg_count => l_msg_count,
77 x_msg_data => l_msg_data,
78 p_from_llca => 'Y');
79
80
81 IF l_return_status <> fnd_api.g_ret_sts_success THEN
82 RAISE excep_set_org_rem_amt_r12;
83 END IF;
84
85 END IF;
86 --- OKL LLCA End
87 --bug6762463
88 IF PG_BAL_CHECK_ENABLED = 'Y' THEN
89 FOR c2 in c1(p_customer_trx_id) LOOP
90
91 l_amount := c2.net_amount;
92 l_acctd_amount := c2.net_acctd_amount;
93
94 IF l_amount <> 0 OR l_acctd_amount <> 0 THEN
95 /* The exception could have been raised here, but continuing to
96 print the debug messages */
97 l_no_balance := 'Y' ;
98 END IF;
99 IF PG_DEBUG in ('Y', 'C') THEN
100 arp_standard.debug('GL_DATE : '||to_char(c2.gl_date,'DD-MON-YYYY'));
101 arp_standard.debug('Net Amount :' || l_amount);
102 arp_standard.debug('Net Acctd Amount :' || l_acctd_amount);
103 END IF;
104 END LOOP;
105
106 --------------------------------------------------------
107 --Set the message on the message stack
108 --------------------------------------------------------
109 IF l_no_balance = 'Y' THEN
110
111 IF p_called_from_api = 'Y' THEN
112 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
113 fnd_msg_pub.Add;
114 END IF;
115
116 RAISE out_of_balance;
117
118 END IF;
119
120 ELSE
121 IF PG_DEBUG in ('Y', 'C') THEN
122 arp_standard.debug('Profile AR: Enable Journal Balance Check is disabled ');
123 END IF;
124 END IF;
125 END IF; -- p_customer_trx_id is not null , bug6762463
126
127 IF PG_DEBUG in ('Y', 'C') THEN
128 arp_standard.debug('ARP_BALANCE_CHK.Check_Transaction_Balance (-)' );
129 END IF;
130
131 EXCEPTION
132 WHEN out_of_balance THEN
133 IF PG_DEBUG in ('Y', 'C') THEN
134 arp_standard.debug('ARP_BALANCE_CHK.Check_Transaction_Balance - OUT_OF_BALANCE');
135 END IF;
136 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
137 app_exception.raise_exception;
138 WHEN NO_DATA_FOUND THEN
139 /* Case for invoice with rules */
140 IF PG_DEBUG in ('Y', 'C') THEN
141 arp_standard.debug( 'ARP_BALANCE_CHK.Check_Transaction_Balance - NO_DATA_FOUND' );
142 END IF;
143 WHEN excep_set_org_rem_amt_r12 THEN --LLCA
144 IF PG_DEBUG in ('Y', 'C') THEN
145 arp_standard.debug('EXCEPTION_set_original_rem_amt_r12 error count:'||l_msg_count);
146 arp_standard.debug('last error:'||l_msg_data);
147 END IF;
148 RAISE;
149
150 WHEN OTHERS THEN
151 IF PG_DEBUG in ('Y', 'C') THEN
152 arp_standard.debug( 'ARP_BALANCE_CHK.Check_Transaction_Balance - OTHERS' );
153 END IF;
154 RAISE;
155
156 END CHECK_TRANSACTION_BALANCE;
157
158 /* =======================================================================
159 | PROCEDURE Check_Recp_Balance
160 |
161 | DESCRIPTION
162 | This procedure takes sum of debits and credits for receipts and
163 | adjustments including discounts and tallies that debits equal
164 | credits, if not then it sets a message on the message stack
165 | indicating that items are out of balance.
166 |
167 | PARAMETERS
168 | p_cr_id IN Cash receipt id
169 | p_request_id IN Request id
170 | p_called_from_api IN Y-api call out
171 * ======================================================================*/
172 PROCEDURE CHECK_RECP_BALANCE(
173 p_cr_id IN NUMBER,
174 p_request_id IN NUMBER,
175 p_called_from_api IN VARCHAR2 default 'N') IS
176 cursor c1(p_cr_id IN NUMBER) is
177 select sum(nvl(amount_dr,0)) sum_amount_dr,
178 sum(nvl(amount_cr,0)) sum_amount_cr,
179 sum(nvl(acctd_amount_dr,0)) sum_acctd_amount_dr,
180 sum(nvl(acctd_amount_cr,0)) sum_acctd_amount_cr,
181 max(src.cc_flag) cc_flag, src.gl_date
182 from (select cash_receipt_id cr_id,
183 misc_cash_distribution_id src_id,
184 'MCD' src_tab,
185 'N' cc_flag,
186 gl_date
187 from ar_misc_cash_distributions
188 where cash_receipt_id = p_cr_id
189 and posting_control_id = -3
190 UNION ALL
191 select cash_receipt_id cr_id,
192 cash_receipt_history_id src_id,
193 'CRH' src_tab,
194 'N' cc_flag,
195 gl_date
196 from ar_cash_receipt_history
197 where cash_receipt_id = p_cr_id
198 and posting_control_id = -3
199 and nvl(postable_flag,'Y') = 'Y'
200 UNION ALL
201 select cash_receipt_id cr_id,
202 receivable_application_id src_id,
203 'RA' src_tab,
204 decode(amount_applied_from,NULL,
205 'N',
206 'Y') cc_flag,
207 gl_date
208 from ar_receivable_applications
209 where cash_receipt_id = p_cr_id
210 and nvl(confirmed_flag,'Y') = 'Y'
211 and nvl(postable,'Y') = 'Y'
212 and posting_control_id = -3) src,
213 ar_distributions ard
214 where ard.source_id = src.src_id
215 and ard.source_table = src.src_tab
216 group by src.gl_date;
217
218 l_no_balance VARCHAR2(1) := 'N';
219
220 BEGIN
221
222 IF PG_DEBUG in ('Y', 'C') THEN
223 arp_standard.debug('ARP_BALANCE_CHK.CHECK_RECP_BALANCE (+)');
224 END IF;
225
226 IF PG_BAL_CHECK_ENABLED = 'Y' THEN
227
228 IF p_cr_id IS NOT NULL AND arp_global.sysparam.accounting_method = 'ACCRUAL' THEN
229
230 FOR c2 in c1(p_cr_id) LOOP
231
232 IF (c2.sum_amount_dr <> c2.sum_amount_cr AND c2.cc_flag = 'N') OR
233 (c2.sum_acctd_amount_dr <> c2.sum_acctd_amount_cr) THEN
234
235 /* Exception Out_of_balance could have been raised here. But continuing the flow
236 to print debug messages */
237 l_no_balance := 'Y' ;
238 END IF;
239
240 IF PG_DEBUG in ('Y', 'C') THEN
241 arp_standard.debug('GL_DATE : '||to_char(c2.gl_date,'DD-MON-YYYY'));
242 arp_standard.debug('Sum_amount_dr :' || c2.sum_amount_dr);
243 arp_standard.debug('Sum_amount_cr :' || c2.sum_amount_cr);
244 arp_standard.debug('Sum_acctd_amount_dr : '||c2.sum_acctd_amount_dr);
245 arp_standard.debug('Sum_acctd_amount_cr : '||c2.sum_acctd_amount_cr);
246 arp_standard.debug('CC_flag : '||c2.cc_flag);
247 END IF;
248 END LOOP;
249
250 --------------------------------------------------------
251 --Set the message on the message stack
252 --------------------------------------------------------
253 IF l_no_balance = 'Y' THEN
254
255 IF p_called_from_api = 'Y' THEN
256 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
257 fnd_msg_pub.Add;
258 END IF;
259
260 RAISE out_of_balance;
261
262 END IF;
263
264 END IF; --p_receipt id is NOT NULL
265
266 ELSE
267 IF PG_DEBUG in ('Y', 'C') THEN
268 arp_standard.debug('Profile AR: Enable Journal Balance Check is disabled ');
269 END IF;
270 END IF;
271
272
273 IF PG_DEBUG in ('Y', 'C') THEN
274 arp_standard.debug('ARP_BALANCE_CHK.CHECK_RECP_BALANCE (-)');
275 END IF;
276
277 EXCEPTION
278 WHEN out_of_balance THEN
279 IF PG_DEBUG in ('Y', 'C') THEN
280 arp_standard.debug('ARP_BALANCE_CHK.CHECK_RECP_BALANCE - OUT_OF_BALANCE');
281 END IF;
282 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
283 app_exception.raise_exception;
284
285 WHEN OTHERS THEN
286 IF PG_DEBUG in ('Y', 'C') THEN
287 arp_standard.debug('ARP_BALANCE_CHK.CHECK_RECP_BALANCE - OTHERS');
288 END IF;
289 RAISE;
290
291 END CHECK_RECP_BALANCE;
292
293 /* =======================================================================
294 | PROCEDURE Check_Adj_Balance
295 |
296 | DESCRIPTION
297 | This procedure takes sum of debits and credits for adjustments
298 | tallies that debits equal credits, if not then it sets a message
299 | on the message stack indicating that items are out of balance.
300 | For Non postable adjustments, it makes sure that the amount is
301 | equal to the amounts assigned to different buckets
302 |
303 | PARAMETERS
304 | p_adj_id IN Adjustment id
305 | p_request_id IN Request id
306 | p_called_from_api IN Y-api call out
307 * ======================================================================*/
308 PROCEDURE CHECK_ADJ_BALANCE(
309 p_adj_id IN NUMBER,
310 p_request_id IN NUMBER,
311 p_called_from_api IN VARCHAR2 default 'N') IS
312
313
314 l_amt_dr NUMBER;
315 l_amt_cr NUMBER;
316 l_acctd_amt_dr NUMBER;
317 l_acctd_amt_cr NUMBER;
318 l_amount NUMBER;
319 l_calc_amount NUMBER;
320 l_status VARCHAR2(1); /*5017553*/
321
322 BEGIN
323 IF PG_DEBUG in ('Y', 'C') THEN
324 arp_standard.debug('ARP_BALANCE_CHK.CHECK_ADJ_BALANCE (+)');
325 END IF;
326
327 IF PG_BAL_CHECK_ENABLED = 'Y' THEN
328
329 IF p_adj_id IS NOT NULL AND arp_global.sysparam.accounting_method = 'ACCRUAL' THEN
330
331 /* Check amount_dr equals to amount_cr */
332
333 select sum(nvl(amount_dr,0)), sum(nvl(amount_cr,0)),
334 sum(nvl(acctd_amount_dr,0)), sum(nvl(acctd_amount_cr,0))
335 into l_amt_dr, l_amt_cr, l_acctd_amt_dr, l_acctd_amt_cr
336 from (select adjustment_id src_id,
337 'ADJ' src_tab
338 from ar_adjustments
339 where adjustment_id = p_adj_id
340 and nvl(postable,'Y') = 'Y'
341 and posting_control_id = -3) src,
342 ar_distributions ard
343 where ard.source_id = src.src_id
344 and ard.source_table = src.src_tab;
345
346 --------------------------------------------------------
347 --Set the message on the message stack
348 --------------------------------------------------------
349 IF (l_amt_dr <> l_amt_cr) OR (l_acctd_amt_dr <> l_acctd_amt_cr) THEN
350
351 IF p_called_from_api = 'Y' THEN
352
353 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
354 fnd_msg_pub.Add;
355
356 END IF;
357
358 RAISE out_of_balance;
359
360 END IF;
361
362 /* Check that Amount = line_adjusted+tax+adjusted+freight_adjusted+
363 receivables_charges_adjusted */
364 select nvl(amount,0), nvl(line_adjusted,0)+nvl(tax_adjusted,0)+
365 nvl(freight_adjusted,0)+nvl(receivables_charges_adjusted,0),
366 status
367 into l_amount, l_calc_amount,l_status
368 from ar_adjustments
369 where adjustment_id = p_adj_id;
370
371 IF l_amount <> l_calc_amount AND l_status = 'A' THEN
372 IF p_called_from_api = 'Y' THEN
373
374 fnd_message.set_name('AR','AR_ADJ_AMT_NO_MATCH');
375 fnd_msg_pub.Add;
376
377 END IF;
378
379 RAISE amount_mismatch;
380 END IF;
381
382 END IF; --adjustment id is not null
383
384 ELSE
385 IF PG_DEBUG in ('Y', 'C') THEN
386 arp_standard.debug('Profile AR: Enable Journal Balance Check is disabled ');
387 END IF;
388 END IF;
389
390 IF PG_DEBUG in ('Y', 'C') THEN
391 arp_standard.debug('ARP_BALANCE_CHK.CHECK_ADJ_BALANCE (-)');
392 END IF;
393
394 EXCEPTION
395 WHEN NO_DATA_FOUND THEN
396 IF PG_DEBUG in ('Y', 'C') THEN
397 arp_standard.debug('ARP_BALANCE_CHK.CHECK_ADJ_BALANCE - NO_DATA_FOUND');
398 END IF;
399 RAISE;
400 WHEN out_of_balance THEN
401 IF PG_DEBUG in ('Y', 'C') THEN
402 arp_standard.debug('ARP_BALANCE_CHK.CHECK_ADJ_BALANCE - OUT_OF_BALANCE');
403 arp_standard.debug('Adjustment_id = '||p_adj_id);
404 arp_standard.debug('Amount Debit = '||l_amt_dr);
405 arp_standard.debug('Amount Credit = '||l_amt_cr);
406 arp_standard.debug('Acctd Amount Debit = '||l_acctd_amt_dr);
407 arp_standard.debug('Acctd AmountCredit = '||l_acctd_amt_cr);
408 END IF;
409 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
410 app_exception.raise_exception;
411
412 WHEN amount_mismatch THEN
413 IF PG_DEBUG in ('Y', 'C') THEN
417 arp_standard.debug('Sum of Buckets = '||l_calc_amount);
414 arp_standard.debug('ARP_BALANCE_CHK.CHECK_ADJ_BALANCE -AMOUNT_MISMATCH');
415 arp_standard.debug('Adjustment_id = '||p_adj_id);
416 arp_standard.debug('Amount = '||l_amount);
418 END IF;
419 fnd_message.set_name('AR','AR_ADJ_AMT_NO_MATCH');
420 app_exception.raise_exception;
421 WHEN OTHERS THEN
422 IF PG_DEBUG in ('Y', 'C') THEN
423 arp_standard.debug('ARP_BALANCE_CHK.CHECK_RECP_BALANCE - OTHERS');
424 END IF;
425 RAISE;
426
427 END CHECK_ADJ_BALANCE;
428
429 /* =======================================================================
430 | PROCEDURE Check_Appln_Balance
431 |
432 | DESCRIPTION
433 | This procedure takes sum of debits and credits for CM Applications
434 | tallies that debits equal credits, if not then it sets a message
435 | on the message stack indicating that items are out of balance.
436 |
437 | PARAMETERS
438 | p_receivable_application_id IN Receivable Application ID
439 | p_request_id IN Request id
440 | p_called_from_api IN Y-api call out
441 * ======================================================================*/
442 PROCEDURE CHECK_APPLN_BALANCE(
443 p_receivable_application_id IN NUMBER,
444 p_request_id IN NUMBER,
445 p_called_from_api IN VARCHAR2 default 'N') IS
446
447 l_amt_dr NUMBER;
448 l_amt_cr NUMBER;
449 l_acctd_amt_dr NUMBER;
450 l_acctd_amt_cr NUMBER;
451
452 BEGIN
453
454 IF PG_DEBUG in ('Y', 'C') THEN
455 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE (+)');
456 END IF;
457
458 IF PG_BAL_CHECK_ENABLED = 'Y' THEN
459
460 IF p_receivable_application_id IS NOT NULL
461 AND arp_global.sysparam.accounting_method = 'ACCRUAL' THEN
462
463 select sum(nvl(amount_dr,0)), sum(nvl(amount_cr,0)),
464 sum(nvl(acctd_amount_dr,0)), sum(nvl(acctd_amount_cr,0))
465 into l_amt_dr, l_amt_cr, l_acctd_amt_dr, l_acctd_amt_cr
466 from (select receivable_application_id src_id,
467 'RA' src_tab
468 from ar_receivable_applications
469 where receivable_application_id = p_receivable_application_id
470 and nvl(postable,'Y') = 'Y'
471 and posting_control_id = -3) src,
472 ar_distributions ard
473 where ard.source_id = src.src_id
474 and ard.source_table = src.src_tab;
475
476 --------------------------------------------------------
477 --Set the message on the message stack
478 --------------------------------------------------------
479 IF (l_amt_dr <> l_amt_cr) OR (l_acctd_amt_dr <> l_acctd_amt_cr) THEN
480 IF p_called_from_api = 'Y' THEN
481
482 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
483 fnd_msg_pub.Add;
484
485 END IF;
486
487 RAISE out_of_balance;
488
489 END IF;
490
491 END IF; --receivable application id is not null
492
493 ELSE
494 IF PG_DEBUG in ('Y', 'C') THEN
495 arp_standard.debug('Profile AR: Enable Journal Balance Check is disabled ');
496 END IF;
497 END IF;
498
499 IF PG_DEBUG in ('Y', 'C') THEN
500 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE (-)');
501 END IF;
502
503 EXCEPTION
504 WHEN NO_DATA_FOUND THEN
505 /* Exception need not be raised as this can happen when the Application
506 is non postable */
507 IF PG_DEBUG in ('Y', 'C') THEN
508 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE - NO_DATA_FOUND');
509 END IF;
510 WHEN out_of_balance THEN
511 IF PG_DEBUG in ('Y', 'C') THEN
512 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE - OUT_OF_BALANCE');
513 arp_standard.debug('Receivable Application_id = '||p_receivable_application_id);
514 arp_standard.debug('Amount Debit = '||l_amt_dr);
515 arp_standard.debug('Amount Credit = '||l_amt_cr);
516 arp_standard.debug('Acctd Amount Debit = '||l_acctd_amt_dr);
517 arp_standard.debug('Acctd AmountCredit = '||l_acctd_amt_cr);
518 END IF;
519 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
520 app_exception.raise_exception;
521 WHEN OTHERS THEN
522 IF PG_DEBUG in ('Y', 'C') THEN
523 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE - OTHERS');
524 END IF;
525 RAISE;
526
527 END CHECK_APPLN_BALANCE;
528
529 /* =======================================================================
530 | PROCEDURE Check_Appln_Balance
531 |
532 | DESCRIPTION
533 | This procedure takes sum of debits and credits for Receipt Applications.
534 | tallies that debits equal credits, if not then it sets a message
535 | on the message stack indicating that items are out of balance.
536 |
537 | PARAMETERS
538 | p_receivable_application_id1 IN Receivable Application ID
539 | p_receivable_application_id2 IN Receivable Application ID of the pair
540 | p_request_id IN Request id
541 | p_called_from_api IN Y-api call out
545 p_receivable_application_id2 IN NUMBER,
542 * ======================================================================*/
543 PROCEDURE CHECK_APPLN_BALANCE(
544 p_receivable_application_id1 IN NUMBER,
546 p_request_id IN NUMBER,
547 p_called_from_api IN VARCHAR2 default 'N') IS
548
549 l_amt_dr NUMBER;
550 l_amt_cr NUMBER;
551 l_acctd_amt_dr NUMBER;
552 l_acctd_amt_cr NUMBER;
553 l_cc_flag VARCHAR2(1);
554
555 BEGIN
556
557 IF PG_DEBUG in ('Y', 'C') THEN
558 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE (+) -> for Receipt Applications');
559 END IF;
560
561 IF PG_BAL_CHECK_ENABLED = 'Y' THEN
562
563 IF p_receivable_application_id1 IS NOT NULL
564 AND p_receivable_application_id2 IS NOT NULL
565 AND arp_global.sysparam.accounting_method = 'ACCRUAL' THEN
566
567 select sum(nvl(amount_dr,0)), sum(nvl(amount_cr,0)),
568 sum(nvl(acctd_amount_dr,0)), sum(nvl(acctd_amount_cr,0)),
569 max(src.cc_flag) cc_flag
570 into l_amt_dr, l_amt_cr, l_acctd_amt_dr, l_acctd_amt_cr, l_cc_flag
571 from (select receivable_application_id src_id,
572 'RA' src_tab,
573 decode(amount_applied_from,NULL,
574 'N',
575 'Y') cc_flag
576 from ar_receivable_applications
577 where ( receivable_application_id = p_receivable_application_id1
578 or receivable_application_id = p_receivable_application_id2)
579 and nvl(postable,'Y') = 'Y'
580 and posting_control_id = -3) src,
581 ar_distributions ard
582 where ard.source_id = src.src_id
583 and ard.source_table = src.src_tab;
584
585 --------------------------------------------------------
586 --Set the message on the message stack
587 --------------------------------------------------------
588 IF (((l_amt_dr <> l_amt_cr) AND (l_cc_flag = 'N'))
589 OR (l_acctd_amt_dr <> l_acctd_amt_cr)) THEN
590 IF p_called_from_api = 'Y' THEN
591
592 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
593 fnd_msg_pub.Add;
594
595 END IF;
596
597 RAISE out_of_balance;
598
599 END IF;
600
601 END IF; --receivable application ids are not null
602
603 ELSE
604 IF PG_DEBUG in ('Y', 'C') THEN
605 arp_standard.debug('Profile AR: Enable Journal Balance Check is disabled ');
606 END IF;
607 END IF;
608
609 IF PG_DEBUG in ('Y', 'C') THEN
610 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE (-) -> for Receipt Applications');
611 END IF;
612
613 EXCEPTION
614 WHEN NO_DATA_FOUND THEN
615 /* Exception need not be raised as this can happen when the Application
616 is non postable */
617 IF PG_DEBUG in ('Y', 'C') THEN
618 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE - NO_DATA_FOUND');
619 END IF;
620 WHEN out_of_balance THEN
621 IF PG_DEBUG in ('Y', 'C') THEN
622 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE - OUT_OF_BALANCE');
623 arp_standard.debug('Receivable Application_id1 = '||p_receivable_application_id1);
624 arp_standard.debug('Receivable Application_id2 = '||p_receivable_application_id2);
625 arp_standard.debug('Amount Debit = '||l_amt_dr);
626 arp_standard.debug('Amount Credit = '||l_amt_cr);
627 arp_standard.debug('Acctd Amount Debit = '||l_acctd_amt_dr);
628 arp_standard.debug('Acctd AmountCredit = '||l_acctd_amt_cr);
629 END IF;
630 fnd_message.set_name('AR','AR_AMOUNTS_NO_MATCH');
631 app_exception.raise_exception;
632 WHEN OTHERS THEN
633 IF PG_DEBUG in ('Y', 'C') THEN
634 arp_standard.debug('ARP_BALANCE_CHK.CHECK_APPLN_BALANCE - OTHERS -> for Receipt Applications');
635 END IF;
636 RAISE;
637
638 END CHECK_APPLN_BALANCE;
639
640 END ARP_BALANCE_CHECK;