DBA Data[Home] [Help]

PACKAGE BODY: APPS.ARP_PROC_RECEIPTS2

Source


1 PACKAGE BODY ARP_PROC_RECEIPTS2 AS
2 /* $Header: ARRERG2B.pls 120.16 2006/10/13 19:42:31 susivara ship $ */
3 
4 /* =======================================================================
5  | Global Data Types
6  * ======================================================================*/
7 SUBTYPE ae_doc_rec_type   IS arp_acct_main.ae_doc_rec_type;
8 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
9 
10 /* ---------------------- Public functions -------------------------------- */
11 
12 
13 FUNCTION revision RETURN VARCHAR2 IS
14 BEGIN
15 
16   RETURN '$Revision: 120.16 $';
17 
18 END revision;
19 
20 
21 /*===========================================================================+
22  | PROCEDURE                                                                 |
23  |    insert_cash_receipt                             			     |
24  |                                                                           |
25  | DESCRIPTION                                                               |
26  |    Function inserts a cash receipt into the database.  This entity 	     |
27  |    handler is called from the Receipts Gateway form and creates records   |
28  |    in the following tables:						     |
29  |       AR_CASH_RECEIPTS						     |
30  |       AR_CASH_RECEIPT_HISTORY					     |
31  |	 AR_DISTRIBUTIONS						     |
32  |       AR_RECEIVABLE_APPLICATIONS					     |
33  |       AR_PAYMENT_SCHEDULES						     |
34  |									     |
35  | SCOPE - PUBLIC                                                            |
36  |                                                                           |
37  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED 	                             |
38  |                                                                           |
39  | ARGUMENTS                                                                 |
40  |    IN:								     |
41  |    OUT:                                                                   |
42  |                                                                           |
43  | RETURNS    		                                                     |
44  |                                                                           |
45  | NOTES                                                                     |
46  |                                                                           |
47  | MODIFICATION HISTORY 						     |
48  |									     |
49  |    08-SEP-95	 OSTEINME	created					     |
50  |    01-NOV-96  OSTEINME	added parameter anticipated_clearing_date    |
51  |				for CashBook enhancement (float support)     |
52  |    				Added parameters for Japan enhancements:     |
53  |				  - customer_bank_branch_id		     |
54  |				as well as logic to handle these properly    |
55  |    04-NOV-96	 OSTEINME	changed call to get_ra_ccid to take new      |
56  |				parameters.  Also changed procedure name     |
57  |				to get_ccids to better reflect purpose of    |
58  |				of procedure.			             |
59  |    30-DEC-96	 OSTEINME	added global flexfield parameters            |
60  |    04-DEC-97  KLAWRANC       Bug #590256.  Modified calls to              |
61  |                              calc_acctd_amount.  Now passes NULL for the  |
62  |                              currency code parameter, therefore the acctd |
63  |                              amount will be calculated based on the       |
64  |                              functional currency.                         |
65  |    21-MAY-98  KTANG		For all calls to calc_acctd_amount which     |
66  |                              calculates header accounted amounts, if the  |
67  |                              exchange_rate_type is not user, call         |
68  |                              gl_currency_api.convert_amount instead. This |
69  |                              is for triangulation.                        |
70  |    29-JUL-98  K.Murphy       Bug #667450.  Modified calculation of the    |
71  |                              accounted factor discount amount.            |
72  |                                                                           |
73  |  14-APR-2000 Jani Rautiainen Added parameter p_called_from. This is needed|
74  |                              inthe logic to decide whether first UNAPP row|
75  |                              is postable or not. In BR scenario when an   |
76  |                              Activity Application of Short Term Debt is   |
77  |                              created the UNAPP rows are not postable.     |
78  |                              This is an user requirement for BR.          |
79  |                              The parameter is defaulted to NULL so no     |
80  |                              impact for the existing functionality.       |
81  |                              Also added logic to prevent accounting       |
82  |                              creation if the row is not postable.         |
83  |  01-May-2002 Debbie Jancis   Modified for Enhancement 2074220. Added      |
84  |                              application_notes.                           |
85  |  05-May-2005 Debbie Jancis   Added Legal Entity Id for LE R12 project     |
86  |                                                                           |
87  +===========================================================================*/
88 
89 
90 PROCEDURE insert_cash_receipt(
91 	p_currency_code		IN VARCHAR2,
92 	p_amount		IN NUMBER,
93 	p_pay_from_customer	IN NUMBER,
94 	p_receipt_number	IN VARCHAR2,
95 	p_receipt_date		IN DATE,
96 	p_gl_date		IN DATE,
97 	p_maturity_date		IN DATE,
98 	p_comments		IN VARCHAR2,
99 	p_exchange_rate_type	IN VARCHAR2,
100 	p_exchange_rate		IN NUMBER,
101 	p_exchange_date		IN DATE,
102 	p_batch_id		IN NUMBER,
103 	p_attribute_category	IN VARCHAR2,
104 	p_attribute1		IN VARCHAR2,
105 	p_attribute2		IN VARCHAR2,
106 	p_attribute3		IN VARCHAR2,
107 	p_attribute4		IN VARCHAR2,
108 	p_attribute5		IN VARCHAR2,
109 	p_attribute6		IN VARCHAR2,
110 	p_attribute7		IN VARCHAR2,
111 	p_attribute8		IN VARCHAR2,
112 	p_attribute9		IN VARCHAR2,
113 	p_attribute10		IN VARCHAR2,
114 	p_attribute11		IN VARCHAR2,
115 	p_attribute12		IN VARCHAR2,
116 	p_attribute13		IN VARCHAR2,
117 	p_attribute14		IN VARCHAR2,
118 	p_attribute15		IN VARCHAR2,
119 	p_override_remit_account_flag IN VARCHAR2,
120 	p_remittance_bank_account_id  IN NUMBER,
121         p_customer_bank_account_id    IN NUMBER,
122 	p_customer_site_use_id	      IN NUMBER,
123 	p_customer_receipt_reference  IN VARCHAR2,
124 	p_factor_discount_amount      IN NUMBER,
125 	p_deposit_date		      IN DATE,
126 	p_receipt_method_id	      IN NUMBER,
127 	p_doc_sequence_value	      IN NUMBER,
128 	p_doc_sequence_id	      IN NUMBER,
129 	p_ussgl_transaction_code      IN VARCHAR2,
130 	p_vat_tax_id		      IN NUMBER,
131 	p_anticipated_clearing_date   IN DATE,
132         p_customer_bank_branch_id     IN NUMBER,
133  -- ARTA Changes
134         p_postmark_date               IN DATE,
135 --
136 -- ******* Global Flexfield parameters *******
137 --
138 	p_global_attribute1		IN VARCHAR2,
139 	p_global_attribute2		IN VARCHAR2,
140 	p_global_attribute3		IN VARCHAR2,
141 	p_global_attribute4		IN VARCHAR2,
142 	p_global_attribute5		IN VARCHAR2,
143 	p_global_attribute6		IN VARCHAR2,
144 	p_global_attribute7		IN VARCHAR2,
145 	p_global_attribute8		IN VARCHAR2,
146 	p_global_attribute9		IN VARCHAR2,
147 	p_global_attribute10		IN VARCHAR2,
148 	p_global_attribute11		IN VARCHAR2,
149 	p_global_attribute12		IN VARCHAR2,
150 	p_global_attribute13		IN VARCHAR2,
151 	p_global_attribute14		IN VARCHAR2,
152 	p_global_attribute15		IN VARCHAR2,
153 	p_global_attribute16		IN VARCHAR2,
154 	p_global_attribute17		IN VARCHAR2,
155 	p_global_attribute18		IN VARCHAR2,
156 	p_global_attribute19		IN VARCHAR2,
157 	p_global_attribute20		IN VARCHAR2,
158 	p_global_attribute_category	IN VARCHAR2,
159 --
160 --      ***  Notes Receivable Additional Information
161 --
162         p_issuer_name			IN VARCHAR2,
163         p_issue_date			IN DATE,
164 	p_issuer_bank_branch_id		IN NUMBER,
165 --
166 --      *** enhancement 2074220 ***
167         p_application_notes             IN VARCHAR2,
168 --
169 	p_cr_id			        OUT NOCOPY NUMBER,
170 	p_ps_id			        OUT NOCOPY NUMBER,
171 	p_row_id		        OUT NOCOPY VARCHAR2,
172 --
173 	p_form_name		        IN varchar2,
174 	p_form_version		        IN varchar2,
175 	p_called_from                   IN VARCHAR2 DEFAULT NULL, /* BR */
176         p_le_id                         IN NUMBER DEFAULT NULL, /* LE */
177 	p_payment_trxn_extension_id    IN NUMBER  DEFAULT NULL /* payment uptake */
178 		) IS
179 l_cr_rec	ar_cash_receipts%ROWTYPE;
180 l_crh_rec	ar_cash_receipt_history%ROWTYPE;
181 l_cr_id		ar_cash_receipts.cash_receipt_id%TYPE;
182 l_ps_id		ar_payment_schedules.payment_schedule_id%TYPE;
183 l_ccid		ar_cash_receipt_history.account_code_combination_id%TYPE;
184 l_ra_ccid	ar_receivable_applications.code_combination_id%TYPE;
185 l_ra_unid_ccid	ar_receivable_applications.code_combination_id%TYPE;
186 l_ra_unapp_ccid	ar_receivable_applications.code_combination_id%TYPE;
187 l_source_type	ar_distributions.source_type%TYPE;
188 l_override_dummy
189 		ar_receipt_method_accounts.override_remit_account_flag%TYPE;
190 l_creation_status ar_cash_receipt_history.status%TYPE;
191 l_status	ar_cash_receipts.status%TYPE;
192 l_crh_amount 		ar_cash_receipt_history.amount%TYPE;
193 l_cr_acctd_amount	ar_payment_schedules.acctd_amount_due_remaining%TYPE;
194 l_crh_acctd_amount  	ar_cash_receipt_history.amount%TYPE;
195 l_acctd_factor_discount_amount ar_cash_receipt_history.acctd_factor_discount_amount%TYPE;
196 l_bank_charges_ccid	ar_cash_receipt_history.bank_charge_account_ccid%TYPE;
197 l_application_rule  	ar_receivable_applications.application_rule%TYPE;
198 l_called_from_api       varchar2(1);
199 
200 l_dummy		NUMBER;
201 l_id_dummy	NUMBER;
202 l_ra_id         ar_receivable_applications.receivable_application_id%TYPE;
203 l_ae_doc_rec    ae_doc_rec_type;
204 
205 BEGIN
206 
207 
208   IF PG_DEBUG in ('Y', 'C') THEN
209      arp_standard.debug('arp_process_receipts.insert_cash_receipt()+');
210   END IF;
211 
212   -- determine creation state (approved, confirmed, remitted, cleared)
213   -- of receipt based on payment method, as well as code combination
214   -- id.
215 
216   arp_cr_util.get_creation_info(p_receipt_method_id,
217 				p_remittance_bank_account_id,
218 	      			l_creation_status,
219 				l_source_type,
220 				l_ccid,
221 				l_override_dummy);
222 
223   IF PG_DEBUG in ('Y', 'C') THEN
224      arp_standard.debug('insert_cash_receipt: ' || 'Creation status = ' || l_creation_status);
225      arp_standard.debug('insert_cash_receipt: ' || 'Source Type     = ' || l_source_type);
226      arp_standard.debug('insert_cash_receipt: ' || 'ccid            = ' || l_ccid);
227   END IF;
228 
229   -- create ar_cash_receipt record:
230 
231   -- first determine if receipt is unidentified or unapplied
232 
233   IF (p_pay_from_customer IS NULL) THEN
234     l_status := 'UNID';
235   ELSE
236     l_status := 'UNAPP';
237   END IF;
238 
239   -- determine receivable application ccid:
240 
241   arp_proc_rct_util.get_ccids(
242 		p_receipt_method_id,
243 		p_remittance_bank_account_id,
244 		l_ra_unid_ccid,
245 		l_ra_unapp_ccid,
246 		l_id_dummy,
247 		l_id_dummy,
248 		l_id_dummy,
249 		l_bank_charges_ccid,
250 		l_id_dummy,
251 		l_id_dummy,
252 		l_id_dummy,
253 		l_id_dummy);
254 
255   IF PG_DEBUG in ('Y', 'C') THEN
256      arp_standard.debug('insert_cash_receipt: ' || 'status	      = ' || l_status);
257      arp_standard.debug('insert_cash_receipt: ' || 'l_ra_unid_ccid	      = ' || l_ra_unid_ccid);
258      arp_standard.debug('insert_cash_receipt: ' || 'l_ra_unapp_ccid	      = ' || l_ra_unapp_ccid);
259      arp_standard.debug('insert_cash_receipt: ' || 'l_bank_charges_ccid      = ' || l_bank_charges_ccid);
260   END IF;
261 
262   l_cr_rec.amount 		:= p_amount;
263   l_cr_rec.currency_code	:= p_currency_code;
264   l_cr_rec.pay_from_customer	:= p_pay_from_customer;
265   l_cr_rec.status 		:= l_status;
266   l_cr_rec.type 		:= 'CASH';
267   l_cr_rec.receipt_number	:= p_receipt_number;
268   l_cr_rec.receipt_date		:= p_receipt_date;
269   l_cr_rec.comments 		:= p_comments;
270   l_cr_rec.exchange_rate_type	:= p_exchange_rate_type;
271   l_cr_rec.exchange_rate	:= p_exchange_rate;
272   l_cr_rec.exchange_date	:= p_exchange_date;
273   l_cr_rec.attribute_category	:= p_attribute_category;
274   l_cr_rec.attribute1 		:= p_attribute1;
275   l_cr_rec.attribute2 		:= p_attribute2;
276   l_cr_rec.attribute3 		:= p_attribute3;
277   l_cr_rec.attribute4 		:= p_attribute4;
278   l_cr_rec.attribute5 		:= p_attribute5;
279   l_cr_rec.attribute6 		:= p_attribute6;
280   l_cr_rec.attribute7 		:= p_attribute7;
281   l_cr_rec.attribute8 		:= p_attribute8;
282   l_cr_rec.attribute9 		:= p_attribute9;
283   l_cr_rec.attribute10 		:= p_attribute10;
284   l_cr_rec.attribute11 		:= p_attribute11;
285   l_cr_rec.attribute12 		:= p_attribute12;
286   l_cr_rec.attribute13 		:= p_attribute13;
287   l_cr_rec.attribute14 		:= p_attribute14;
288   l_cr_rec.attribute15 		:= p_attribute15;
289   l_cr_rec.override_remit_account_flag := p_override_remit_account_flag;
290   l_cr_rec.remit_bank_acct_use_id	:= p_remittance_bank_account_id;
291   l_cr_rec.confirmed_flag	:= 'Y';
292   l_cr_rec.customer_bank_account_id     := p_customer_bank_account_id;
293   l_cr_rec.customer_site_use_id	:= p_customer_site_use_id;
294   l_cr_rec.deposit_date		:= p_deposit_date;
295   l_cr_rec.receipt_method_id	:= p_receipt_method_id;
296   l_cr_rec.doc_sequence_value	:= p_doc_sequence_value;
297   l_cr_rec.doc_sequence_id	:= p_doc_sequence_id;
298   l_cr_rec.ussgl_transaction_code := p_ussgl_transaction_code;
299   l_cr_rec.factor_discount_amount := 0;
300   l_cr_rec.customer_receipt_reference := p_customer_receipt_reference;
301   l_cr_rec.vat_tax_id	:= p_vat_tax_id;
302   l_cr_rec.anticipated_clearing_date := p_anticipated_clearing_date;
303   l_cr_rec.customer_bank_branch_id := p_customer_bank_branch_id;
304 
305   l_cr_rec.global_attribute1	:= p_global_attribute1;
306   l_cr_rec.global_attribute2	:= p_global_attribute2;
307   l_cr_rec.global_attribute3	:= p_global_attribute3;
308   l_cr_rec.global_attribute4	:= p_global_attribute4;
309   l_cr_rec.global_attribute5	:= p_global_attribute5;
310   l_cr_rec.global_attribute6	:= p_global_attribute6;
311   l_cr_rec.global_attribute7	:= p_global_attribute7;
312   l_cr_rec.global_attribute8	:= p_global_attribute8;
313   l_cr_rec.global_attribute9	:= p_global_attribute9;
314   l_cr_rec.global_attribute10	:= p_global_attribute10;
315   l_cr_rec.global_attribute11	:= p_global_attribute11;
316   l_cr_rec.global_attribute12	:= p_global_attribute12;
317   l_cr_rec.global_attribute13	:= p_global_attribute13;
318   l_cr_rec.global_attribute14	:= p_global_attribute14;
319   l_cr_rec.global_attribute15	:= p_global_attribute15;
320   l_cr_rec.global_attribute16	:= p_global_attribute16;
321   l_cr_rec.global_attribute17	:= p_global_attribute17;
322   l_cr_rec.global_attribute18	:= p_global_attribute18;
323   l_cr_rec.global_attribute19	:= p_global_attribute19;
324   l_cr_rec.global_attribute20	:= p_global_attribute20;
325   l_cr_rec.global_attribute_category	:= p_global_attribute_category;
326 
327 --
328 --  Notes Receivable Additional Information
329 --
330 
331   l_cr_rec.issuer_name           := p_issuer_name;
332   l_cr_rec.issue_date            := p_issue_date;
333   l_cr_rec.issuer_bank_branch_id := p_issuer_bank_branch_id;
334 
335 -- ARTA Changes
336   l_cr_rec.postmark_date        := p_postmark_date;
337 
338   -- enhancment 2074220
339   l_cr_rec.application_notes    := p_application_notes;
340 
341   --  Legal Entity project
342   l_cr_rec.legal_entity_id      := p_le_id;
343 
344   l_cr_rec.payment_trxn_extension_id	:= p_payment_trxn_extension_id; /* bichatte payment uptake */
345   arp_cash_receipts_pkg.insert_p(l_cr_rec);
346 
347   -- determine the amount for the cash receipt history record:
348   --
349   -- crh.amount := cr.amount - p_factor_discount_amount
350 
351   l_crh_amount := l_cr_rec.amount - NVL(p_factor_discount_amount,0);
352 
353   -- determine accounted amount for history record:
354   -- Changes for triangulation: If exchange rate type is not user, call
355   -- GL API to calculate accounted amount
356   IF (p_exchange_rate_type = 'User') THEN
357     arp_util.calc_acctd_amount( NULL,
358 				NULL,
359 				NULL,
360 				l_cr_rec.exchange_rate,
361 				'+',
362 				l_crh_amount,
363 				l_crh_acctd_amount,
364 				0,
365 				l_dummy,
366 				l_dummy,
367 				l_dummy);
368   ELSE
369     l_crh_acctd_amount := gl_currency_api.convert_amount(
370 				arp_global.set_of_books_id,
371 				l_cr_rec.currency_code,
372 				l_cr_rec.exchange_date,
373 				l_cr_rec.exchange_rate_type,
374 				l_crh_amount);
375   END IF;
376 
377   -- Need to work out NOCOPY acctd factor discount amount value.
378   --
379   -- The correct definition for the acctd factor discount amount is:
380   --
381   -- acctd factor discount amount := acctd cr amount -
382   --                                 acctd crh amount
383   --
384   -- Firstly, need to calculate the acctd cr amount.  If the rate type
385   -- is not "User", call the GL API to get the triangulated value.
386 
387   IF (p_exchange_rate_type = 'User') THEN
388 
389     arp_util.calc_acctd_amount( NULL,
390                                 NULL,
391                                 NULL,
392                                 l_cr_rec.exchange_rate,
393                                 '+',
394                                 l_cr_rec.amount,
395                                 l_cr_acctd_amount,
396                                 0,
397                                 l_dummy,
398                                 l_dummy,
399                                 l_dummy);
400 
401   ELSE
402 
403     l_cr_acctd_amount := gl_currency_api.convert_amount(
404 				arp_global.set_of_books_id,
405                                 l_cr_rec.currency_code,
406                                 l_cr_rec.exchange_date,
407                                 l_cr_rec.exchange_rate_type,
408                                 l_cr_rec.amount);
409   END IF;
410 
411   -- Now calculate the acctd fda amount.  Note that for the
412   -- cases where the rate type is not "User", this is
413   -- calculated using all triangulated values, i.e. both
414   -- l_cr_acctd_amount and l_crh_acctd_amount are
415   -- triangulated values.
416 
417   l_acctd_factor_discount_amount := l_cr_acctd_amount -
418                                       l_crh_acctd_amount;
419 
420   -- create related cash receipt history record
421 
422   arp_proc_rct_util.insert_crh_rec(
423 			l_cr_rec,
424 			l_crh_amount,
425 			l_crh_acctd_amount,
426 			p_factor_discount_amount,
427 			l_acctd_factor_discount_amount,
428 			p_gl_date,
429 			l_creation_status,
430 			p_batch_id,
431 			l_ccid,
432 			l_bank_charges_ccid,
433 			l_crh_rec);
434 
435 
436   -- create related payment schedule record
437 
438   arp_proc_rct_util.insert_ps_rec_cash(
439 			l_cr_rec,
440 			p_gl_date,
441 			nvl(p_maturity_date, p_deposit_date),
442 			l_cr_acctd_amount,
443 			l_ps_id);
444 
445    --apandit
446    --Bug 2641517 : Raise the Receipt Creation  business event.
447    -- Bug 4147586, Raising BE always.
448      AR_BUS_EVENT_COVER.Raise_Rcpt_Creation_Event(l_ps_id);
449 
450 
451   -- create related receivable applications record
452 
453   IF (l_cr_rec.status = 'UNID') THEN
454     l_application_rule		:= '60.1';
455     l_ra_ccid			:= l_ra_unid_ccid;
456   ELSE
457     l_application_rule		:= '60.2';
458     l_ra_ccid			:= l_ra_unapp_ccid;
459   END IF;
460 
461   arp_proc_rct_util.insert_ra_rec_cash(
462 			l_cr_rec.cash_receipt_id,
463 			l_cr_rec.amount,
464 			l_cr_rec.receipt_date,
465 			l_cr_rec.status,
466 			l_cr_acctd_amount,
467 			p_gl_date,
468 			l_ra_ccid,
469 			l_ps_id,
470 			l_application_rule,
471                         '',
472                         l_ra_id,
473                         p_called_from); -- jrautiai BR project
474 
475   /* 14-APR-2000
476    * In this BR specific situation the first UNAPP row created is not POSTABLE so no accounting created.
477    * See procedure description for more information */
478 
479 
480   IF nvl(p_called_from,'NONE') NOT IN ('BR_FACTORED_WITH_RECOURSE', 'AUTORECAPI') THEN --
481     --
482     --Release 11.5 VAT changes, create UNID receivable application accounting
483     --in ar_distributions
484     --
485     l_ae_doc_rec.document_type             := 'RECEIPT';
486     l_ae_doc_rec.document_id               := l_cr_rec.cash_receipt_id;
487     l_ae_doc_rec.accounting_entity_level   := 'ONE';
488     l_ae_doc_rec.source_table              := 'RA';
489     l_ae_doc_rec.source_id                 := l_ra_id;
490     l_ae_doc_rec.source_id_old             := '';
491     l_ae_doc_rec.other_flag                := '';
492 
493     arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
494 
495   END IF;
496 
497   -- create distributions record(s)
498 
499 IF nvl(p_called_from,'NONE') <> 'AUTORECAPI' THEN  -- bichatte autorecapi changes
500   arp_proc_rct_util.insert_dist_rec(
501 			l_crh_rec.amount,
502 			l_crh_acctd_amount,
503 			l_crh_rec.cash_receipt_history_id,
504 			l_source_type,
505 			l_ccid);
506 END IF;  -- bichatte autorecapi
507 
508   IF (NVL(p_factor_discount_amount,0) > 0 ) THEN
509 
510     -- if bank charges exist, create distribution record
511     -- for them:
512 
513     IF PG_DEBUG in ('Y', 'C') THEN
514        arp_standard.debug('insert_cash_receipt: ' || 'Before creating distribution for bank charges:');
515        arp_standard.debug('insert_cash_receipt: ' || 'p_factor_discount_amount = ' ||
516 			to_char(p_factor_discount_amount));
517        arp_standard.debug('insert_cash_receipt: ' || 'l_acctd_factor_discount_amount = ' ||
518 			to_char(l_acctd_factor_discount_amount));
519        arp_standard.debug('insert_cash_receipt: ' || 'l_crh_rec.cash_receipt_history_id = ' ||
520 			to_char(l_crh_rec.cash_receipt_history_id));
521        arp_standard.debug('insert_cash_receipt: ' || 'l_bank_charges_ccid = ' ||
522 			to_char(l_bank_charges_ccid));
523     END IF;
524 
525     arp_proc_rct_util.insert_dist_rec(
526 			p_factor_discount_amount,
527 			l_acctd_factor_discount_amount,
528 			l_crh_rec.cash_receipt_history_id,
529 			'BANK_CHARGES',
530 			l_bank_charges_ccid);
531   END IF;
532 
533   /* Bug 4910860: Check if the journals are balanced */
534   IF p_form_name = 'RAPI' THEN
535      l_called_from_api := 'Y';
536   ELSE
537      l_called_from_api := 'N';
538   END IF;
539 
540   /*Bug 5017553 check for balance if the call is not from BR*/
541   IF NVL(p_called_from,'NONE') not in ('BR_REMITTED','BR_FACTORED_WITH_RECOURSE','BR_FACTORED_WITHOUT_RECOURSE') THEN
542     arp_balance_check.Check_Recp_Balance(l_cr_rec.cash_receipt_id,NULL,l_called_from_api);
543   END IF;
544 
545   -- copy cash_receipt_id into return variable:
546 
547   p_cr_id := l_cr_rec.cash_receipt_id;
548   p_ps_id := l_ps_id;
549 
550   -- update batch status
551 
552   IF (p_batch_id IS NOT NULL) THEN
553     arp_rw_batches_check_pkg.update_batch_status(
554 		p_batch_id);
555   END IF;
556 
557   -- get the ROWID out NOCOPY parameter:
558 
559   SELECT rowid
560   INTO   p_row_id
561   FROM   ar_cash_receipts
562   WHERE  cash_receipt_id = l_cr_rec.cash_receipt_id;
563 
564   IF PG_DEBUG in ('Y', 'C') THEN
565      arp_standard.debug('arp_process_receipts.insert_cash_receipt()-');
566   END IF;
567 
568   EXCEPTION
569     WHEN OTHERS THEN
570       IF PG_DEBUG in ('Y', 'C') THEN
571          arp_standard.debug('Exception in insert_cash_receipt');
572       END IF;
573       RAISE;
574 
575 END insert_cash_receipt;
576 
577 /*===========================================================================+
578  | PROCEDURE                                                                 |
579  |    remit_cash_receipt                             			     |
580  |                                                                           |
581  | DESCRIPTION                                                               |
582  |    This entity handler is created for remitting a confirmed receipt.	     |
583  |    Review this routine if you are planing to use it for anyother purpose  |
584  |       AR_CASH_RECEIPT_HISTORY					     |
585  |	 AR_DISTRIBUTIONS						     |
586  |									     |
587  | SCOPE - PUBLIC                                                            |
588  |                                                                           |
589  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED 	                             |
590  |                                                                           |
591  | ARGUMENTS                                                                 |
592  |    IN:								     |
593  |    OUT:                                                                   |
594  |                                                                           |
595  | RETURNS    		                                                     |
596  |                                                                           |
597  | NOTES                                                                     |
598  |                                                                           |
599  | MODIFICATION HISTORY 						     |
600  |									     |
601  |    19-Mar-02	 S.Nambiar	created					     |
602  |                                                                           |
603  +===========================================================================*/
604 PROCEDURE remit_cash_receipt(
605 	p_cash_receipt_id		IN NUMBER,
606         x_return_status                 OUT NOCOPY VARCHAR2
607         ) IS
608 
609 l_cr_rec	ar_cash_receipts%ROWTYPE;
610 l_crh_rec	ar_cash_receipt_history%ROWTYPE;
611 l_new_crh_rec	ar_cash_receipt_history%ROWTYPE;
612 
613 l_cr_id		     ar_cash_receipts.cash_receipt_id%TYPE;
614 l_prev_crh_id	     ar_cash_receipt_history.cash_receipt_history_id%TYPE;
615 l_new_crh_id	     ar_cash_receipt_history.cash_receipt_history_id%TYPE;
616 l_confirmation_ccid  ar_cash_receipt_history.account_code_combination_id%TYPE;
617 l_remittance_ccid  ar_cash_receipt_history.account_code_combination_id%TYPE;
618 
619 l_ra_ccid	ar_receivable_applications.code_combination_id%TYPE;
620 l_ra_unid_ccid	ar_receivable_applications.code_combination_id%TYPE;
621 l_ra_unapp_ccid	ar_receivable_applications.code_combination_id%TYPE;
622 
623 l_crh_amount 		ar_cash_receipt_history.amount%TYPE;
624 l_cr_acctd_amount	ar_payment_schedules.acctd_amount_due_remaining%TYPE;
625 l_crh_acctd_amount  	ar_cash_receipt_history.amount%TYPE;
626 l_bank_charges_ccid	ar_cash_receipt_history.bank_charge_account_ccid%TYPE;
627 
628 l_dummy		NUMBER;
629 l_id_dummy	NUMBER;
630 
631 BEGIN
632 
633     IF PG_DEBUG in ('Y', 'C') THEN
634        arp_standard.debug('arp_process_receipts.remit_cash_receipt()+');
635     END IF;
636     x_return_status := FND_API.G_RET_STS_SUCCESS;
637 
638     l_cr_rec.cash_receipt_id := p_cash_receipt_id;
639 
640   --fetch cash receipt record
641     arp_cash_receipts_pkg.fetch_p(l_cr_rec);
642 
643   --fetch cash receipt history record
644     arp_cr_history_pkg.fetch_f_crid(l_cr_rec.cash_receipt_id, l_crh_rec );
645 
646     IF l_crh_rec.status <> 'CONFIRMED' then
647        IF PG_DEBUG in ('Y', 'C') THEN
648           arp_standard.debug('remit_cash_receipt: ' || 'This receipt is in '||l_crh_rec.status||
649                           ' status. Does not require Remittance ');
650        END IF;
651        x_return_status := FND_API.G_RET_STS_ERROR;
652        RETURN;
653     END IF;
654 
655     l_prev_crh_id := l_crh_rec.cash_receipt_history_id;
656     l_new_crh_rec := l_crh_rec;
657     l_new_crh_rec.current_record_flag := 'Y';
658     l_new_crh_rec.first_posted_record_flag := 'N';
659     l_new_crh_rec.status := 'REMITTED';
660 
661    --Insert a new cash receipt history record
662     arp_cr_history_pkg.insert_p(l_new_crh_rec,l_new_crh_id );
663 
664     l_crh_rec.reversal_cash_receipt_hist_id := l_new_crh_id;
665     l_crh_rec.reversal_created_from := 'PREPAY';
666     l_crh_rec.current_record_flag := null;
667 
668   --Update the previous cash receipt history record
669     arp_cr_history_pkg.update_p(l_crh_rec,l_prev_crh_id );
670 
671   --Get the ccids
672     arp_proc_rct_util.get_ccids(
673 		l_cr_rec.receipt_method_id,
674 		l_cr_rec.remit_bank_acct_use_id,
675 		l_ra_unid_ccid,
676 		l_ra_unapp_ccid,
677 		l_id_dummy,
678 		l_id_dummy,
679 		l_id_dummy,
680 		l_bank_charges_ccid,
681 		l_id_dummy,
682 		l_confirmation_ccid,
683 		l_remittance_ccid,
684 		l_id_dummy);
685 
686   --create distributions record(s)
687   --Debit remittance
688     arp_proc_rct_util.insert_dist_rec(
689 			l_new_crh_rec.amount,
690 			l_new_crh_rec.acctd_amount,
691 			l_new_crh_id,
692 			'REMITTANCE',
693                         l_remittance_ccid);
694 
695   --Credit confirmation
696     arp_proc_rct_util.insert_dist_rec(
697 			(l_new_crh_rec.amount * -1),
698 			(l_new_crh_rec.acctd_amount * -1),
699 			l_new_crh_id,
700 			'CONFIRMATION',
701                         l_confirmation_ccid);
702 
703     IF PG_DEBUG in ('Y', 'C') THEN
704        arp_standard.debug('arp_process_receipts.remit_cash_receipt()-');
705     END IF;
706 
707   EXCEPTION
708     WHEN OTHERS THEN
709       x_return_status := FND_API.G_RET_STS_ERROR;
710       IF PG_DEBUG in ('Y', 'C') THEN
711          arp_standard.debug('Exception in remit_cash_receipt '||SQLERRM);
712       END IF;
713       RAISE;
714 
715 END remit_cash_receipt;
716 
717 END ARP_PROC_RECEIPTS2;