[Home] [Help]
PACKAGE BODY: APPS.JL_AR_RECEIVABLE_APPLICATIONS
Source
1 PACKAGE BODY jl_ar_receivable_applications AS
2 /* $Header: jlbrrrab.pls 120.22 2011/07/12 20:55:53 abuissa ship $ */
3
4 /*----------------------------------------------------------------------------*
5 | PRIVATE FUNCTIONS/PROCEDURES |
6 *----------------------------------------------------------------------------*/
7
8 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
9
10 PROCEDURE adjustment_generation (
11 x_user_id IN NUMBER,
12 x_rectrx_id IN NUMBER,
13 x_acc_id IN NUMBER,
14 x_amount IN NUMBER,
15 x_receipt_date IN DATE,
16 x_payment_schedule_id IN NUMBER,
17 x_cash_receipt_id IN NUMBER,
18 x_customer_trx_id IN NUMBER
19 )
20 IS
21
22 adj_rec ar_adjustments%ROWTYPE;
23 x_approved_amount VARCHAR2(1);
24 x_adjustment_id ar_adjustments.adjustment_id%TYPE;
25 x_adjustment_number ar_adjustments.adjustment_number%TYPE;
26 x_msg_count NUMBER :=0;
27 x_msg_data VARCHAR2(2000);
28 x_return_status VARCHAR2(1);
29 x_data VARCHAR2(4000);
30 x_msgindex_out NUMBER;
31 x_trans_date Date;
32 x_rcpt_out Date;
33 x_def_rule varchar2(100);
34 x_err_msg varchar2(1000);
35 l_rec_appln_id NUMBER; --bug 12323016
36 l_result boolean;
37
38 -- variables added for bug 12742020
39 data_error exception;
40 x_floating NUMBER;
41 x_rec_date DATE;
42 x_city VARCHAR2(60);
43 x_state VARCHAR2(60);
44 x_payment_action VARCHAR2(1);
45 x_calendar VARCHAR2(60);
46 x_rec_date_char VARCHAR2(10);
47 x_rec_workdate_char VARCHAR2(10);
48 x_rec_workdate DATE;
49 x_check_date_return_code NUMBER(1);
50 x_org_id ar_payment_schedules.org_id%TYPE;
51
52
53 BEGIN
54
55 /* Check if the adjustment amount is within the limit from the user */
56 fnd_file.put_line(fnd_file.log,'adjgen1');
57 fnd_file.put_line(fnd_file.log,' adjustment generation');
58
59 BEGIN
60 SELECT 'Y'
61 INTO x_approved_amount
62 FROM ar_approval_user_limits araul,
63 gl_sets_of_books glsb,
64 ar_system_parameters arsp
65 WHERE araul.user_id = x_user_id
66 AND araul.document_type = 'ADJ'
67 AND glsb.set_of_books_id = arsp.set_of_books_id
68 AND araul.currency_code = glsb.currency_code
69 AND araul.amount_to >= x_amount
70 AND araul.amount_from <= x_amount;
71 EXCEPTION
72 WHEN NO_DATA_FOUND THEN
73 x_approved_amount:= 'N';
74 END;
75
76 --Bug 12323016 start
77 BEGIN
78 SELECT receivable_application_id
79 INTO l_rec_appln_id
80 FROM ar_receivable_applications_all
81 WHERE cash_receipt_id = x_cash_receipt_id
82 AND applied_payment_schedule_id = x_payment_schedule_id;
83 EXCEPTION
84 WHEN OTHERS THEN null;
85 END;
86 --Bug 12323016 end
87
88 SELECT trx_date
89 INTO x_trans_date
90 FROM ra_customer_trx
91 WHERE customer_trx_id = x_customer_trx_id;
92
93 --Bug 12742020 start
94
95 /* Get city and State */
96
97 SELECT loc.city,
98 loc.state,
99 arps.org_id
100 INTO x_city,
101 x_state,
102 x_org_id
103 FROM hz_locations loc,
104 hz_cust_acct_sites ad,
105 hz_party_sites pty,
106 ra_customer_trx ract,
107 hz_cust_site_uses rasu,
108 ar_payment_schedules arps,
109 jl_br_ar_collection_docs dc
110 WHERE dc.payment_schedule_id = x_payment_schedule_id
111 AND arps.payment_schedule_id = dc.payment_schedule_id
112 AND ract.customer_trx_id = arps.customer_trx_id
113 AND rasu.site_use_id = ract.bill_to_site_use_id
114 AND ad.cust_acct_site_id = rasu.cust_acct_site_id
115 AND ad.party_site_id = pty.party_site_id
116 AND loc.location_id = pty.location_id;
117
118 SELECT distinct nvl(arrma.floating,0)
119 INTO x_floating
120 FROM ar_receipt_methods arrm,
121 ar_system_parameters arsp,
122 ar_payment_schedules arps,
123 jl_br_ar_collection_docs dc,
124 jl_br_ar_rec_met_accts_ext arrma
125 WHERE dc.payment_schedule_id = x_payment_schedule_id
126 AND arps.payment_schedule_id = dc.payment_schedule_id
127 AND arrma.bank_account_id = dc.bank_account_id
128 AND arrma.receipt_method_id = dc.receipt_method_id
129 AND arrm.receipt_method_id = arrma.receipt_method_id;
130
131 /* Get Payment Action and Calendar */
132
133 -- Payment Action = 3 means 'Keep', no validation needed
134 x_payment_action := nvl(jl_zz_sys_options_pkg.get_payment_action_AR(x_org_id),'3');
135 x_calendar := jl_zz_sys_options_pkg.get_calendar(x_org_id);
136
137 fnd_file.put_line(fnd_file.log,' x_org_id='||x_org_id);
138 fnd_file.put_line(fnd_file.log,' x_payment_action='||x_payment_action);
139 fnd_file.put_line(fnd_file.log,' x_calendar='||x_calendar);
140
141 /* Check if the date is a workday date */
142
143 SELECT x_receipt_date + x_floating
144 INTO x_rec_date
145 FROM dual;
146
147 -- l_result := ARP_STANDARD.validate_and_default_gl_date(x_rec_date,x_trans_date,null,null,null,null,null,null,null,null,null,null,x_rcpt_out,x_def_rule,x_err_msg);
148
149 select to_char(x_rec_date,'DD-MM-YYYY')
150 into x_rec_date_char
151 from dual;
152
153 jl_br_workday_calendar.jl_br_check_date( x_rec_date_char,
154 x_calendar,
155 x_city,
156 x_payment_action,
157 x_rec_workdate_char,
158 x_check_date_return_code,
159 x_state);
160
161 IF x_check_date_return_code = -1 THEN
162 RAISE DATA_ERROR;
163 END IF;
164
165 select to_date(x_rec_workdate_char,'DD-MM-YYYY')
166 into x_rec_workdate
167 from dual;
168
169 --Bug 12742020 end
170
171 fnd_file.put_line(fnd_file.log,'After validate and def');
172 SELECT x_user_id,
173 sysdate,
174 x_user_id,
175 x_user_id,
176 sysdate,
177 x_amount,
178 sysdate,
179 -- bug 12742020 x_rcpt_out,
180 x_rec_workdate,
181 arsp.set_of_books_id,
182 x_acc_id,
183 'CHARGES',
184 decode(x_approved_amount,'Y','A','M'),
185 decode(x_approved_amount,'Y','A','W'),
186 x_cash_receipt_id,
187 x_customer_trx_id,
188 x_payment_schedule_id,
189 x_rectrx_id,
190 'ARXCAERA',
191 decode(x_approved_amount,'Y','Y','N'),
192 decode(x_approved_amount,'Y',x_user_id,NULL),
193 -3,
194 x_amount,
195 l_rec_appln_id, --bug 12323016
196 org_id
197 INTO adj_rec.LAST_UPDATED_BY,
198 adj_rec.LAST_UPDATE_DATE,
199 adj_rec.LAST_UPDATE_LOGIN,
200 adj_rec.CREATED_BY,
201 adj_rec.CREATION_DATE,
202 adj_rec.AMOUNT,
203 adj_rec.APPLY_DATE,
204 adj_rec.GL_DATE,
205 adj_rec.SET_OF_BOOKS_ID,
206 adj_rec.CODE_COMBINATION_ID,
207 adj_rec.TYPE,
208 adj_rec.ADJUSTMENT_TYPE,
209 adj_rec.STATUS,
210 adj_rec.ASSOCIATED_CASH_RECEIPT_ID,
211 adj_rec.CUSTOMER_TRX_ID,
212 adj_rec.PAYMENT_SCHEDULE_ID,
213 adj_rec.RECEIVABLES_TRX_ID,
214 adj_rec.CREATED_FROM,
215 adj_rec.POSTABLE,
216 adj_rec.APPROVED_BY,
217 adj_rec.POSTING_CONTROL_ID,
218 adj_rec.ACCTD_AMOUNT,
219 adj_rec.ASSOCIATED_APPLICATION_ID, --bug 12323016
220 adj_rec.ORG_ID
221 FROM ar_system_parameters arsp;
222 fnd_file.put_line(fnd_file.log,'After ar_system_params');
223
224 arp_util.enable_debug;
225
226 fnd_file.put_line(fnd_file.log,'Before create_adjustment');
227 ar_adjust_pub.create_adjustment( p_api_name => 'AR_ADJUST_PUB',
228 p_api_version => 1.0,
229 p_msg_count => x_msg_count,
230 p_msg_data => x_msg_data,
231 p_return_status => x_return_status,
232 p_adj_rec => adj_rec,
233 p_new_adjust_number => x_adjustment_number,
234 p_new_adjust_id => x_adjustment_id);
235 fnd_file.put_line(fnd_file.log,'After create_adjustment');
236
237 IF PG_DEBUG in ('Y', 'C') THEN
238 arp_util.debug ('adjustment_generation: ' || 'return status: ' || x_return_status);
239 arp_util.debug ('adjustment_generation: ' || 'msg_count : ' || x_msg_count);
240 arp_util.debug ('adjustment_generation: ' || 'msg_data : ' || x_msg_data);
241 END IF;
242
243
244 IF (x_return_status <> 'S') THEN
245 IF PG_DEBUG in ('Y', 'C') THEN
246 arp_util.debug('adjustment_generation: ' || '>>>>>>>>>> Problems during Adjustment Creation');
247 arp_util.debug('adjustment_generation: ' || 'x_return_status : ' || x_return_status);
248 arp_util.debug('adjustment_generation: ' || 'x_msg_count : ' || x_msg_count);
249 arp_util.debug('adjustment_generation: ' || 'x_msg_data : ' || x_msg_data);
250 END IF;
251
252 IF (x_msg_count > 0) THEN
253 FND_MSG_PUB.Get(FND_MSG_PUB.G_FIRST,FND_API.G_TRUE,x_data,x_msgindex_out);
254 FND_MESSAGE.Set_Encoded(x_data);
255 app_exception.raise_exception;
256 ELSE
257 app_exception.raise_exception;
258 END IF;
259
260 END IF;
261
262 IF PG_DEBUG in ('Y', 'C') THEN
263 arp_util.debug ('adjustment_generation: ' || 'Adjustment ID created : ' || x_adjustment_id);
264 arp_util.debug ('adjustment_generation: ' || 'Adjustment Number created : ' || x_adjustment_number);
265 END IF;
266
267 EXCEPTION
268 WHEN DATA_ERROR THEN
269 fnd_file.put_line(FND_FILE.log, 'Error in Workday Calendar check date!');
270 RAISE;
271 WHEN OTHERS THEN
272 fnd_file.put_line(fnd_file.log,'Exception in Procedure adjustment_generation :'||SQLERRM );
273 RAISE;
274
275 END adjustment_generation;
276
277 PROCEDURE get_accounts (x_rcpt_method_id IN NUMBER,
278 x_bank_acct_id IN NUMBER,
279 x_writeoff_tolerance IN OUT NOCOPY NUMBER,
280 x_writeoff_amount IN OUT NOCOPY NUMBER,
281 x_writeoff_ccid IN OUT NOCOPY NUMBER,
282 x_writeoff_rectrx_id IN OUT NOCOPY NUMBER,
283 x_calc_interest_ccid IN OUT NOCOPY NUMBER,
284 x_calc_interest_rectrx_id IN OUT NOCOPY NUMBER,
285 x_int_revenue_ccid IN OUT NOCOPY NUMBER,
286 x_int_revenue_rectrx_id IN OUT NOCOPY NUMBER,
287 x_return IN OUT NOCOPY NUMBER) IS
288 BEGIN
289
290 x_return := 0;
291 SELECT writeoff_perc_tolerance,
292 writeoff_amount_tolerance,
293 interest_writeoff_rectrx_id,
294 interest_writeoff_ccid,
295 interest_revenue_rectrx_id,
296 interest_revenue_ccid,
297 calculated_interest_ccid,
298 calculated_interest_rectrx_id
299 INTO x_writeoff_tolerance,
300 x_writeoff_amount,
301 x_writeoff_rectrx_id,
302 x_writeoff_ccid,
303 x_int_revenue_rectrx_id,
304 x_int_revenue_ccid,
305 x_calc_interest_ccid,
306 x_calc_interest_rectrx_id
307 FROM jl_br_ar_rec_met_accts_ext
308 WHERE receipt_method_id = x_rcpt_method_id
309 AND bank_acct_use_id = x_bank_acct_id;
310 EXCEPTION
311 WHEN NO_DATA_FOUND THEN x_return := -1;
312 END get_accounts;
313
314 PROCEDURE get_ps_parameters(x_payment_schedule_id IN NUMBER,
315 x_amount_due_original IN OUT NOCOPY NUMBER,
316 x_amount_due_remaining IN OUT NOCOPY NUMBER,
317 x_return IN OUT NOCOPY NUMBER) IS
318 BEGIN
319 x_return := 0;
320 SELECT amount_due_original, amount_due_remaining
321 INTO x_amount_due_original, x_amount_due_remaining
322 FROM ar_payment_schedules
323 WHERE payment_schedule_id = x_payment_schedule_id;
324 EXCEPTION
325 WHEN NO_DATA_FOUND THEN x_return := -1;
326 END get_ps_parameters;
327
328 PROCEDURE calc_greaterthan_rec( x_writeoff_tolerance IN NUMBER,
329 x_writeoff_amount IN NUMBER,
330 x_calculated_interest IN NUMBER,
331 x_received_interest IN NUMBER,
332 x_payment_amount IN NUMBER,
333 x_rcpt_date IN DATE,
334 x_invoice_amount IN NUMBER,
335 x_payment_schedule_id IN NUMBER,
336 x_writeoff_ccid IN NUMBER,
337 x_writeoff_rectrx_id IN NUMBER,
338 x_calc_interest_ccid IN NUMBER,
339 x_calc_interest_rectrx_id IN NUMBER,
340 x_cash_receipt_id IN NUMBER,
341 x_trx_type_idm IN NUMBER,
342 x_batch_source_idm IN NUMBER,
343 x_receipt_method_idm IN NUMBER,
344 x_user_id IN NUMBER,
345 x_customer_trx_id IN NUMBER,
346 x_interest_difference_action IN VARCHAR2,
347 x_writeoff_date OUT NOCOPY VARCHAR2,
348 x_int_revenue_ccid IN NUMBER) IS
349
350 x_status VARCHAR2(1);
351 x_return VARCHAR2(1);
352
353 x_rcpt_date_char VARCHAR2(30);
354 x_rcpt_date_mm date;
355 x_rcpt_date_mm_char varchar2(11);
356 l_error_code NUMBER;
357 l_error_msg VARCHAR2(2000);
358 l_error_token VARCHAR2(100);
359
360 BEGIN
361
362 if NVL(x_interest_difference_action,'$') = 'WRITEOFF' then
363 IF (( x_writeoff_tolerance IS NOT NULL ) AND
364 (((x_calculated_interest - x_received_interest )/
365 x_invoice_amount) <= x_writeoff_tolerance ))
366 OR
367 (( x_writeoff_amount IS NOT NULL ) AND
368 ((x_calculated_interest - x_received_interest ) <=
369 x_writeoff_amount ))
370 THEN
371 fnd_file.put_line(fnd_file.log,'Before adjustment generation(1)');
372 adjustment_generation (
373 fnd_global.user_id,
374 x_calc_interest_rectrx_id,
375 x_calc_interest_ccid,
376 x_calculated_interest,
377 x_rcpt_date,
378 x_payment_schedule_id,
379 x_cash_receipt_id,
380 x_customer_trx_id
381 );
382
383 fnd_file.put_line(fnd_file.log,'Before adjustment generation(2)');
384 adjustment_generation (
385 fnd_global.user_id,
386 x_writeoff_rectrx_id,
387 x_writeoff_ccid,
388 x_received_interest - x_calculated_interest,
389 x_rcpt_date,
390 x_payment_schedule_id,
391 x_cash_receipt_id,
392 x_customer_trx_id
393 );
394 ELSE
395 fnd_file.put_line(fnd_file.log,'Before adjustment generation(3)');
396 adjustment_generation (
397 fnd_global.user_id,
398 x_calc_interest_rectrx_id,
399 x_calc_interest_ccid,
400 x_received_interest,
401 x_rcpt_date,
402 x_payment_schedule_id,
403 x_cash_receipt_id,
404 x_customer_trx_id
405 );
406 fnd_file.put_line(fnd_file.log,'Before adjustment generation(4)');
407 adjustment_generation (
408 fnd_global.user_id,
409 x_calc_interest_rectrx_id,
410 x_calc_interest_ccid,
411 x_calculated_interest - x_received_interest,
412 x_rcpt_date,
413 x_payment_schedule_id,
414 x_cash_receipt_id,
415 x_customer_trx_id
416 );
417 fnd_file.put_line(fnd_file.log,'Before adjustment generation(5)');
418 adjustment_generation (
419 fnd_global.user_id,
420 x_writeoff_rectrx_id,
421 x_writeoff_ccid,
422 x_received_interest - x_calculated_interest,
423 x_rcpt_date,
424 x_payment_schedule_id,
425 x_cash_receipt_id,
426 x_customer_trx_id
427 );
428 END IF;
429 x_writeoff_date := fnd_date.date_to_canonical(x_rcpt_date);
430
431 elsif NVL(x_interest_difference_action,'$') = 'GENERATE_IDM' then
432 fnd_file.put_line(fnd_file.log,'Before generate idm');
433 adjustment_generation (
434 fnd_global.user_id,
435 x_calc_interest_rectrx_id,
436 x_calc_interest_ccid,
437 x_received_interest,
438 x_rcpt_date,
439 x_payment_schedule_id,
440 x_cash_receipt_id,
441 x_customer_trx_id
442 );
443
444 x_rcpt_date_char := to_char(x_rcpt_date,'DD-MON-YYYY');
445
446
447 /* Date format for Stored Procedures */
448 x_rcpt_date_mm := to_date(x_rcpt_date_char,'DD-MM-YYYY');
449 x_rcpt_date_mm_char := to_char(x_rcpt_date_mm,'DD-MM-YYYY');
450
451 fnd_file.put_line(fnd_file.log,'Before jlbrinterestdebitmemo');
452
453 jl_br_ar_generate_debit_memo.jl_br_interest_debit_memo (x_customer_trx_id,
454 x_calculated_interest - x_received_interest ,
455 x_user_id,
456 x_trx_type_idm,
457 x_batch_source_idm,
458 x_receipt_method_idm,
459 x_payment_schedule_id ,
460 x_rcpt_date_mm_char,
461 x_return,
462 x_int_revenue_ccid,
463 l_error_code,
464 l_error_msg,
465 l_error_token);
466 fnd_file.put_line(fnd_file.log,'After jlbrinterestdebitmemo'||x_return);
467 IF x_return = '1' THEN
468 fnd_file.put_line(fnd_file.log,'After jlbrinterestdebitmemo');
469 IF PG_DEBUG in ('Y', 'C') THEN
470 arp_util.debug('calc_greaterthan_rec: ' || 'PROBLEMA NA CRIACAO DA NOTA DE DEBITO DE JUROS !!!');
471 END IF;
472 END IF;
473
474 end if;
475 END calc_greaterthan_rec;
476
477
478 PROCEDURE calc_greaterthan_rec_tol( x_writeoff_tolerance IN NUMBER,
479 x_writeoff_amount IN NUMBER,
480 x_calculated_interest IN NUMBER,
481 x_received_interest IN NUMBER,
482 x_payment_amount IN NUMBER,
483 x_rcpt_date IN DATE,
484 x_invoice_amount IN NUMBER,
485 x_payment_schedule_id IN NUMBER,
486 x_writeoff_ccid IN NUMBER,
487 x_writeoff_rectrx_id IN NUMBER,
488 x_calc_interest_ccid IN NUMBER,
489 x_calc_interest_rectrx_id IN NUMBER,
490 x_cash_receipt_id IN NUMBER,
491 x_trx_type_idm IN NUMBER,
492 x_batch_source_idm IN NUMBER,
493 x_receipt_method_idm IN NUMBER,
494 x_user_id IN NUMBER,
495 x_customer_trx_id IN NUMBER,
496 x_writeoff_date OUT NOCOPY VARCHAR2,
497 x_int_revenue_ccid IN NUMBER) IS
498 x_return NUMBER;
499 l_error_code NUMBER;
500 l_error_msg VARCHAR2(2000);
501 l_error_token VARCHAR2(100);
502 BEGIN
503 fnd_file.put_line(fnd_file.log,'Before calc greaterthan rec tol');
504 IF (( x_writeoff_tolerance IS NOT NULL ) AND
505 (((x_calculated_interest - x_received_interest )/
506 x_invoice_amount) <= x_writeoff_tolerance ))
507 OR
508 (( x_writeoff_amount IS NOT NULL ) AND
509 ((x_calculated_interest - x_received_interest ) <=
510 x_writeoff_amount ))
511 THEN
512 fnd_file.put_line(fnd_file.log,'Before adjustment generation 6');
513 adjustment_generation (
514 fnd_global.user_id,
515 x_calc_interest_rectrx_id,
516 x_calc_interest_ccid,
517 x_calculated_interest,
518 x_rcpt_date,
519 x_payment_schedule_id,
520 x_cash_receipt_id,
521 x_customer_trx_id);
522
523 fnd_file.put_line(fnd_file.log,'Before adjustment generation 7');
524 fnd_file.put_line(fnd_file.log,'After 1st adjustment');
525 adjustment_generation (
526 fnd_global.user_id,
527 x_writeoff_rectrx_id,
528 x_writeoff_ccid,
529 x_received_interest - x_calculated_interest,
530 x_rcpt_date,
531 x_payment_schedule_id,
532 x_cash_receipt_id,
533 x_customer_trx_id);
534 fnd_file.put_line(fnd_file.log,'After 2nd adjustment');
535
536 x_writeoff_date := fnd_date.date_to_canonical(x_rcpt_date);
537
538 fnd_file.put_line(fnd_file.log,'After 3rd adjustment');
539
540 ELSE
541 IF nvl(x_received_interest,0) > 0 THEN
542 fnd_file.put_line(fnd_file.log,'Before adjustment generation 8');
543 adjustment_generation (
544 fnd_global.user_id,
545 x_calc_interest_rectrx_id,
546 x_calc_interest_ccid,
547 x_received_interest,
548 x_rcpt_date,
549 x_payment_schedule_id,
550 x_cash_receipt_id,
551 x_customer_trx_id);
552 END IF;
553
554 fnd_file.put_line(fnd_file.log,'Before debit memogeneration 8');
555 jl_br_ar_generate_debit_memo.jl_br_interest_debit_memo (
556 x_customer_trx_id,
557 x_calculated_interest - x_received_interest ,
558 x_user_id,
559 x_trx_type_idm,
560 x_batch_source_idm,
561 x_receipt_method_idm,
562 x_payment_schedule_id ,
563 to_char(x_rcpt_date,'DD-MM-YYYY'),
564 x_return,
565 x_int_revenue_ccid,
566 l_error_code,
567 l_error_msg,
568 l_error_token
569 );
570
571 IF x_return = '1' THEN
572 IF PG_DEBUG in ('Y', 'C') THEN
573 arp_util.debug('calc_greaterthan_rec: ' || 'PROBLEMA NA CRIACAO DA NOTA DE DEBITO DE JUROS !!!');
574 END IF;
575 END IF;
576 END IF;
577 END calc_greaterthan_rec_tol;
578
579 PROCEDURE calc_lessthan_rec( x_writeoff_tolerance IN NUMBER,
580 x_writeoff_amount IN NUMBER,
581 x_calculated_interest IN NUMBER,
582 x_received_interest IN NUMBER,
583 x_payment_amount IN NUMBER,
584 x_rcpt_date IN DATE,
585 x_payment_schedule_id IN NUMBER,
586 x_int_revenue_ccid IN NUMBER,
587 x_int_revenue_rectrx_id IN NUMBER,
588 x_calc_interest_ccid IN NUMBER,
589 x_calc_interest_rectrx_id IN NUMBER,
590 x_cash_receipt_id IN NUMBER,
591 x_user_id IN NUMBER,
592 x_customer_trx_id IN NUMBER) IS
593 BEGIN
594 IF NVL(x_calculated_interest ,0) > 0 THEN
595 fnd_file.put_line(fnd_file.log,'Before adjustment generation 9');
596 adjustment_generation (
597 fnd_global.user_id,
598 x_calc_interest_rectrx_id,
599 x_calc_interest_ccid,
600 x_calculated_interest ,
601 x_rcpt_date,
602 x_payment_schedule_id,
603 x_cash_receipt_id,
604 x_customer_trx_id );
605 END IF;
606 fnd_file.put_line(fnd_file.log,'Before adjustment generation 10');
607 adjustment_generation (
608 fnd_global.user_id,
609 x_int_revenue_rectrx_id,
610 x_int_revenue_ccid,
611 x_received_interest - x_calculated_interest ,
612 x_rcpt_date,
613 x_payment_schedule_id,
614 x_cash_receipt_id,
615 x_customer_trx_id );
616 END calc_lessthan_rec;
617
618 PROCEDURE calc_equal_rec( x_writeoff_tolerance IN NUMBER,
619 x_writeoff_amount IN NUMBER,
620 x_calculated_interest IN NUMBER,
621 x_received_interest IN NUMBER,
622 x_payment_amount IN NUMBER,
623 x_rcpt_date IN DATE,
624 x_payment_schedule_id IN NUMBER,
625 x_int_revenue_ccid IN NUMBER,
626 x_int_revenue_rectrx_id IN NUMBER,
627 x_calc_interest_ccid IN NUMBER,
628 x_calc_interest_rectrx_id IN NUMBER,
629 x_cash_receipt_id IN NUMBER,
630 x_user_id IN NUMBER,
631 x_customer_trx_id IN NUMBER) IS
632 BEGIN
633 fnd_file.put_line(fnd_file.log,'Before adjustment generation 11');
634 adjustment_generation (
635 fnd_global.user_id,
636 x_calc_interest_rectrx_id,
637 x_calc_interest_ccid,
638 x_calculated_interest ,
639 x_rcpt_date,
640 x_payment_schedule_id,
641 x_cash_receipt_id,
642 x_customer_trx_id );
643 END calc_equal_rec;
644
645 PROCEDURE interest_treatment (
646 x_payment_schedule_id IN NUMBER,
647 x_customer_trx_id IN NUMBER,
648 x_payment_amount IN NUMBER,
649 x_due_date IN DATE,
650 x_calc_interest IN VARCHAR2,
651 x_rec_interest IN VARCHAR2,
652 x_main_amount_received IN VARCHAR2,
653 x_base_interest_calc IN VARCHAR2,
654 x_interest_payment_date IN VARCHAR2,
655 x_interest_diff_action VARCHAR2,
656 x_cash_receipt_id IN NUMBER,
657 x_rcpt_date IN DATE,
658 x_rcpt_method_id IN NUMBER,
659 x_trx_type_idm IN NUMBER,
660 x_batch_source_idm IN NUMBER,
661 x_receipt_method_idm IN NUMBER,
662 x_user_id IN NUMBER,
663 x_remit_bank_acct_id IN NUMBER,
664 x_writeoff_date OUT NOCOPY VARCHAR2
665 )
666 IS
667 x_writeoff_tolerance NUMBER;
668 x_writeoff_amount NUMBER;
669 x_writeoff_ccid NUMBER(15);
670 x_writeoff_rectrx_id NUMBER(15);
671 x_calc_interest_ccid NUMBER(15);
672 x_calc_interest_rectrx_id NUMBER(15);
673 x_int_revenue_ccid NUMBER(15);
674 x_int_revenue_rectrx_id NUMBER(15);
675 x_return NUMBER;
676 x_amount_due_original NUMBER;
677 x_amount_due_remaining NUMBER;
678 x_calculated_interest NUMBER;
679 x_received_interest NUMBER;
680 BEGIN
681
682 x_calculated_interest := fnd_number.canonical_to_number(x_calc_interest);
683 x_received_interest := fnd_number.canonical_to_number(x_rec_interest);
684
685 fnd_file.put_line(fnd_file.log,'Inside Int treatment');
686 fnd_file.put_line(fnd_file.log,'calc int'||to_char(x_calculated_interest));
687 fnd_file.put_line(fnd_file.log,'rec int'||to_char(x_received_interest));
688
689 fnd_file.put_line(fnd_file.log,'Before get_accounts()');
690 get_accounts(x_rcpt_method_id,
691 x_remit_bank_acct_id,
692 x_writeoff_tolerance,
693 x_writeoff_amount,
694 x_writeoff_ccid,
695 x_writeoff_rectrx_id,
696 x_calc_interest_ccid,
697 x_calc_interest_rectrx_id,
698 x_int_revenue_ccid,
699 x_int_revenue_rectrx_id,
700 x_return);
701
702 fnd_file.put_line(fnd_file.log,'After get_accounts');
703
704 get_ps_parameters(x_payment_schedule_id,
705 x_amount_due_original,
706 x_amount_due_remaining,
707 x_return);
708
709 fnd_file.put_line(fnd_file.log,'After get_psparams');
710
711 IF NVL(x_calculated_interest ,0) > NVL(x_received_interest ,0) THEN
712 IF x_interest_diff_action is NOT NULL THEN
713 fnd_file.put_line(fnd_file.log,'calc_greater_than_rec');
714 calc_greaterthan_rec( x_writeoff_tolerance,
715 x_writeoff_amount,
716 x_calculated_interest,
717 x_received_interest,
718 x_payment_amount,
719 x_rcpt_date,
720 x_amount_due_original,
721 x_payment_schedule_id,
722 x_writeoff_ccid,
723 x_writeoff_rectrx_id,
724 x_calc_interest_ccid,
725 x_calc_interest_rectrx_id,
726 x_cash_receipt_id,
727 x_trx_type_idm,
728 x_batch_source_idm,
729 x_receipt_method_idm,
730 x_user_id,
731 x_customer_trx_id,
732 x_interest_diff_action,
733 x_writeoff_date,
734 x_int_revenue_ccid);
735 ELSE
736 fnd_file.put_line(fnd_file.log,'calc_greater_than_rec_tol');
737 calc_greaterthan_rec_tol( x_writeoff_tolerance,
738 x_writeoff_amount,
739 x_calculated_interest,
740 x_received_interest,
741 x_payment_amount,
742 x_rcpt_date,
743 x_amount_due_original,
744 x_payment_schedule_id,
745 x_writeoff_ccid,
746 x_writeoff_rectrx_id,
747 x_calc_interest_ccid,
748 x_calc_interest_rectrx_id,
749 x_cash_receipt_id,
750 x_trx_type_idm,
751 x_batch_source_idm,
752 x_receipt_method_idm,
753 x_user_id,
754 x_customer_trx_id,
755 x_writeoff_date,
756 x_int_revenue_ccid);
757 END IF;
758
759 ELSIF NVL(x_calculated_interest ,0) < NVL(x_received_interest ,0) THEN
760 fnd_file.put_line(fnd_file.log,'calc_less_than_rec_tol');
761 calc_lessthan_rec( x_writeoff_tolerance,
762 x_writeoff_amount,
763 x_calculated_interest,
764 x_received_interest,
765 x_payment_amount,
766 x_rcpt_date,
767 x_payment_schedule_id,
768 x_int_revenue_ccid,
769 x_int_revenue_rectrx_id,
770 x_calc_interest_ccid,
771 x_calc_interest_rectrx_id,
772 x_cash_receipt_id,
773 x_user_id,
774 x_customer_trx_id);
775 ELSIF x_received_interest > 0 THEN
776 fnd_file.put_line(fnd_file.log,'calc_equal_rec');
777 calc_equal_rec( x_writeoff_tolerance,
778 x_writeoff_amount,
779 x_calculated_interest,
780 x_received_interest,
781 x_payment_amount,
782 x_rcpt_date,
783 x_payment_schedule_id,
784 x_int_revenue_ccid,
785 x_int_revenue_rectrx_id,
786 x_calc_interest_ccid,
787 x_calc_interest_rectrx_id,
788 x_cash_receipt_id,
789 x_user_id,
790 x_customer_trx_id);
791 END IF;
792 END interest_treatment;
793
794 PROCEDURE Apply_br(p_apply_before_after IN VARCHAR2 ,
795 p_global_attribute_category IN VARCHAR2 ,
796 p_set_of_books_id IN NUMBER ,
797 p_cash_receipt_id IN VARCHAR2 ,
798 p_receipt_date IN DATE ,
799 p_applied_payment_schedule_id IN NUMBER ,
800 p_amount_applied IN NUMBER ,
801 p_unapplied_amount IN NUMBER ,
802 p_due_date IN DATE ,
803 p_receipt_method_id IN NUMBER ,
804 p_remittance_bank_account_id IN NUMBER ,
805 p_global_attribute1 IN OUT NOCOPY VARCHAR2 ,
806 p_global_attribute2 IN OUT NOCOPY VARCHAR2 ,
807 p_global_attribute3 IN OUT NOCOPY VARCHAR2 ,
808 p_global_attribute4 IN OUT NOCOPY VARCHAR2 ,
809 p_global_attribute5 IN OUT NOCOPY VARCHAR2 ,
810 p_global_attribute6 IN OUT NOCOPY VARCHAR2 ,
811 p_global_attribute7 IN OUT NOCOPY VARCHAR2 ,
812 p_global_attribute8 IN OUT NOCOPY VARCHAR2 ,
813 p_global_attribute9 IN OUT NOCOPY VARCHAR2 ,
814 p_global_attribute10 IN OUT NOCOPY VARCHAR2 ,
815 p_global_attribute11 IN OUT NOCOPY VARCHAR2 ,
816 p_global_attribute12 IN OUT NOCOPY VARCHAR2 ,
817 p_global_attribute13 IN OUT NOCOPY VARCHAR2 ,
818 p_global_attribute14 IN OUT NOCOPY VARCHAR2 ,
819 p_global_attribute15 IN OUT NOCOPY VARCHAR2 ,
820 p_global_attribute16 IN OUT NOCOPY VARCHAR2 ,
821 p_global_attribute17 IN OUT NOCOPY VARCHAR2 ,
822 p_global_attribute18 IN OUT NOCOPY VARCHAR2 ,
823 p_global_attribute19 IN OUT NOCOPY VARCHAR2 ,
824 p_global_attribute20 IN OUT NOCOPY VARCHAR2 ,
825 p_return_status OUT NOCOPY VARCHAR2) IS
826
827 validation_error exception;
828
829 x_amount_due_remaining NUMBER;
830 x_customer_trx_id NUMBER;
831 x_interest_type VARCHAR2(30);
832 x_interest_rate_amount NUMBER(38,2);
833 x_interest_period NUMBER;
834 x_interest_formula VARCHAR2(30);
835 x_interest_grace_days NUMBER;
836 x_penalty_type VARCHAR2(30);
837 x_penalty_rate_amount NUMBER(38,2);
838 x_invoice_amount NUMBER(38,2);
839 x_calculated_interest NUMBER(38,2);
840 x_calculated_interest_out NUMBER(38,2);
841 x_city VARCHAR2(80);
842 x_state VARCHAR2(60);
843 x_calendar VARCHAR2(30);
844 x_payment_action VARCHAR2(30);
845 x_days_late NUMBER;
846 x_payment_date DATE;
847 x_trans_date DATE;
848 x_trx_type_idm NUMBER;
849 x_batch_source_idm NUMBER;
850 x_receipt_method_idm NUMBER;
851 x_exit_status NUMBER;
852 x_org_id ar_payment_schedules.org_id%TYPE;
853 errcode NUMBER;
854 l_ps_rec ar_payment_schedules%ROWTYPE;
855
856 BEGIN
857
858 IF PG_DEBUG in ('Y', 'C') THEN
859 arp_util.debug('jl_ar_receivable_applications.Apply_br()+');
860 END IF;
861
862 p_return_status := FND_API.G_RET_STS_SUCCESS;
863
864 IF p_apply_before_after = 'BEFORE' THEN
865
866 IF p_due_date < p_receipt_date THEN
867
868
869 x_calendar := jl_zz_sys_options_pkg.get_calendar(mo_global.get_current_org_id);
870
871 /* Bug 2374054 : Multiorg changes */
872 BEGIN
873 SELECT org_id
874 INTO x_org_id
875 FROM ar_payment_schedules
876 WHERE payment_schedule_id = p_applied_payment_schedule_id;
877 EXCEPTION
878 WHEN OTHERS THEN
879 IF PG_DEBUG in ('Y', 'C') THEN
880 arp_util.debug('Apply_br: ' || to_char(SQLCODE));
881 END IF;
882 END;
883 -- fnd_profile.get('JLBR_PAYMENT_ACTION',x_payment_action);
884 x_payment_action := jl_zz_sys_options_pkg.get_payment_action_AR(x_org_id);
885
886 IF x_calendar IS Null THEN
887 FND_MESSAGE.SET_NAME('JL','JL_BR_CALENDAR_PROFILE');
888 FND_MSG_PUB.Add;
889 RAISE validation_error;
890 END IF;
891 IF x_payment_action IS Null THEN
892 FND_MESSAGE.SET_NAME('JL','JL_BR_PAYMENT_ACTION_PROFILE');
893 FND_MSG_PUB.Add;
894 RAISE validation_error;
895 END IF;
896
897 JL_ZZ_AR_LIBRARY_1_PKG.get_idm_profiles_from_syspa (
898 x_trx_type_idm,
899 x_batch_source_idm,
900 x_receipt_method_idm,
901 1,
902 errcode);
903
904 IF errcode <> 0 THEN
905 IF PG_DEBUG in ('Y', 'C') THEN
906 arp_util.debug('Apply_br: ' || to_char(SQLCODE));
907 END IF;
908 RAISE validation_error;
909 END IF;
910
911 IF x_trx_type_idm IS Null THEN
912 FND_MESSAGE.SET_NAME('JL','JL_BR_AR_TRX_TYPE_PROFILE');
913 FND_MSG_PUB.Add;
914 RAISE validation_error;
915 END IF;
916
917 IF x_batch_source_idm IS Null THEN
918 FND_MESSAGE.SET_NAME('JL','JL_BR_AR_BATCH_SOURCE_PROFILE');
919 FND_MSG_PUB.Add;
920 RAISE validation_error;
921 END IF;
922
923 IF x_receipt_method_idm IS Null THEN
924 FND_MESSAGE.SET_NAME('JL','JL_BR_AR_REC_METHOD_PROFILE');
925 FND_MSG_PUB.Add;
926 RAISE validation_error;
927 END IF;
928
929 IF p_global_attribute1 < 0 THEN
930 FND_MESSAGE.SET_NAME('JL','JL_BR_INVALID_MAIN_AMOUNT');
931 FND_MSG_PUB.Add;
932 RAISE validation_error;
933 END IF;
934
935 IF p_global_attribute4 < 0 THEN
936 FND_MESSAGE.SET_NAME('JL','JL_BR_INVALID_INT_AMOUNT');
937 FND_MSG_PUB.Add;
938 RAISE validation_error;
939 END IF;
940
941 IF p_global_attribute1 is NULL THEN
942 p_global_attribute1 := p_amount_applied - nvl(p_global_attribute4,0);
943 END IF;
944
945 IF p_global_attribute2 is NULL THEN
946 p_global_attribute2 := 'TOTAL';
947 END IF;
948
949 IF p_global_attribute1 + nvl(p_global_attribute4,0) > p_amount_applied
950 THEN
951 FND_MESSAGE.SET_NAME('JL','JL_BR_INVALID_MAIN_RCVD_SUM');
952 FND_MSG_PUB.Add;
953 RAISE validation_error;
954 END IF;
955
956 BEGIN
957
958 SELECT amount_due_remaining,
959 global_attribute7
960 INTO x_amount_due_remaining,
961 p_global_attribute11
962 FROM ar_payment_schedules
963 WHERE payment_schedule_id = p_applied_payment_schedule_id;
964
965 EXCEPTION
966 WHEN OTHERS THEN
967 RAISE validation_error;
968 END;
969
970 x_payment_date := fnd_date.canonical_to_date(p_global_attribute11);
971
972 JL_ZZ_AR_LIBRARY_1_PKG.get_customer_trx_id(
973 p_applied_payment_schedule_id,
974 x_customer_trx_id,
975 x_trans_date,
976 1,
977 errcode);
978 IF errcode <> 0 THEN
979 IF PG_DEBUG in ('Y', 'C') THEN
980 arp_util.debug('Apply_br: ' || to_char(SQLCODE));
981 END IF;
982 RAISE validation_error;
983 END IF;
984
985 JL_ZZ_AR_LIBRARY_1_PKG.get_customer_interest_dtls (
986 x_customer_trx_id,
987 x_interest_type,
988 x_interest_rate_amount,
989 x_interest_period,
990 x_interest_formula,
991 x_interest_grace_days,
992 x_penalty_type,
993 x_penalty_rate_amount,
994 1,
995 errcode);
996 IF errcode <> 0 THEN
997 IF PG_DEBUG in ('Y', 'C') THEN
998 arp_util.debug('Apply_br: ' || to_char(SQLCODE));
999 END IF;
1000 RAISE validation_error;
1001 END IF;
1002
1003 JL_ZZ_AR_LIBRARY_1_PKG.get_city_from_ra_addresses (
1004 p_applied_payment_schedule_id,
1005 x_city,
1006 1,
1007 errcode,
1008 x_state); --Bug # 2319552
1009 IF errcode <> 0 THEN
1010 IF PG_DEBUG in ('Y', 'C') THEN
1011 arp_util.debug('Apply_br: ' || to_char(SQLCODE));
1012 END IF;
1013 RAISE validation_error;
1014 END IF;
1015
1016 IF p_global_attribute2 = 'TOTAL' THEN
1017 x_invoice_amount := x_amount_due_remaining;
1018 ELSIF p_global_attribute2 = 'PARTIAL' THEN
1019 x_invoice_amount := p_global_attribute1;
1020 END IF;
1021
1022 JL_BR_INTEREST_HANDLING.JL_BR_INTEREST(
1023 x_interest_type,
1024 x_interest_rate_amount,
1025 x_interest_period,
1026 x_interest_formula,
1027 x_interest_grace_days,
1028 x_penalty_type,
1029 x_penalty_rate_amount,
1030 p_due_date,
1031 x_payment_date,
1032 x_invoice_amount,
1033 x_calendar,
1034 x_city,
1035 x_payment_action,
1036 x_calculated_interest,
1037 x_days_late,
1038 x_exit_status,
1039 x_state); --Bug # 2319552
1040
1041 IF x_exit_status = 0 THEN
1042 x_calculated_interest_out := NVL(x_calculated_interest,0);
1043 ELSE
1044 FND_MESSAGE.SET_NAME('JL','JL_BR_INCONSISTENT_DATE');
1045 FND_MSG_PUB.Add;
1046 RAISE validation_error;
1047 END IF;
1048
1049 p_global_attribute3 := x_calculated_interest_out;
1050
1051 IF (p_global_attribute2 = 'TOTAL')
1052 AND (x_calculated_interest_out <> 0) THEN
1053 p_global_attribute7 := p_receipt_date;
1054 ELSE
1055 p_global_attribute7 := '';
1056 END IF;
1057
1058 interest_treatment (
1059 p_applied_payment_schedule_id,
1060 x_customer_trx_id,
1061 p_amount_applied,
1062 p_due_date,
1063 fnd_number.canonical_to_number(p_global_attribute3),
1064 fnd_number.canonical_to_number(p_global_attribute4),
1065 fnd_number.canonical_to_number(p_global_attribute1),
1066 p_global_attribute2,
1067 fnd_date.canonical_to_date(p_global_attribute7),
1068 p_global_attribute5,
1069 p_cash_receipt_id,
1070 p_receipt_date,
1071 p_receipt_method_id,
1072 x_trx_type_idm,
1073 x_batch_source_idm,
1074 x_receipt_method_idm,
1075 fnd_global.user_id,
1076 p_remittance_bank_account_id,
1077 p_global_attribute8);
1078
1079 ELSE
1080
1081 p_global_attribute1 := '';
1082 p_global_attribute2 := '';
1083 p_global_attribute3 := '';
1084 p_global_attribute4 := '';
1085 p_global_attribute5 := '';
1086 p_global_attribute6 := '';
1087 p_global_attribute7 := '';
1088 p_global_attribute8 := '';
1089 p_global_attribute9 := '';
1090 p_global_attribute10 := '';
1091 p_global_attribute11 := '';
1092
1093 END IF;
1094
1095 ELSIF p_apply_before_after = 'AFTER' THEN
1096
1097 /* UPDATE ar_payment_schedules
1098 SET global_attribute1 = p_global_attribute1,
1099 global_attribute2 = p_global_attribute2,
1100 global_attribute3 = p_global_attribute3,
1101 global_attribute4 = p_global_attribute4,
1102 global_attribute5 = p_global_attribute5,
1103 global_attribute6 = p_global_attribute6,
1104 global_attribute7 = nvl(p_global_attribute7,p_global_attribute11),
1105 global_attribute15 = p_global_attribute8
1106 WHERE payment_schedule_id = p_applied_payment_schedule_id;
1107 */
1108
1109 /* Replace Update by AR's table handlers. Bug # 2249731 */
1110
1111 arp_ps_pkg.fetch_p(p_applied_payment_schedule_id, l_ps_rec);
1112 arp_ps_pkg.lock_p(p_applied_payment_schedule_id);
1113 l_ps_rec.global_attribute1 := p_global_attribute1;
1114 l_ps_rec.global_attribute2 := p_global_attribute2;
1115 l_ps_rec.global_attribute3 := p_global_attribute3;
1116 l_ps_rec.global_attribute4 := p_global_attribute4;
1117 l_ps_rec.global_attribute5 := p_global_attribute5;
1118 l_ps_rec.global_attribute6 := p_global_attribute6;
1119 l_ps_rec.global_attribute7 := nvl(p_global_attribute7, p_global_attribute11);
1120 l_ps_rec.global_attribute15 := p_global_attribute8;
1121 arp_ps_pkg.update_p(l_ps_rec, p_applied_payment_schedule_id);
1122
1123 END IF;
1124
1125 IF PG_DEBUG in ('Y', 'C') THEN
1126 arp_util.debug('jl_ar_receivable_applications.Apply_br()-');
1127 END IF;
1128
1129 EXCEPTION
1130 WHEN validation_error THEN
1131 p_return_status := FND_API.G_RET_STS_ERROR;
1132
1133 END Apply_br;
1134 PROCEDURE Unapply_br(
1135 p_cash_receipt_id IN VARCHAR2 ,
1136 p_applied_payment_schedule_id IN NUMBER ,
1137 p_return_status OUT NOCOPY VARCHAR2) IS
1138
1139 x_apply_date DATE;
1140 x_main_amnt_rec VARCHAR2(30);
1141 x_base_int_calc VARCHAR2(30);
1142 x_calculated_interest VARCHAR2(30);
1143 x_received_interest VARCHAR2(30);
1144 x_int_diff_action VARCHAR2(30);
1145 x_int_writeoff_reason VARCHAR2(30);
1146 x_payment_date VARCHAR2(30);
1147 x_writeoff_date VARCHAR2(80);
1148 x_error_code NUMBER;
1149 l_ps_rec ar_payment_schedules%ROWTYPE;
1150
1151 BEGIN
1152
1153 IF PG_DEBUG in ('Y', 'C') THEN
1154 arp_util.debug('jl_ar_receivable_applications.Unapply_br()+');
1155 END IF;
1156
1157 p_return_status := FND_API.G_RET_STS_SUCCESS;
1158
1159 BEGIN
1160 SELECT apply_date
1161 INTO x_apply_date
1162 FROM ar_receivable_applications
1163 WHERE cash_receipt_id = p_cash_receipt_id
1164 AND applied_payment_schedule_id = p_applied_payment_schedule_id;
1165 EXCEPTION
1166 WHEN OTHERS THEN
1167 IF PG_DEBUG in ('Y', 'C') THEN
1168 arp_util.debug('Unapply_br: ' || to_char(SQLCODE));
1169 END IF;
1170 p_return_status := FND_API.G_RET_STS_ERROR;
1171 END;
1172
1173 IF p_return_status = FND_API.G_RET_STS_SUCCESS THEN
1174
1175 jl_zz_ar_library_1_pkg.get_prev_interest_values(p_applied_payment_schedule_id,
1176 p_cash_receipt_id,
1177 x_apply_date,
1178 x_main_amnt_rec,
1179 x_base_int_calc,
1180 x_calculated_interest,
1181 x_received_interest,
1182 x_int_diff_action,
1183 x_int_writeoff_reason,
1184 x_payment_date,
1185 x_writeoff_date,
1186 x_error_code);
1187
1188 IF x_error_code = 0 then
1189
1190 /* UPDATE ar_payment_schedules
1191 SET global_attribute1 = x_main_amnt_rec,
1192 global_attribute2 = x_base_int_calc,
1193 global_attribute3 = x_calculated_interest,
1194 global_attribute4 = x_received_interest,
1195 global_attribute5 = x_int_diff_action,
1196 global_attribute6 = x_int_writeoff_reason,
1197 global_attribute7 = x_payment_date,
1198 global_attribute15 = x_writeoff_date
1199 WHERE payment_schedule_id = p_applied_payment_schedule_id;
1200 */
1201
1202 /* Replace Update by AR's table handlers. Bug # 2249731 */
1203
1204 arp_ps_pkg.fetch_p(p_applied_payment_schedule_id, l_ps_rec);
1205 arp_ps_pkg.lock_p(p_applied_payment_schedule_id);
1206 l_ps_rec.global_attribute1 := x_main_amnt_rec;
1207 l_ps_rec.global_attribute2 := x_base_int_calc;
1208 l_ps_rec.global_attribute3 := x_calculated_interest;
1209 l_ps_rec.global_attribute4 := x_received_interest;
1210 l_ps_rec.global_attribute5 := x_int_diff_action;
1211 l_ps_rec.global_attribute6 := x_int_writeoff_reason;
1212 l_ps_rec.global_attribute7 := x_payment_date;
1213 l_ps_rec.global_attribute15 := x_writeoff_date;
1214 arp_ps_pkg.update_p(l_ps_rec, p_applied_payment_schedule_id);
1215
1216 ELSE
1217 p_return_status := FND_API.G_RET_STS_ERROR;
1218 END IF;
1219
1220 END IF;
1221
1222 IF PG_DEBUG in ('Y', 'C') THEN
1223 arp_util.debug('jl_ar_receivable_applications.Unapply_br()-');
1224 END IF;
1225
1226 END Unapply_br;
1227
1228 PROCEDURE Reverse_br(
1229 p_cash_receipt_id IN NUMBER,
1230 p_return_status OUT NOCOPY VARCHAR2) IS
1231
1232 Cursor pay_sched is
1233 Select applied_payment_schedule_id pay_sched_id,
1234 global_attribute3 calculated_interest,
1235 apply_date
1236 from ar_receivable_applications
1237 where status = 'APP'
1238 and cash_receipt_id = p_cash_receipt_id;
1239
1240 ps_rec pay_sched%ROWTYPE;
1241
1242 x_main_amnt_rec VARCHAR2(30);
1243 x_base_int_calc VARCHAR2(30);
1244 x_calculated_interest VARCHAR2(30);
1245 x_received_interest VARCHAR2(30);
1246 x_int_diff_action VARCHAR2(30);
1247 x_int_writeoff_reason VARCHAR2(30);
1248 x_payment_date VARCHAR2(30);
1249 x_writeoff_date VARCHAR2(30);
1250
1251 x_error_code NUMBER;
1252 x_interest_reversal BOOLEAN;
1253 l_ps_rec ar_payment_schedules%ROWTYPE;
1254
1255 BEGIN
1256
1257 IF PG_DEBUG in ('Y', 'C') THEN
1258 arp_util.debug('jl_ar_receivable_applications.Reverse_br()+');
1259 END IF;
1260
1261 jl_zz_ar_library_1_pkg.get_interest_reversal_flag(p_cash_receipt_id,
1262 x_interest_reversal,
1263 x_error_code);
1264
1265 IF x_error_code = 0 then
1266
1267 IF x_interest_reversal THEN
1268 p_return_status := FND_API.G_RET_STS_SUCCESS;
1269 OPEN pay_sched;
1270 IF PG_DEBUG in ('Y', 'C') THEN
1271 arp_util.debug('Reverse_br: ' || 'Cursor pay_sched +');
1272 END IF;
1273 LOOP
1274
1275 FETCH pay_sched INTO ps_rec;
1276 EXIT when pay_sched%NOTFOUND
1277 or pay_sched%NOTFOUND is NULL;
1278
1279 IF ps_rec.calculated_interest IS NOT NULL THEN
1280
1281 jl_zz_ar_library_1_pkg.get_prev_interest_values(ps_rec.pay_sched_id,
1282 p_cash_receipt_id,
1283 ps_rec.apply_date,
1284 x_main_amnt_rec,
1285 x_base_int_calc,
1286 x_calculated_interest,
1287 x_received_interest,
1288 x_int_diff_action,
1289 x_int_writeoff_reason,
1290 x_payment_date,
1291 x_writeoff_date,
1292 x_error_code);
1293
1294 IF x_error_code = 0 then
1295 /* UPDATE ar_payment_schedules
1296 SET global_attribute1 = x_main_amnt_rec,
1297 global_attribute2 = x_base_int_calc,
1298 global_attribute3 = x_calculated_interest,
1299 global_attribute4 = x_received_interest,
1300 global_attribute5 = x_int_diff_action,
1301 global_attribute6 = x_int_writeoff_reason,
1302 global_attribute7 = x_payment_date,
1303 global_attribute15 = x_writeoff_date
1304 WHERE payment_schedule_id = ps_rec.pay_sched_id;
1305 */
1306
1307 /* Replace Update by AR's table handlers. Bug # 2249731 */
1308
1309 arp_ps_pkg.fetch_p(ps_rec.pay_sched_id, l_ps_rec);
1310 arp_ps_pkg.lock_p(ps_rec.pay_sched_id);
1311 l_ps_rec.global_attribute1 := x_main_amnt_rec;
1312 l_ps_rec.global_attribute2 := x_base_int_calc;
1313 l_ps_rec.global_attribute3 := x_calculated_interest;
1314 l_ps_rec.global_attribute4 := x_received_interest;
1315 l_ps_rec.global_attribute5 := x_int_diff_action;
1316 l_ps_rec.global_attribute6 := x_int_writeoff_reason;
1317 l_ps_rec.global_attribute7 := x_payment_date;
1318 l_ps_rec.global_attribute15 := x_writeoff_date;
1319 arp_ps_pkg.update_p(l_ps_rec, ps_rec.pay_sched_id);
1320
1321 ELSE
1322 p_return_status := FND_API.G_RET_STS_ERROR;
1323 END IF;
1324
1325 END IF;
1326
1327 END LOOP;
1328 IF PG_DEBUG in ('Y', 'C') THEN
1329 arp_util.debug('Reverse_br: ' || 'Cursor pay_sched -');
1330 END IF;
1331 CLOSE pay_sched;
1332 ELSE
1333 FND_MESSAGE.SET_NAME('JL','JL_BR_AR_STD_REV');
1334 FND_MSG_PUB.Add;
1335 p_return_status := FND_API.G_RET_STS_ERROR;
1336 END IF;
1337 ELSE
1338 p_return_status := FND_API.G_RET_STS_ERROR;
1339 END IF;
1340
1341 IF PG_DEBUG in ('Y', 'C') THEN
1342 arp_util.debug('jl_ar_receivable_applications.Reverse_br()-');
1343 END IF;
1344
1345 END Reverse_br;
1346
1347 /*----------------------------------------------------------------------------*
1348 | PUBLIC FUNCTIONS/PROCEDURES |
1349 *----------------------------------------------------------------------------*/
1350
1351 PROCEDURE Apply(p_apply_before_after IN VARCHAR2 ,
1352 p_global_attribute_category IN VARCHAR2 ,
1353 p_set_of_books_id IN NUMBER ,
1354 p_cash_receipt_id IN VARCHAR2 ,
1355 p_receipt_date IN DATE ,
1356 p_applied_payment_schedule_id IN NUMBER ,
1357 p_amount_applied IN NUMBER ,
1358 p_unapplied_amount IN NUMBER ,
1359 p_due_date IN DATE ,
1360 p_receipt_method_id IN NUMBER ,
1361 p_remittance_bank_account_id IN NUMBER ,
1362 p_global_attribute1 IN OUT NOCOPY VARCHAR2 ,
1363 p_global_attribute2 IN OUT NOCOPY VARCHAR2 ,
1364 p_global_attribute3 IN OUT NOCOPY VARCHAR2 ,
1365 p_global_attribute4 IN OUT NOCOPY VARCHAR2 ,
1366 p_global_attribute5 IN OUT NOCOPY VARCHAR2 ,
1367 p_global_attribute6 IN OUT NOCOPY VARCHAR2 ,
1368 p_global_attribute7 IN OUT NOCOPY VARCHAR2 ,
1369 p_global_attribute8 IN OUT NOCOPY VARCHAR2 ,
1370 p_global_attribute9 IN OUT NOCOPY VARCHAR2 ,
1371 p_global_attribute10 IN OUT NOCOPY VARCHAR2 ,
1372 p_global_attribute11 IN OUT NOCOPY VARCHAR2 ,
1373 p_global_attribute12 IN OUT NOCOPY VARCHAR2 ,
1374 p_global_attribute13 IN OUT NOCOPY VARCHAR2 ,
1375 p_global_attribute14 IN OUT NOCOPY VARCHAR2 ,
1376 p_global_attribute15 IN OUT NOCOPY VARCHAR2 ,
1377 p_global_attribute16 IN OUT NOCOPY VARCHAR2 ,
1378 p_global_attribute17 IN OUT NOCOPY VARCHAR2 ,
1379 p_global_attribute18 IN OUT NOCOPY VARCHAR2 ,
1380 p_global_attribute19 IN OUT NOCOPY VARCHAR2 ,
1381 p_global_attribute20 IN OUT NOCOPY VARCHAR2 ,
1382 p_return_status OUT NOCOPY VARCHAR2) IS
1383
1384
1385 l_country_code VARCHAR2(2);
1386 l_org_id NUMBER;
1387 x_gac_valid BOOLEAN;
1388
1389 BEGIN
1390
1391
1392 IF PG_DEBUG in ('Y', 'C') THEN
1393 arp_util.debug('jl_ar_receivable_applications.Apply()+');
1394 END IF;
1395
1396 --l_country_code := FND_PROFILE.VALUE('JGZZ_COUNTRY_CODE');
1397 l_org_id := MO_GLOBAL.get_current_org_id;
1398
1399 l_country_code := JG_ZZ_SHARED_PKG.get_country(l_org_id,null);
1400
1401 IF l_country_code IS NULL THEN
1402
1403 p_return_status := FND_API.G_RET_STS_ERROR;
1404
1405 ELSIF l_country_code = 'BR' THEN
1406
1407 jg_zz_global_flex_vald_pkg.validate_global_attb_cat(
1408 p_global_attribute_category,
1409 'JL',
1410 'BR',
1411 'ARXRWMAI',
1412 x_gac_valid);
1413
1414 IF x_gac_valid THEN
1415
1416 Apply_br(p_apply_before_after,
1417 p_global_attribute_category,
1418 p_set_of_books_id,
1419 p_cash_receipt_id,
1420 p_receipt_date,
1421 p_applied_payment_schedule_id,
1422 p_amount_applied,
1423 p_unapplied_amount,
1424 p_due_date,
1425 p_receipt_method_id,
1426 p_remittance_bank_account_id,
1427 p_global_attribute1,
1428 p_global_attribute2,
1429 p_global_attribute3,
1430 p_global_attribute4,
1431 p_global_attribute5,
1432 p_global_attribute6,
1433 p_global_attribute7,
1434 p_global_attribute8,
1435 p_global_attribute9,
1436 p_global_attribute10,
1437 p_global_attribute11,
1438 p_global_attribute12,
1439 p_global_attribute13,
1440 p_global_attribute14,
1441 p_global_attribute15,
1442 p_global_attribute16,
1443 p_global_attribute17,
1444 p_global_attribute18,
1445 p_global_attribute19,
1446 p_global_attribute20,
1447 p_return_status);
1448
1449 ELSE
1450
1451 FND_MESSAGE.SET_NAME('JG','JG_ZZ_INVALID_GLOBAL_ATTB_CAT');
1452 FND_MSG_PUB.Add;
1453 p_return_status := FND_API.G_RET_STS_ERROR;
1454
1455 END IF;
1456 END IF;
1457
1458 IF PG_DEBUG in ('Y', 'C') THEN
1459 arp_util.debug('jl_ar_receivable_applications.Apply()-');
1460 END IF;
1461
1462
1463 END Apply;
1464
1465 PROCEDURE Unapply(
1466 p_cash_receipt_id IN VARCHAR2 ,
1467 p_applied_payment_schedule_id IN NUMBER ,
1468 p_return_status OUT NOCOPY VARCHAR2) IS
1469
1470 l_country_code VARCHAR2(2);
1471 l_org_id NUMBER;
1472
1473 BEGIN
1474
1475 IF PG_DEBUG in ('Y', 'C') THEN
1476 arp_util.debug('jl_ar_receivable_applications.Unapply()+');
1477 END IF;
1478
1479 l_org_id := MO_GLOBAL.get_current_org_id;
1480
1481 l_country_code := JG_ZZ_SHARED_PKG.get_country(l_org_id,null);
1482
1483 --l_country_code := FND_PROFILE.VALUE('JGZZ_COUNTRY_CODE');
1484
1485 IF l_country_code IS NULL THEN
1486 p_return_status := FND_API.G_RET_STS_SUCCESS;
1487 ELSIF l_country_code = 'BR' THEN
1488 Unapply_br(
1489 p_cash_receipt_id,
1490 p_applied_payment_schedule_id,
1491 p_return_status);
1492 END IF;
1493
1494 IF PG_DEBUG in ('Y', 'C') THEN
1495 arp_util.debug('jl_ar_receivable_applications.Unapply()-');
1496 END IF;
1497
1498
1499 END Unapply;
1500
1501 PROCEDURE Reverse(
1502 p_cash_receipt_id IN NUMBER,
1503 p_return_status OUT NOCOPY VARCHAR2) IS
1504
1505 l_country_code VARCHAR2(2);
1506 l_org_id NUMBER;
1507
1508 BEGIN
1509
1510 IF PG_DEBUG in ('Y', 'C') THEN
1511 arp_util.debug('jl_ar_receivable_applications.Reverse()+');
1512 END IF;
1513
1514 l_org_id := MO_GLOBAL.get_current_org_id;
1515
1516 l_country_code := JG_ZZ_SHARED_PKG.get_country(l_org_id,null);
1517 --l_country_code := FND_PROFILE.VALUE('JGZZ_COUNTRY_CODE');
1518
1519 IF l_country_code IS NULL THEN
1520 p_return_status := FND_API.G_RET_STS_SUCCESS;
1521 ELSIF l_country_code = 'BR' THEN
1522 Reverse_br(
1523 p_cash_receipt_id,
1524 p_return_status);
1525 END IF;
1526
1527 IF PG_DEBUG in ('Y', 'C') THEN
1528 arp_util.debug('jl_ar_receivable_applications.Reverse()-');
1529 END IF;
1530
1531 END Reverse;
1532
1533 PROCEDURE create_interest_adjustment (
1534 p_post_quickcash_req_id IN NUMBER,
1535 x_return_status OUT NOCOPY VARCHAR2) IS
1536 l_country_code VARCHAR2(2);
1537 l_interest_instruction VARCHAR2(2);
1538 l_interest_occurrence VARCHAR2(2);
1539 l_city VARCHAR2(100);
1540 l_state VARCHAR2(15);
1541 l_calculated_interest NUMBER;
1542 l_interest_type VARCHAR2(15);
1543 l_interest_rate_amount NUMBER;
1544 l_penalty_type VARCHAR2(15);
1545 l_penalty_rate_amount NUMBER;
1546 l_period_days NUMBER;
1547 l_interest_formula VARCHAR2(100);
1548 l_grace_days NUMBER;
1549 l_due_date DATE;
1550 l_occurrence_date DATE;
1551 l_days_late NUMBER;
1552 x_exit_code VARCHAR2(2);
1553 l_inttrxid NUMBER;
1554 l_intccid NUMBER;
1555 l_trx_type_id NUMBER;
1556 l_batch_source_id NUMBER;
1557 l_int_writeoff_rectrx_id NUMBER;
1558 l_int_writeoff_ccid NUMBER;
1559 l_writeoff_tolerance NUMBER;
1560 l_writeoff_amount NUMBER;
1561 l_writeoff_date VARCHAR2(30);
1562 l_trade_note_amount NUMBER;
1563 l_abate_rev_rectrx_id NUMBER;
1564 l_int_rev_rectrx_id NUMBER;
1565 l_int_rev_ccid NUMBER;
1566 l_abate_rev_ccid NUMBER;
1567 l_cust_trx_id NUMBER;
1568 l_amount_due_remaining NUMBER;
1569 l_payment_amount NUMBER;
1570 l_trx_type_idm NUMBER;
1571 l_batch_source_idm NUMBER;
1572 l_receipt_method_idm NUMBER;
1573 x_return varchar2(1);
1574 l_error_code NUMBER;
1575 l_error_msg VARCHAR2(2000);
1576 l_error_token VARCHAR2(100);
1577 l_ps_rec ar_payment_schedules%ROWTYPE;
1578 l_payment_action VARCHAR2(100);
1579 l_calendar_name VARCHAR2(100);
1580 l_pay_sch_id NUMBER;
1581 l_cash_rec_id NUMBER;
1582 l_count NUMBER;
1583
1584 Cursor c_int(p_request_id IN NUMBER) is
1585 select ara.receivable_application_id,
1586 acr.cash_receipt_id,
1587 ara.applied_payment_schedule_id,
1588 acr.receipt_method_id,
1589 acr.receipt_date,
1590 acr.remit_bank_acct_use_id,
1591 aicl.global_attribute1,
1592 aicl.global_attribute2,
1593 aicl.global_attribute3,
1594 aicl.global_attribute4,
1595 aicl.global_attribute5,
1596 aicl.global_attribute6,
1597 aicl.global_attribute7,
1598 aicl.global_attribute8,
1599 aicl.global_attribute10
1600 from ar_receivable_applications_all ara,
1601 ar_cash_receipts_all acr,
1602 ar_interim_cash_rcpt_lines_all aicl
1603 --ar_interim_cash_receipts_all aic
1604 where ara.request_id = p_request_id
1605 AND ara.cash_receipt_id = acr.cash_receipt_id
1606 AND ara.cash_receipt_id = aicl.cash_receipt_id
1607 AND ara.applied_payment_schedule_id = aicl.payment_schedule_id
1608 AND ara.global_attribute_category is NULL;
1609
1610 cursor p(p_request_id IN NUMBER) is
1611 select ara.cash_receipt_id,
1612 ara.applied_payment_schedule_id
1613 from ar_receivable_applications_all ara
1614 where request_id = p_request_id;
1615
1616
1617 BEGIN
1618
1619 --IF PG_DEBUG in ('Y', 'C') THEN
1620 fnd_file.put_line(fnd_file.log,'Inside3 jl_ar_receivable_applications.Create_interest_adjustment()+');
1621 --END IF;
1622
1623 fnd_file.put_line(fnd_file.log,'Rec Appl Id :'||to_char(p_post_quickcash_req_id));
1624
1625 x_return_status := FND_API.G_RET_STS_SUCCESS;
1626 For rint in c_int(p_post_quickcash_req_id)
1627 Loop
1628
1629 fnd_file.put_line(fnd_file.log,'After opening the cursor()+');
1630
1631 update ar_receivable_applications_all
1632 set global_attribute1 = rint.global_attribute3 ,
1633 global_attribute2 = rint.global_attribute4 ,
1634 global_attribute3 = rint.global_attribute1 ,
1635 global_attribute4 = rint.global_attribute2 ,
1636 global_attribute7 = rint.global_attribute5 ,
1637 global_attribute9 = rint.global_attribute6 ,
1638 global_attribute10 = rint.global_attribute7,
1639 global_attribute11 = rint.global_attribute8,
1640 global_attribute12 = rint.global_attribute10,
1641 global_attribute_category = 'JL.BR.ARXRWMAI.Additional Info'
1642 where receivable_application_id = rint.receivable_application_id;
1643
1644 fnd_file.put_line(fnd_file.log,'After update statement()+');
1645
1646 /* ---------------------------------------------------------------------- */
1647 /* Interest Treatment */
1648 /* ---------------------------------------------------------------------- */
1649 fnd_file.put_line(fnd_file.log,'Before get_idm_profiles');
1650 fnd_file.put_line(fnd_file.log,'User Id '||to_char(fnd_global.user_id));
1651
1652 JL_ZZ_AR_LIBRARY_1_PKG.get_idm_profiles_from_syspa (
1653 l_trx_type_idm,
1654 l_batch_source_idm,
1655 l_receipt_method_idm,
1656 1,
1657 l_error_code);
1658
1659 SELECT ract.cust_trx_type_id,
1660 ract.batch_source_id,
1661 arps.due_date,
1662 nvl(arps.amount_due_remaining,0),
1663 ract.customer_trx_id,
1664 arps.amount_applied
1665 INTO
1666 l_trx_type_id,
1667 l_batch_source_id,
1668 l_due_date,
1669 l_amount_due_remaining,
1670 l_cust_trx_id,
1671 l_payment_amount
1672 FROM ra_customer_trx ract,
1673 ar_payment_schedules arps
1674 WHERE arps.payment_schedule_id = rint.applied_payment_schedule_id
1675 AND ract.customer_trx_id = arps.customer_trx_id;
1676
1677 fnd_file.put_line(fnd_file.log,'calc int'||rint.global_attribute1);
1678 fnd_file.put_line(fnd_file.log,'rec int'||rint.global_attribute2);
1679 fnd_file.put_line(fnd_file.log,'main amt'||rint.global_attribute3);
1680
1681 Interest_treatment (
1682 rint.applied_payment_schedule_id,
1683 l_cust_trx_id,
1684 l_payment_amount,
1685 l_due_date,
1686 nvl(rint.global_attribute1,0),
1687 nvl(rint.global_attribute2,0),
1688 nvl(rint.global_attribute3,0),
1689 rint.global_attribute4,
1690 rint.global_attribute5,
1691 NULL,
1692 rint.cash_receipt_id,
1693 rint.receipt_date,
1694 rint.receipt_method_id,
1695 l_trx_type_idm,
1696 l_batch_source_idm,
1697 l_receipt_method_idm,
1698 fnd_global.user_id,
1699 rint.remit_bank_acct_use_id,
1700 l_writeoff_date);
1701
1702 fnd_file.put_line(fnd_file.log,'After interest_treatment');
1703
1704 End Loop;
1705
1706 --IF PG_DEBUG in ('Y', 'C') THEN
1707 arp_util.debug('jl_ar_receivable_applications.Create_interest_adjustments()-');
1708 --END IF;
1709
1710 END Create_interest_adjustment;
1711
1712 PROCEDURE delete_interest_adjustment (
1713 p_cash_receipt_id IN NUMBER,
1714 x_return_status OUT NOCOPY VARCHAR2) IS
1715 BEGIN
1716 delete from ar_adjustments_all
1717 where associated_cash_receipt_id = p_cash_receipt_id;
1718 END delete_interest_adjustment;
1719
1720 END jl_ar_receivable_applications;