DBA Data[Home] [Help]

PACKAGE BODY: APPS.ARP_PROCESS_RCTS

Source


1 PACKAGE BODY ARP_PROCESS_RCTS AS
2 /* $Header: ARRERGWB.pls 120.26.12000000.2 2007/10/12 07:04:44 mpsingh 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.26.12000000.2 $';
17 
18 END revision;
19 
20 
21 /*===========================================================================+
22  | PROCEDURE                                                                 |
23  |    lock_cash_receipt                             			     |
24  |                                                                           |
25  | DESCRIPTION                                                               |
26  |    Locks a cash receipt.						     |
27  |									     |
28  | SCOPE - PUBLIC                                                            |
29  |                                                                           |
30  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED 	                             |
31  |                                                                           |
32  | ARGUMENTS                                                                 |
33  |    IN:								     |
34  |    OUT:                                                                   |
35  |                                                                           |
36  | RETURNS    		                                                     |
37  |                                                                           |
38  | NOTES                                                                     |
39  |                                                                           |
40  | MODIFICATION HISTORY 						     |
41  |									     |
42  |    20-NOV-95	OSTEINME	created					     |
43  |    01-NOV-96  OSTEINME	added parameter anticipated_clearing_date    |
44  |				for CashBook enhancement (float support)     |
45  |    01-NOV-96  OSTEINME	added parameters for Japan project:	     |
46  |				  - customer_bank_branch_id		     |
47  |    30-DEC-96	 OSTEINME	added global flexfield parameters            |
48  |    05-FEB-03  RVSHARMA       added new parameter p_receipt_status for     |
49  |                              Bug 2688648.                                 |   |                                                                           |
50  +===========================================================================*/
51 
52 
53 PROCEDURE lock_cash_receipt(
54   	p_cash_receipt_id	IN NUMBER,
55 	p_currency_code		IN VARCHAR2,
56 	p_amount		IN NUMBER,
57 	p_pay_from_customer	IN NUMBER,
58 	p_receipt_number	IN VARCHAR2,
59 	p_receipt_date		IN DATE,
60 	p_gl_date		IN DATE,
61 	p_maturity_date		IN DATE,
62 	p_comments		IN VARCHAR2,
63 	p_exchange_rate_type	IN VARCHAR2,
64 	p_exchange_rate		IN NUMBER,
65 	p_exchange_date		IN DATE,
66 	p_batch_id		IN NUMBER,
67 	p_attribute_category	IN VARCHAR2,
68 	p_attribute1		IN VARCHAR2,
69 	p_attribute2		IN VARCHAR2,
70 	p_attribute3		IN VARCHAR2,
71 	p_attribute4		IN VARCHAR2,
72 	p_attribute5		IN VARCHAR2,
73 	p_attribute6		IN VARCHAR2,
74 	p_attribute7		IN VARCHAR2,
75 	p_attribute8		IN VARCHAR2,
76 	p_attribute9		IN VARCHAR2,
77 	p_attribute10		IN VARCHAR2,
78 	p_attribute11		IN VARCHAR2,
79 	p_attribute12		IN VARCHAR2,
80 	p_attribute13		IN VARCHAR2,
81 	p_attribute14		IN VARCHAR2,
82 	p_attribute15		IN VARCHAR2,
83 	p_override_remit_account_flag IN VARCHAR2,
84 	p_remittance_bank_account_id  IN NUMBER,
85 	p_customer_bank_account_id    IN NUMBER,
86 	p_customer_site_use_id	      IN NUMBER,
87 	p_customer_receipt_reference  IN VARCHAR2,
88 	p_factor_discount_amount      IN NUMBER,
89 	p_deposit_date		      IN DATE,
90 	p_receipt_method_id	      IN NUMBER,
91 	p_doc_sequence_value	      IN NUMBER,
92 	p_doc_sequence_id	      IN NUMBER,
93 	p_ussgl_transaction_code      IN VARCHAR2,
94 	p_vat_tax_id		      IN NUMBER,
95 	p_anticipated_clearing_date   IN DATE,
96 	p_customer_bank_branch_id     IN NUMBER,
97 --
98 -- ******* Global Flexfield parameters *******
99 --
100 	p_global_attribute1		IN VARCHAR2,
101 	p_global_attribute2		IN VARCHAR2,
102 	p_global_attribute3		IN VARCHAR2,
103 	p_global_attribute4		IN VARCHAR2,
104 	p_global_attribute5		IN VARCHAR2,
105 	p_global_attribute6		IN VARCHAR2,
106 	p_global_attribute7		IN VARCHAR2,
107 	p_global_attribute8		IN VARCHAR2,
108 	p_global_attribute9		IN VARCHAR2,
109 	p_global_attribute10		IN VARCHAR2,
110 	p_global_attribute11		IN VARCHAR2,
111 	p_global_attribute12		IN VARCHAR2,
112 	p_global_attribute13		IN VARCHAR2,
113 	p_global_attribute14		IN VARCHAR2,
114 	p_global_attribute15		IN VARCHAR2,
115 	p_global_attribute16		IN VARCHAR2,
116 	p_global_attribute17		IN VARCHAR2,
117 	p_global_attribute18		IN VARCHAR2,
118 	p_global_attribute19		IN VARCHAR2,
119 	p_global_attribute20		IN VARCHAR2,
120 	p_global_attribute_category	IN VARCHAR2,
121 --
122 --      Notes Receivable
123 --
124         p_issuer_name			IN VARCHAR2,
125 	p_issue_date			IN DATE,
126 	p_issuer_bank_branch_id		IN NUMBER,
127 --
128         p_application_notes             IN VARCHAR2,
129 --
130 --
131 	p_form_name		        IN VARCHAR2,
132 	p_form_version		        IN VARCHAR2,
133         p_payment_server_order_num      IN VARCHAR2,
134         p_approval_code                 IN VARCHAR2,
135         p_receipt_status                IN VARCHAR2,   /* Bug 2688648 */
136         p_rec_version_number            IN NUMBER,      /* Bug fix 3032059 */
137         p_payment_trxn_extension_id     IN NUMBER
138 				) IS
139 --
140 l_cr_rec	AR_CASH_RECEIPTS%ROWTYPE;
141 --
142 BEGIN
143 
144   IF PG_DEBUG in ('Y', 'C') THEN
145      arp_standard.debug('arp_process_receipts.lock_cash_receipt()+');
146   END IF;
147 
148   arp_cash_receipts_pkg.set_to_dummy(l_cr_rec);
149 
150   l_cr_rec.cash_receipt_id	:= p_cash_receipt_id;
151   l_cr_rec.currency_code 	:= p_currency_code;
152   l_cr_rec.amount 		:= p_amount;
153   l_cr_rec.receipt_number 	:= p_receipt_number;
154   l_cr_rec.receipt_date 	:= p_receipt_date;
155   l_cr_rec.comments 		:= p_comments;
156   l_cr_rec.exchange_rate_type	:= p_exchange_rate_type;
157   l_cr_rec.exchange_rate	:= p_exchange_rate;
158   l_cr_rec.exchange_date 	:= p_exchange_date;
159   l_cr_rec.attribute_category   := p_attribute_category;
160   l_cr_rec.attribute1		:= p_attribute1;
161   l_cr_rec.attribute2		:= p_attribute2;
162   l_cr_rec.attribute3		:= p_attribute3;
163   l_cr_rec.attribute4		:= p_attribute4;
164   l_cr_rec.attribute5		:= p_attribute5;
165   l_cr_rec.attribute6		:= p_attribute6;
166   l_cr_rec.attribute7		:= p_attribute7;
167   l_cr_rec.attribute8		:= p_attribute8;
168   l_cr_rec.attribute9		:= p_attribute9;
169   l_cr_rec.attribute10		:= p_attribute10;
170   l_cr_rec.attribute11		:= p_attribute11;
171   l_cr_rec.attribute12		:= p_attribute12;
172   l_cr_rec.attribute13		:= p_attribute13;
173   l_cr_rec.attribute14		:= p_attribute14;
174   l_cr_rec.attribute15		:= p_attribute15;
175 
176   l_cr_rec.remittance_bank_account_id  := p_remittance_bank_account_id;
177   l_cr_rec.override_remit_account_flag := p_override_remit_account_flag;
178   l_cr_rec.deposit_date		       := p_deposit_date;
179   l_cr_rec.receipt_method_id	       := p_receipt_method_id;
180 
181   l_cr_rec.doc_sequence_value	      := p_doc_sequence_value;
182   l_cr_rec.doc_sequence_id	      := p_doc_sequence_id;
183   l_cr_rec.pay_from_customer          := p_pay_from_customer;
184   l_cr_rec.customer_site_use_id       := p_customer_site_use_id;
185   l_cr_rec.customer_receipt_reference := p_customer_receipt_reference;
186   l_cr_rec.customer_bank_account_id   := p_customer_bank_account_id;
187   l_cr_rec.ussgl_transaction_code     := p_ussgl_transaction_code;
188   l_cr_rec.vat_tax_id	              := p_vat_tax_id;
189   l_cr_rec.anticipated_clearing_date  := p_anticipated_clearing_date;
190   l_cr_rec.customer_bank_branch_id    := p_customer_bank_branch_id;
191 
192   l_cr_rec.global_attribute1	:= p_global_attribute1;
193   l_cr_rec.global_attribute2	:= p_global_attribute2;
194   l_cr_rec.global_attribute3	:= p_global_attribute3;
195   l_cr_rec.global_attribute4	:= p_global_attribute4;
196   l_cr_rec.global_attribute5	:= p_global_attribute5;
197   l_cr_rec.global_attribute6	:= p_global_attribute6;
198   l_cr_rec.global_attribute7	:= p_global_attribute7;
199   l_cr_rec.global_attribute8	:= p_global_attribute8;
200   l_cr_rec.global_attribute9	:= p_global_attribute9;
201   l_cr_rec.global_attribute10	:= p_global_attribute10;
202   l_cr_rec.global_attribute11	:= p_global_attribute11;
203   l_cr_rec.global_attribute12	:= p_global_attribute12;
204   l_cr_rec.global_attribute13	:= p_global_attribute13;
205   l_cr_rec.global_attribute14	:= p_global_attribute14;
206   l_cr_rec.global_attribute15	:= p_global_attribute15;
207   l_cr_rec.global_attribute16	:= p_global_attribute16;
208   l_cr_rec.global_attribute17	:= p_global_attribute17;
209   l_cr_rec.global_attribute18	:= p_global_attribute18;
210   l_cr_rec.global_attribute19	:= p_global_attribute19;
211   l_cr_rec.global_attribute20	:= p_global_attribute20;
212   l_cr_rec.global_attribute_category	:= p_global_attribute_category;
213 
214   l_cr_rec.issuer_name              := p_issuer_name;
215   l_cr_rec.issue_date 		    := p_issue_date;
216   l_cr_rec.issuer_bank_branch_id    := p_issuer_bank_branch_id;
217 
218 -- Enh. 2074220:
219   l_cr_rec.application_notes := p_application_notes;
220 
221   l_cr_rec.payment_server_order_num := p_payment_server_order_num;
222   l_cr_rec.approval_code            := p_approval_code;
223   /* Bug fix 2963757 : Revert the fix for bug 2688648 */
224 /*  l_cr_rec.status                   := p_receipt_status;  */  /* bug 2688648 */
225 
226    /* Bug fix 3032059 */
227    l_cr_rec.rec_version_number      := p_rec_version_number;
228 
229    /* PAYMENT_UPTAKE  */
230    l_cr_rec.payment_trxn_extension_id := p_payment_trxn_extension_id;
231 
232   IF PG_DEBUG in ('Y', 'C') THEN
233      arp_standard.debug('lock_cash_receipt: ' || 'Exchange rate = ' || p_exchange_rate);
234      arp_standard.debug('lock_cash_receipt: ' || 'Exchange rate date = ' || p_exchange_date);
235      arp_standard.debug('lock_cash_receipt: ' || 'Exchange rate type = ' || p_exchange_rate_type);
236      arp_standard.debug('lock_cash_receipt: ' || 'Currency code = ' || p_currency_code);
237      arp_standard.debug('lock_cash_receipt: ' || 'Receipt Number = ' || p_receipt_number);
238      arp_standard.debug('lock_cash_receipt: ' || 'Payment server ord num = ' || p_payment_server_order_num);
239      arp_standard.debug('lock_cash_receipt: ' || 'Approval code = ' || p_approval_code);
240   END IF;
241 
242   arp_cash_receipts_pkg.lock_compare_p(l_cr_rec);
243 
244   IF PG_DEBUG in ('Y', 'C') THEN
245      arp_standard.debug('arp_process_receipts.lock_cash_receipt()-');
246   END IF;
247 
248   EXCEPTION
249      WHEN NO_DATA_FOUND THEN
250        FND_MESSAGE.Set_Name('FND', 'FORM_RECORD_CHANGED');
251        APP_EXCEPTION.Raise_Exception;
252      WHEN  OTHERS THEN
253        IF PG_DEBUG in ('Y', 'C') THEN
254           arp_standard.debug('EXCEPTION: arp_process_receipts.lock_cash_receipt()');
255        END IF;
256        RAISE;
257 
258 END lock_cash_receipt;
259 
260 
261 /*===========================================================================+
262  | PROCEDURE                                                                 |
263  |    delete_cash_receipt                              			     |
264  |                                                                           |
265  | DESCRIPTION                                                               |
266  |    Entity handler that delete cash receipts.				     |
267  |									     |
268  | SCOPE - PUBLIC                                                            |
269  |                                                                           |
270  | NOTES                                                                     |
271  |                                                                           |
272  | MODIFICATION HISTORY 						     |
273  |									     |
274  |    30-NOV-95	OSTEINME	created					     |
275  |    28-Dec-98 DJANCIS         added call to set posted flag to deterime if |
276  |                              receipt was posted before deleting it        |
277  |    08-Nov-01 DJANCIS		Modified for mrc trigger elimination project |
278  |				added call to ar_mrc_engine for deletes to   |
279  |				ar_payment_schedules    		     |
280  +===========================================================================*/
281 
282 PROCEDURE delete_cash_receipt(
283 	p_cash_receipt_id	IN NUMBER,
284 	p_batch_id		IN NUMBER) IS
285 
286 CURSOR get_app_C IS
287        select app.receivable_application_id app_id
288        from   ar_receivable_applications app
289        where  app.cash_receipt_id = p_cash_receipt_id
290        and    nvl(app.confirmed_flag,'Y') = 'Y'   --confirmed records have accounting only
291        and exists (select 'x'
292                    from  ar_distributions ard
293                    where ard.source_table = 'RA'
294                    and   ard.source_id    = app.receivable_application_id)
295        order by decode(app.status,
296                        'UNAPP',1,  --Delete UNAPP related accounting first as record may be paired
297                        2);
298 
299 /* Bug 4173339 */
300 l_trx_sum_hist_rec        AR_TRX_SUMMARY_HIST%rowtype;
301 
302 CURSOR get_existing_ps  IS
303 SELECT payment_schedule_id,
304        invoice_currency_code,
305        due_date,
306        amount_in_dispute,
307        amount_due_original,
308        amount_due_remaining,
309        amount_adjusted,
310        cash_receipt_id,
311        customer_id,
312        customer_site_use_id,
313        trx_date
314 FROM   ar_payment_schedules
315 WHERE  cash_receipt_id  = p_cash_receipt_id;
316 
317 CURSOR cReceiptDtls IS
318    SELECT receipt_number,
319           receipt_date
320    FROM   ar_cash_receipts
321    WHERE  cash_receipt_id = p_cash_receipt_id;
322 
323 
324 l_history_id		  NUMBER;
325 
326 p_posted_flag 		  BOOLEAN;
327 l_get_app_rec 		  get_app_C%ROWTYPE;
328 l_ae_doc_rec  		  ae_doc_rec_type;
329 
330 l_ar_ps_key_value_list    gl_ca_utility_pkg.r_key_value_arr;
331 l_ar_dist_key_value_list  gl_ca_utility_pkg.r_key_value_arr;
332 l_rec_app_key_value_list  gl_ca_utility_pkg.r_key_value_arr;
333 
334 l_receipt_number 	  ar_cash_receipts.receipt_number%type;
335 l_receipt_date 	  	  ar_cash_receipts.receipt_date%type;
336 
337 
338 BEGIN
339   IF PG_DEBUG in ('Y', 'C') THEN
340      arp_standard.debug('arp_process_receipts.delete_cash_receipt()+');
341   END IF;
342 
343   ARP_PROCESS_RCTS.set_posted_flag(p_cash_receipt_id,
344                                     p_posted_flag);
345   IF ( p_posted_flag = TRUE) THEN
346      -- raise and error and exit
347   IF PG_DEBUG in ('Y', 'C') THEN
348      arp_standard.debug('delete_cash_receipt: ' || 'posted flag = true ');
349   END IF;
350     fnd_message.set_name('AR','AR_RW_DEL_REC_POSTED');
351     app_exception.raise_exception;
352 
353   END IF;
354 
355   -- lock receipt record to make sure no one else has it locked
356 
357   arp_cash_receipts_pkg.lock_p(p_cash_receipt_id);
358 
359   -- delete AR_CASH_RECEIPTS receipt record:
360 
361   -- Before Deletion get the recipt details for Summary Tables
362   FOR ReceiptDtlsRec IN cReceiptDtls
363   LOOP
364 	l_receipt_number := ReceiptDtlsRec.receipt_number;
365 	l_receipt_date := ReceiptDtlsRec.receipt_date;
366   END LOOP;
367 
368   arp_cash_receipts_pkg.delete_p(p_cash_receipt_id);
369 
370   -- delete AR_DISTRIBUTIONS records created for each
371   -- AR_CASH_RECEIPT_HISTORY record.
372 
373   DELETE AR_DISTRIBUTIONS
374   WHERE source_table = 'CRH'
375     AND	source_id IN (
376     SELECT cash_receipt_history_id
377     FROM ar_cash_receipt_history
381 
378     WHERE cash_receipt_id = p_cash_receipt_id)
379   RETURNING line_id
380   BULK COLLECT INTO l_ar_dist_key_value_list;
382   /*---------------------------------+
383    | Calling central MRC library     |
384    | for MRC Integration             |
385    +---------------------------------*/
386 
387    ar_mrc_engine.maintain_mrc_data(
388              p_event_mode        => 'DELETE',
389              p_table_name        => 'AR_DISTRIBUTIONS',
390              p_mode              => 'BATCH',
391              p_key_value_list    => l_ar_dist_key_value_list);
392 
393 
394     --Bug # 6450286
395     --------------------------------
396     -- Delete the corresponding event in XLA schema
397     --------------------------------
398      ARP_XLA_EVENTS.delete_event( p_document_id  => p_cash_receipt_id,
399                                   p_doc_table    => 'CRH');
400 
401 
402   -- delete all AR_CASH_RECEIPT_HISTORY records created for this
403   -- receipt:
404   -- Bug 2021718:  Call entity handler for delete
405   arp_cr_history_pkg.delete_p_cr(p_cash_receipt_id);
406 
407   -- DELETE AR_CASH_RECEIPT_HISTORY
408   -- WHERE cash_receipt_id = p_cash_receipt_id;
409 
410   --Delete all associated accounting with the receivable applications
411   --first.
412 
413   FOR l_get_app_rec IN get_app_C LOOP
414 
415       l_ae_doc_rec.document_type           := 'RECEIPT';
416       l_ae_doc_rec.document_id             := p_cash_receipt_id;
417       l_ae_doc_rec.accounting_entity_level := 'ONE';
418       l_ae_doc_rec.source_table            := 'RA';
419       l_ae_doc_rec.source_id               := l_get_app_rec.app_id;
420       l_ae_doc_rec.source_id_old           := '';
421       l_ae_doc_rec.other_flag              := '';
422 
423       arp_acct_main.Delete_Acct_Entry(l_ae_doc_rec);
424 
425   END LOOP;
426 
427   -- delete all AR_RECEIVABLE_APPLICATIONS records created for this
428   -- receipt:
429 
430   DELETE AR_RECEIVABLE_APPLICATIONS
431   WHERE cash_receipt_id = p_cash_receipt_id
432   RETURNING receivable_application_id
433   BULK COLLECT INTO l_rec_app_key_value_list;
434 
435  /*---------------------------------+
436    | Calling central MRC library     |
437    | for MRC Integration             |
438   +---------------------------------*/
439 
440   ar_mrc_engine.maintain_mrc_data(
441              p_event_mode        => 'DELETE',
442              p_table_name        => 'AR_RECEIVABLE_APPLICATIONS',
443              p_mode              => 'BATCH',
444              p_key_value_list    => l_rec_app_key_value_list);
445 
446   /* Bug 4173339
447      Store the ps record values into history table before deleting.
448   */
449   OPEN get_existing_ps;
450 
451   FETCH get_existing_ps
452   INTO  l_trx_sum_hist_rec.payment_schedule_id,
453         l_trx_sum_hist_rec.currency_code,
454         l_trx_sum_hist_rec.due_date,
455         l_trx_sum_hist_rec.amount_in_dispute,
456         l_trx_sum_hist_rec.amount_due_original,
457         l_trx_sum_hist_rec.amount_due_remaining,
458         l_trx_sum_hist_rec.amount_adjusted,
459         l_trx_sum_hist_rec.customer_trx_id,
460         l_trx_sum_hist_rec.customer_id,
461         l_trx_sum_hist_rec.site_use_id,
462         l_trx_sum_hist_rec.trx_date;
463 
464   AR_BUS_EVENT_COVER.p_insert_trx_sum_hist(l_trx_sum_hist_rec,
465                                            l_history_id,
466          				   'PMT',
467                                            'DELETE_PMT');
468 
469   CLOSE get_existing_ps;
470 
471   -- delete AR_PAYMENT_SCHEDULE record created for this receipt:
472 
473   DELETE AR_PAYMENT_SCHEDULES
474   WHERE cash_receipt_id = p_cash_receipt_id
475   RETURNING payment_schedule_id
476   BULK COLLECT INTO l_ar_ps_key_value_list;
477 
478   /*---------------------------------+
479    | Calling central MRC library     |
480    | for MRC Integration             |
481    +---------------------------------*/
482 
483     ar_mrc_engine.maintain_mrc_data(
484                 p_event_mode        => 'DELETE',
485                 p_table_name        => 'AR_PAYMENT_SCHEDULES',
486                 p_mode              => 'BATCH',
487                 p_key_value_list    => l_ar_ps_key_value_list);
488 --
489 
490   -- update batch status
491 
492   IF (p_batch_id IS NOT NULL) THEN
493     arp_rw_batches_check_pkg.update_batch_status(
494 		p_batch_id);
495   END IF;
496 
497   -- Raise the Deletion Business Event
498   AR_BUS_EVENT_COVER.Raise_Rcpt_Deletion_Event(
499 				l_trx_sum_hist_rec.payment_schedule_id,
500 				l_receipt_number,
501 				l_receipt_date
502 					     ) ;
503 
504   IF PG_DEBUG in ('Y', 'C') THEN
505      arp_standard.debug('arp_process_receipts.delete_cash_receipt()-');
506   END IF;
507 
508   EXCEPTION
509     WHEN OTHERS THEN
510        IF PG_DEBUG in ('Y', 'C') THEN
511           arp_standard.debug('EXCEPTION: arp_process_receipts.delete_cash_receipts');
512        END IF;
513        RAISE;
514 
515 END delete_cash_receipt;
516 
517 
518 /*===========================================================================+
522  | DESCRIPTION                                                               |
519  | PROCEDURE                                                                 |
520  |   post_query_logic              					     |
521  |                                                                           |
523  |    Executes post-query logic for the ARXRWRCT.fmb form		     |
524  | SCOPE - PRIVATE                                                           |
525  |                                                                           |
526  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED 	                             |
527  |                                                                           |
528  | ARGUMENTS                                                                 |
529  |    IN:								     |
530  |    OUT:                                                                   |
531  |                                                                           |
532  | RETURNS    		                                                     |
533  |                                                                           |
534  | NOTES                                                                     |
535  |                                                                           |
536  | MODIFICATION HISTORY 						     |
537  |									     |
538  |   21-FEB-95	OSTEINME	created					     |
539  |   21-JUL-97  KLAWRANC	Release 11.				     |
540  |				Added cross currency logic.  Should select   |
541  |                              amount_applied_from when this is populated   |
542  |                              otherwise use amount_applied.  See notes.    |
543  |            			Added the calculation and return of the total|
544  |				exchange gain/loss at the header level.      |
545  |                              Added cross currency apps flag as out NOCOPY        |
546  |                              parameter.                                   |
547  |   22-OCT-97	KLAWRANC	Bug #550743.  Changed query of applications. |
548  |				For APP rows, don't include where confirmed  |
549  |				is 'N'.                                      |
550  |   04-DEC-97  KLAWRANC        Bug #591462.  Removed distinct clause when   |
551  |                              counting cash receipt history records.  This |
552  |                              did not cater for the case where the cash    |
553  |                              receipt record has been rate adjusted (the   |
554  |                              receipt has not changed state but there is   |
555  |                              more than one history record).               |
556  |    10-MAR-98 KLAWRANC        Bug #584086.  Receipts Query Performance.    |
557  |                              Added the selection and return of reversal   |
558  |                              and confirmation details.  These were        |
559  |                              removed from the view and added to post query|
560  |                              for performance reasons.                     |
561  |                              Bug #584086.  Added code to explicitly set   |
562  |                              p_debit_memo to 'N' when no_data_found or    |
563  |                              the receipt is not reversed.                 |
564  |                                                                           |
565  |    20-APR-2000 J Rautiainen  BR Implementation. Activity application of   |
566  |                              type Short Term debt is considered as        |
567  |                              applied amount.                              |
568  |    09-Oct-2000 S Nambiar     Receipt write-off is considered as applied   |
569  |                              But still we need to calculate write-off for |
570  |                              validation purpose                           |
571  |    22-DEC-2000 Yashaskar     Bug # 1431322 : A check is made to see if the|
572  |                              Chargeback is posted .                       |
573  |    28-Mar-2001 S Nambiar     Receipt chargeback is considered as applied  |
574  |                              But still we need to calculate chargeback for |
575  |                              validation purpose                           |
576  |    02-DEC-2002 R Muthuraman  Bug 2421800 : Reverted the fix for	     |
577  |                              bug 1431322. 				     |
578  |    12-JUN-2003 J Beckett     Bug 2821139 ACTIVITY is considered as applied|
579  |                              for exchange gain/loss calculation 	     |
580  |    06-DEC-2003 P Pawar       Bug 3252322 : Performance Issue. In procedure|
581  |                              post_query_logic, replaced                   |
582  |                              "ra.applied_payment_schedule_id = -6 " with  |
583  |                              "ra.applied_payment_schedule_id+0 = -6 "     |
584  |    02-FEB-2005 J Beckett     Bug 4112494 CM refunds                       |
585  |    02-FEB-2005 J Pandey      Bug 4166986 Credit Card Chargebacks added    |
586  |                              p_cc_chargeback_amount in the parameter      |
587  |    21-MAR-2005 J Pandey      Bug 4166986 Credit Card Chargebacks amt      |
588  |                              to be added to the amount_applied and in     |
589  |                              logic preventing unapp/reversal of misc rct  |
590  +===========================================================================*/
591 
592 Procedure post_query_logic(
593    p_cr_id			IN	ar_cash_receipts.cash_receipt_id%TYPE,
594    p_receipt_type		IN	VARCHAR2,
595    p_reference_type		IN 	VARCHAR2,
596    p_reference_id		IN	NUMBER,
597    p_std_reversal_possible 	OUT NOCOPY  	VARCHAR2,
598    p_apps_exist_flag		OUT NOCOPY 	VARCHAR2,
599    p_rec_moved_state_flag 	OUT NOCOPY	VARCHAR2,
600    p_amount_applied		OUT NOCOPY	NUMBER,
601    p_amount_unapplied   	OUT NOCOPY     NUMBER,
605    p_chargeback_amount   	OUT NOCOPY     NUMBER,
602    p_write_off_amount   	OUT NOCOPY     NUMBER,
603    p_cc_refund_amount   	OUT NOCOPY     NUMBER,
604    p_cc_chargeback_amount   	OUT NOCOPY     NUMBER,
606    p_amount_on_account  	OUT NOCOPY     NUMBER,
607    p_amount_in_claim	  	OUT NOCOPY     NUMBER,
608    p_prepayment_amount	  	OUT NOCOPY     NUMBER,
609    p_amount_unidentified 	OUT NOCOPY    	NUMBER,
610    p_discounts_earned    	OUT NOCOPY    	NUMBER,
611    p_discounts_unearned  	OUT NOCOPY    	NUMBER,
612    p_tot_exchange_gain_loss 	OUT NOCOPY 	NUMBER,
613    p_statement_number    	OUT NOCOPY    	VARCHAR2,
614    p_line_number	 	OUT NOCOPY	VARCHAR2,
615    p_statement_date	 	OUT NOCOPY    	DATE,
616    p_reference_id_dsp	 	OUT NOCOPY	VARCHAR2,
617    p_cross_curr_apps_flag 	OUT NOCOPY	VARCHAR2,
618    p_reversal_date              IN      DATE,
619    p_reversal_gl_date       	OUT NOCOPY 	DATE,
620    p_debit_memo             	OUT NOCOPY 	VARCHAR2,
621    p_debit_memo_ccid        	OUT NOCOPY 	NUMBER,
622    p_debit_memo_type        	OUT NOCOPY 	VARCHAR2,
623    p_debit_memo_number      	OUT NOCOPY 	VARCHAR2,
624    p_debit_memo_doc_number  	OUT NOCOPY 	NUMBER,
625    p_confirm_date           	OUT NOCOPY 	DATE,
626    p_confirm_gl_date        	OUT NOCOPY 	DATE
627 
628 ) IS
629 
630    l_apps_exist			VARCHAR2(1);
631    l_rec_moved_state		NUMBER;
632    l_amount_on_account		NUMBER;
633    l_amount_in_claim		NUMBER;
634    l_prepayment_amount		NUMBER;
635    l_amount_applied		NUMBER;
636    l_tot_exchange_gain_loss	NUMBER;
637    l_dummy			NUMBER;
638    l_cr_currency_code		ar_cash_receipts.currency_code%TYPE;
639 
640 BEGIN
641 
642    IF PG_DEBUG in ('Y', 'C') THEN
643       arp_standard.debug('ARP_PROCESS_RCT_UTIL.post_query_logic()+');
644       arp_standard.debug('post_query_logic: ' || '   p_cr_id = ' || p_cr_id);
645       arp_standard.debug('post_query_logic: ' || '   p_type  = ' || p_receipt_type);
646    END IF;
647 
648    -- check if receipt has moved from creation state to a later state
649    /* Bug 2211303 Modified to SELECT count(distinct status) so that
650          the FLAG for Checking Receipt with changed states is SET
651          Properly . */
652 
653    SELECT	count(distinct status)
654    INTO		l_rec_moved_state
655    FROM 	AR_CASH_RECEIPT_HISTORY
656    WHERE	cash_receipt_id = p_cr_id;
657 
658    IF (l_rec_moved_state > 1) THEN
659      p_rec_moved_state_flag := 'Y';
660    ELSE
661      p_rec_moved_state_flag := 'N';
662    END IF;
663 
664 
665    -- get the cash management items
666 
667 /* bug4751467 -- added the call to cep_standard.init and replaced CE_STATEMENT_RECONCILIATIONS with
668    ce_statement_recon_gt_v  */
669 
670    cep_standard.init_security;
671 
672    SELECT
673 	MAX(cb_sh.statement_number)			statement_number,
674 	MAX(cb_sl.line_number)		  		line_number,
675 	MAX(cb_sh.statement_date)			statement_date
676    INTO
677 	p_statement_number,
678 	p_line_number,
679 	p_statement_date
680    FROM
681 	ce_statement_headers		cb_sh,
682 	ce_statement_lines		cb_sl,
683 	ce_statement_recon_gt_v 	cb_sr,
684 	ar_cash_receipt_history 	crh_cb
685    WHERE
686 	 crh_cb.cash_receipt_id = p_cr_id
687      AND crh_cb.cash_receipt_history_id = cb_sr.reference_id (+)
688      AND cb_sr.reference_type (+) = 'RECEIPT'
689      AND cb_sr.current_record_flag (+) = 'Y'
690      AND cb_sr.status_flag (+) = 'M'
691      AND cb_sr.statement_line_id = cb_sl.statement_line_id (+)
692      AND cb_sl.statement_header_id = cb_sh.statement_header_id (+);
693 
694 
695    -- for cash receipts, get the application amounts from
696    -- ar_receivable_applications
697 
698    IF (p_receipt_type = 'MISC') THEN
699 
700      p_apps_exist_flag := 'N';
701      p_std_reversal_possible := 'Y';
702 
703      -- get reference number if necessary
704 
705     IF (p_reference_type IS NOT NULL) THEN
706 
707       IF (p_reference_type = 'REMITTANCE') THEN
708 
709 	SELECT name
710         INTO   p_reference_id_dsp
711         FROM   AR_BATCHES
712         WHERE  BATCH_ID = p_reference_id;
713 
714       ELSIF (p_reference_type = 'RECEIPT') THEN
715 
716 	SELECT receipt_number
717 	INTO   p_reference_id_dsp
718         FROM   AR_CASH_RECEIPTS
719         WHERE  cash_receipt_id = p_reference_id;
720 
721       ELSIF (p_reference_type = 'PAYMENT_BATCH') THEN
722 
723         SELECT checkrun_name
724 	INTO   p_reference_id_dsp
725         FROM   AP_INVOICE_SELECTION_CRITERIA
726         WHERE  CHECKRUN_ID = p_reference_id;
727 
728       ELSIF (p_reference_type = 'PAYMENT') THEN
729 
730 	SELECT check_number
731 	INTO   p_reference_id_dsp
732         FROM   AP_CHECKS
733         WHERE  CHECK_ID = p_reference_id;
734 
735       /* Bug 4122494 CM refunds */
736       ELSIF (p_reference_type = 'CREDIT_MEMO') THEN
737 
738 	SELECT trx_number
739 	INTO   p_reference_id_dsp
740 	FROM   RA_CUSTOMER_TRX
741 	WHERE customer_trx_id = p_reference_id;
742 
743       END IF;
744 
745     END IF;
746 
747    ELSE
748 
749      -----------------------------------------------------------------------
753      -- currency of the transaction, i.e. the amount allocated to the
750      -- For APP rows in receivable applications ...
751      --
752      -- Amount_applied stores the total amount of the application in the
754      -- transaction.  Also represents the receipt allocation for same
755      -- currency applications.
756      --
757      -- Amount_applied_from stores the total amount of the application in
758      -- the currency of the receipt, i.e. that portion of the receipt
759      -- allocated to the transaction.  This is only populated for cross
760      -- currency applications.
761      --
762      -- As we are calculating the total amount applied in the context of
763      -- the receipt, we need to firstly select amount_applied_from (as if
764      -- populated, the application is cross currency and the receipt amount
765      -- is stored in this column), otherwise select amount_applied (as
766      -- the amount_applied_from must be null and the receipt amount is
767      -- stored in amount_applied).
768      -----------------------------------------------------------------------
769      /* 20-APR-2000 J Rautiainen BR Implementation
770       * Short Term Debt Activity application is considered as applied amount */
771 
772      /* snambiar write-off amount is considered as applied. But for maximum
773         write-off amount on a receipts needs to be validated. So we are doing
774         a sum for the write-off amount with PS id -3                          */
775 
776     /* snambiar chargeback amount is considered as applied.                   */
777     /* Bug 2751910 Netting amount is considered as applied.                   */
778     /* Bug 2821139 Netting amount is considered as applied.                   */
779     /* Bug 2821139 ACTIVITY amount is considered as applied for exchange gain
780        loss calculation.     					              */
781     /* jypandey cc_chargeback amount is considered as applied.                */
782     /* Bug 4948423 Refund amount is considered as applied  (-8)               */
783 
784      SELECT
785 	SUM(DECODE(ra.status,
786                    'APP',DECODE(ra.confirmed_flag,
787                                'N', 0,
788                                 NVL(nvl(ra.amount_applied_from, ra.amount_applied),0)),
789                    'ACTIVITY',DECODE(ra.applied_payment_schedule_id,
790                                      -2,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),
791                                      -3,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),
792                                      -5,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),
793                                      -6,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),
794                                      -8,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),
795                                      -9,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),
796                                      DECODE(ra.receivables_trx_id,-16,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0)))
797                    ,0)) applied_amount,
798         SUM(DECODE(ra.status,'ACTIVITY',DECODE(applied_payment_schedule_id,
799                 -3,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),0),0)) write_off_amount,
800         SUM(DECODE(ra.status,'ACTIVITY',DECODE(applied_payment_schedule_id,
801                 -5,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),0),0)) chargeback_amount,
802         SUM(DECODE(ra.status,'ACTIVITY',DECODE(applied_payment_schedule_id,
803                 -6,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),0),0)) cc_refund_amount,
804         /* Bug 4166986 CC Chargeback */
805         SUM(DECODE(ra.status,'ACTIVITY',DECODE(applied_payment_schedule_id,
806                 -9,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),0),0)) cc_chargeback_amount,
807         SUM(DECODE(ra.status,'UNAPP',
808 	NVL(ra.amount_applied,0),0))	unapplied_amount,
809         SUM(DECODE(ra.status,'ACC',
810         NVL(ra.amount_applied, 0),0))    on_account_amount,
811         SUM(DECODE(ra.status,'OTHER ACC',DECODE(applied_payment_schedule_id,
812                 -4,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),0),0)) claim_amount,
813         SUM(DECODE(ra.status,'OTHER ACC',DECODE(applied_payment_schedule_id,
814                 -7,NVL(nvl(ra.amount_applied_from, ra.amount_applied),0),0),0)) prepayment_amount,
815         SUM(DECODE(ra.status,'UNID',
816         NVL(ra.amount_applied, 0),0))    unidentified_amount,
817         SUM(DECODE(ra.status,'APP',
818         NVL(ra.earned_discount_taken, 0),0))     discounts_earned,
819         SUM(DECODE(ra.status,'APP',
820         NVL(ra.unearned_discount_taken, 0),0))   discounts_unearned,
821         SUM(DECODE(ra.status,'APP',
822         NVL(ra.acctd_amount_applied_from - ra.acctd_amount_applied_to, 0),'ACTIVITY',
823 	NVL(ra.acctd_amount_applied_from - ra.acctd_amount_applied_to, 0),0)) tot_exchange_gain_loss
824      INTO
825 	l_amount_applied,
826         p_write_off_amount,
827         p_chargeback_amount,
828         p_cc_refund_amount,
829         p_cc_chargeback_amount,
830 	p_amount_unapplied,
831 	l_amount_on_account,
832         l_amount_in_claim,
833         l_prepayment_amount,
834 	p_amount_unidentified,
835 	p_discounts_earned,
836 	p_discounts_unearned,
837         l_tot_exchange_gain_loss
838      FROM
839 	ar_receivable_applications ra
840      WHERE
841 	ra.cash_receipt_id = p_cr_id;
842 
843      p_amount_on_account := l_amount_on_account;
847      p_tot_exchange_gain_loss := l_tot_exchange_gain_loss;
844      p_amount_in_claim   := l_amount_in_claim;
845      p_prepayment_amount := l_prepayment_amount;
846      p_amount_applied    := l_amount_applied;
848 
849      /* 20-APR-2000 J Rautiainen BR Implementation
850       * Short Term Debt Activity application is considered as application */
851 
852      -- Determine if the receipt has applications.
853      SELECT max(decode(ra.status, 'APP', 'Y',
854                                   'ACC', 'Y',
855                                   'OTHER ACC', 'Y',
856                                   'ACTIVITY', 'Y', 'N'))
857      INTO   l_apps_exist
858      FROM   ar_receivable_applications ra
859      WHERE  ra.cash_receipt_id = p_cr_id
860      AND    ra.reversal_gl_date is NULL;
861 
862      p_apps_exist_flag := l_apps_exist;
863 
864      -- Determine if the receipt currently has a cross currency
865      -- application(s).  No point doint the select if it doesn't
866      -- have applications in the first place.
867      BEGIN
868        IF l_apps_exist = 'Y' THEN
869 
870           SELECT cr.currency_code
871           INTO   l_cr_currency_code
872           FROM   ar_cash_receipts cr
873           WHERE  cr.cash_receipt_id = p_cr_id
874           AND    exists
875                  (select 1
876                   from   ar_receivable_applications ra,
877                          ar_payment_schedules ps
878                   where  ra.cash_receipt_id = cr.cash_receipt_id
879                   and    ra.applied_payment_schedule_id = ps.payment_schedule_id
880                   and    ps.invoice_currency_code <> cr.currency_code
881                   and    ra.reversal_gl_date is NULL
882                   and    ra.applied_payment_schedule_id <> -1);
883 
884        END IF;
885      EXCEPTION
886        WHEN NO_DATA_FOUND THEN
887          l_cr_currency_code := NULL;
888      END;
889 
890      IF l_cr_currency_code is not NULL THEN
891         p_cross_curr_apps_flag := 'Y';
892      ELSE
893         p_cross_curr_apps_flag := 'N';
894      END IF;
895 
896    /* --------------------------------------------------------------------
897     *   Check if a 'CB' was created against this PMT to be reversed.
898     *   Check if there are any PMT, ADJ, or CM or CB against this 'CB' records
899     *   in AR_PAYMENT_SCHEDULES table.  Also check to see if the CB has
900     *   already been posted.  If any of these 2 conditions is TRUE, then
901     *   PMT can only be reversed using DM Reversal.
902     *
903     *   Make sure that the adj which is automatically created against the CB
904     *   associated with the receipt being reversed does not get caught in
905     *   the SQL.  For such an adj, the adj.receivables_trx_id = -12
906     * -------------------------------------------------------------------- */
907 
908 
909      SELECT COUNT(payment_schedule_id)
910      INTO l_dummy
911      FROM    ar_payment_schedules    ps,
912              ra_cust_trx_line_gl_dist rctlg
913      WHERE   ps.associated_cash_receipt_id = p_cr_id
914      AND     ps.class = 'CB'
915      AND     ps.customer_trx_id = rctlg.customer_trx_id
916      AND (       nvl(ps.amount_applied, 0) <> 0
917             OR  nvl(ps.amount_credited, 0) <> 0
918             OR 0 <> ( SELECT sum(adj.amount)
919                       FROM ar_adjustments adj
920                       WHERE adj.payment_schedule_id =
921                              ps.payment_schedule_id
922                         AND adj.receivables_trx_id <> -12
923                      )
924           );
925 
926      IF (l_dummy > 0) THEN
927        p_std_reversal_possible := 'N';
928      ELSE
929        p_std_reversal_possible := 'Y';
930      END IF;
931 
932 	 IF p_std_reversal_possible = 'Y' THEN
933 	    BEGIN
934 	      /** If the -ve Miscellaneous receipt of CC Refund is already remitted or
935 		   ** cleared then do not allow the reversal or unapplication ***/
936 
937               /*  Added CC chargeback -ve misc receipt too for this condition */
938 
939 	      SELECT 1
940 	      INTO l_dummy
941 	      FROM dual
942 	      WHERE
943 		  EXISTS
944 	      ( SELECT 1
945 	        FROM  AR_CASH_RECEIPT_HISTORY crh, ar_receivable_applications ra
946 		    WHERE crh.cash_receipt_id = ra.application_ref_id
947 			AND   ra.cash_receipt_id = p_cr_id
948 			AND   ra.applied_payment_schedule_id+0 in (-6 , -9)
949 			AND   ra.application_ref_type = 'MISC_RECEIPT'
950 		    AND   crh.status IN ('REMITTED', 'CLEARED'));
951           --
952           p_std_reversal_possible := 'N';
953         EXCEPTION
954 	      WHEN NO_DATA_FOUND THEN
955 		     NULL;
956 		  WHEN OTHERS THEN
957 		     RAISE;
958         END;
959 
960 	 END IF;
961 
962      -- Get Confirmation Details.
963      -- This query was removed from the view to speed up
964      -- performance.
965 
966      BEGIN
967        select crh_conf.trx_date,
968               crh_conf.gl_date
969        into   p_confirm_date,
970               p_confirm_gl_date
971        from   ar_cash_receipt_history crh_conf
972        where  crh_conf.cash_receipt_id = p_cr_id
973        and    crh_conf.status = 'CONFIRMED'
974        and    not exists (
975                            select cash_receipt_history_id
976                            from ar_cash_receipt_history crh2
980      EXCEPTION
977                            where crh2.status = 'CONFIRMED'
978                            and crh2.cash_receipt_id = p_cr_id
979                            and crh2.cash_receipt_history_id > crh_conf.cash_receipt_history_id);
981 
982      WHEN no_data_found THEN
983 
984        p_confirm_date := NULL;
985        p_confirm_gl_date := NULL;
986      END;
987 
988    END IF;
989 
990    ---------------------------------------------------------
991    -- If the Receipt has been Reversed then get DM Reversal
992    -- details.
993    -- This query was removed from the view to speed up
994    -- performance.
995    ---------------------------------------------------------
996 
997    IF p_reversal_date is not null THEN
998 
999      BEGIN
1000 
1001       /*Bug3185358 Changed the ps_dm.gl_date to NVL(dm_gld.gl_Date,ct.gl_Date)
1002         and removed reference to ar_payment_schedultes as the record may not be
1003         there while the dm is incompleted */
1004 
1005        select NVL(dm_gld.gl_date,ct_dm.trx_date),
1006               'Y',
1007               dm_gld.code_combination_id,
1008               ctt_dm.name,
1009               ct_dm.trx_number,
1010               ct_dm.doc_sequence_value
1011        into   p_reversal_gl_date,
1012               p_debit_memo,
1013               p_debit_memo_ccid,
1014               p_debit_memo_type,
1015               p_debit_memo_number,
1016               p_debit_memo_doc_number
1017        from   ra_cust_trx_types ctt_dm,
1018               ra_customer_trx ct_dm,
1019               ra_cust_trx_line_gl_dist dm_gld
1020        where  ct_dm.reversed_cash_receipt_id = p_cr_id
1021        and    ct_dm.cust_trx_type_id = ctt_dm.cust_trx_type_id
1022        and    ct_dm.customer_trx_id = dm_gld.customer_trx_id
1023        and    dm_gld.account_class = 'REC'
1024        and    dm_gld.latest_rec_flag = 'Y';
1025 
1026      EXCEPTION
1027 
1028      WHEN no_data_found THEN
1029 
1030        select crh_current.gl_date
1031        into   p_reversal_gl_date
1032        from   ar_cash_receipt_history crh_current
1033        where  crh_current.cash_receipt_id = p_cr_id
1034        and    crh_current.current_record_flag = 'Y';
1035 
1036        p_debit_memo := 'N';
1037        p_debit_memo_ccid := NULL;
1038        p_debit_memo_type := NULL;
1039        p_debit_memo_number := NULL;
1040        p_debit_memo_doc_number := NULL;
1041 
1042      END;
1043 
1044    ELSE
1045 
1046      p_debit_memo := 'N';
1047 
1048    END IF;
1049 
1050    IF PG_DEBUG in ('Y', 'C') THEN
1051       arp_standard.debug('ARP_PROCESS_RCT_UTIL.post_query_logic()+');
1052    END IF;
1053 
1054 END post_query_logic;
1055 
1056 /*===========================================================================+
1057  | PROCEDURE                                                                 |
1058  |    set_posted_flag                                                        |
1059  |                                                                           |
1060  | DESCRIPTION                                                               |
1061  |    Deterimines if a cash receipt has been posted                          |
1062  |                                                                           |
1063  | SCOPE - PRIVATE                                                           |
1064  |                                                                           |
1065  | EXTERNAL PROCEDURES/FUNCTIONS ACCESSED                                    |
1066  |      arp_util.debug                                                       |
1067  |                                                                           |
1068  | ARGUMENTS                                                                 |
1069  |    IN:                                                                    |
1070  |          p_cash_receipt_id                                                |
1071  |    OUT:                                                                   |
1072  |          p_posted_flag                                                    |
1073  |                                                                           |
1074  | RETURNS : NONE                                                            |
1075  |                                                                           |
1076  | NOTES                                                                     |
1077  |                                                                           |
1078  | MODIFICATION HISTORY                                                      |
1079  |                                                                           |
1080  |    28-NOV-98  Debbie Sue Jancis        created                            |
1081  |    03-FEB-99  Debbie Sue Jancis        modified declaration of            |
1082  | 					  l_posted_flag from varchar to      |
1083  |                                        varchar2.                          |
1084  +===========================================================================*/
1085 
1086 PROCEDURE set_posted_flag( p_cash_receipt_id  IN number,
1087                            p_posted_flag   OUT NOCOPY BOOLEAN) IS
1088 l_posted_flag varchar2(2);
1089 
1090 BEGIN
1091     IF PG_DEBUG in ('Y', 'C') THEN
1092        arp_util.debug('ARP_PROC_RCT_UTIL.set_posted_flag()+');
1093     END IF;
1094 
1095     SELECT decode ( max(dummy), NULL, 'N','Y')
1096      INTO l_posted_flag
1097     FROM   dual
1098     WHERE EXISTS
1099             (SELECT 'posted distribution exists'
1100              FROM  ar_cash_receipt_history
1101              WHERE cash_receipt_id = p_cash_receipt_id
1102              AND  gl_posted_date IS NOT NULL);
1103 
1104   IF (l_posted_flag ='Y')
1105   THEN
1106     IF PG_DEBUG in ('Y', 'C') THEN
1107        arp_util.debug('set_posted_flag: ' || 'flag = true +');
1108     END IF;
1109       p_posted_flag := TRUE;
1110   ELSE
1111     IF PG_DEBUG in ('Y', 'C') THEN
1112        arp_util.debug('set_posted_flag: ' || 'flag = false +');
1113     END IF;
1114       p_posted_flag := FALSE;
1115 
1116   END IF;
1117 
1118   IF PG_DEBUG in ('Y', 'C') THEN
1119      arp_util.debug('ARP_PROC_RCT_UTIL.set_posted_flag()-');
1120   END IF;
1121 
1122 EXCEPTION
1123      WHEN OTHERS THEN
1124          IF PG_DEBUG in ('Y', 'C') THEN
1125             arp_util.debug('EXCEPTION:  ARP_PROC_RCT_UTIL.set_posted_flag()');
1126          END IF;
1127          RAISE;
1128 
1129 END set_posted_flag;
1130 
1131 
1132 --Bug 5033971
1133 PROCEDURE Delete_Transaction_Extension(
1134 
1135            --   *****  Standard API parameters *****
1136                 p_api_version                   IN  NUMBER                      ,
1137                 p_init_msg_list                 IN  VARCHAR2 := FND_API.G_TRUE  ,
1138                 p_commit                        IN  VARCHAR2 := FND_API.G_FALSE ,
1139                 x_return_status                 OUT NOCOPY VARCHAR2             ,
1140                 x_msg_count                     OUT NOCOPY NUMBER               ,
1141                 x_msg_data                      OUT NOCOPY VARCHAR2             ,
1142 
1143            --   *****  Receipt  Header information parameters *****
1144                 p_org_id                        IN  NUMBER      DEFAULT NULL    ,
1145                 p_cust_Account_id               IN  NUMBER      DEFAULT NULL    ,
1146                 p_account_site_use_id           IN  NUMBER      DEFAULT NULL    ,
1147                 p_payment_trxn_extn_id          IN  IBY_TRXN_EXTENSIONS_V.TRXN_EXTENSION_ID%TYPE    )
1148 IS
1149     l_payer_rec            IBY_FNDCPT_COMMON_PUB.payercontext_rec_type;
1150     l_trxn_attribs_rec     IBY_FNDCPT_TRXN_PUB.trxnextension_rec_type;
1151     l_response             IBY_FNDCPT_COMMON_PUB.result_rec_type;
1152 Begin
1153         arp_standard.debug('ARP_PROCESS_RCTS.Delete_Transaction_Extension()+ ');
1154         x_msg_count          := NULL;
1155         x_msg_data           := NULL;
1156         x_return_status      := FND_API.G_RET_STS_SUCCESS;
1157         l_payer_rec.party_id :=  arp_trx_defaults_3.get_party_Id(p_cust_Account_id);
1158         l_payer_rec.payment_function                  := 'CUSTOMER_PAYMENT';
1159         l_payer_rec.org_type                          := 'OPERATING_UNIT';
1160         l_payer_rec.cust_account_id                   :=  p_cust_Account_id;
1161         l_payer_rec.org_id                            :=  P_ORG_ID;
1162         l_payer_rec.account_site_id                   :=  p_account_site_use_id;
1163 
1164            /*-------------------------+
1165             |   Call the IBY API      |
1166             +-------------------------*/
1167             arp_standard.debug('Call TO IBY API ()+ ');
1168 
1169             IBY_FNDCPT_TRXN_PUB.delete_transaction_extension(
1170                p_api_version           => 1.0,
1171                p_init_msg_list         => p_init_msg_list,
1172                p_commit                => p_commit,
1173                x_return_status         => x_return_status,
1174                x_msg_count             => x_msg_count,
1175                x_msg_data              => x_msg_data,
1176                p_payer                 => l_payer_rec,
1177                p_payer_equivalency     => 'UPWARD',
1178                p_entity_id             => p_payment_trxn_extn_id,
1179                x_response              => l_response);
1180 
1181     IF x_return_status  = fnd_api.g_ret_sts_success
1182     THEN
1183        arp_standard.debug('Payment_Trxn_Extension_Id : ' || p_payment_trxn_extn_id);
1184     ElSIF  l_response.result_code= 'EXTENSION_NOT_UPDATEABLE'  and
1185            l_response.result_Category = 'INCORRECT_FLOW'
1186     THEN
1187       fnd_message.set_name('AR','AR_AUTH_RCT_NO_DELETE');
1188       app_exception.raise_exception;
1189     Else
1190        arp_standard.debug('Errors Reported by IBY API in ARP_PROCESS_RCTS.Delete Transaction Extension ');
1191        raise fnd_api.g_exc_unexpected_error;
1192     END IF;
1193 EXCEPTION
1194      WHEN OTHERS THEN
1195        arp_standard.debug('exception in ARP_PROCESS_RCTS.Delete_Transaction_Extension');
1196        RAISE;
1197 END Delete_Transaction_Extension;
1198 
1199 
1200 
1201 
1202 
1203 END ARP_PROCESS_RCTS;