DBA Data[Home] [Help]

PACKAGE BODY: APPS.ARP_PROC_RECEIPTS1

Source


1 PACKAGE BODY ARP_PROC_RECEIPTS1 AS
2 /* $Header: ARRERG1B.pls 120.22.12010000.2 2008/11/11 09:28:27 spdixit 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 FUNCTION revision RETURN VARCHAR2 IS
11 BEGIN
12 
13    RETURN '$Revision: 120.22.12010000.2 $';
14 
15 END revision;
16 
17 
18 /*===========================================================================+
19  | PROCEDURE                                                                 |
20  |    update_cash_receipt                              			     |
21  |                                                                           |
22  | DESCRIPTION                                                               |
23  |    Entity handler that updates cash transactions.		     	     |
24  |									     |
25  | SCOPE - PRIVATE                                                           |
26  |                                                                           |
27  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED 	                             |
28  |                                                                           |
29  | ARGUMENTS                                                                 |
30  |    IN:								     |
31  |    OUT:                                                                   |
32  |                                                                           |
33  | RETURNS    		                                                     |
34  |                                                                           |
35  | NOTES                                                                     |
36  |                                                                           |
37  | MODIFICATION HISTORY 						     |
38  |									     |
39  |    21-AUG-95	OSTEINME	created					     |
40  |    15-MAR-96 OSTEINME	removed calls to procedure                   |
41  |				arp_cr_util.get_creation_info as they cause  |
42  | 				problems if the receipt is created as        |
43  |				approved (in this case it doesn't have       |
44  |				entries in AR_DISTRIBUTIONS yet.	     |
45  |    05-APR-96 OSTEINME	added functionality (and parameters) to      |
46  |				return receipt state and status info after   |
47  |				update.					     |
48  |    30-MAY-96 OSTEINME	added parameter p_status for bug 370072      |
49  |    19-NOV-96  OSTEINME	modified update_cash_receipts procedure to   |
50  |				support changing the amount even if apps     |
51  |				exist.					     |
52  |    27-DEC-96 OSTEINME	added global flexfield parameters            |
53  |    05-MAY-97 KLAWRANC        Added section to determine a valid GL and    |
54  |                              Reversal GL date for receivable applications.|
55  |                              This date is then used for update and        |
56  |                              creation of application records.             |
57  |    01-JUL-97 KLAWRANC        Bug fixes #511576, 511312.                   |
58  |                              Use valid GL date when updating and creating |
59  |                              receipt records.                             |
60  |                              Corrected calculation of amount due remain   |
61  |                              used to update receipt payment schedule row. |
62  |    29-AUG-97 KLAWRANC        Bug fix #462056.                             |
63  |                              Added update of AP Bank Uses for MICR #      |
64  |                              functionality.                               |
65  |    04-DEC-97 KLAWRANC        Bug #590256.  Modified calls to              |
66  |                              calc_acctd_amount.  Now passes NULL for the  |
67  |                              currency code parameter, therefore the acctd |
68  |                              amount will be calculated based on the       |
69  |                              functional currency.
70  |    20-FEB-97 KLAWRANC        Bugs #616531, 625124, 625132.                |
71  |                              Moved the update of receipt payment          |
72  |                              schedule amounts to outside the              |
73  |                              posted/not posted check.                     |
74  |                              Corrected the calculation of                 |
75  |                              l_crh_fda_delta and l_crh_acctd_fda_delta.   |
76  |                              This did not use nvl in calculations which   |
77  |                              caused an incorrect result if the bank       |
78  |                              was initially null or changed to null.       |
79  |                              Created a select statement to check for      |
80  |                              the existance of a bank charges row in the   |
81  |                              distributions table.  This is used to        |
82  |                              determine if a row needs to be created or    |
83  |                              we can simply update the existing one.       |
84  |                              If a bank charges row already exists and     |
85  |                              bank charges is set to NULL, update the row  |
86  |                              with zero amounts.                           |
87  |                              Included select statement to sum existing    |
88  |                              bank charge DR and CR entries.  This is used |
89  |                              to calculate the new DR and CR amounts       |
90  |                              (taking into account previously posted rows).|
91  |     16-APR-1998 GJWANG       Bug # 635872 Added condition checking whether|
92  |                              amount_due_remaining <> 0 and update cash    |
93  |                              receipt status to UNAPP and payment schedule |
94  |                              status to UNAPP and payment schedule staus to|
95  |                              'OP' and call populate_closed_dates to       |
96  |                              determine correct gl_date_closed and         |
97  |                              actual_date_closed                           |
98  |     21-MAY-1998 KTANG	For all calls to calc_acctd_amount which     |
99  |				calculates header accounted amounts, if the  |
100  |				exchange_rate_type is not user, call 	     |
101  |				gl_currency_api.convert_amount instead. This |
102  |				is for triangulation.			     |
103  |     29-JUL-1998 K.Murphy     Bug #667450.  Modified calculation of acctd  |
104  |                              factor discount amount.                      |
105  |     28-MAY-1999 J Rautiainen Bug #894443. The status of unidentified      |
106  |                              receipts cannot be changed to unapp.         |
107  |     12-OCT-2001 R Muthuraman Bug #2024016. Rate adjustment fail when      |
108  |				rate type is changed from 'User' to another  |
109  |				rate type.                                   |
110  |     25-03-2003  Ravi Sharma  Bug 2855253.debit and credit mismatch when   |
111  |                              the bank charges are updated.                |
112  |     07-MAY-2003 Jon Beckett  Bug 2946734 - moved claim update from        |
113  |                              ARXRWRCT.pld                                 |
114  |     30-JUL-2004 Jon Beckett  Bug 3796142 - removed unnecessary calls to   |
115  | 				gl_currency_api to convert receipt amount    |
116  |                              to functional currency. Receipt rate used    |
117  |				instead of GL daily rate in all cases.       |
118  |				Currency conversion only performed if amount |
119  |				has changed, otherwise acctd amount retrieved|
120  |                              from receipt history.                        |
121  |                                                                           |
122  |     01-JUN-2006  Herve Yu    BUG#4353362 Third Party Merge api uptake     |
123  +===========================================================================*/
124 
125 
126 PROCEDURE update_cash_receipt(
127 	p_cash_receipt_id	IN NUMBER,
128 --	p_batch_id		IN NUMBER,
129 	p_status		IN VARCHAR2,
130 	p_currency_code		IN VARCHAR2,
131 	p_amount		IN NUMBER,
132 	p_pay_from_customer	IN NUMBER,
133 	p_receipt_number	IN VARCHAR2,
134 	p_receipt_date		IN DATE,
135 	p_gl_date		IN DATE,
136 	p_maturity_date		IN DATE,
137 	p_comments		IN VARCHAR2,
138 	p_exchange_rate_type	IN VARCHAR2,
139 	p_exchange_rate		IN NUMBER,
140 	p_exchange_date		IN DATE,
141 	p_attribute_category	IN VARCHAR2,
142 	p_attribute1		IN VARCHAR2,
143 	p_attribute2		IN VARCHAR2,
144 	p_attribute3		IN VARCHAR2,
145 	p_attribute4		IN VARCHAR2,
146 	p_attribute5		IN VARCHAR2,
147 	p_attribute6		IN VARCHAR2,
148 	p_attribute7		IN VARCHAR2,
149 	p_attribute8		IN VARCHAR2,
150 	p_attribute9		IN VARCHAR2,
151 	p_attribute10		IN VARCHAR2,
152 	p_attribute11		IN VARCHAR2,
153 	p_attribute12		IN VARCHAR2,
154 	p_attribute13		IN VARCHAR2,
155 	p_attribute14		IN VARCHAR2,
156 	p_attribute15		IN VARCHAR2,
157 	p_override_remit_account_flag IN VARCHAR2,
158 	p_remittance_bank_account_id  IN NUMBER,
159 	p_customer_bank_account_id    IN NUMBER,
160 	p_customer_site_use_id	      IN NUMBER,
161 	p_customer_receipt_reference  IN VARCHAR2,
162 	p_factor_discount_amount      IN NUMBER,
163 	p_deposit_date		      IN DATE,
164 	p_receipt_method_id	      IN NUMBER,
165 	p_doc_sequence_value	      IN NUMBER,
166 	p_doc_sequence_id	      IN NUMBER,
167 	p_ussgl_transaction_code      IN VARCHAR2,
168 	p_vat_tax_id		      IN NUMBER,
169 --
170 	p_confirm_date		      IN  DATE,
171 	p_confirm_gl_date	      IN  DATE,
172 	p_unconfirm_gl_date	      IN DATE,
173         p_postmark_date               IN date, -- ARTA Changes
174 -- ******* Rate Adjustment parameters: ********
175 	p_rate_adjust_gl_date	      IN DATE,
176 	p_new_exchange_date	      IN DATE,
177 	p_new_exchange_rate	      IN NUMBER,
178 	p_new_exchange_rate_type      IN VARCHAR2,
179 	p_gain_loss		      IN NUMBER,
180 	p_exchange_rate_attr_cat      IN VARCHAR2,
181  	p_exchange_rate_attr1	      IN VARCHAR2,
182  	p_exchange_rate_attr2	      IN VARCHAR2,
183  	p_exchange_rate_attr3	      IN VARCHAR2,
184  	p_exchange_rate_attr4	      IN VARCHAR2,
185  	p_exchange_rate_attr5	      IN VARCHAR2,
186  	p_exchange_rate_attr6	      IN VARCHAR2,
187  	p_exchange_rate_attr7	      IN VARCHAR2,
188  	p_exchange_rate_attr8	      IN VARCHAR2,
189  	p_exchange_rate_attr9	      IN VARCHAR2,
190  	p_exchange_rate_attr10	      IN VARCHAR2,
191  	p_exchange_rate_attr11	      IN VARCHAR2,
192  	p_exchange_rate_attr12	      IN VARCHAR2,
193  	p_exchange_rate_attr13	      IN VARCHAR2,
194  	p_exchange_rate_attr14	      IN VARCHAR2,
195  	p_exchange_rate_attr15	      IN VARCHAR2,
196 --
197 -- ********* Reversal Info ***********
198 --
199 	p_reversal_date		IN DATE,
200 	p_reversal_gl_date	IN DATE,
201 	p_reversal_category	IN VARCHAR2,
202 	p_reversal_comments	IN VARCHAR2,
203 	p_reversal_reason_code  IN VARCHAR2,
204 	p_dm_reversal_flag  	IN varchar2,
205 	p_dm_cust_trx_type_id	IN NUMBER,
206 	p_dm_cust_trx_type	IN VARCHAR2,
207 	p_cc_id			IN NUMBER,
208 	p_dm_number		OUT NOCOPY VARCHAR2,
209 	p_dm_doc_sequence_value IN NUMBER,
210 	p_dm_doc_sequence_id	IN NUMBER,
211 	p_tw_status		IN OUT NOCOPY VARCHAR2,
212 
213 	p_anticipated_clearing_date	IN DATE,
214 	p_customer_bank_branch_id	IN NUMBER,
215 --
216 -- ******* Global Flexfield parameters *******
217 --
218 	p_global_attribute1		IN VARCHAR2,
219 	p_global_attribute2		IN VARCHAR2,
220 	p_global_attribute3		IN VARCHAR2,
221 	p_global_attribute4		IN VARCHAR2,
222 	p_global_attribute5		IN VARCHAR2,
223 	p_global_attribute6		IN VARCHAR2,
224 	p_global_attribute7		IN VARCHAR2,
225 	p_global_attribute8		IN VARCHAR2,
226 	p_global_attribute9		IN VARCHAR2,
227 	p_global_attribute10		IN VARCHAR2,
228 	p_global_attribute11		IN VARCHAR2,
229 	p_global_attribute12		IN VARCHAR2,
230 	p_global_attribute13		IN VARCHAR2,
231 	p_global_attribute14		IN VARCHAR2,
232 	p_global_attribute15		IN VARCHAR2,
233 	p_global_attribute16		IN VARCHAR2,
234 	p_global_attribute17		IN VARCHAR2,
235 	p_global_attribute18		IN VARCHAR2,
236 	p_global_attribute19		IN VARCHAR2,
237 	p_global_attribute20		IN VARCHAR2,
238 	p_global_attribute_category	IN VARCHAR2,
239 --
240 -- ******* Notes Receivable Information *******
241         p_issuer_name           	IN VARCHAR2,
242         p_issue_date            	IN DATE,
243         p_issuer_bank_branch_id 	IN NUMBER,
244 --
245 -- ******* enhancement 2074220 *****************
246         p_application_notes             IN VARCHAR2,
247 --
248 -- ******* Receipt State/Status Return information ******
249 --
250 	p_new_state		OUT NOCOPY VARCHAR2,
251 	p_new_state_dsp		OUT NOCOPY VARCHAR2,
252 	p_new_status		OUT NOCOPY VARCHAR2,
253 	p_new_status_dsp	OUT NOCOPY VARCHAR2,
254 --
255 --
256 -- ******* Form information ********
257         p_form_name                     IN  VARCHAR2,
258         p_form_version                  IN  VARCHAR2,
259 --
260 -- ******* Credit Card changes
261         p_payment_server_order_num      IN  VARCHAR2,
262         p_approval_code                 IN  VARCHAR2,
263         p_legal_entity_id               IN  NUMBER default NULL,
264         p_payment_trxn_extension_id     IN  NUMBER default NULL   /* PAYMENT_UPTAKE */
265 			) IS
266 
267 l_cr_rec		ar_cash_receipts%ROWTYPE;
268 l_crh_rec		ar_cash_receipt_history%ROWTYPE;
269 l_crh_rec_new		ar_cash_receipt_history%ROWTYPE;
270 l_ps_rec		ar_payment_schedules%ROWTYPE;
271 l_dist_rec		ar_distributions%ROWTYPE;
272 l_crh_id_new		ar_cash_receipt_history.cash_receipt_history_id%TYPE;
273 l_ra_id_unapp           ar_receivable_applications.receivable_application_id%TYPE;
274 l_ra_id_unid            ar_receivable_applications.receivable_application_id%TYPE;
275 l_ae_doc_rec            ae_doc_rec_type;
276 
277 -- boolean flags:
278 
279 l_cr_amount_changed_flag	BOOLEAN := FALSE;
280 l_crh_fda_changed_flag		BOOLEAN	:= FALSE;
281 l_crh_acctd_fda_changed_flag    BOOLEAN := FALSE;
282 l_crh_rec_posted_flag		BOOLEAN := FALSE;
283 l_crh_rec_gl_date_changed       BOOLEAN := FALSE;
284 l_rct_identified_flag		BOOLEAN := FALSE;
285 l_rct_unidentified_flag		BOOLEAN := FALSE;
286 
287 -- accounts:
288 
289 l_crh_ccid			NUMBER;
290 l_bank_charges_ccid		NUMBER;
291 l_unidentified_ccid		NUMBER;
292 l_unapplied_ccid		NUMBER;
293 l_dummy_ccid			NUMBER;		-- dummy ccid parameter
294 
295 -- amounts:
296 
297 l_cr_acctd_amount_new		NUMBER;
298 l_cr_acctd_amount_old		NUMBER;
299 l_cr_amount_delta		NUMBER;
300 l_cr_acctd_amount_delta		NUMBER;
301 l_crh_amount_new		NUMBER;
302 l_crh_amount_delta		NUMBER;
303 l_crh_acctd_amount_new		NUMBER;
304 l_crh_acctd_amount_delta	NUMBER;
305 l_crh_acctd_fda_new		NUMBER;
306 l_crh_acctd_fda_delta		NUMBER;
307 l_crh_fda_delta			NUMBER;
308 l_sum_fda_debits                NUMBER;
309 l_sum_fda_credits               NUMBER;
310 l_sum_acctd_fda_debits          NUMBER;
311 l_sum_acctd_fda_credits         NUMBER;
312 
313 -- other stuff:
314 
315 l_source_type			ar_distributions.source_type%TYPE;
316 l_creation_status		ar_cash_receipt_history.status%TYPE;
317 l_rev_crh_id			ar_cash_receipt_history.reversal_cash_receipt_hist_id%TYPE;
318 
319 -- dummy variables:
320 
321 l_override_dummy		ar_cash_receipts.override_remit_account_flag%TYPE;
322 l_number_dummy			NUMBER;
323 
324 -- GL date defaulting variables
325 l_error_message                 VARCHAR2(128);
326 l_defaulting_rule_used          VARCHAR2(50);
327 l_valid_gl_date                 DATE;
328 error_defaulting_gl_date        EXCEPTION;
329 
330 l_bank_charges_row_exists       VARCHAR2(1);
331 l_bcharge_row_on_current_crh    VARCHAR2(1); /* Bug fix 3677912 */
332 l_dist_row_on_current_crh       VARCHAR2(1); /* Bug fix 3677912 */
333 
334 
335 -- old stuff:
336 /*
337 l_source_type_old	ar_distributions.source_type%TYPE;
338 l_creation_status_old	ar_cash_receipt_history.status%TYPE;
339 l_acctd_amount_old	ar_cash_receipt_history.acctd_amount%TYPE;
340 l_ccid_old		ar_cash_receipt_history.account_code_combination_id%TYPE;
341 l_source_type_new	ar_distributions.source_type%TYPE;
342 l_creation_status_new	ar_cash_receipt_history.status%TYPE;
343 l_acctd_amount_new	ar_cash_receipt_history.acctd_amount%TYPE;
344 l_ccid_new		ar_cash_receipt_history.account_code_combination_id%TYPE;
345 l_ps_id			ar_payment_schedules.payment_schedule_id%TYPE;
346 l_id_dummy		NUMBER;
347 l_amount_changed	BOOLEAN := FALSE;
348 l_rev_crh_id		ar_cash_receipt_history.cash_receipt_history_id%TYPE;
349 l_ra_unapp_ccid		NUMBER;
350 l_ra_unid_ccid		NUMBER;
351 l_ra_unapp_ccid_old	NUMBER;
352 l_ra_unid_ccid_old	NUMBER;
353 
354 */
355 
356 /* Bug 2103139
357    variable to store the number of bank accounts already existing
358    for the customer and the given bank_account_id */
359 l_no_of_accounts number;
360 
361 /*added for the bug 2641517 */
362 l_rct_site_changed_flag     BOOLEAN := FALSE;
363 l_rct_customer_changed_flag BOOLEAN := FALSE;
364 l_trx_sum_hist_rec          AR_TRX_SUMMARY_HIST%rowtype;
365 l_history_id     NUMBER;
366 l_return_status         VARCHAR2(1);
367 l_msg_count             NUMBER;
368 l_msg_data              VARCHAR2(2000);
369 
370 --{BUG#4353362
371 CURSOR cu_current_customer IS
372 SELECT pay_from_customer,
373        customer_site_use_id
374   FROM ar_cash_receipts
375  WHERE cash_receipt_id = p_cash_receipt_id;
376 l_current_customer_id     NUMBER;
377 l_current_csu_id          NUMBER;
378 x_errbuf                  VARCHAR2(2000);
379 x_retcode                 VARCHAR2(10);
380 x_event_ids               xla_third_party_merge_pub.t_event_ids;
381 x_request_id              NUMBER;
382 --}
383 BEGIN
384 
385   IF PG_DEBUG in ('Y', 'C') THEN
386      arp_standard.debug('arp_process_receipts.update_cash_receipt()+');
387   END IF;
388 
389   -- --------------------------------------------------------------
390   -- First fetch and lock existing records from database for update
391   -- --------------------------------------------------------------
392 
393   -- get current cash_receipt_history record:
394 
395   l_crh_rec.cash_receipt_id	:= p_cash_receipt_id;
396   arp_cr_history_pkg.nowaitlock_fetch_f_cr_id(l_crh_rec);
397 
398   -- get cash receipt record:
399 
400   l_cr_rec.cash_receipt_id 	:= p_cash_receipt_id;
401   arp_cash_receipts_pkg.nowaitlock_fetch_p(l_cr_rec);
402 
403   -- get payment schedule record for receipt:
404 
405   arp_proc_rct_util.get_ps_rec(l_cr_rec.cash_receipt_id,
406 	     l_ps_rec);
407 
408    --apandit
409    --Bug 2641517, populating the history rec.
410    l_trx_sum_hist_rec.cash_receipt_id := l_ps_rec.cash_receipt_id;
411    l_trx_sum_hist_rec.site_use_id   := l_ps_rec.customer_site_use_id;
412    l_trx_sum_hist_rec.customer_id   := l_ps_rec.customer_id;
413    l_trx_sum_hist_rec.currency_code := l_ps_rec.invoice_currency_code;
414    l_trx_sum_hist_rec.amount_due_original := l_ps_rec.amount_due_original;
415    l_trx_sum_hist_rec.amount_due_remaining := l_ps_rec.amount_due_remaining;
416    l_trx_sum_hist_rec.payment_schedule_id := l_ps_rec.payment_schedule_id;
417    l_trx_sum_hist_rec.trx_date            := l_ps_rec.trx_date;
418 
419     IF nvl(p_customer_site_use_id,0) <> nvl(l_ps_rec.customer_site_use_id,0)
420      THEN
421         l_rct_site_changed_flag := TRUE;
422     END IF;
423 
424     IF p_pay_from_customer IS NOT NULL AND
425        l_ps_rec.customer_id IS NOT NULL AND
426        p_pay_from_customer <> l_ps_rec.customer_id  THEN
427       l_rct_customer_changed_flag := TRUE;
428     END IF;
429 
430   -- KML 05-13-97
431   -----------------------------------------------------
432   -- Determine a valid GL date for receipt and apps
433   -- use the receipt gl_date as a base
434   -- need to make sure that it is in a valid GL period
435   -----------------------------------------------------
436   IF (arp_util.validate_and_default_gl_date(
437                 l_crh_rec.gl_date,
438                 NULL,
439                 NULL,
440                 NULL,
441                 NULL,
442                 l_crh_rec.gl_date,
443                 NULL,
444                 NULL,
445                 'N',
446                 NULL,
447                 arp_global.set_of_books_id,
448                 222,
449                 l_valid_gl_date,
450                 l_defaulting_rule_used,
451                 l_error_message) = TRUE) THEN
452      null;
453   ELSE
454      RAISE error_defaulting_gl_date;
455   END IF;
456 
457   -- -------------------------------------------------------------
458   -- Now compare parameters with database values to find out NOCOPY what
459   -- has changed and what needs to be done.  Depending on whether
460   -- the amounts have changed and whether the receipt was already
461   -- posted, more or less complicated things need to be done.
462   -- -------------------------------------------------------------
463 
464   -- check if cr.amount has changed
465 
466   IF (p_amount <> l_cr_rec.amount)
467     THEN
468       l_cr_amount_changed_flag := TRUE;
469       IF PG_DEBUG in ('Y', 'C') THEN
470          arp_standard.debug('update_cash_receipt: ' || 'l_cr_amount_changed_flag = TRUE');
471       END IF;
472   END IF;
473 
474   -- check if the gl date of the receipt is still valid
475 
476   IF PG_DEBUG in ('Y', 'C') THEN
477      arp_standard.debug('update_cash_receipt: ' || 'P_GL_DATE is:' || to_char(p_gl_date, 'DD-MM-YYYY:HH:SS'));
478      arp_standard.debug('update_cash_receipt: ' || 'l_valid_gl_date is:' || to_char(l_valid_gl_date, 'DD-MM-YYYY:HH:SS'));
479   END IF;
480 
481   IF (p_gl_date <> l_valid_gl_date)
482     THEN
483       l_crh_rec_gl_date_changed := TRUE;
484       IF PG_DEBUG in ('Y', 'C') THEN
485          arp_standard.debug('update_cash_receipt: ' || 'l_crh_rec_gl_date_changed = TRUE');
486       END IF;
487   END IF;
488 
489 
490   -- check if crh.factor_discount_amount has changed
491 
492   IF (NVL(p_factor_discount_amount,0) <>
493       NVL(l_crh_rec.factor_discount_amount,0))
494     THEN
495       l_crh_fda_changed_flag := TRUE;
496       IF PG_DEBUG in ('Y', 'C') THEN
497          arp_standard.debug('update_cash_receipt: ' || 'l_crh_fda_changed_flag = TRUE');
498       END IF;
499 
500   END IF;
501 
502   -- check if crh record was posted to GL
503 
504   IF (l_crh_rec.posting_control_id <> -3)
505     THEN
506       l_crh_rec_posted_flag := TRUE;
507       IF PG_DEBUG in ('Y', 'C') THEN
508          arp_standard.debug('update_cash_receipt: ' || 'l_crh_rec_posted_flag = TRUE');
509       END IF;
510   END IF;
511 
512   -- check if receipt was identified  (UNID -> UNAPP)
513 
514   IF (l_cr_rec.pay_from_customer IS NULL AND
515       p_pay_from_customer IS NOT NULL)
516     THEN
517       l_rct_identified_flag := TRUE;
518       IF PG_DEBUG in ('Y', 'C') THEN
519          arp_standard.debug('update_cash_receipt: ' || 'l_rct_identified_flag = TRUE');
520       END IF;
521   END IF;
522 
523   -- check if receipt was "un-identified" (UNAPP -> UNID)
524 
525   IF (l_cr_rec.pay_from_customer IS NOT NULL AND
526       p_pay_from_customer IS NULL)
527     THEN
528       l_rct_unidentified_flag := TRUE;
529       IF PG_DEBUG in ('Y', 'C') THEN
530          arp_standard.debug('update_cash_receipt: ' || 'l_rct_unidentified_flag = TRUE');
531       END IF;
532   END IF;
533 
534   -- -------------------------------------------------------------
535   -- determine account code combination ids
536   -- -------------------------------------------------------------
537 
538   arp_proc_rct_util.get_ccids(
539 		p_receipt_method_id,
540 		p_remittance_bank_account_id,
541 		l_unidentified_ccid,
542 		l_unapplied_ccid,
543 		l_dummy_ccid,		-- on account
544 		l_dummy_ccid,		-- earned ccid
545 		l_dummy_ccid,		-- unearned ccid
546 		l_bank_charges_ccid,
547 		l_dummy_ccid,		-- factor ccid
548 		l_dummy_ccid,		-- confirmation_ccid
549 		l_dummy_ccid,		-- remittance ccid
550 		l_dummy_ccid		-- cash ccid
551 	   );
552 
553   -- -------------------------------------------------------------
554   -- determine the source type and creation status
555   -- -------------------------------------------------------------
556 
557   -- the source type is needed for AR_DISTRIBUTIONS records
558 
559   arp_cr_util.get_creation_info(p_receipt_method_id,
560 				p_remittance_bank_account_id,
561 	      			l_creation_status,
562 				l_source_type,
563 				l_crh_ccid,
564 				l_override_dummy);
565 
566   -- -------------------------------------------------------------
567   -- determine the amounts
568   -- -------------------------------------------------------------
569 
570   -- convert new cr.amount into functional currency:
571 
572   /* Bug 3796142 - receipt exchange rate should be used for updates, but
573      only if amount has actually changed */
574   l_cr_acctd_amount_old := (NVL(l_crh_rec.acctd_amount,0) + NVL(l_crh_rec.acctd_factor_discount_amount,0));
575   IF (l_cr_amount_changed_flag) THEN
576     arp_util.calc_acctd_amount(	NULL,
577 				NULL,
578 				NULL,
579 				l_cr_rec.exchange_rate,
580 				'+',
581 				p_amount,
582 				l_cr_acctd_amount_new,
583 				0,
584 				l_number_dummy,
585 				l_number_dummy,
586 				l_number_dummy);
587   ELSE
588      l_cr_acctd_amount_new := l_cr_acctd_amount_old;
589   END IF;
590 
591   -- determine the new cash_receipt_history amount:
592 
593   l_crh_amount_new := p_amount - NVL(p_factor_discount_amount,0);
594 
595   /* Bug 3796142 - receipt exchange rate should be used for updates, but
596      only if amount has actually changed */
597 
598   IF (l_cr_amount_changed_flag OR l_crh_fda_changed_flag) THEN
599     arp_util.calc_acctd_amount(	NULL,
600 				NULL,
601 				NULL,
602 				l_cr_rec.exchange_rate,
603 				'+',
604 				l_crh_amount_new,
605 				l_crh_acctd_amount_new,
606 				0,
607 				l_number_dummy,
608 				l_number_dummy,
609 				l_number_dummy);
610   ELSE
611     l_crh_acctd_amount_new := l_crh_rec.acctd_amount;
612   END IF;
613 
614   -- acctd_factor_discount_amount = triangulated(amount +
615   --				      factor_discount_amount) -
616   --				      triangulated(amount)
617 
618   l_crh_acctd_fda_new := l_cr_acctd_amount_new -
619                  	 l_crh_acctd_amount_new;
620 
621   -- This will help us to identify the situation where the fda has not
622   -- changed but the acctd fda has as a result of a receipt amount change.
623 
624   IF (NVL(l_crh_rec.acctd_factor_discount_amount,0) <>
625       NVL(l_crh_acctd_fda_new,0)) THEN
626      l_crh_acctd_fda_changed_flag := TRUE;
627   END IF;
628 
629   -- determine deltas:
630 
631   l_cr_amount_delta 		:= p_amount -
632 				   l_cr_rec.amount;
633 
634   l_cr_acctd_amount_delta 	:= l_cr_acctd_amount_new -
635 				   l_cr_acctd_amount_old;
636 
637   l_crh_amount_delta		:= l_crh_amount_new -
638 				   l_crh_rec.amount;
639 
640   l_crh_acctd_amount_delta	:= l_crh_acctd_amount_new -
641 				   l_crh_rec.acctd_amount;
642 
643   l_crh_fda_delta		:= p_factor_discount_amount -
644 				   l_crh_rec.factor_discount_amount;
645 
646   l_crh_acctd_fda_delta		:= l_crh_acctd_fda_new -
647 				   l_crh_rec.acctd_factor_discount_amount;
648 
649   --
650   -- Factor Discount Amount
651   -- Need to use NVL as the Bank Charges may be null or modified to
652   -- be null.
653   --
654   l_crh_fda_delta               := nvl(p_factor_discount_amount,0) -
655                                    nvl(l_crh_rec.factor_discount_amount,0);
656 
657   l_crh_acctd_fda_delta         := nvl(l_crh_acctd_fda_new,0) -
658                                    nvl(l_crh_rec.acctd_factor_discount_amount,0);
659 
660   IF PG_DEBUG in ('Y', 'C') THEN
661      arp_standard.debug('update_cash_receipt: ' || 'p_amount = 		'|| to_char(p_amount));
662      arp_standard.debug('update_cash_receipt: ' || 'l_crh_amount_new =	'|| to_char(l_crh_amount_new));
663      arp_standard.debug('update_cash_receipt: ' || 'l_crh_acctd_amount_new =  '|| to_char(l_crh_acctd_amount_new));
664   END IF;
665 
666   -- -------------------------------------------------------------
667   -- handle changes in rct identification status
668   -- -------------------------------------------------------------
669 
670   -- customer information:  can be updated as long as receipt has no
671   --			    applications.  Form checks this; no check
672   --			    required here.
673 
674   -- check if receipt status changed from UNID to UNAPP (i.e, receipt is
675   -- now identified.  In this case, the UNID record
676   -- needs to be reversed, and a new UNAPP record needs to be created.
677 
678   IF (l_rct_identified_flag = TRUE) THEN
679 
680     -- first reverse existing UNID record by setting reversal GL Date:
681 
682     UPDATE	ar_receivable_applications
683     SET 	reversal_gl_date = l_valid_gl_date
684     WHERE	cash_receipt_id  = p_cash_receipt_id
685     AND	        reversal_gl_date IS NULL
686     AND 	status = 'UNID';
687 
688     -- now create matching UNID record with negative amount
689 
690     arp_proc_rct_util.insert_ra_rec_cash(
691 			p_cash_receipt_id,
692 			-l_cr_rec.amount,
693 			p_receipt_date,
694 			'UNID',
695 			-l_cr_acctd_amount_old,
696 			l_valid_gl_date,
697 			l_unidentified_ccid,
698 			l_ps_rec.payment_schedule_id,
699 			'60.5',
700                         l_valid_gl_date,
701                         l_ra_id_unid     );
702 
703     --
704     --Release 11.5 VAT changes, create UNID receivable application accounting
705     --in ar_distributions
706     --
707     l_ae_doc_rec.document_type             := 'RECEIPT';
708     l_ae_doc_rec.document_id               := p_cash_receipt_id;
709     l_ae_doc_rec.accounting_entity_level   := 'ONE';
710     l_ae_doc_rec.source_table              := 'RA';
711     l_ae_doc_rec.source_id                 := l_ra_id_unid;
712     l_ae_doc_rec.source_id_old             := '';
713     l_ae_doc_rec.other_flag                := '';
714     arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
715 
716     -- now create new UNAPP record for this receipt:
717 
718     arp_proc_rct_util.insert_ra_rec_cash(
719 		      p_cash_receipt_id,
720 		      l_cr_rec.amount,
721 		      p_receipt_date,
722 		      'UNAPP',
723 		      l_cr_acctd_amount_old,
724 		      l_valid_gl_date,
725 		      l_unapplied_ccid,
726 		      l_ps_rec.payment_schedule_id,
727 		      '60.2',
728                       '',
729                       l_ra_id_unapp);
730 
731     --
732     --Release 11.5 VAT changes, create Paired UNAPP receivable application accounting
733     --in ar_distributions
734     --
735     l_ae_doc_rec.document_type             := 'RECEIPT';
736     l_ae_doc_rec.document_id               := p_cash_receipt_id;
737     l_ae_doc_rec.accounting_entity_level   := 'ONE';
738     l_ae_doc_rec.source_table              := 'RA';
739     l_ae_doc_rec.source_id                 := l_ra_id_unapp;
740     l_ae_doc_rec.source_id_old             := l_ra_id_unid;
741     l_ae_doc_rec.other_flag                := 'PAIR';
742 
743   /* We need to set the third party id and sub id as the cash receipt
744      is updated later */
745     l_ae_doc_rec.miscel5                   := p_pay_from_customer;
746     l_ae_doc_rec.miscel6                   := p_customer_site_use_id;
747     arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
748 
749     -- also don't forget to set the pay_from_customer column in
750     -- ar_cash_receipts to new customer and the status of the receipt:
751 
752     l_cr_rec.pay_from_customer := p_pay_from_customer;
753     l_cr_rec.status := 'UNAPP';
754 
755   ELSIF	(l_rct_unidentified_flag = TRUE) THEN
756 
757     -- now take care of the case where the user NULL'ed out NOCOPY the customer
758     -- fields:
759 
760     -- In this case, first reverse the UNAPP record and then create an
761     -- UNID record.
762 
763     UPDATE	ar_receivable_applications
764     SET 	reversal_gl_date = l_valid_gl_date
765     WHERE	cash_receipt_id  = p_cash_receipt_id
766     AND	        reversal_gl_date IS NULL
767     AND 	status = 'UNAPP';
768 
769     -- now create matching UNAPP record with negative amount
770 
771     arp_proc_rct_util.insert_ra_rec_cash(
772 			p_cash_receipt_id,
773 			-l_cr_rec.amount,
774 			p_receipt_date,
775 			'UNAPP',
776 			-l_cr_acctd_amount_old,
777 			l_valid_gl_date,
778 			l_unapplied_ccid,
779 			l_ps_rec.payment_schedule_id,
780 			'60.3',
781                         l_valid_gl_date,
782                         l_ra_id_unapp);
783 
784     -- now create new UNID record for this receipt:
785 
786     arp_proc_rct_util.insert_ra_rec_cash(
787 		      p_cash_receipt_id,
788 		      l_cr_rec.amount,
789 		      p_receipt_date,
790 		      'UNID',
791 		      l_cr_acctd_amount_old,
792 		      l_valid_gl_date,
793 		      l_unidentified_ccid,
794 		      l_ps_rec.payment_schedule_id,
795 		      '60.4',
796                       '',
797                       l_ra_id_unid);
798     --
799     --Release 11.5 VAT changes, create UNID receivable application accounting
800     --in ar_distributions
801     --
802     l_ae_doc_rec.document_type             := 'RECEIPT';
803     l_ae_doc_rec.document_id               := p_cash_receipt_id;
804     l_ae_doc_rec.accounting_entity_level   := 'ONE';
805     l_ae_doc_rec.source_table              := 'RA';
806     l_ae_doc_rec.source_id                 := l_ra_id_unid;
807     l_ae_doc_rec.source_id_old             := '';
808     l_ae_doc_rec.other_flag                := '';
809     arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
810 
811     --
812     --Release 11.5 VAT changes, create paired UNAPP receivable application accounting
813     --in ar_distributions
814     --
815     l_ae_doc_rec.document_type             := 'RECEIPT';
816     l_ae_doc_rec.document_id               := p_cash_receipt_id;
817     l_ae_doc_rec.accounting_entity_level   := 'ONE';
818     l_ae_doc_rec.source_table              := 'RA';
819     l_ae_doc_rec.source_id                 := l_ra_id_unapp;
820     l_ae_doc_rec.source_id_old             := l_ra_id_unid;
821     l_ae_doc_rec.other_flag                := 'PAIR';
822 
823   /* In this case as the receipt is unidentified, the third party id
824      and sub id is from the cash receipt, so no need to pass these */
825     arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
826 
827     -- also don't forget to set the pay_from_customer column in
828     -- ar_cash_receipts to NULL and the status to UNID.
829 
830     l_cr_rec.pay_from_customer := NULL;
831     l_cr_rec.status := 'UNID';
832 
833     --
834   ELSIF (l_cr_rec.pay_from_customer IS NOT NULL AND
835          p_pay_from_customer IS NOT NULL) THEN
836     --
837     -- in this case the user has changed the customer; applications
838     -- do not exist (otherwise the form would not have allowed the
839     -- update).  So just update the pay_from_customer column.
840 
841     l_cr_rec.pay_from_customer := p_pay_from_customer;
842     --
843   END IF;
844 
845   -- -------------------------------------------------------------
846   -- deal with amount changes
847   -- -------------------------------------------------------------
848 
849   -- if the receipt status is APPROVED, we only update the amounts in
850   -- ar_cash_receipts, ar_cash_receipt_history, and ar_payment_schedules,
851   -- but not ar_receivable_applications, since this is being taken
852   -- care of by the applications form and its server-side code:
853 
854 
855   IF (l_crh_rec.status = 'APPROVED') THEN
856 
857     l_cr_rec.amount 			:= p_amount;
858     l_crh_rec.amount 			:= p_amount;
859     l_crh_rec.acctd_amount		:= l_cr_acctd_amount_new;
860     l_ps_rec.amount_due_original	:= - p_amount;
861     l_ps_rec.amount_due_remaining 	:= - p_amount;
862     l_ps_rec.acctd_amount_due_remaining := - l_cr_acctd_amount_new;
863 
864     /* Bug fix 2964295
865        The cash_receipt_history record needs to be updated for APPROVED receipts */
866     arp_cr_history_pkg.update_p(l_crh_rec);
867 
868   ELSE  -- (l_crh_rec.status <> 'APPROVED')
869 
870     IF (l_cr_amount_changed_flag = TRUE or l_crh_fda_changed_flag = TRUE) THEN
871 
872       -- Update of the receipt payment schedule row and cr.amount is the same
873       -- regardless of the posting status of the receipt so we will do the
874       -- calculations now.
875 
876       -- ps.amount_due_remaining is defined as:
877 
878       -- ps.adr = - (unapplied amount + unid amount + on_account amount)
879       -- of course, the unapplied amount should be null if there is an
880       -- unidentified amount and vice versa.
881       -- Thus an amount update means that we take the previous ps.adr
882       -- and subtract (since adr is negative) the difference between
883       -- the new receipt amount and the old receipt amount.
884 
885       IF PG_DEBUG in ('Y', 'C') THEN
886          arp_standard.debug('update_cash_receipt: ' || 'l_ps_rec.amount_due_remaining: ' || to_char(l_ps_rec.amount_due_remaining));
887          arp_standard.debug('update_cash_receipt: ' || 'p_amount: ' || to_char(p_amount));
888          arp_standard.debug('update_cash_receipt: ' || 'l_cr_rec.amount: ' || to_char(l_cr_rec.amount));
889          arp_standard.debug('update_cash_receipt: ' || 'l_cr_acctd_amount_delta: ' || to_char(l_cr_acctd_amount_delta));
890       END IF;
891 
892       l_ps_rec.amount_due_remaining             :=
893                                 l_ps_rec.amount_due_remaining -
894                                 (p_amount - l_cr_rec.amount) ;
895 
896       l_ps_rec.acctd_amount_due_remaining       :=
897                                 l_ps_rec.acctd_amount_due_remaining -
898                                 l_cr_acctd_amount_delta;
899 
900       IF PG_DEBUG in ('Y', 'C') THEN
901          arp_standard.debug('update_cash_receipt: ' || 'l_ps_rec.amount_due_remaining: ' || to_char(l_ps_rec.amount_due_remaining));
902          arp_standard.debug('update_cash_receipt: ' || 'l_ps_rec.acctd_amount_due_remaining: ' || to_char(l_ps_rec.acctd_amount_due_remaining));
903       END IF;
904 
905       l_ps_rec.amount_due_original              := -p_amount;
906 
907       l_cr_rec.amount                           := p_amount;
908 
909       /* Bug 4294346 : In populating closed dates ,We should also consider the new RA
910          records which will be created to account for Difference in Receipt Amount */
911    /* arp_ps_util.populate_closed_dates( NULL, NULL, 'PMT', l_ps_rec ); */
912       IF ( NVL(l_ps_rec.amount_due_remaining,0)= 0) THEN
913         l_cr_rec.status := 'APP';
914         l_ps_rec.status := 'CL';
915       /* 28-MAY-1999 J Rautiainen
916        * The status of unidentified receipts cannot be changed to unapp.
917        * Bugfix for 894443 Start */
918       ELSIF (l_cr_rec.pay_from_customer IS NULL AND
919          p_pay_from_customer IS NULL) THEN
920         l_cr_rec.status := 'UNID';
921         l_ps_rec.status := 'OP';
922       /* Bugfix for 894443 end */
923       ELSE
924         l_cr_rec.status := 'UNAPP';
925         l_ps_rec.status := 'OP';
926       END IF;
927 
928 
929       IF (l_crh_rec_posted_flag = FALSE and l_crh_rec_gl_date_changed = FALSE ) THEN
930 
931         -- amount changes are fairly straight-forward if the current
932         -- history record has not been posted yet and gl period is stil
933         -- valid. We just update the cash receipt history record and
934         -- distribution records.
935 
936         IF (l_crh_amount_new <> l_crh_rec.amount) THEN
937  /* modified the parameter values passed for bug 2311742 */
938 
939           /* Bug fix 3677912 */
940           /* The distribution record can be updated only if the current CRH record has
941              one record in ARD corresponding to the l_source_type. Else we need to create one */
942            BEGIN
943             select 'Y'
944             into   l_dist_row_on_current_crh
945             from   ar_distributions dis
946             where  dis.source_id = l_crh_rec.cash_receipt_history_id
947             and    dis.source_table = 'CRH'
948             and    dis.source_type = l_source_type;
949           EXCEPTION
950             WHEN no_data_found THEN
951               l_dist_row_on_current_crh := 'N';
952           END;
953           IF PG_DEBUG in ('Y', 'C') THEN
954              arp_standard.debug('update_cash_receipt: '||'l_dist_row_on_current_crh : '||l_dist_row_on_current_crh);
955           END IF;
956           IF l_dist_row_on_current_crh = 'Y' THEN
957             arp_proc_rct_util.update_dist_rec(
958 			l_crh_rec.cash_receipt_history_id,
959 			l_source_type,
960 			l_crh_amount_new - l_crh_rec.amount,
961 			l_crh_acctd_amount_new - l_crh_rec.acctd_amount);
962           ELSE
963             IF PG_DEBUG in ('Y', 'C') THEN
964               arp_standard.debug('update_cash_receipt: ' || 'l_crh_amount_delta : ' || to_char(l_crh_amount_delta));
965               arp_standard.debug('update_cash_receipt: ' || 'l_crh_acctd_amount_delta : ' || to_char(l_crh_acctd_amount_delta));
966               arp_standard.debug('update_cash_receipt: ' || 'cash_receipt_history_id : ' || to_char(l_crh_rec.cash_receipt_history_id));
967               arp_standard.debug('update_cash_receipt: ' || 'l_source_type : ' || l_source_type);
968               arp_standard.debug('update_cash_receipt: ' || 'l_crh_ccid : ' || l_crh_ccid);
969            END IF;
970 
971             arp_proc_rct_util.insert_dist_rec(l_crh_amount_delta,
972                         l_crh_acctd_amount_delta,
973                         l_crh_rec.cash_receipt_history_id,
974                         l_source_type,
975                         l_crh_ccid);
976           END IF;
977 
978         END IF;
979 
980         -- Need to check the acctd fda flag.  The fda may not have
981         -- changed but the acctd fda may have been altered implicitly
982         -- as a result of a receipt amount change.
983 
984         IF (l_crh_fda_changed_flag = TRUE OR
985             l_crh_acctd_fda_changed_flag = TRUE) THEN
986 
987           --
988           -- Check to see if a Bank Charges distribution row
989           -- already exists.
990           --
991 
992           BEGIN
993             /* Bug fix 3677912
994                Bank charges record can be present for any CRH record */
995              select 'Y'
996              into   l_bank_charges_row_exists
997              from dual
998              where exists (select crh.cash_receipt_history_id
999                            from ar_cash_receipt_history crh, ar_distributions dis
1000                             where crh.cash_receipt_id = l_crh_rec.cash_receipt_id
1001                               and   dis.source_id = crh.cash_receipt_history_id
1002                               and   dis.source_table  = 'CRH'
1003                               and   dis.source_type ='BANK_CHARGES');
1004           EXCEPTION
1005             WHEN no_data_found THEN
1006               l_bank_charges_row_exists := 'N';
1007           END;
1008 
1009           /* Bug fix 3677912
1010              Check if the Bank Charge distribution exists for the current CRH record
1011              If not, we have to create it */
1012 
1013           BEGIN
1014             select 'Y'
1015             into   l_bcharge_row_on_current_crh
1016             from   ar_distributions dis
1017             where  dis.source_id = l_crh_rec.cash_receipt_history_id
1018             and    dis.source_table = 'CRH'
1019             and    dis.source_type = 'BANK_CHARGES';
1020           EXCEPTION
1021             WHEN no_data_found THEN
1022               l_bcharge_row_on_current_crh := 'N';
1023           END;
1024 
1025           IF l_bank_charges_row_exists = 'Y' THEN
1026 
1027              --
1028              -- If bank charge record existed before, then we can go ahead and
1029              -- update this record.
1030              --
1031              -- Firstly, we need to calculate what the updated amount should be.
1032              -- To do this we need to check if there are any existing (posted)
1033              -- distribution amounts for BANK_CHARGES.
1034              --
1035              -- Consider the following example:
1036              -- Cash Receipt: 'A'
1037              --                Posted   Amount   FDA   Dist Source   Amt DR  Amt CR
1038              --    History 1:    Y      10000    2000  BANK_CAHRGES  2000
1039              --    History 2:    N      10000    1500  BANK_CHARGES          500
1040              --
1041              -- If the Bank Charges are modified from 1500 to 2500, the result should
1042              -- be a DR entry of 500 (Total DR of 1500) which will replace the CR entry
1043              -- of 500.
1044              --
1045              -- Resulting in:
1046              -- Cash Receipt: 'A'
1047              --                Posted   Amount   FDA   Dist Source   Amt DR  Amt CR
1048              --    History 1:    Y      10000    2000  BANK_CAHRGES  2000
1049              --    History 2:    N      10000    2500  BANK_CHARGES   500
1050              --
1051              -- It is not sufficient to use the Factor Discount Amount for the current
1052              -- Cash Receipt History row as this doesn't take into account any prior/posted
1053              -- FDA amounts.
1054              --
1055 
1056              select nvl(sum(dis.amount_dr),0),
1057                     nvl(sum(dis.amount_cr),0),
1058                     nvl(sum(dis.acctd_amount_dr),0),
1059                     nvl(sum(dis.acctd_amount_cr),0)
1060              into   l_sum_fda_debits,
1061                     l_sum_fda_credits,
1062                     l_sum_acctd_fda_debits,
1063                     l_sum_acctd_fda_credits
1064              from   ar_distributions dis
1065              where  dis.source_id in
1066                     (select crh.cash_receipt_history_id
1067                      from   ar_cash_receipt_history crh
1068                      where  crh.cash_receipt_id = p_cash_receipt_id ) /* Bug2855253 removed  and    crh.current_record_flag ='N' */
1069 
1070              and    dis.source_table = 'CRH'
1071              and    dis.source_type = 'BANK_CHARGES';
1072 
1073              IF PG_DEBUG in ('Y', 'C') THEN
1074                 arp_standard.debug('update_cash_receipt: ' || 'p_factor_discount_amount: ' || to_char(p_factor_discount_amount));
1075                 arp_standard.debug('update_cash_receipt: ' || 'l_sum_fda_debits : ' || to_char(l_sum_fda_debits));
1076                 arp_standard.debug('update_cash_receipt: ' || 'l_sum_fda_credits: ' || to_char(l_sum_fda_credits));
1077                 arp_standard.debug('update_cash_receipt: ' || 'l_sum_acctd_fda_debits: ' || to_char(l_sum_acctd_fda_debits));
1078                 arp_standard.debug('update_cash_receipt: ' || 'l_sum_acctd_fda_credits: ' || to_char(l_sum_acctd_fda_credits));
1079              END IF;
1080 
1081              -- Positive result will create a DR entry, negative a CR entry.
1082 
1083             /* Bug fix 3677912 */
1084             IF l_bcharge_row_on_current_crh = 'Y' THEN
1085                arp_proc_rct_util.update_dist_rec(
1086                         l_crh_rec.cash_receipt_history_id,
1087                         'BANK_CHARGES',
1088                         nvl(p_factor_discount_amount,0) - (l_sum_fda_debits - l_sum_fda_credits),
1089                         nvl(l_crh_acctd_fda_new,0) - (l_sum_acctd_fda_debits - l_sum_acctd_fda_credits) );
1090             ELSE
1091                 arp_proc_rct_util.insert_dist_rec(
1092                    nvl(p_factor_discount_amount,0) - (l_sum_fda_debits - l_sum_fda_credits),
1093                    nvl(l_crh_acctd_fda_new,0) - (l_sum_acctd_fda_debits - l_sum_acctd_fda_credits),
1094                    l_crh_rec.cash_receipt_history_id,
1095                    'BANK_CHARGES',
1096                     l_bank_charges_ccid);
1097             END IF;
1098 
1099           ELSE          -- (NVL(l_crh_rec.factor_discount_amount,0) <= 0)
1100 
1101              --
1102              -- If no bank charge record existed before, we need to create one.
1103              --
1104 
1105              arp_proc_rct_util.insert_dist_rec(
1106                         p_factor_discount_amount,
1107                         l_crh_acctd_fda_new,
1108                         l_crh_rec.cash_receipt_history_id,
1109                         'BANK_CHARGES',
1110                         l_bank_charges_ccid);
1111 
1112           END IF;
1113 
1114         END IF;         -- (l_crh_fda_changed_flag = TRUE)
1115 
1116         -- now update amount columns in l_cr_rec
1117 
1118         l_crh_rec.amount 			:= l_crh_amount_new;
1119         l_crh_rec.acctd_amount  		:= l_crh_acctd_amount_new;
1120 	l_crh_rec.factor_discount_amount	:= p_factor_discount_amount;
1121 	l_crh_rec.acctd_factor_discount_amount  := l_crh_acctd_fda_new;
1122 
1123         -- populate the bank charge ccid only if there is a bank charge amount
1124 
1125 	IF (l_crh_rec.factor_discount_amount IS NOT NULL) THEN
1126           l_crh_rec.bank_charge_account_ccid	:= l_bank_charges_ccid;
1127 	ELSE
1128           l_crh_rec.bank_charge_account_ccid    := NULL;
1129         END IF;
1130 
1131         arp_cr_history_pkg.update_p(l_crh_rec);
1132 
1133       ELSE
1134 
1135 	-- Current cash receipt history record was posted.
1136         -- Date of the receipt is no longer valid
1137 	-- That means we need to create a new cash receipt history
1138         -- record and distribution records for it.
1139 
1140         -- make copy of cash receipt history record and null out/update
1141         -- columns that will be different in the new record.
1142 
1143         l_crh_rec_new := l_crh_rec;
1144 
1145 	l_crh_rec_new.cash_receipt_history_id 	:= NULL;
1146 	l_crh_rec_new.posting_control_id	:= -3;
1147 	l_crh_rec_new.gl_posted_date		:= NULL;
1148         -- #511576  Set the gl date for the new record.
1149 	l_crh_rec_new.gl_date		        := l_valid_gl_date;
1150 	l_crh_rec_new.first_posted_record_flag	:= 'N';
1151 
1152 	l_crh_rec_new.amount 			:= l_crh_amount_new;
1153 	l_crh_rec_new.acctd_amount 		:= l_crh_acctd_amount_new;
1154 	l_crh_rec_new.factor_discount_amount	:= p_factor_discount_amount;
1155 	l_crh_rec_new.acctd_factor_discount_amount := l_crh_acctd_fda_new;
1156 
1157         arp_cr_history_pkg.insert_p(l_crh_rec_new, l_crh_id_new);
1158 
1159         l_crh_rec_new.cash_receipt_history_id := l_crh_id_new;
1160 
1161 	-- modify the previously current cash receipt history record:
1162 
1163 	l_crh_rec.current_record_flag		:= 'N';
1164 	l_crh_rec.reversal_cash_receipt_hist_id := l_crh_id_new;
1165         -- #511576  Set the reversal gl date for the updated record.
1166 	l_crh_rec.reversal_gl_date		:= l_valid_gl_date;
1167 	l_crh_rec.reversal_created_from		:= 'ARRERG1B';
1168 
1169 	arp_cr_history_pkg.update_p(l_crh_rec);
1170 
1171 	-- from now on the new record is the current one:
1172 
1173         l_crh_rec := l_crh_rec_new;
1174 
1175         -- create new distributions for the new record.  These
1176 	-- distribution records are for the difference between the
1177 	-- amounts and factor_discount_amounts in the old and new
1178 	-- cash_receipt_history records.
1179 
1180         IF (l_crh_amount_delta <> 0) THEN
1181 
1182           IF PG_DEBUG in ('Y', 'C') THEN
1183              arp_standard.debug('update_cash_receipt: ' || 'l_crh_amount_delta : ' || to_char(l_crh_amount_delta));
1184              arp_standard.debug('update_cash_receipt: ' || 'l_crh_acctd_amount_delta : ' || to_char(l_crh_acctd_amount_delta));
1185              arp_standard.debug('update_cash_receipt: ' || 'cash_receipt_history_id : ' || to_char(l_crh_rec.cash_receipt_history_id));
1186              arp_standard.debug('update_cash_receipt: ' || 'l_source_type : ' || l_source_type);
1187              arp_standard.debug('update_cash_receipt: ' || 'l_crh_ccid : ' || l_crh_ccid);
1188           END IF;
1189 
1190   	  arp_proc_rct_util.insert_dist_rec(l_crh_amount_delta,
1191 			l_crh_acctd_amount_delta,
1192 			l_crh_rec.cash_receipt_history_id,
1193 			l_source_type,
1194 			l_crh_ccid);
1195         END IF;
1196 
1197         -- Need to check the acctd fda change also.  The fda may not have
1198         -- changed but the acctd fda may have been altered implicitly
1199         -- as a result of a receipt amount change.
1200 
1201         IF (l_crh_fda_delta <> 0 OR
1202             l_crh_acctd_fda_delta <> 0) THEN
1203 
1204          IF PG_DEBUG in ('Y', 'C') THEN
1205             arp_standard.debug('update_cash_receipt: ' || 'l_crh_fda_delta : ' || to_char(l_crh_fda_delta));
1206 	    arp_standard.debug('update_cash_receipt: ' || 'l_crh_acctd_fda_delta : ' || to_char(l_crh_acctd_fda_delta));
1207             arp_standard.debug('update_cash_receipt: ' || 'cash_receipt_history_id : ' || to_char(l_crh_rec.cash_receipt_history_id));
1208              arp_standard.debug('update_cash_receipt: ' || 'l_crh_ccid : ' || l_bank_charges_ccid);
1209           END IF;
1210 
1211           arp_proc_rct_util.insert_dist_rec(
1212 			l_crh_fda_delta,
1213 			l_crh_acctd_fda_delta,
1214 			l_crh_rec.cash_receipt_history_id,
1215 			'BANK_CHARGES',
1216 			l_bank_charges_ccid);
1217         END IF;
1218 
1219       END IF;
1220 
1221       -- now create receivable applications record to account for
1222       -- the difference in the receipt amount:
1223 
1224       IF (l_cr_rec.pay_from_customer IS NULL) THEN
1225 
1226  	-- receipt is unidentified; create UNID record in
1227 	-- AR_RECEIVABLE_APPLICATIONS
1228 
1229 	arp_proc_rct_util.insert_ra_rec_cash(
1230 			p_cash_receipt_id,
1231 			l_cr_amount_delta,
1232 			p_receipt_date,
1233 			'UNID',
1234 			l_cr_acctd_amount_delta,
1235 			l_valid_gl_date,
1236 			l_unidentified_ccid,
1237 			l_ps_rec.payment_schedule_id,
1238 			'60.4',
1239                         '',
1240                         l_ra_id_unid);
1241 
1242           /*mrc trigger elimination project*/
1243            ar_mrc_engine3.update_ra_rec_cash_diff(
1244                         p_rec_app_id           => l_ra_id_unid,
1245                         p_cash_receipt_id      => p_cash_receipt_id,
1246                         p_diff_amount          => l_cr_amount_delta,
1247                         p_old_rcpt_amount      => l_cr_rec.amount,
1248                         p_payment_schedule_id  =>l_ps_rec.payment_schedule_id
1249                         );
1250 
1251      --
1252      --Release 11.5 VAT changes, create UNID receivable application accounting
1253      --in ar_distributions
1254      --
1255        l_ae_doc_rec.document_type             := 'RECEIPT';
1256        l_ae_doc_rec.document_id               := p_cash_receipt_id;
1257        l_ae_doc_rec.accounting_entity_level   := 'ONE';
1258        l_ae_doc_rec.source_table              := 'RA';
1259        l_ae_doc_rec.source_id                 := l_ra_id_unid;
1260        l_ae_doc_rec.source_id_old             := '';
1261        l_ae_doc_rec.other_flag                := '';
1262        arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
1263 
1264       ELSE
1265 
1266  	-- receipt is identified; create UNAPP record in
1267 	-- AR_RECEIVABLE_APPLICATIONS
1268 
1269 	arp_proc_rct_util.insert_ra_rec_cash(
1270 			p_cash_receipt_id,
1271 			l_cr_amount_delta,
1272 			p_receipt_date,
1273 			'UNAPP',
1274 			l_cr_acctd_amount_delta,
1275 			l_valid_gl_date,
1276 			l_unapplied_ccid,
1277 			l_ps_rec.payment_schedule_id,
1278 			'60.2',
1279                         '',
1280                         l_ra_id_unapp);
1281 
1282      --
1283      --Release 11.5 VAT changes, create UNAPP receivable application accounting
1284      --in ar_distributions
1285      --
1286        l_ae_doc_rec.document_type             := 'RECEIPT';
1287        l_ae_doc_rec.document_id               := p_cash_receipt_id;
1288        l_ae_doc_rec.accounting_entity_level   := 'ONE';
1289        l_ae_doc_rec.source_table              := 'RA';
1290        l_ae_doc_rec.source_id                 := l_ra_id_unapp;
1291        l_ae_doc_rec.source_id_old             := '';
1292        l_ae_doc_rec.other_flag                := '';
1293 
1294   /* We need to set the third party id and sub id as the cash receipt
1295      is updated later */
1296        l_ae_doc_rec.miscel5                   := p_pay_from_customer;
1297        l_ae_doc_rec.miscel6                   := p_customer_site_use_id;
1298        arp_acct_main.Create_Acct_Entry(l_ae_doc_rec);
1299 
1300       END IF;
1301 
1302      arp_ps_util.populate_closed_dates( NULL, NULL, 'PMT', l_ps_rec ); /* Bug 4294346 */
1303 
1304     END IF;
1305 
1306   END IF;
1307 
1308   -- -------------------------------------------------------------
1309   -- Now update columns that don't require any special logic
1310   -- -------------------------------------------------------------
1311 
1312   -- update the 'easy stuff':
1313 
1314   l_cr_rec.customer_bank_branch_id := p_customer_bank_branch_id;
1315   l_cr_rec.anticipated_clearing_date := p_anticipated_clearing_date;
1316   l_cr_rec.receipt_number := p_receipt_number;
1317   l_cr_rec.doc_sequence_value := p_doc_sequence_value;
1318   l_cr_rec.doc_sequence_id := p_doc_sequence_id;
1319   l_cr_rec.customer_site_use_id := p_customer_site_use_id;
1320   l_cr_rec.customer_receipt_reference := p_customer_receipt_reference;
1321   l_cr_rec.customer_bank_account_id := p_customer_bank_account_id;
1322   l_cr_rec.comments := p_comments;
1323   l_cr_rec.attribute1 := p_attribute1;
1324   l_cr_rec.attribute2 := p_attribute2;
1325   l_cr_rec.attribute3 := p_attribute3;
1326   l_cr_rec.attribute4 := p_attribute4;
1327   l_cr_rec.attribute5 := p_attribute5;
1328   l_cr_rec.attribute6 := p_attribute6;
1329   l_cr_rec.attribute7 := p_attribute7;
1330   l_cr_rec.attribute8 := p_attribute8;
1331   l_cr_rec.attribute9 := p_attribute9;
1332   l_cr_rec.attribute10 := p_attribute10;
1333   l_cr_rec.attribute11 := p_attribute11;
1334   l_cr_rec.attribute12 := p_attribute12;
1335   l_cr_rec.attribute13 := p_attribute13;
1336   l_cr_rec.attribute14 := p_attribute14;
1337   l_cr_rec.attribute15 := p_attribute15;
1338   l_cr_rec.attribute_category := p_attribute_category;
1339   l_cr_rec.ussgl_transaction_code := p_ussgl_transaction_code;
1340   l_cr_rec.override_remit_account_flag := p_override_remit_account_flag;
1341   l_cr_rec.deposit_date	:= p_deposit_date;
1342   l_cr_rec.remit_bank_acct_use_id := p_remittance_bank_account_id;
1343   l_cr_rec.vat_tax_id	:= p_vat_tax_id;
1344 
1345   l_cr_rec.global_attribute1	:= p_global_attribute1;
1346   l_cr_rec.global_attribute2	:= p_global_attribute2;
1347   l_cr_rec.global_attribute3	:= p_global_attribute3;
1348   l_cr_rec.global_attribute4	:= p_global_attribute4;
1349   l_cr_rec.global_attribute5	:= p_global_attribute5;
1350   l_cr_rec.global_attribute6	:= p_global_attribute6;
1351   l_cr_rec.global_attribute7	:= p_global_attribute7;
1352   l_cr_rec.global_attribute8	:= p_global_attribute8;
1353   l_cr_rec.global_attribute9	:= p_global_attribute9;
1354   l_cr_rec.global_attribute10	:= p_global_attribute10;
1355   l_cr_rec.global_attribute11	:= p_global_attribute11;
1356   l_cr_rec.global_attribute12	:= p_global_attribute12;
1357   l_cr_rec.global_attribute13	:= p_global_attribute13;
1358   l_cr_rec.global_attribute14	:= p_global_attribute14;
1359   l_cr_rec.global_attribute15	:= p_global_attribute15;
1360   l_cr_rec.global_attribute16	:= p_global_attribute16;
1361   l_cr_rec.global_attribute17	:= p_global_attribute17;
1362   l_cr_rec.global_attribute18	:= p_global_attribute18;
1363   l_cr_rec.global_attribute19	:= p_global_attribute19;
1364   l_cr_rec.global_attribute20	:= p_global_attribute20;
1365   l_cr_rec.global_attribute_category	:= p_global_attribute_category;
1366 
1367   l_cr_rec.issuer_name           := p_issuer_name;
1368   l_cr_rec.issue_date            := p_issue_date;
1369   l_cr_rec.issuer_bank_branch_id := p_issuer_bank_branch_id;
1370 
1371   -- Credit Card changes.
1372 
1373   l_cr_rec.payment_server_order_num := p_payment_server_order_num;
1374   l_cr_rec.approval_code            := p_approval_code;
1375 
1376   -- ARTA Changes
1377   l_cr_rec.postmark_date        := p_postmark_date;
1378 
1379   -- Enhancement 2074220
1380   l_cr_rec.application_notes   := p_application_notes;
1381 
1382   -- LE
1383   l_cr_rec.legal_entity_id := p_legal_entity_id;
1384   -- PAYMENT_UPTAKE
1385   l_cr_rec.payment_trxn_extension_id := p_payment_trxn_extension_id;
1386 
1387 
1388   IF (l_crh_rec.status = 'APPROVED' AND
1389       p_status = 'CONFIRMED') THEN
1390     l_cr_rec.confirmed_flag := 'Y';
1391   ELSIF (l_crh_rec.status = 'CONFIRMED' AND
1392       p_status = 'APPROVED') THEN
1393     l_cr_rec.confirmed_flag := 'N';
1394   END IF;
1395 
1396   -- update payment schedule customer columns:
1397 
1398   l_ps_rec.customer_id := p_pay_from_customer;
1399   l_ps_rec.customer_site_use_id := p_customer_site_use_id;
1400 
1401   -- set payment schedule due date
1402 
1403   l_ps_rec.due_date := NVL(p_maturity_date, p_deposit_date);
1404 
1405   IF PG_DEBUG in ('Y', 'C') THEN
1406      arp_standard.debug('Before Inserting CR/CRH record in update_cash_receipt.');
1407   END IF;
1408 
1409 --{BUG#4353362
1410 OPEN cu_current_customer;
1411 FETCH cu_current_customer INTO l_current_customer_id, l_current_csu_id;
1412 IF cu_current_customer%FOUND THEN
1413 arp_acct_event_pkg.update_cr_dist
1414 ( p_ledger_id                 => arp_global.set_of_books_id
1415  ,p_source_id_int_1           => p_cash_receipt_id
1416  ,p_third_party_merge_date    => l_valid_gl_date
1417  ,p_original_third_party_id   => l_current_customer_id
1418  ,p_original_site_id          => l_current_csu_id
1419  ,p_new_third_party_id        => p_pay_from_customer
1420  ,p_new_site_id               => p_customer_site_use_id
1421  ,p_create_update             => 'U'
1422  ,p_entity_code               => 'RECEIPTS'
1423  ,p_type_of_third_party_merge => 'PARTIAL'
1424  ,p_mapping_flag              => 'N'
1425  ,p_execution_mode            => 'SYNC'
1426  ,p_accounting_mode           => 'F'
1427  ,p_transfer_to_gl_flag       => 'Y'
1428  ,p_post_in_gl_flag           => 'Y'
1429  ,p_third_party_type          => 'C'
1430  ,x_errbuf                    => x_errbuf
1431  ,x_retcode                   => x_retcode
1432  ,x_event_ids                 => x_event_ids
1433  ,x_request_id                => x_request_id);
1434 END IF;
1435 CLOSE cu_current_customer;
1436 --}
1437 
1438 
1439   -- update actual receipt record:
1440 
1441   arp_cash_receipts_pkg.update_p(l_cr_rec);
1442 
1443 /*
1444   -- update the history record:
1445 
1446   -- this should've happened earlier if the amount changed.
1447 
1448   arp_cr_history_pkg.update_p(l_crh_rec);
1449 
1450 */
1451 
1452   -- update payment schedule record:
1453 
1454   arp_ps_pkg.update_p(l_ps_rec);
1455 
1456   --apandit
1457   --Bug 2641517 creating a history record for the modification
1458   --and raising the business event.
1459   IF (l_cr_amount_changed_flag) OR
1460      (l_crh_fda_changed_flag) OR
1461      (l_rct_identified_flag) OR
1462      (l_rct_unidentified_flag) OR
1463      (l_rct_site_changed_flag) OR
1464      (l_rct_customer_changed_flag)
1465     THEN
1466    --Insert the history record
1467    AR_BUS_EVENT_COVER.p_insert_trx_sum_hist(l_trx_sum_hist_rec,
1468                                             l_history_id,
1469                                             'PMT',
1470                                             'MODIFY_PMT');
1471 
1472    --Raise the business event
1473    AR_BUS_EVENT_COVER.Raise_Rcpt_Modify_Event(l_ps_rec.cash_receipt_id,
1474                                         l_ps_rec.payment_schedule_id,
1475                                         l_history_id);
1476   END IF;
1477 
1478   -- check if receipt has been confirmed:
1479 
1480   IF (l_crh_rec.status = 'APPROVED' AND
1481       p_status = 'CONFIRMED') THEN
1482 
1483     arp_confirmation.confirm(
1484 		p_cash_receipt_id,
1485 		p_confirm_gl_date,
1486 		p_confirm_date,
1487 		p_form_name,
1488 		p_form_version);
1489 
1490   ELSIF (l_crh_rec.status = 'CONFIRMED' AND
1491       p_status = 'APPROVED') THEN
1492 
1493     arp_confirmation.unconfirm(
1494 		p_cash_receipt_id,
1495 		p_unconfirm_gl_date,
1496 		SYSDATE,
1497 		p_form_name,
1498 		p_form_version);
1499 
1500   END IF;
1501 
1502   IF (p_reversal_date IS NOT NULL AND
1503       l_cr_rec.reversal_date IS NULL) THEN
1504     IF PG_DEBUG in ('Y', 'C') THEN
1505        arp_standard.debug('update_cash_receipt: ' || 'Receipt needs to be reversed.');
1506     END IF;
1507     IF (p_dm_reversal_flag = 'Y') THEN
1508       IF PG_DEBUG in ('Y', 'C') THEN
1509          arp_standard.debug('update_cash_receipt: ' || 'Debit memo reversal required');
1510       END IF;
1511 
1512       arp_reverse_receipt.debit_memo_reversal(
1513 		l_cr_rec,
1514 		p_cc_id,
1515 		p_dm_cust_trx_type_id,
1516 		p_dm_cust_trx_type,
1517 		p_reversal_gl_date,
1518 		p_reversal_date,
1519 		p_reversal_category,
1520 		p_reversal_reason_code,
1521                 p_reversal_comments,
1522                 p_attribute_category, p_attribute1,
1523                 p_attribute2, p_attribute3, p_attribute4,
1524                 p_attribute5, p_attribute6, p_attribute7,
1525                 p_attribute8, p_attribute9, p_attribute10,
1526                 p_attribute11, p_attribute12, p_attribute13,
1527                 p_attribute14, p_attribute15,
1528 		p_dm_number,
1529 		p_dm_doc_sequence_value,
1530 		p_dm_doc_sequence_id,
1531 		p_tw_status,
1532 		p_form_name,
1533 		p_form_version);
1534        --apandit
1535        --Bug 2641517 Insert the history record and raising
1536        --the business event
1537        AR_BUS_EVENT_COVER.p_insert_trx_sum_hist(l_trx_sum_hist_rec,
1538                                                 l_history_id,
1539                                                 'PMT',
1540                                                 'DM_REVERSE_PMT');
1541 
1542        --Raise the business event
1543 
1544        AR_BUS_EVENT_COVER.Raise_Rcpt_DMReverse_Event(l_ps_rec.cash_receipt_id,
1545                                              l_ps_rec.payment_schedule_id,
1546                                              l_history_id);
1547     ELSE
1548       IF PG_DEBUG in ('Y', 'C') THEN
1549          arp_standard.debug('update_cash_receipt: ' || 'Regular reversal required');
1550       END IF;
1551 
1552       -- Bug 2946734 - update all claims on this receipt
1553       arp_reverse_receipt.cancel_claims(
1554                  p_cr_id               => l_cr_rec.cash_receipt_id
1555                , p_include_trx_claims  => 'Y'
1556                , x_return_status       => l_return_status
1557                , x_msg_count           => l_msg_count
1558                , x_msg_data            => l_msg_data);
1559       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1560          APP_EXCEPTION.raise_exception;
1561       END IF;
1562 
1563       arp_reverse_receipt.reverse(
1564 		l_cr_rec.cash_receipt_id,
1565 		p_reversal_category,
1566 		p_reversal_gl_date,
1567 		p_reversal_date,
1568 		p_reversal_reason_code,
1569 		p_reversal_comments,
1570 		NULL,			-- clear_batch_id
1571 		p_attribute_category,
1572 		p_attribute1,
1573 		p_attribute2,
1574 		p_attribute3,
1575 		p_attribute4,
1576 		p_attribute5,
1577 		p_attribute6,
1578 		p_attribute7,
1579 		p_attribute8,
1580 		p_attribute9,
1581 		p_attribute10,
1582 		p_attribute11,
1583 		p_attribute12,
1584 		p_attribute13,
1585 		p_attribute14,
1586 		p_attribute15,
1587 		p_form_name,
1588 		p_form_version,
1589 		l_rev_crh_id);
1590 
1591    --apandit
1592    --Bug 2641517 Insert the history record and raising
1593    --the business event
1594    IF PG_DEBUG in ('Y', 'C') THEN
1595       arp_standard.debug('update_cash_receipt: ' || 'before creating the history rec for BusinessEvent');
1596    END IF;
1597    AR_BUS_EVENT_COVER.p_insert_trx_sum_hist(l_trx_sum_hist_rec,
1598                                             l_history_id,
1599                                             'PMT',
1600                                             'REVERSE_PMT');
1601 
1602    --Raise the business event
1603    IF PG_DEBUG in ('Y', 'C') THEN
1604       arp_standard.debug('update_cash_receipt: ' || 'before raising the new business event');
1605    END IF;
1606    AR_BUS_EVENT_COVER.Raise_Rcpt_Reverse_Event(l_ps_rec.cash_receipt_id,
1607                                         l_ps_rec.payment_schedule_id,
1608                                         l_history_id);
1609     END IF;
1610 
1611   END IF;
1612 
1613   -- check if receipt needs to be rate-adjusted:
1614 
1615   IF (p_rate_adjust_gl_date IS NOT NULL) THEN
1616     arp_proc_rct_util.rate_adjust(
1617 		p_cash_receipt_id,
1618 		p_rate_adjust_gl_date,
1619 		p_new_exchange_date,
1620 		p_new_exchange_rate,
1621 		p_new_exchange_rate_type,
1622 		l_cr_rec.exchange_date,
1623 		l_cr_rec.exchange_rate,
1624 		l_cr_rec.exchange_rate_type,
1625 		p_gain_loss,
1626 		p_exchange_rate_attr_cat,
1627  		p_exchange_rate_attr1,
1628  		p_exchange_rate_attr2,
1629  		p_exchange_rate_attr3,
1630  		p_exchange_rate_attr4,
1631  		p_exchange_rate_attr5,
1632  		p_exchange_rate_attr6,
1633  		p_exchange_rate_attr7,
1634  		p_exchange_rate_attr8,
1635  		p_exchange_rate_attr9,
1636  		p_exchange_rate_attr10,
1637  		p_exchange_rate_attr11,
1638 		p_exchange_rate_attr12,
1639  		p_exchange_rate_attr13,
1640  		p_exchange_rate_attr14,
1641  		p_exchange_rate_attr15);
1642   END IF;
1643   IF PG_DEBUG in ('Y', 'C') THEN
1644      arp_standard.debug('arp_process_receipts.update_cash_receipt()+');
1645   END IF;
1646 
1647   -- determine receipt's new state and status and return it to form:
1648 
1649   -- Bug no 968913 SRAJASEK   Modified the sql statement to retrieve the data
1650   -- from the base tables rather than the ar_cash_receipt_v view for
1651   -- performance reasons
1652 
1653   SELECT cr.status,
1654 	 l_cr_status.meaning,
1655 	 crh_current.status ,
1656 	 l_crh_status.meaning
1657   INTO   p_new_status,
1658 	 p_new_status_dsp,
1659 	 p_new_state,
1660 	 p_new_state_dsp
1661   FROM
1662         ar_cash_receipt_history crh_current,
1663         ar_cash_receipts        cr,
1664         ar_lookups              l_cr_status,
1665         ar_lookups              l_crh_status
1666   WHERE
1667         cr.cash_receipt_id = p_cash_receipt_id
1668   AND   l_cr_status.lookup_type = 'CHECK_STATUS'
1669   AND   l_cr_status.lookup_code = cr.status
1670   AND   l_crh_status.lookup_type = 'RECEIPT_CREATION_STATUS'
1671   AND   l_crh_status.lookup_code = crh_current.status
1672   AND   crh_current.cash_receipt_id     = cr.cash_receipt_id
1673   AND   crh_current.current_record_flag = 'Y';
1674 
1675   EXCEPTION
1676     WHEN OTHERS THEN
1677       IF PG_DEBUG in ('Y', 'C') THEN
1678          arp_standard.debug('Exception in arp_process_receipts.update_cash_receipts');
1679          arp_standard.debug('update_cash_receipt: ' || 'p_cash_receipt_id =		'|| to_char(p_cash_receipt_id));
1680          arp_standard.debug('update_cash_receipt: ' || 'p_amount =			'|| to_char(p_amount));
1681          arp_standard.debug('update_cash_receipt: ' || 'p_factor_discount_amount =	'|| to_char(p_factor_discount_amount));
1682       END IF;
1683       RAISE;
1684 
1685   IF PG_DEBUG in ('Y', 'C') THEN
1686      arp_standard.debug('arp_process_rct_util.update_cash_receipts()-');
1687   END IF;
1688 
1689 END update_cash_receipt;
1690 
1691 END ARP_PROC_RECEIPTS1;