DBA Data[Home] [Help]

PACKAGE BODY: APPS.ARP_CHARGEBACK_COVER

Source


1 PACKAGE BODY arp_chargeback_cover AS
2 /* $Header: ARXCBCVB.pls 120.24 2005/06/22 16:50:34 jbeckett noship $ */
3 G_PKG_NAME     CONSTANT VARCHAR2(30) := 'ARP_CHARGEBACK_COVER';
4 
5 /*=======================================================================+
6  | PROCEDURE                                                             |
7  |      create_chargeback                                                |
8  |                                                                       |
9  | DESCRIPTION                                                           |
10  |      Procedure create_chargback  -  Entry point for full              |
11  |      chargeback creation                                              |
12  | ARGUMENTS  : IN:                                                      |
13  |                                                                       |
14  |                                                                       |
15  |                                                                       |
16  |              OUT:                                                     |
17  |          IN/ OUT:                                                     |
18  |                                                                       |
19  | RETURNS    :                                                          |
20  |                                                                       |
21  | NOTES                                                                 |
22  |                                                                       |
23  | KNOWN BUGS                                                            |
24  |                                                                       |
25  | MODIFICATION HISTORY                                                  |
26  |    JBECKETT    03-OCT-01 Created                                      |
27  |    JBECKETT    15-OCT-01 Modified to make generic so it handles both  |
28  |                          chargebacks against receipts and transactions|
29  |    S.Nambiar   18-JUN-02 Bug 2465176 -Added bill_to_site_use_id to    |
30  |                          Chargeback_Rec_Type. If bill to location is  |
31  |                          not passed, and receipt bill to site use id  |
32  |                          is not passed, show error.If passed, validate|
33  |                          bill to_site use id.                         |
34  |    S.Nambiar   22-JUL-02 Bug 2474471-Corrected the validation logicfor
35  |                          bill to site used id
36  |    S.Nambiar   20-AUG-02 Bug 2516618 - Bill to site use id should be
37  |                          validated with the customer id from invoice,
38  |                          if its a invoice related chargeback.
39  |    J.Beckett   04-NOV-02 Bug 2654633 - passed bill to site used instead
40  |                          of site on receipt for a receipt chargeback.
41  |    J.Beckett   15-JAN-03 Bug 2751910 - added internal_notes.
42  |    J.Beckett   09-MAR-03 Bug 2751910 - caters for subsequent applications.
43  |    J.Beckett   29-APR-04 Bug 3590399 - removed to_date causing data type
44  |			    conflict in Trade Management
45  |    J.Beckett   25-MAY-05 R12 LE uptake - legal_entity_id passed to handler.
46  +=======================================================================*/
47 
48 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
49 
50 PROCEDURE create_chargeback (
51   p_chargeback_rec           IN  arp_chargeback_cover.Chargeback_Rec_Type,
52   p_init_msg_list            IN  VARCHAR2,
53   x_doc_sequence_id          OUT NOCOPY NUMBER,
54   x_doc_sequence_value       OUT NOCOPY ra_customer_trx.doc_sequence_value%TYPE,
55   x_trx_number               OUT NOCOPY ra_customer_trx.trx_number%TYPE,
56   x_customer_trx_id          OUT NOCOPY NUMBER,
57   x_return_status            OUT NOCOPY VARCHAR2,
58   x_msg_count                OUT NOCOPY NUMBER,
59   x_msg_data                 OUT NOCOPY VARCHAR2)
60 
61 IS
62    l_set_of_books_id               NUMBER;
63    l_default_code_combination_id   NUMBER;
64    l_code_combination_id           NUMBER;
65    l_default_cb_due_date           VARCHAR2(30);
66    l_application_id                NUMBER;
67    l_applied_ps_id                 NUMBER; -- bug 3682568
68    l_app_due_date                  DATE;
69    l_due_date                      DATE;
70    l_apply_date                    DATE;
71    l_app_gl_date                   DATE;
72    l_amount                        NUMBER;
73    l_acctd_amount                  NUMBER;
74    l_bal_due_remaining             NUMBER;
75    l_app_receivables_trx_id        NUMBER;
76    l_app_comments                  ar_receivable_applications.comments%TYPE;
77    l_customer_reference            ar_receivable_applications.customer_reference%TYPE;
78    l_claim_reason_name             VARCHAR2(80);
79    l_application_ref_num           ar_receivable_applications.application_ref_num%TYPE;
80    l_application_ref_reason        ar_receivable_applications.application_ref_reason%TYPE;
81    l_application_ref_type          ar_receivable_applications.application_ref_type%TYPE;
82    l_application_ref_id            NUMBER;
83    l_dum_app_ref_type              ar_receivable_applications.application_ref_type%TYPE;
84    l_dum_app_ref_id                NUMBER;
85    l_dum_app_ref_num               ar_receivable_applications.application_ref_num%TYPE;
86    l_dum_sec_app_ref_id            NUMBER;
87    l_payment_set_id                NUMBER;
88    l_attribute_rec                 AR_Receipt_API_PUB.attribute_rec_type;
89    l_global_attribute_rec          AR_Receipt_API_PUB.global_attribute_rec_type;
90    l_receipt_number                ar_cash_receipts.receipt_number%TYPE;
91    l_receipt_date                  DATE;
92    l_trx_date                      DATE;
93    l_cr_gl_date                    DATE;
94    l_cr_payment_schedule_id        NUMBER;
95    l_currency_code                 ar_cash_receipts.currency_code%TYPE;
96    l_exchange_rate                 NUMBER;
97    l_exchange_rate_type            ar_cash_receipts.exchange_rate_type%TYPE;
98    l_exchange_rate_date            DATE;
99    l_bill_to_site_use_id           NUMBER;
100    l_remit_to_address_id           NUMBER;
101    l_cb_exchange_rate              NUMBER;
102    l_cb_exchange_rate_type         ar_cash_receipts.exchange_rate_type%TYPE;
103    l_cb_exchange_rate_date         DATE;
104    l_cb_currency_code              ar_cash_receipts.currency_code%TYPE;
105    l_cb_bill_to_site_use_id        NUMBER;
106    l_cb_remit_to_address_id        NUMBER;
107    l_cb_amount                     NUMBER;
108    l_cb_acctd_amount               NUMBER;
109    l_deposit_date                  DATE;
110    l_customer_id                   NUMBER;
111    l_gl_date                       DATE; -- bug 2621114
112    l_app_gl_date_prof              VARCHAR2(240); -- bug 2621114
113    l_default_gl_date               DATE;
114    l_defaulting_rule_used          VARCHAR2(50);
115    l_customer_trx_id               NUMBER;
116    l_installment                   ar_payment_schedules.terms_sequence_number%TYPE;
117    l_new_claim_num                 ar_receivable_applications.application_ref_num%TYPE;
118    l_doc_sequence_id               NUMBER := NULL;
119    l_doc_sequence_value            ra_customer_trx.doc_sequence_value%TYPE := NULL;
120    l_trx_number                    ra_customer_trx.trx_number%TYPE;
121    l_new_customer_trx_id           NUMBER;
122    l_new_application_id            NUMBER;
123    l_new_app_ref_num               ar_receivable_applications.application_ref_num%TYPE;
124    l_new_app_ref_id                ar_receivable_applications.application_ref_id%TYPE;
125    l_balance                       NUMBER := 0;
126    l_functional_curr               VARCHAR2(100);
127    l_error_message                 VARCHAR2(2000);
128    l_error_count                   NUMBER := 0;
129    l_return_status                 VARCHAR2(1);
130    l_msg_count                     NUMBER;
131    l_msg_data                      VARCHAR2(2000);
132    l_api_name                      CONSTANT VARCHAR2(30)
133                                             := 'create_chargeback';
134    l_site_required_flag            ar_system_parameters.site_required_flag%TYPE := 'N';
135    lp_bill_to_site_use_id          NUMBER; --Stores the bill_to_site_id passed from claim
136    l_cb_trx_type 		   ra_cust_trx_types.name%TYPE;
137    l_sequence_name		   fnd_document_sequences.name%TYPE;
138    l_legal_entity_id               ra_customer_trx.legal_entity_id%TYPE;
139 
140 BEGIN
141   IF PG_DEBUG in ('Y', 'C') THEN
142      arp_standard.debug('arp_chargeback_cover.create_chargeback()+');
143   END IF;
144 
145   -- Standard Start of API savepoint
146   SAVEPOINT	Create_Chargeback;
147   -- Initialize message list if p_init_msg_list is set to TRUE.
148   IF FND_API.to_Boolean( p_init_msg_list )
149   THEN
150     FND_MSG_PUB.initialize;
151   END IF;
152   --  Initialize API return status to success
153   x_return_status := FND_API.G_RET_STS_SUCCESS;
154 
155   /* Bug 3022077 - initialize global variables in case SOB or org changed */
156   arp_global.init_global;
157   arp_standard.init_standard;
158 
159  /*---------------------------------------------------------------------+
160   | A) Validate and Default parameters                                  |
161   +---------------------------------------------------------------------*/
162   IF PG_DEBUG in ('Y', 'C') THEN
163      arp_standard.debug('create_chargeback: ' || 'PARAMETER VALUES: ');
164      arp_standard.debug('create_chargeback: ' || 'amount = '||p_chargeback_rec.amount);
165      arp_standard.debug('create_chargeback: ' || 'cust_trx_type_id = '||p_chargeback_rec.cust_trx_type_id);
166      arp_standard.debug('create_chargeback: ' || 'code_combination_id = '||p_chargeback_rec.code_combination_id);
167      arp_standard.debug('create_chargeback: ' || 'reason_code = '||p_chargeback_rec.reason_code);
168      arp_standard.debug('create_chargeback: ' || 'gl_date = '||p_chargeback_rec.gl_date);
169      arp_standard.debug('create_chargeback: ' || 'due_date = '||p_chargeback_rec.due_date);
170      arp_standard.debug('create_chargeback: ' || 'cash_receipt_id = '||p_chargeback_rec.cash_receipt_id);
171      arp_standard.debug('create_chargeback: ' || 'secondary_application_ref_id = '||p_chargeback_rec.secondary_application_ref_id);
172      arp_standard.debug('create_chargeback: ' || 'new_second_application_ref_id = '||p_chargeback_rec.new_second_application_ref_id);
173      arp_standard.debug('create_chargeback: ' || 'application_ref_type = '||p_chargeback_rec.application_ref_type);
174      arp_standard.debug('create_chargeback: ' || 'Bill to site use id Passed = '||p_chargeback_rec.bill_to_site_use_id);
175   END IF;
176 
177  /*---------------------------------------------------------------------+
178   | 1)   Check receipt valid / get receipt details                      |
179   +---------------------------------------------------------------------*/
180   IF PG_DEBUG in ('Y', 'C') THEN
181      arp_standard.debug('create_chargeback: ' || 'Checking cash receipt ...');
182   END IF;
183   IF (p_chargeback_rec.cash_receipt_id IS NULL)
184   THEN
185      FND_MESSAGE.SET_NAME('AR','AR_RAPI_CASH_RCPT_ID_NULL');
186      FND_MSG_PUB.Add;
187      l_error_count := l_error_count + 1;
188   ELSE
189     BEGIN
190       SELECT cr.receipt_number
191            , cr.receipt_date
192            , crh.gl_date
193            , cr.deposit_date
194            , cr.pay_from_customer
195            , ps.payment_schedule_id
196            , cr.currency_code
197            , cr.exchange_rate
198            , cr.exchange_rate_type
199            , cr.exchange_date
200            , cr.customer_site_use_id
201       INTO   l_receipt_number
202            , l_receipt_date
203            , l_cr_gl_date
204            , l_deposit_date
205            , l_customer_id
206            , l_cr_payment_schedule_id
207            , l_currency_code
208            , l_exchange_rate
209            , l_exchange_rate_type
210            , l_exchange_rate_date
211            , l_bill_to_site_use_id
212       FROM   ar_cash_receipts cr
213            , ar_payment_schedules ps
214            , ar_cash_receipt_history crh
215       WHERE  cr.cash_receipt_id = crh.cash_receipt_id(+)
216       AND    crh.first_posted_record_flag(+) = 'Y'
217       AND    cr.cash_receipt_id = ps.cash_receipt_id(+)
218       AND    cr.cash_receipt_id = p_chargeback_rec.cash_receipt_id;
219     EXCEPTION
220       WHEN NO_DATA_FOUND
221       THEN
222         FND_MESSAGE.SET_NAME('AR','ARTA_ERR_FINDING_CASH_RCPT');
223         FND_MESSAGE.SET_TOKEN('CR_ID',p_chargeback_rec.cash_receipt_id);
224         FND_MSG_PUB.Add;
225         l_error_count := l_error_count + 1;
226     END;
227   END IF;
228 
229  /*---------------------------------------------------------------------+
230   | 2)  Get required system parameters                                  |
231   +---------------------------------------------------------------------*/
232   IF PG_DEBUG in ('Y', 'C') THEN
233      arp_standard.debug('create_chargeback: ' || 'Getting system parameters... ');
234   END IF;
235   SELECT set_of_books_id
236        , default_cb_due_date
237        , nvl(site_required_flag,'N')
238   INTO   l_set_of_books_id
239        , l_default_cb_due_date
240        , l_site_required_flag
241   FROM   ar_system_parameters;
242 
243 
244  /*---------------------------------------------------------------------+
245   | 4)   Check secondary app ref id valid / get application details     |
246   +---------------------------------------------------------------------*/
247   IF PG_DEBUG in ('Y', 'C') THEN
248      arp_standard.debug('create_chargeback: ' || 'Checking application ...');
249   END IF;
250   IF (p_chargeback_rec.secondary_application_ref_id IS NULL)
251   THEN
252      FND_MESSAGE.SET_NAME('AR','AR_RW_NULL_SECOND_APP_REF_ID');
253      FND_MSG_PUB.Add;
254      l_error_count := l_error_count + 1;
255   END IF;
256 
257   IF (p_chargeback_rec.application_ref_type IS NULL)
258   THEN
259      FND_MESSAGE.SET_NAME('AR','AR_RW_NULL_APP_REF_TYPE');
260      FND_MSG_PUB.Add;
261      l_error_count := l_error_count + 1;
262   END IF;
263 
264   IF (p_chargeback_rec.secondary_application_ref_id IS NOT NULL AND
265       p_chargeback_rec.application_ref_type IS NOT NULL AND
266       p_chargeback_rec.cash_receipt_id IS NOT NULL)
267   THEN
268     BEGIN
269       SELECT
270              app.receivable_application_id
271            , app.applied_payment_schedule_id -- bug 3682568
272            , DECODE(SIGN(app.applied_payment_schedule_id),-1,NULL,
273                    ps.due_date) due_date -- Bug 3590399: removed to_date
274            , app.apply_date
275            , app.gl_date
276            , app.amount_applied
277            , app.acctd_amount_applied_from
278            , DECODE(SIGN(app.applied_payment_schedule_id),
279                          -1,app.applied_payment_schedule_id,
280                             app.applied_customer_trx_id)
281            , TO_NUMBER(DECODE(SIGN(app.applied_payment_schedule_id),-1,NULL,
282                         ps.terms_sequence_number)) installment
283            , app.application_ref_num
284            , app.application_ref_reason
285            , app.receivables_trx_id
286            , app.comments
287            , app.customer_reference
288            , app.attribute_category
289            , app.attribute1
290            , app.attribute2
291            , app.attribute3
292            , app.attribute4
293            , app.attribute5
294            , app.attribute6
295            , app.attribute7
296            , app.attribute8
297            , app.attribute9
298            , app.attribute10
299            , app.attribute11
300            , app.attribute12
301            , app.attribute13
302            , app.attribute14
303            , app.attribute15
304            , app.global_attribute_category
305            , app.global_attribute1
306            , app.global_attribute2
307            , app.global_attribute3
308            , app.global_attribute4
309            , app.global_attribute5
310            , app.global_attribute6
311            , app.global_attribute7
312            , app.global_attribute8
313            , app.global_attribute9
314            , app.global_attribute10
315            , app.global_attribute11
316            , app.global_attribute12
317            , app.global_attribute13
318            , app.global_attribute14
319            , app.global_attribute15
320            , app.global_attribute16
321            , app.global_attribute17
322            , app.global_attribute18
323            , app.global_attribute19
324            , app.global_attribute20
325       INTO
326              l_application_id
327            , l_applied_ps_id -- bug 3682568
328            , l_app_due_date
332            , l_acctd_amount
329            , l_apply_date
330            , l_app_gl_date
331            , l_amount
333            , l_customer_trx_id
334            , l_installment
335            , l_application_ref_num
336            , l_application_ref_reason
337            , l_app_receivables_trx_id
338            , l_app_comments
339            , l_customer_reference
340            , l_attribute_rec.attribute_category
341            , l_attribute_rec.attribute1
342            , l_attribute_rec.attribute2
343            , l_attribute_rec.attribute3
344            , l_attribute_rec.attribute4
345            , l_attribute_rec.attribute5
346            , l_attribute_rec.attribute6
347            , l_attribute_rec.attribute7
348            , l_attribute_rec.attribute8
349            , l_attribute_rec.attribute9
350            , l_attribute_rec.attribute10
351            , l_attribute_rec.attribute11
352            , l_attribute_rec.attribute12
353            , l_attribute_rec.attribute13
354            , l_attribute_rec.attribute14
355            , l_attribute_rec.attribute15
356            , l_global_attribute_rec.global_attribute_category
357            , l_global_attribute_rec.global_attribute1
358            , l_global_attribute_rec.global_attribute2
359            , l_global_attribute_rec.global_attribute3
360            , l_global_attribute_rec.global_attribute4
361            , l_global_attribute_rec.global_attribute5
362            , l_global_attribute_rec.global_attribute6
363            , l_global_attribute_rec.global_attribute7
364            , l_global_attribute_rec.global_attribute8
365            , l_global_attribute_rec.global_attribute9
366            , l_global_attribute_rec.global_attribute10
367            , l_global_attribute_rec.global_attribute11
368            , l_global_attribute_rec.global_attribute12
369            , l_global_attribute_rec.global_attribute13
370            , l_global_attribute_rec.global_attribute14
371            , l_global_attribute_rec.global_attribute15
372            , l_global_attribute_rec.global_attribute16
373            , l_global_attribute_rec.global_attribute17
374            , l_global_attribute_rec.global_attribute18
375            , l_global_attribute_rec.global_attribute19
376            , l_global_attribute_rec.global_attribute20
377       FROM   ar_payment_schedules ps
378            , ar_receivable_applications app
379       WHERE  app.applied_payment_schedule_id = ps.payment_schedule_id
380       AND    app.secondary_application_ref_id = p_chargeback_rec.secondary_application_ref_id
381       AND    app.application_ref_type = p_chargeback_rec.application_ref_type
382       AND    app.applied_payment_schedule_id = ps.payment_schedule_id
383       AND    app.display = 'Y'
384       AND    app.status IN ('APP','OTHER ACC')
385       AND    app.cash_receipt_id = p_chargeback_rec.cash_receipt_id
386       AND    ROWNUM = 1;
387     EXCEPTION
388       WHEN NO_DATA_FOUND
389       THEN
390         FND_MESSAGE.SET_NAME('AR','AR_RW_SEC_APP_REF_ID_NOTFOUND');
391         FND_MESSAGE.SET_TOKEN('SECOND_APP_REF_ID',p_chargeback_rec.secondary_application_ref_id);
392         FND_MESSAGE.SET_TOKEN
393                    ('APP_REF_TYPE',p_chargeback_rec.application_ref_type);
394         FND_MSG_PUB.Add;
395         l_error_count := l_error_count + 1;
396     END;
397   END IF;
398 
399  /*---------------------------------------------------------------------+
400   |If this is an invoice related CB, then take the bill to site id of   |
401   |the invoice. There could be posibility the receipt customer and the  |
402   |invoice customer is different.                                       |
403   +---------------------------------------------------------------------*/
404   --Bug 2516618
405   IF SIGN(l_customer_trx_id) <> -1 THEN
406     BEGIN
407       SELECT bill_to_customer_id,
408              bill_to_site_use_id,
409              trx_date
410       INTO   l_customer_id,
411              l_bill_to_site_use_id ,
412              l_trx_date
413       FROM   ra_customer_trx
414       WHERE  customer_trx_id=l_customer_trx_id;
415     EXCEPTION
416       WHEN no_data_found THEN
417         FND_MESSAGE.SET_NAME('AR','AR_RAPI_TRX_NUM_INVALID');
418         FND_MSG_PUB.Add;
419         l_error_count := l_error_count + 1;
420     END;
421    END IF;
422 
423     /*---------------------------------------------------------------------+
424      | 3)  Check bill_to_site_use_id exist                                 |
425      +---------------------------------------------------------------------*/
426      --if bill to site id is not passed,or not entered on the receipt,raise error.
427 
428      IF l_bill_to_site_use_id IS NULL THEN
429          IF p_chargeback_rec.bill_to_site_use_id IS NULL THEN
430            FND_MESSAGE.SET_NAME('AR','AR_CUST_BILL_TO_SITE_REQUIRED');
431            FND_MSG_PUB.Add;
432            l_error_count := l_error_count + 1;
433          ELSE
434            l_bill_to_site_use_id := p_chargeback_rec.bill_to_site_use_id;
435          END IF;
436      END IF;
437 
438      /* Bug 2654633 - If bill to site has been passed for a receipt chargeback
439         then use it in preference to the receipt site */
440      IF (SIGN(l_customer_trx_id) = -1 AND
441          p_chargeback_rec.bill_to_site_use_id IS NOT NULL )
442      THEN
443        l_bill_to_site_use_id := p_chargeback_rec.bill_to_site_use_id;
444      END IF;
445 
446     /*---------------------------------------------------------------------+
447      | 5)  Validate  bill_to_site_use_id passed                            |
451      IF l_bill_to_site_use_id IS NOT NULL THEN
448      |     we will take the passed bill to site only for non-invoice claim.|
449      |     for invoice, take it from the invoice.                          |
450      +---------------------------------------------------------------------*/
452      BEGIN
453        --Bug 2474471- Corrected the validation logic take from customer
454        --account.
455 
456        SELECT  site_uses.site_use_id
457        INTO    l_bill_to_site_use_id
458        FROM    hz_cust_acct_sites acct_site,
459                hz_party_sites party_site,
460                hz_locations loc,
461                hz_cust_site_uses site_uses
462        WHERE   acct_site.cust_acct_site_id = site_uses.cust_acct_site_id
463        AND     acct_site.party_site_id = party_site.party_site_id
464        AND     loc.location_id = party_site.location_id
465        AND     site_uses.site_use_code in ('BILL_TO','DRAWEE')
466        AND     acct_site.cust_account_id = l_customer_id
467        AND     site_uses.site_use_id=l_bill_to_site_use_id;
468 
469        EXCEPTION
470         WHEN no_data_found THEN
471           FND_MESSAGE.SET_NAME('AR','AR_RAPI_CUS_STE_USE_ID_INVALID');
472           FND_MSG_PUB.Add;
473           l_error_count := l_error_count + 1;
474        END;
475 
476      END IF;
477 
478 
479  /*---------------------------------------------------------------------+
480   | 6)   Check trx type is valid                                        |
481   +---------------------------------------------------------------------*/
482   IF PG_DEBUG in ('Y', 'C') THEN
483      arp_standard.debug('create_chargeback: ' || 'Checking trx type... ');
484   END IF;
485   IF p_chargeback_rec.cust_trx_type_id IS NULL
486   THEN
487     FND_MESSAGE.SET_NAME('AR','AR_BR_TRX_TYPE_NULL');
488     FND_MSG_PUB.Add;
489     l_error_count := l_error_count + 1;
490   ELSE
491     BEGIN
492       SELECT name,
493 	     gl_id_rec
494       INTO   l_cb_trx_type,
495 	     l_default_code_combination_id
496       FROM   ra_cust_trx_types
497       WHERE  cust_trx_type_id = p_chargeback_rec.cust_trx_type_id
498       AND    type = 'CB'
499       AND NVL(status,'A') = 'A'
500       AND post_to_gl = 'Y'
501       AND accounting_affect_flag = 'Y'
502       AND (l_receipt_date BETWEEN start_date AND nvl(end_date+1,l_receipt_date));
503     EXCEPTION
504       WHEN NO_DATA_FOUND
505       THEN
506         FND_MESSAGE.SET_NAME('AR','AR_RW_INVALID_CB_TRX_TYPE');
507         FND_MESSAGE.SET_TOKEN('TRX_TYPE_ID',p_chargeback_rec.cust_trx_type_id);
508         FND_MSG_PUB.Add;
509         l_error_count := l_error_count + 1;
510     END;
511   END IF;
512   IF p_chargeback_rec.code_combination_id IS NULL
513   THEN
514     l_code_combination_id := l_default_code_combination_id;
515   ELSE
516     l_code_combination_id := p_chargeback_rec.code_combination_id;
517   END IF;
518  /*---------------------------------------------------------------------+
519   | 7)  If the chargeback is to resolve a non invoice related claim and |
520   |     the applied amount differs from the amount to be written off    |
521   |     check the new claim is valid                                    |
522   +---------------------------------------------------------------------*/
523   IF PG_DEBUG in ('Y', 'C') THEN
524      arp_standard.debug('create_chargeback: ' || 'Checking new claim... ');
525   END IF;
526   IF (p_chargeback_rec.application_ref_type = 'CLAIM' AND
527       l_customer_trx_id = -4 AND
528       l_amount <> p_chargeback_rec.amount)
529   THEN
530     l_balance := (l_amount - p_chargeback_rec.amount);
531     IF p_chargeback_rec.new_second_application_ref_id IS NULL
532     THEN
533       FND_MESSAGE.set_name('AR','AR_RWAPP_NEW_CLAIM_ID_NULL');
534       FND_MSG_PUB.Add;
535       l_error_count := l_error_count + 1;
536     ELSE
537       IF NOT arp_deduction_cover.claim_valid(
538             p_claim_id => p_chargeback_rec.new_second_application_ref_id,
539 	    p_receipt_id => p_chargeback_rec.cash_receipt_id,
540 	    p_curr_code => l_currency_code,
541             p_amount   => l_balance,
542             x_claim_num  => l_new_claim_num)
543       THEN
544         l_error_count := l_error_count + 1;
545       END IF;
546     END IF;
547   END IF;
548 
549 
550  /*---------------------------------------------------------------------+
551   | 8)  Get GL date if null                                             |
552   +---------------------------------------------------------------------*/
553   IF PG_DEBUG in ('Y', 'C') THEN
554      arp_standard.debug('create_chargeback: ' || 'Validating/defaulting GL date ... ');
555   END IF;
556 
557   /* Bug 2621114 - get GL date from Profile Option AR: Application GL Date
558      Default if null */
559   IF p_chargeback_rec.gl_date IS NULL
560   THEN
561     l_gl_date := NULL;
562     l_app_gl_date_prof :=
563        NVL(fnd_profile.value('AR_APPLICATION_GL_DATE_DEFAULT'),'INV_REC_DT');
564     IF (l_app_gl_date_prof = 'INV_REC_DT') THEN
565       IF l_cr_gl_date >  l_app_gl_date THEN
566         l_gl_date := l_cr_gl_date;
567       END IF;
568     ELSIF (l_app_gl_date_prof = 'INV_REC_SYS_DT') THEN
569       IF l_cr_gl_date > SYSDATE THEN
570         l_gl_date := l_cr_gl_date;
571       ELSE
575       l_gl_date := SYSDATE;
572         l_gl_date := SYSDATE;
573       END IF;
574     ELSE
576     END IF;
577   ELSE
578     l_gl_date := p_chargeback_rec.gl_date;
579   END IF;
580 
581   IF (arp_util.validate_and_default_gl_date(
582                 l_gl_date,
583                 NULL,
584                 NULL,
585                 NULL,
586                 NULL,
587                 NULL,
588                 NULL,
589                 NULL,
590                 'N',
591                 NULL,
592 		l_set_of_books_id,
593                 222,
594                 l_default_gl_date,
595                 l_defaulting_rule_used,
596                 l_error_message) = TRUE)
597   THEN
598     NULL;
599   ELSE
600     FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
601     FND_MESSAGE.SET_TOKEN('GENERIC_TEXT', l_error_message);
602     FND_MSG_PUB.Add;
603     l_error_count := l_error_count + 1;
604   END IF;
605 
606  /*---------------------------------------------------------------------+
607   | 9)  Default due date if null                                        |
608   +---------------------------------------------------------------------*/
609   IF PG_DEBUG in ('Y', 'C') THEN
610      arp_standard.debug('create_chargeback: ' || 'Defaulting due date... ');
611   END IF;
612 
613   --
614   -- Bug 3404131 - Due date defaulted for receipt chargeback in the same way
615   -- as for transaction chargebacks
616   --
617   IF p_chargeback_rec.due_date IS NULL
618   THEN
619     IF l_default_cb_due_date = 'DUE_DATE'
620     THEN
621       l_due_date := l_app_due_date;
622     ELSIF l_default_cb_due_date = 'RECEIPT_DATE'
623     THEN
624       l_due_date := l_receipt_date;
625     ELSIF l_default_cb_due_date = 'SYSDATE'
626     THEN
627       l_due_date := SYSDATE;
628     ELSIF l_default_cb_due_date = 'DEPOSIT_DATE'
629     THEN
630       l_due_date := l_deposit_date;
631     ELSE
632       l_due_date := SYSDATE;
633     END IF;
634     IF l_due_date IS NULL
635     THEN
636       l_due_date := SYSDATE;
637     END IF;
638   ELSE
639     l_due_date := p_chargeback_rec.due_date;
640   END IF;
641 
642 
643   IF SIGN(l_customer_trx_id) = -1
644   THEN
645      IF (p_chargeback_rec.due_date IS NOT NULL AND
646          p_chargeback_rec.due_date < l_receipt_date)
647      THEN
648         FND_MESSAGE.SET_NAME('AR','AR_RW_DUE_DATE');
649         FND_MSG_PUB.Add;
650         l_error_count := l_error_count + 1;
651      ELSE
652        IF l_due_date < l_receipt_date THEN
653          l_due_date := l_receipt_date;
654        END IF;
655      END IF;
656     l_cb_exchange_rate := l_exchange_rate;
657     l_cb_exchange_rate_type := l_exchange_rate_type;
658     l_cb_exchange_rate_date := l_exchange_rate_date;
659     l_cb_currency_code := l_currency_code;
660     l_cb_bill_to_site_use_id := l_bill_to_site_use_id;
661     l_cb_remit_to_address_id :=
662       AR_INVOICE_SQL_FUNC_PUB.get_remit_to_given_bill_to(l_bill_to_site_use_id);
663   ELSE
664     l_cb_exchange_rate := NULL;
665     l_cb_exchange_rate_type := NULL;
666     l_cb_exchange_rate_date := NULL;
667     l_cb_currency_code := NULL;
668     l_cb_bill_to_site_use_id := NULL;
669     l_cb_remit_to_address_id := NULL;
670   END IF;
671 
672   /*-------------------------------------------------+
673    | R12 LE uptake
674    | Validating the legal_entity_id
675    +--------------------------------------------------*/
676   IF p_chargeback_rec.legal_entity_id IS NOT NULL THEN
677     BEGIN
678        SELECT legal_entity_id
679        INTO   l_legal_entity_id
680        FROM   XLE_FIRSTPARTY_INFORMATION_V LE
681        WHERE  LE.legal_entity_id = p_chargeback_rec.legal_entity_id;
682     EXCEPTION
683        WHEN NO_DATA_FOUND THEN
684 	  FND_MESSAGE.SET_NAME('AR','AR_INVALID_LEGAL_ENTITY');
685           FND_MSG_PUB.Add;
686           l_error_count := l_error_count + 1;
687        WHEN OTHERS THEN
688           NULL;
689     END;
690   END IF;
691 
692   IF l_error_count > 0
693   THEN
694     RAISE FND_API.G_EXC_ERROR;
695   ELSE
696  /*---------------------------------------------------------------------+
697   | B)  Insert new records                                              |
698   +---------------------------------------------------------------------*/
699 
700   -- Bug 3682568 lock the receipt or ps before calling the entity handlers
701   IF SIGN(l_customer_trx_id) = -1
702   THEN
703     BEGIN
704       arp_cash_receipts_pkg.nowaitlock_p(p_cr_id => p_chargeback_rec.cash_receipt_id);
705     EXCEPTION
706       WHEN OTHERS THEN
707         FND_MESSAGE.SET_NAME('AR','ARCABP_CANT_UPD_CR');
708         FND_MSG_PUB.Add;
709         FND_MESSAGE.SET_NAME('AR','AR_TW_FORM_RECORD_CHANGED');
710         FND_MSG_PUB.Add;
711         RAISE FND_API.G_EXC_ERROR;
712     END;
713   ELSIF l_applied_ps_id IS NOT NULL THEN
714     BEGIN
715       arp_ps_pkg.nowaitlock_p (p_ps_id => l_applied_ps_id);
716     EXCEPTION
717       WHEN OTHERS THEN
718         FND_MESSAGE.SET_NAME('AR','AR_TW_FORM_RECORD_CHANGED');
719         FND_MSG_PUB.Add;
720         RAISE FND_API.G_EXC_ERROR;
721     END;
722 
726   THEN
723   END IF;
724 
725   IF SIGN(l_customer_trx_id) <> -1
727    /*---------------------------------------------------------------------+
728     | 1)  Chargeback against a transaction so update amount in dispute    |
729     +---------------------------------------------------------------------*/
730     IF PG_DEBUG in ('Y', 'C') THEN
731        arp_standard.debug('create_chargeback: ' || 'Updating amount in dispute... ');
732     END IF;
733 
734 
735     arp_deduction_cover.update_amount_in_dispute(
736              p_customer_trx_id => l_customer_trx_id,
737              p_claim_number    => l_application_ref_num,
738              p_amount          => (p_chargeback_rec.amount * -1),
739              x_return_status   => x_return_status,
740              x_msg_count       => x_msg_count,
741              x_msg_data        => x_msg_data);
742   END IF;
743 
744   /* Bug 3013567 - get the next document sequence if enabled */
745   IF (NVL(fnd_profile.value('UNIQUE:SEQ_NUMBERS'),'N') <> 'N')
746   THEN
747 
748    BEGIN
749 
750     l_doc_sequence_value :=
751        FND_SEQNUM.GET_NEXT_SEQUENCE(
752                 appid           => arp_standard.application_id,
753                 cat_code        => l_cb_trx_type,
754                 sobid           => arp_global.set_of_books_id,
755                 met_code        => 'A',
756                 trx_date        => SYSDATE,
757                 dbseqnm         => l_sequence_name,
758                 dbseqid         => l_doc_sequence_id);
759 
760      IF PG_DEBUG in ('Y', 'C') THEN
761         arp_standard.debug('ARXCBCVB.create_chargeback: ' || 'doc sequence name = '  || l_sequence_name);
762         arp_standard.debug('ARXCBCVB.create_chargeback: ' || 'doc sequence id    = ' || l_doc_sequence_id);
763         arp_standard.debug('ARXCBCVB.create_chargeback: ' || 'doc sequence value = ' || l_doc_sequence_value);
764      END IF;
765    EXCEPTION
766      WHEN OTHERS THEN
767      IF NVL(fnd_profile.value('UNIQUE:SEQ_NUMBERS'),'N') = 'A' THEN
768          FND_MESSAGE.set_name ('AR', 'AR_RW_NO_DOC_SEQ' );
769          FND_MSG_PUB.Add;
770     	 RAISE FND_API.G_EXC_ERROR;
771      END IF;
772    END;
773 
774  ELSE
775     l_doc_sequence_value      := NULL;
776     l_doc_sequence_id         := NULL;
777  END IF;
778 
779  /*---------------------------------------------------------------------+
780   | 2)  Call chargeback entity handler to create chargeback             |
781   +---------------------------------------------------------------------*/
782     l_functional_curr := arp_global.functional_currency;
783 
784     l_cb_amount :=  (p_chargeback_rec.amount * SIGN(l_customer_trx_id));
785     l_cb_acctd_amount :=
786                  (ARPCURR.functional_amount( p_chargeback_rec.amount,
787                                             l_functional_curr,
788                                             l_cb_exchange_rate,
789                                             NULL, NULL )
790                   * SIGN(l_customer_trx_id));
791 
792     IF PG_DEBUG in ('Y', 'C') THEN
793        arp_standard.debug('create_chargeback: ' || 'Creating chargeback ... ');
794     END IF;
795 
796    -- Enh 4103090: pass the reason code sent by TM or if null, pass
797    -- INVALID_CLAIM
798 
799     arp_process_chargeback.create_chargeback (
800 	  p_attribute_category =>
801 			p_chargeback_rec.attribute_category
802 	, p_attribute1  => p_chargeback_rec.attribute1
803 	, p_attribute2  => p_chargeback_rec.attribute2
804 	, p_attribute3  => p_chargeback_rec.attribute3
805 	, p_attribute4  => p_chargeback_rec.attribute4
806 	, p_attribute5  => p_chargeback_rec.attribute5
807 	, p_attribute6  => p_chargeback_rec.attribute6
808 	, p_attribute7  => p_chargeback_rec.attribute7
809 	, p_attribute8  => p_chargeback_rec.attribute8
810 	, p_attribute9  => p_chargeback_rec.attribute9
811 	, p_attribute10 => p_chargeback_rec.attribute10
812 	, p_attribute11 => p_chargeback_rec.attribute11
813 	, p_attribute12 => p_chargeback_rec.attribute12
814 	, p_attribute13 => p_chargeback_rec.attribute13
815 	, p_attribute14 => p_chargeback_rec.attribute14
816 	, p_attribute15 => p_chargeback_rec.attribute15
817 	, p_cust_trx_type_id => p_chargeback_rec.CUST_TRX_TYPE_ID
818 	, p_set_of_books_id => l_set_of_books_id
819 	, p_reason_code => NVL( p_chargeback_rec.reason_code,
820                                 'INVALID_CLAIM')  /* TM reason code */
821 	, p_trx_date => SYSDATE -- BUG 2621114
822 	, p_comments => p_chargeback_rec.COMMENTS
823 	, p_def_ussgl_trx_code_context => p_chargeback_rec.DEFAULT_USSGL_TRX_CODE_CONTEXT
824 	, p_def_ussgl_transaction_code => p_chargeback_rec.DEFAULT_USSGL_TRANSACTION_CODE
825 	, p_app_customer_trx_id => l_customer_trx_id
826         , p_app_terms_sequence_number => l_installment
827 	, p_due_date 		=> l_due_date
828 	, p_form_name 		=> 'ARXRWAPP'
829 	, p_receipt_gl_date 	=> l_cr_gl_date
830 	, p_apply_date		=> SYSDATE -- bug 2621114
831 	, p_inv_trx_number	=> NULL
832 	, p_cash_receipt_id	=> p_chargeback_rec.cash_receipt_id
833 	, p_cr_trx_number	=> l_receipt_number
834 	, p_customer_id		=> l_customer_id
835 	, p_gl_date		=> l_default_gl_date
836 	, p_gl_id_ar_trade	=> l_code_combination_id
837 	, p_amount		=> l_cb_amount
838 	, p_acctd_amount	=> l_cb_acctd_amount
839         , p_exchange_rate_type  => l_cb_exchange_rate_type
840         , p_exchange_date       => l_cb_exchange_rate_date
844         , p_bill_to_site_use_id => l_cb_bill_to_site_use_id
841         , p_exchange_rate       => l_cb_exchange_rate
842         , p_currency_code       => l_cb_currency_code
843         , p_remit_to_address_id => l_cb_remit_to_address_id
845 	-- IN OUT NOCOPY
846 	, p_doc_sequence_id => l_doc_sequence_id
847 	, p_doc_sequence_value => l_doc_sequence_value
848 
849 	-- OUT NOCOPY
850 	, p_out_trx_number 	=> l_trx_number
851 	, p_out_customer_trx_id	=> l_new_customer_trx_id
852        --Bug 2444737
853         ,p_interface_header_context     => p_chargeback_rec.interface_header_context
854         ,p_interface_header_attribute1  => p_chargeback_rec.interface_header_attribute1
855         ,p_interface_header_attribute2  => p_chargeback_rec.interface_header_attribute2
856         ,p_interface_header_attribute3  => p_chargeback_rec.interface_header_attribute3
857         ,p_interface_header_attribute4  => p_chargeback_rec.interface_header_attribute4
858         ,p_interface_header_attribute5  => p_chargeback_rec.interface_header_attribute5
859         ,p_interface_header_attribute6  => p_chargeback_rec.interface_header_attribute6
860         ,p_interface_header_attribute7  => p_chargeback_rec.interface_header_attribute7
861         ,p_interface_header_attribute8  => p_chargeback_rec.interface_header_attribute8
862         ,p_interface_header_attribute9  => p_chargeback_rec.interface_header_attribute9
863         ,p_interface_header_attribute10 => p_chargeback_rec.interface_header_attribute10
864         ,p_interface_header_attribute11 => p_chargeback_rec.interface_header_attribute11
865         ,p_interface_header_attribute12 => p_chargeback_rec.interface_header_attribute12
866         ,p_interface_header_attribute13 => p_chargeback_rec.interface_header_attribute13
867         ,p_interface_header_attribute14 => p_chargeback_rec.interface_header_attribute14
868         ,p_interface_header_attribute15 => p_chargeback_rec.interface_header_attribute15
869 -- Bug 2751910
870         ,p_internal_notes               => p_chargeback_rec.internal_notes
871         ,p_customer_reference           => p_chargeback_rec.customer_reference
872         ,p_legal_entity_id              => p_chargeback_rec.legal_entity_id  /* R12 LE uptake */
873 );
874   END IF;
875 
876   x_doc_sequence_id := l_doc_sequence_id;
877   x_doc_sequence_value := l_doc_sequence_value;
878   x_trx_number := l_trx_number;
879   x_customer_trx_id := l_new_customer_trx_id;
880 
881  /*---------------------------------------------------------------------+
882   | 3)  If a receipt chargeback then unapply the claim investigation    |
883   +---------------------------------------------------------------------*/
884   IF l_customer_trx_id = -4
885   THEN
886     --
887     -- Unapply the application
888     --
889     IF PG_DEBUG in ('Y', 'C') THEN
890        arp_standard.debug('create_chargeback: ' || 'Unapplying OTHER ACC application ... ');
891     END IF;
892     arp_process_application.reverse(
893           p_ra_id		=> l_application_id
894 	, p_reversal_gl_date   	=> l_default_gl_date
895 	, p_reversal_date      	=> TRUNC(SYSDATE)
896 	, p_module_name		=> 'ARXRWAPP'
897 	, p_module_version	=> '1.0'
898         , p_bal_due_remaining   => l_bal_due_remaining);
899 
900    /*---------------------------------------------------------------------+
901     | 4)  Apply against dummy activity with PS id -5 using entity handler |
902     +---------------------------------------------------------------------*/
903     --
904     -- We can't use the receipt API here because it can't handle negative
905     -- amounts.  For claims, the amount_applied is normally negative
906     --
907     IF PG_DEBUG in ('Y', 'C') THEN
908        arp_standard.debug('create_chargeback: ' || 'Applying chargeback amount to dummy activity ... ');
909     END IF;
910 
911     l_application_ref_type  := 'CHARGEBACK';
912     l_application_ref_id    :=  l_new_customer_trx_id;
913     l_dum_sec_app_ref_id    := NULL;
914 
915     -- Bug 3590399: trx date not relevant for non trx-related chargeback
916     l_apply_date := GREATEST(SYSDATE, NVL(l_receipt_date,SYSDATE));
917 
918     arp_process_application.activity_application (
919              p_receipt_ps_id   => l_cr_payment_schedule_id,
920              p_application_ps_id => -5,
921              p_link_to_customer_trx_id => NULL,
922              p_amount_applied  => p_chargeback_rec.amount,
923              p_apply_date      => l_apply_date, -- Bug 2621114
924              p_gl_date         => l_default_gl_date, -- Bug 2621114
925              p_receivables_trx_id => -11,
926              p_ussgl_transaction_code => p_chargeback_rec.default_ussgl_transaction_code,
927              p_attribute_category=> l_attribute_rec.attribute_category,
928              p_attribute1        => l_attribute_rec.attribute1,
929              p_attribute2        => l_attribute_rec.attribute2,
930              p_attribute3        => l_attribute_rec.attribute3,
931              p_attribute4        => l_attribute_rec.attribute4,
932              p_attribute5        => l_attribute_rec.attribute5,
933              p_attribute6        => l_attribute_rec.attribute6,
934              p_attribute7        => l_attribute_rec.attribute7,
935              p_attribute8        => l_attribute_rec.attribute8,
936              p_attribute9        => l_attribute_rec.attribute9,
937              p_attribute10       => l_attribute_rec.attribute10,
938              p_attribute11       => l_attribute_rec.attribute11,
939              p_attribute12       => l_attribute_rec.attribute12,
943              p_global_attribute_category => l_global_attribute_rec.global_attribute_category,
940              p_attribute13       => l_attribute_rec.attribute13,
941              p_attribute14       => l_attribute_rec.attribute14,
942              p_attribute15       => l_attribute_rec.attribute15,
944              p_global_attribute1 => l_global_attribute_rec.global_attribute1,
945              p_global_attribute2 => l_global_attribute_rec.global_attribute2,
946              p_global_attribute3 => l_global_attribute_rec.global_attribute3,
947              p_global_attribute4 => l_global_attribute_rec.global_attribute4,
948              p_global_attribute5 => l_global_attribute_rec.global_attribute5,
949              p_global_attribute6 => l_global_attribute_rec.global_attribute6,
950              p_global_attribute7 => l_global_attribute_rec.global_attribute7,
951              p_global_attribute8 => l_global_attribute_rec.global_attribute8,
952              p_global_attribute9 => l_global_attribute_rec.global_attribute9,
953              p_global_attribute10 =>l_global_attribute_rec.global_attribute10,
954              p_global_attribute11 =>l_global_attribute_rec.global_attribute11,
955              p_global_attribute12 =>l_global_attribute_rec.global_attribute12,
956              p_global_attribute13 =>l_global_attribute_rec.global_attribute13,
957              p_global_attribute14 =>l_global_attribute_rec.global_attribute14,
958              p_global_attribute15 =>l_global_attribute_rec.global_attribute15,
959              p_global_attribute16 =>l_global_attribute_rec.global_attribute16,
960              p_global_attribute17 =>l_global_attribute_rec.global_attribute17,
961              p_global_attribute18 =>l_global_attribute_rec.global_attribute18,
962              p_global_attribute19 =>l_global_attribute_rec.global_attribute19,
963              p_global_attribute20 =>l_global_attribute_rec.global_attribute20,
964              p_module_name         => 'ARXRWAPP',
965              p_module_version      => 1.0,
966              p_secondary_application_ref_id => l_dum_sec_app_ref_id,
967              p_application_ref_type  => l_application_ref_type,
968              p_application_ref_id  => l_application_ref_id,
969              p_application_ref_num  => l_application_ref_num,
970                                              -- *** OUT NOCOPY
971              p_out_rec_application_id => l_new_application_id
972                                   );
973 
974   END IF;
975 
976   /*---------------------------------------------------------------------+
977    | 5)  For non invoice related deduction, reapply balance to new claim |
978    +---------------------------------------------------------------------*/
979   IF (p_chargeback_rec.application_ref_type = 'CLAIM' AND
980       l_customer_trx_id = -4 AND
981       l_amount <> p_chargeback_rec.amount)
982   THEN
983     IF PG_DEBUG in ('Y', 'C') THEN
984        arp_standard.debug('create_chargeback: ' || 'Before Inserting Claim Application (+)');
985     END IF;
986 
987     /* Bug 2821139 - under no circumstances should AR update claims when
988      they are settled from TM */
989 
990     arp_process_application.other_account_application (
991         -- *** IN
992 	  p_receipt_ps_id	   => l_cr_payment_schedule_id
993 	, p_amount_applied	   => l_balance
994 	, p_apply_date		   => l_apply_date
995 	, p_gl_date	           => l_default_gl_date -- bug 2621114
996         , p_receivables_trx_id     => l_app_receivables_trx_id
997         , p_applied_ps_id          => -4    /* Claim Investigation */
998 	, p_ussgl_transaction_code => p_chargeback_rec.default_ussgl_transaction_code
999     , p_application_ref_type       => 'CLAIM'
1000     , p_application_ref_id         => NULL
1001     , p_application_ref_num        => l_new_claim_num
1002     , p_secondary_application_ref_id => p_chargeback_rec.new_second_application_ref_id
1003     , p_comments                   => l_app_comments
1004     , p_attribute_category=> l_attribute_rec.attribute_category
1005     , p_attribute1        => l_attribute_rec.attribute1
1006     , p_attribute2        => l_attribute_rec.attribute2
1007     , p_attribute3        => l_attribute_rec.attribute3
1008     , p_attribute4        => l_attribute_rec.attribute4
1009     , p_attribute5        => l_attribute_rec.attribute5
1010     , p_attribute6        => l_attribute_rec.attribute6
1011     , p_attribute7        => l_attribute_rec.attribute7
1012     , p_attribute8        => l_attribute_rec.attribute8
1013     , p_attribute9        => l_attribute_rec.attribute9
1014     , p_attribute10       => l_attribute_rec.attribute10
1015     , p_attribute11       => l_attribute_rec.attribute11
1016     , p_attribute12       => l_attribute_rec.attribute12
1017     , p_attribute13       => l_attribute_rec.attribute13
1018     , p_attribute14       => l_attribute_rec.attribute14
1019     , p_attribute15       => l_attribute_rec.attribute15
1020     , p_global_attribute_category    => l_global_attribute_rec.global_attribute_category
1021     , p_global_attribute1 => l_global_attribute_rec.global_attribute1
1022     , p_global_attribute2 => l_global_attribute_rec.global_attribute2
1023     , p_global_attribute3 => l_global_attribute_rec.global_attribute3
1024     , p_global_attribute4 => l_global_attribute_rec.global_attribute4
1025     , p_global_attribute5 => l_global_attribute_rec.global_attribute5
1026     , p_global_attribute6 => l_global_attribute_rec.global_attribute6
1027     , p_global_attribute7 => l_global_attribute_rec.global_attribute7
1028     , p_global_attribute8 => l_global_attribute_rec.global_attribute8
1029     , p_global_attribute9 => l_global_attribute_rec.global_attribute9
1030     , p_global_attribute10 =>l_global_attribute_rec.global_attribute10
1034     , p_global_attribute14 =>l_global_attribute_rec.global_attribute14
1031     , p_global_attribute11 =>l_global_attribute_rec.global_attribute11
1032     , p_global_attribute12 =>l_global_attribute_rec.global_attribute12
1033     , p_global_attribute13 =>l_global_attribute_rec.global_attribute13
1035     , p_global_attribute15 =>l_global_attribute_rec.global_attribute15
1036     , p_global_attribute16 =>l_global_attribute_rec.global_attribute16
1037     , p_global_attribute17 =>l_global_attribute_rec.global_attribute17
1038     , p_global_attribute18 =>l_global_attribute_rec.global_attribute18
1039     , p_global_attribute19 =>l_global_attribute_rec.global_attribute19
1040     , p_global_attribute20 =>l_global_attribute_rec.global_attribute20
1041     , p_module_name		=> 'ARXRWAPP'
1042     , p_module_version 	=> '1.0'
1043     , p_payment_set_id         => l_payment_set_id
1044 	-- *** OUT NOCOPY
1045     , x_application_ref_id     => l_new_app_ref_id
1046     , x_application_ref_num    => l_new_app_ref_num
1047     , x_return_status          => l_return_status
1048     , x_msg_count              => l_msg_count
1049     , x_msg_data               => l_msg_data
1050     , p_out_rec_application_id => l_new_application_id
1051     , p_application_ref_reason => l_application_ref_reason
1052     , p_customer_reference     => l_customer_reference
1053     , x_claim_reason_name      => l_claim_reason_name
1054     , p_called_from	       => 'TRADE_MANAGEMENT'
1055 	);
1056     IF l_return_status = 'E'
1057     THEN
1058       RAISE FND_API.G_EXC_ERROR;
1059     ELSIF l_return_status = 'U'
1060     THEN
1061       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1062     END IF;
1063     IF PG_DEBUG in ('Y', 'C') THEN
1064        arp_standard.debug('create_chargeback: ' || 'After Inserting Claim Application (-)');
1065     END IF;
1066   END IF;
1067 
1068   IF PG_DEBUG in ('Y', 'C') THEN
1069      arp_standard.debug ('arp_chargeback_cover.create_chargeback()-');
1070   END IF;
1071 
1072 EXCEPTION
1073     WHEN FND_API.G_EXC_ERROR THEN
1074 		ROLLBACK TO Create_Chargeback;
1075 		x_return_status := FND_API.G_RET_STS_ERROR ;
1076 		FND_MSG_PUB.Count_And_Get
1077                            (p_encoded => FND_API.G_FALSE,
1078                             p_count   => x_msg_count,
1079                             p_data    => x_msg_data);
1080     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1081                 IF PG_DEBUG in ('Y', 'C') THEN
1082                    arp_standard.debug('create_chargeback: ' || 'Unexpected error '||sqlerrm||
1083                 ' at arp_chargeback_cover.create_chargeback()+');
1084                 END IF;
1085 		ROLLBACK TO Create_Chargeback;
1086 		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1087 		FND_MSG_PUB.Count_And_Get
1088                            (p_encoded => FND_API.G_FALSE,
1089                             p_count   => x_msg_count,
1090                             p_data    => x_msg_data);
1091     WHEN OTHERS THEN
1092                 IF (SQLCODE = -20001)
1093                 THEN
1094                   IF PG_DEBUG in ('Y', 'C') THEN
1095                      arp_standard.debug('create_chargeback: ' || '20001 error '||
1096                     ' at arp_chargeback_cover.create_chargeback()+');
1097                   END IF;
1098                   x_return_status := FND_API.G_RET_STS_ERROR ;
1099                 ELSE
1100                   IF PG_DEBUG in ('Y', 'C') THEN
1101                      arp_standard.debug('create_chargeback: ' || 'Unexpected error '||sqlerrm||
1102                     ' at arp_chargeback_cover.create_chargeback()+');
1103                   END IF;
1104 		  x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1105   		  IF 	FND_MSG_PUB.Check_Msg_Level
1106 			(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1107 		  THEN
1108         		FND_MSG_PUB.Add_Exc_Msg
1109     	    		(	G_PKG_NAME  	    ,
1110     	    			l_api_name
1111 	    		);
1112 		  END IF;
1113 		END IF;
1114 	  	ROLLBACK TO Create_Chargeback;
1115 		FND_MSG_PUB.Count_And_Get
1116                            (p_encoded => FND_API.G_FALSE,
1117                             p_count   => x_msg_count,
1118                             p_data    => x_msg_data);
1119 
1120 END create_chargeback;
1121 
1122 END ARP_CHARGEBACK_COVER;