DBA Data[Home] [Help]

PACKAGE BODY: APPS.AR_DEPOSIT_API_PUB

Source


1 Package BODY  AR_DEPOSIT_API_PUB AS
2 /* $Header: ARXCDEPB.pls 120.28 2008/09/30 10:11:32 nemani ship $           */
3 
4 /*=======================================================================+
5  |  Package Global Constants
6  +=======================================================================*/
7 G_PKG_NAME      CONSTANT VARCHAR2(30)    := 'AR_DEPOSIT_API_PUB';
8 G_MSG_UERROR    CONSTANT NUMBER         := FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR;
9 G_MSG_ERROR     CONSTANT NUMBER         := FND_MSG_PUB.G_MSG_LVL_ERROR;
10 G_MSG_SUCCESS   CONSTANT NUMBER         := FND_MSG_PUB.G_MSG_LVL_SUCCESS;
11 G_MSG_HIGH      CONSTANT NUMBER         := FND_MSG_PUB.G_MSG_LVL_DEBUG_HIGH;
12 G_MSG_MEDIUM    CONSTANT NUMBER         := FND_MSG_PUB.G_MSG_LVL_DEBUG_MEDIUM;
13 G_MSG_LOW       CONSTANT NUMBER         := FND_MSG_PUB.G_MSG_LVL_DEBUG_LOW;
14 PG_DEBUG        VARCHAR2(1) := nvl(fnd_profile.value('AFLOG_ENABLED'),'N');
15 
16  FUNCTION CurrRound( p_amount IN number,
17                       p_currency_code IN varchar2) RETURN NUMBER;
18 
19  FUNCTION CurrRound( p_amount IN number,
20                       p_currency_code IN varchar2) RETURN NUMBER IS
21 
22 
23         l_precision           NUMBER(1);
24         l_extended_precision  NUMBER;
25         l_mau                 NUMBER;
26 
27   BEGIN
28         fnd_currency.Get_Info( p_currency_code,
29                                l_precision,
30                                l_extended_precision,
31                                l_mau );
32 
33        IF l_mau IS NOT NULL
34         THEN
35             RETURN( ROUND( p_amount / l_mau) * l_mau );
36         ELSE
37             RETURN( ROUND( p_amount, l_precision ));
38         END IF;
39 
40     RETURN NULL; EXCEPTION
41         WHEN OTHERS THEN
42             RAISE;
43   END CurrRound;
44 
45 
46 /*========================================================================
47 | Prototype Declarations Procedures
48 | This routine initialize_profile_globals is used to set the profile option
49 | values in the corresponding package global variables. This kind of approach
50 | was adopted to enable the testing routine to assign different testcase values
51 | to the package global variables having the profile option values. So when we
52 | run the testing routine, the profile option package variables are overidden
53 | and the procedure initialize_profile_globals would not do any initialization
54 | in that case
55  *============================================================================*/
56 
57 /*========================================================================
58  | PUBLIC PROCEDURE initialize_profile_globals
59  |
60  | DESCRIPTION
61  |      Enter a brief description of what the package procedure does.
62  |      ----------------------------------------
63  |      This procedure does the following: Initialize all profile option values
64  |      required by AR_DEPOSIT_API_PUB.Create_Deposit to create deposit.
65  |      Values are set at public variables in ar_deposit_lib_pvt package spec
66  |
67  | CALLED FROM PROCEDURES/FUNCTIONS (local to this package body)
68  |      Enter a list of all local procedures and functions which
69  |      are call this package.
70  |      AR_DEPOSIT_API_PUB.Create_Deposit
71  |
72  |
73  | CALLS PROCEDURES/FUNCTIONS (local to this package body)
74  |      Enter a list of all local procedures and funtions which
75  |      this package calls.
76  |      fnd_profile.value
77  |
78  | PARAMETERS
79  |
80  |          None
81  |
82  | KNOWN ISSUES
83  |
84  | NOTES
85  |
86  | MODIFICATION HISTORY
87  | Date                  Author            Description of Changes
88  | 21-MAY-2001           Anuj              Created
89  | DD-MON-YYYY           Name              Bug #####, modified amount ..
90  |
91  *=======================================================================*/
92 PROCEDURE initialize_profile_globals IS
93   l_dummy varchar2(1);
94   BEGIN
95   arp_util.debug('AR_DEPOSIT_API_PUB.initialize_profile_globals()+ ');
96   IF ar_deposit_lib_pvt.pg_profile_batch_source = FND_API.G_MISS_NUM  THEN
97      ar_deposit_lib_pvt.pg_profile_batch_source
98                        := fnd_profile.value('AR_RA_BATCH_SOURCE');
99     --To make sure that Batch derived from profile option belongs to same org
100    BEGIN
101      IF ar_deposit_lib_pvt.pg_profile_batch_source is not null then
102        select 'X' into l_dummy
103        from ra_batch_sources
104        where batch_source_id = ar_deposit_lib_pvt.pg_profile_batch_source;
105     end if;
106    EXCEPTION
107        when others then
108          ar_deposit_lib_pvt.pg_profile_batch_source := null;
109    END;
110 
111   END IF;
112 
113   IF ar_deposit_lib_pvt.pg_profile_doc_seq = FND_API.G_MISS_CHAR THEN
114      ar_deposit_lib_pvt.pg_profile_doc_seq
115                        := fnd_profile.value('UNIQUE:SEQ_NUMBERS');
116   END IF;
117 
118   IF ar_deposit_lib_pvt.pg_profile_trxln_excpt_flag = FND_API.G_MISS_CHAR THEN
119       ar_deposit_lib_pvt.pg_profile_trxln_excpt_flag
120                         := fnd_profile.value('ZX_ALLOW_TRX_LINE_EXEMPTIONS');
121   END IF;
122 
123  -- Profile option AR_ENABLE_CROSS_CURRENCY has been obsolited instead it
124  -- now always state 'Y'
125  -- IF ar_deposit_lib_pvt.pg_profile_enable_cc = FND_API.G_MISS_CHAR THEN
126       ar_deposit_lib_pvt.pg_profile_enable_cc := 'Y';
127  --                      := fnd_profile.value('AR_ENABLE_CROSS_CURRENCY');
128  -- END IF;
129 
130 
131    IF ar_deposit_lib_pvt.pg_profile_cc_rate_type = FND_API.G_MISS_CHAR  THEN
132       ar_deposit_lib_pvt.pg_profile_cc_rate_type
133                        := ar_setup.value('AR_CROSS_CURRENCY_RATE_TYPE',null);
134    -- null should be replaced with org_id, to find profile for diffrent org
135    END IF;
136 
137    IF ar_deposit_lib_pvt.pg_profile_dsp_inv_rate = FND_API.G_MISS_CHAR  THEN
138       ar_deposit_lib_pvt.pg_profile_dsp_inv_rate
139                        := fnd_profile.value('DISPLAY_INVERSE_RATE');
140    END IF;
141 
142    IF ar_deposit_lib_pvt.pg_profile_def_x_rate_type = FND_API.G_MISS_CHAR  THEN
143       ar_deposit_lib_pvt.pg_profile_def_x_rate_type
144                         := fnd_profile.value('AR_DEFAULT_EXCHANGE_RATE_TYPE');
145    END IF;
146 
147   arp_util.debug('pg_profile_enable_cc        :'
148                          ||ar_deposit_lib_pvt.pg_profile_enable_cc);
149   arp_util.debug('pg_profile_trxln_excpt_flag :'
150                          ||ar_deposit_lib_pvt.pg_profile_trxln_excpt_flag);
151   arp_util.debug('pg_profile_doc_seq          :'
152                          || ar_deposit_lib_pvt.pg_profile_doc_seq);
153   arp_util.debug('pg_profile_batch_source     :'
154                          ||ar_deposit_lib_pvt.pg_profile_batch_source);
155   arp_util.debug('pg_profile_def_x_rate_type  :'
156                          ||ar_deposit_lib_pvt.pg_profile_def_x_rate_type);
157   arp_util.debug('pg_profile_dsp_inv_rate     :'
158                          ||ar_deposit_lib_pvt.pg_profile_dsp_inv_rate);
159   arp_util.debug('pg_profile_cc_rate_type     :'
160                          ||ar_deposit_lib_pvt.pg_profile_cc_rate_type);
161 
162    arp_util.debug('AR_DEPOSIT_API_PUB.initialize_profile_globals()- ');
163 
164  END initialize_profile_globals;
165 
166 /*========================================================================
167  | PUBLIC PROCEDURE CREATE_DEPOSIT
168  |
169  | DESCRIPTION
170  |      Enter a brief description of what the package procedure does.
171  |      ----------------------------------------
172  |     This procedure does the following ......
173  |     This routine is called to create deposit for the Transactions.
174  |     This API routine has  8 output and 136 input parameters in total.
175  |     As of some of the Out NOCOPY parameters, the API returns are Customer_trx_id ,
176  |     Customer_trx_line_id, new  trx_number,  if generated during deposit
177  |     creation.
178  |
179  | CALLED FROM PROCEDURES/FUNCTIONS (local to this package body)
180  |      Enter a list of all local procedures and functions which
181  |      are call this package.
182  |      It will be used by ideposit UI's
183  |
184  |
185  | CALLS PROCEDURES/FUNCTIONS (local to this package body)
186  |      Enter a list of all local procedures and funtions which
187  |      this package calls.
188  |      arp_util.debug(
189  |      FND_API.Compatible_API_Call
190  |      FND_API.G_EXC_UNEXPECTED_ERROR
191  |      FND_API.to_Boolean
192  |      FND_MSG_PUB.initialize
193  |      AR_DEPOSIT_LIB_PVT.Default_deposit_ids
194  |      AR_DEPOSIT_LIB_PVT.Get_deposit_Defaults
195  |      ar_deposit_val_pvt.Validate_Deposit
196  |      Arp_trx_defaults.get_header_defaults
197  |      ARP_TRX_VALIDATE.val_and_dflt_pay_mthd_and_bank
198  |      ar_deposit_lib_pvt.Validate_Desc_Flexfield
199  |      ar_deposit_lib_pvt.get_doc_seq
200  |      FND_MSG_PUB.Count_And_Get
201  |      arp_process_header_insrt_cover.insert_header_cover
202  |      FND_MESSAGE.SET_NAME
203  |      FND_MSG_PUB.Add;
204  |      arp_process_header.post_commit
205  |
206  | PARAMETERS
207  | Parameter		Type	Description
208  | p_api_version	IN	Used to compare version numbers of
209  |                              incoming calls to its current version
210  |                              number.
211  |p_init_msg_list       IN	Allows API callers to request that the API does
212  |                              initialization of the
213                                 message list on their behalf.
214  |p_commit		IN	Used by API callers to ask the API to commit on
215  |				their behalf.
216  |p_validation_level	IN 	Not to be used currently as this is a public API .
217  |x_return_status  	OUT NOCOPY     Represents the API overall return status.
218  |x_msg_count		OUT NOCOPY	Number of messages in the API message list
219  |x_msg_data		OUT NOCOPY	This is the message in encoded format
220  |				if x_msg_count=1
221  |
222  |2. Parameters relevant to the deposit
223  |
224  |Parameter		Type	Description
225  |p_deposit_number	IN	The deposit number of the deposit to be created.
226  |p_deposit_date	IN	The Deposit date of the entered deposit.
227  |p_usr_currency_code	IN	The translated currency code.Used to derive the
228  |				p_currency_code
229  |                              if it is not entered
230  |p_currency_code	IN	The actual currency code that gets stored in
231  |				AR tables.
232  |p_usr_exchange_rate_type IN	The translated exchange rate type.Used to derive
233  |				the p_exchange_rate_type
234  |                              if it has not been entered.
235  |p_exchange_rate_type	IN	Exchange rate type stored in AR tables.
236  |p_exchange_rate	IN	The exchange rate between the receipt currency
237  |				and the functional currency.
238  |p_exchange_rate_date	IN	The date on which the exchange rate is valid.
239  |p_batch_source_id	IN	Batch source identifier for the commitment
240  |p_batch_source_name	IN	Batch source name for the commitment
241  |p_cust_trx_type_id	IN	Transaction Type identifier
242  |p_cust_trx_type	IN	Transaction Type name
243  |p_class		IN	It is constant value = "DEP", for
244  |				future enhancement.
245  |p_gl_date		IN	Date that this deposit will be posted to
246  |				the General Ledger.
247  |
248  |p_bill_to_customer_id	 	IN	The customer_id for the bill
249  |					to  customer.
250  |p_bill_to_customer_name 	IN	The name for the entered customer.
251  |p_bill_to_customer_number 	IN	The number for the entered customer.
252  |p_bill_to_location		IN	The Location for the bill to  customer.
253  |p_bill_to_contact_id		IN	The contact identifier for the bill
254  |					to  customer.
255  |p_bill_to_contact_first_name	IN	The first name of contact for the
256  |					bill to  customer.
257  |p_bill_to_contact_last_name	IN	The last name of contact for the
258  |					bill to  customer.
259  |p_ship_to_customer_id		IN	The customer_id for the ship
260  |					to  customer.
261  |p_ship_to_customer_name	IN	The name for the entered customer.
262  |p_ship_to_customer_number	IN	The number for the entered customer.
263  |p_ship_to_location		IN	The Location for the bill to  customer.
264  |p_ship_to_contact_id		IN	The contact identifier for the bill
265  |					to  customer.
266  |p_ship_to_contact_first_name	IN	The first name of contact for the
267  |                                      bill to  customer.
268  |p_ship_to_contact_last_name	IN	The last name of contact for the bill
269  |					to  customer.
270  |p_term_id			IN	Payment terms identifier for the
271  |					transactions.
272  |p_term_name			IN	Payment terms name for the transactions.
273  |p_salesrep_id			IN	Salesrep identifier for transactions.
274  |p_salesrep_name		IN	Salesrep name for the transactions.
275  |p_interface_header_context	IN	Interface header context
276  |p_interface_header_attribute1
277  |to
278  |p_interface_header_attribute15
279  |                              IN	Interface header attribute
280  |p_attribute_category		IN	Descriptive Flexfield structure
281  |					defining column
282  |p_attribute1top_attribute15	IN	Descriptive Flexfield segment column
283  |
284  |p_global_attr_cust_rec	IN	This is a record type which contains
285  |                                      all the 25 global descriptive
286  |                                      flexfield segments and One global
287  |                                      descriptive flexfield structure
288  |					defining column.
289  |p_document_number		IN	Value assigned to document receipt.
290  |p_ussgl_transaction_code	IN	Code defined by Public Sec. accounting.
291  |p_printing_option		IN	Printing option for the invoice
292  |p_default_tax_exempt_flag	IN	Tax exempt flag.
293  |p_status_trx			IN	Status of the transaction
294  |p_financial_charges		IN	To indicate whether financial charges
295  |					are calculated.
296  |p_agreement_id		IN	Agreement associated with transaction
297  |					for the customer.
298  |p_special_instructions	In	Any special instruction for the
299  |					transaction uptp 240 character.
300  |p_comments		        IN      User comments
301  |p_purchase_order		In	Perchase order number
302  |p_purchase_order_revision	In	Perchase order revision number
303  |p_purchase_order_date		In	Perchase order date
304  |p_remit_to_address_id		In	Remit to address id for the customer
305  |p_sold_to_customer_id		IN	The customer_id for the sold to  customer.
306  |p_sold_to_customer_name	IN	The name for the entered/defaulted
307  |					sold to customer.
308  |p_sold_to_customer_number	IN	The number for the entered/defaulted
309  |					sold to customer.
310  |p_paying_customer_id		IN      The customer_id associated with the
311  |					customer bank account assigned
312  |                                      to your transaction
313  |p_paying_customer_name	IN      The name for the entered/defaulted
314  |					paying customer
315  |p_paying_customer_number	IN	The number for the entered/defaulted
316  |					paying customer
317  |p_paying_location		IN	The Location for the paying  customer
318  |p_receipt_method_name		IN	The Payment method name of transactions.
319  |p_cust_bank_account_id	IN	Customer bank account  identifier.
320  |p_cust_bank_account_name	IN	Customer bank account  name.
321  |p_cust_bank_account_number	IN	Customer bank account  number.
322  |p_start_date_commitment	IN	Start date of commitment
323  |p_end_date_commitment	IN	End date of commitment
324  |p_amount			IN	Deposit amount
325  |p_inventory_id		IN	Item id of commitment,
326  |				****	You can enter item id or Memo line id
327  |p_memo_line_id		IN	Memo line id
328  |p_memo_line_name		IN	Deposit amount
329  |p_description			IN	Description of deposit
330  |p_comm_interface_line_context	IN	Interface line context,for deposit
331  |p_comm_interface_line_attr1
332  |to
333  |p_comm_interface_line_attr15	In	Interface line attribute value
334  |p_global_attr_cust_lines_rec	In	This is a record type which contains all
335  |					the 25 global descriptive flexfield
336  |					segments for deposit lines and
337  |					One global descriptive flexfield
338  |					structure defining column.
339  |p_owner_id			In	Id of the commitment owner
340  |p_owners_name			In	Name of the commitment owner
341  |X_new_trx_number		Out NOCOPY	New transaction no if generated
342  |X_new_customer_trx_id		Out NOCOPY	New customer_trx_id of the deposit
343  |					being created
344  |X_new_customer_trx_line_id	Out NOCOPY	New customer_trx_line_id of the
345  |					deposit being created
346  |X_new_rowid			Out NOCOPY	Rowid of the deposit being created
347  | KNOWN ISSUES
348  |      Enter business functionality which was de-scoped as part of the
349  |      implementation. Ideally this should never be used.
350  |
351  | NOTES
352  |      Any interesting aspect of the code in the package body which needs
353  |      to be stated.
354  |
355  | MODIFICATION HISTORY
356  | Date                  Author            Description of Changes
357  | 21-MAY-2001           Anuj              Created
358  | DD-MON-YYYY           Name              Bug #####, modified amount ..
359  |
360  *=======================================================================*/
361 
362 
363 PROCEDURE CREATE_DEPOSIT(
364            -- Standard API parameters.
365                  p_api_version      IN  NUMBER,
366                  p_init_msg_list    IN  VARCHAR2 := FND_API.G_TRUE,
367                  p_commit           IN  VARCHAR2 := FND_API.G_TRUE,
368                  p_validation_level IN  NUMBER   := FND_API.G_VALID_LEVEL_FULL,
369                  x_return_status    OUT NOCOPY VARCHAR2,
370                  x_msg_count        OUT NOCOPY NUMBER,
371                  x_msg_data         OUT NOCOPY VARCHAR2,
372 
373                  -- Commitment, deposit info. parameters
374                  p_deposit_number               IN  VARCHAR2,
375                  p_deposit_date                 IN  DATE     DEFAULT trunc(sysdate),
376                  p_usr_currency_code            IN  VARCHAR2 DEFAULT NULL,
377                  p_currency_code                IN  VARCHAR2 DEFAULT NULL,
378                  p_usr_exchange_rate_type       IN  VARCHAR2 DEFAULT NULL,
379                  p_exchange_rate_type           IN  VARCHAR2 DEFAULT NULL,
380                  p_exchange_rate                IN  NUMBER   DEFAULT NULL,
381                  p_exchange_rate_date           IN  DATE     DEFAULT NULL,
382                  p_batch_source_id              IN  NUMBER   DEFAULT NULL,
383                  p_batch_source_name            IN  VARCHAR2 DEFAULT NULL,
384                  p_cust_trx_type_id             IN  NUMBER   DEFAULT NULL,
385                  p_cust_trx_type                IN  VARCHAR2 DEFAULT NULL,
386                  p_class                        IN  VARCHAR2 DEFAULT 'DEP',
387                  p_gl_date                      IN  DATE     DEFAULT trunc(sysdate),
388                  p_bill_to_customer_id          IN  NUMBER   DEFAULT NULL,
389                  p_bill_to_customer_name        IN  VARCHAR2 DEFAULT NULL,
390                  p_bill_to_customer_number      IN  VARCHAR2 DEFAULT NULL,
391                  p_bill_to_location             IN  VARCHAR2 DEFAULT NULL,
392                  p_bill_to_contact_id           IN  NUMBER   DEFAULT NULL,
393                  p_bill_to_contact_first_name   IN  VARCHAR2 DEFAULT NULL,
394                  p_bill_to_contact_last_name    IN  VARCHAR2 DEFAULT NULL,
395                  p_ship_to_customer_id          IN  NUMBER   DEFAULT NULL,
396                  p_ship_to_customer_name        IN  VARCHAR2 DEFAULT NULL,
397                  p_ship_to_customer_number      IN  VARCHAR2 DEFAULT NULL,
398                  p_ship_to_location             IN  VARCHAR2 DEFAULT NULL,
399                  p_ship_to_contact_id           IN  NUMBER   DEFAULT NULL,
400                  p_ship_to_contact_first_name   IN  VARCHAR2 DEFAULT NULL,
401                  p_ship_to_contact_last_name    IN  VARCHAR2 DEFAULT NULL,
402                  p_term_id                      IN  NUMBER    DEFAULT NULL,
403                  p_term_name                    IN  VARCHAR2  DEFAULT NULL,
404                  p_salesrep_id                  IN  NUMBER    DEFAULT NULL,
405                  p_salesrep_name                IN  VARCHAR2  DEFAULT NULL,
406                --flexfeild for Header
407                  p_interface_header_context       IN VARCHAR2  DEFAULT NULL,
408                  p_interface_header_attribute1    IN VARCHAR2  DEFAULT NULL,
409                  p_interface_header_attribute2    IN VARCHAR2  DEFAULT NULL,
410                  p_interface_header_attribute3    IN VARCHAR2  DEFAULT NULL,
411                  p_interface_header_attribute4    IN VARCHAR2  DEFAULT NULL,
412                  p_interface_header_attribute5    IN VARCHAR2  DEFAULT NULL,
413                  p_interface_header_attribute6    IN VARCHAR2  DEFAULT NULL,
414                  p_interface_header_attribute7    IN VARCHAR2  DEFAULT NULL,
415                  p_interface_header_attribute8    IN VARCHAR2  DEFAULT NULL,
416                  p_interface_header_attribute9    IN VARCHAR2  DEFAULT NULL,
417                  p_interface_header_attribute10   IN VARCHAR2 DEFAULT NULL,
418                  p_interface_header_attribute11   IN  VARCHAR2 DEFAULT NULL,
419                  p_interface_header_attribute12   IN VARCHAR2 DEFAULT NULL,
420                  p_interface_header_attribute13   IN VARCHAR2 DEFAULT NULL,
421                  p_interface_header_attribute14   IN VARCHAR2 DEFAULT NULL,
422                  p_interface_header_attribute15   IN  VARCHAR2 DEFAULT NULL,
423 
424                  p_attribute_category       IN      VARCHAR2  DEFAULT NULL,
425                  p_attribute1               IN      VARCHAR2 DEFAULT NULL,
426                  p_attribute2               IN      VARCHAR2 DEFAULT NULL,
427                  p_attribute3               IN      VARCHAR2 DEFAULT NULL,
428                  p_attribute4               IN      VARCHAR2 DEFAULT NULL,
429                  p_attribute5               IN      VARCHAR2 DEFAULT NULL,
430                  p_attribute6               IN      VARCHAR2 DEFAULT NULL,
431                  p_attribute7               IN      VARCHAR2 DEFAULT NULL,
432                  p_attribute8               IN      VARCHAR2 DEFAULT NULL,
433                  p_attribute9               IN      VARCHAR2 DEFAULT NULL,
434                  p_attribute10              IN      VARCHAR2 DEFAULT NULL,
435                  p_attribute11              IN      VARCHAR2 DEFAULT NULL,
436                  p_attribute12              IN      VARCHAR2 DEFAULT NULL,
437                  p_attribute13              IN      VARCHAR2 DEFAULT NULL,
438                  p_attribute14              IN      VARCHAR2 DEFAULT NULL,
439                  p_attribute15              IN      VARCHAR2 DEFAULT NULL,
440                 -- ******* Global Flexfield parameters *******
441                  p_global_attr_cust_rec       IN global_attr_rec_type
442                                               DEFAULT g_attr_cust_rec_const,
443 
444                  p_document_number            IN  VARCHAR2  DEFAULT NULL,
445                  p_ussgl_transaction_code     IN  VARCHAR2  DEFAULT NULL,
446 		 p_printing_option            IN  VARCHAR2  DEFAULT 'PRI',
447                  p_default_tax_exempt_flag    IN  VARCHAR2  DEFAULT 'S',
448                  p_status_trx                 IN  VARCHAR2  DEFAULT NULL,
449                  p_financial_charges          IN  VARCHAR2  DEFAULT NULL,
450                  p_agreement_id               IN  NUMBER    DEFAULT NULL,
451                  p_special_instructions       IN  VARCHAR2  DEFAULT NULL,
452                  p_comments                   IN  VARCHAR2  DEFAULT NULL,
453                  p_purchase_order             IN  VARCHAR2  DEFAULT NULL,
454                  p_purchase_order_revision    IN  VARCHAR2  DEFAULT NULL,
455                  p_purchase_order_date        IN  DATE      DEFAULT NULL,
456                  p_remit_to_address_id        IN  NUMBER    DEFAULT NULL,
457                  p_sold_to_customer_id        IN  NUMBER    DEFAULT NULL,
458                  p_sold_to_customer_name      IN  VARCHAR2  DEFAULT NULL,
459                  p_sold_to_customer_number    IN  VARCHAR2  DEFAULT NULL ,
460                  p_paying_customer_id         IN  NUMBER    DEFAULT NULL,
461                  p_paying_customer_name       IN  VARCHAR2  DEFAULT NULL,
462                  p_paying_customer_number     IN  VARCHAR2  DEFAULT NULL ,
463                  p_paying_location            IN  VARCHAR2  DEFAULT NULL,
464                  p_receipt_method_id          IN  NUMBER    DEFAULT NULL,
465                  p_receipt_method_name        IN  VARCHAR2  DEFAULT NULL ,
466                  p_cust_bank_account_id       IN  NUMBER    DEFAULT NULL,
467                  p_cust_bank_account_name     IN  VARCHAR2  DEFAULT NULL ,
468                  p_cust_bank_account_number   IN  VARCHAR2  DEFAULT NULL ,
469                  p_start_date_commitment     IN  DATE      DEFAULT NULL,
470                  p_end_date_commitment       IN  DATE      DEFAULT NULL,
471                  p_amount                     IN  NUMBER,
472                  p_inventory_id               IN  NUMBER    DEFAULT NULL,
473                  p_memo_line_id               IN  NUMBER    DEFAULT NULL,
474                  p_memo_line_name             IN  VARCHAR2  DEFAULT NULL,
475                  p_description                IN  VARCHAR2  DEFAULT NULL,
476                 --flexfeild for Lines
477                  p_comm_interface_line_context  IN VARCHAR2  DEFAULT NULL,
478                  p_comm_interface_line_attr1    IN VARCHAR2  DEFAULT NULL,
479                  p_comm_interface_line_attr2    IN VARCHAR2  DEFAULT NULL,
480                  p_comm_interface_line_attr3    IN VARCHAR2  DEFAULT NULL,
481                  p_comm_interface_line_attr4    IN VARCHAR2  DEFAULT NULL,
482                  p_comm_interface_line_attr5    IN VARCHAR2  DEFAULT NULL,
483                  p_comm_interface_line_attr6    IN VARCHAR2  DEFAULT NULL,
484                  p_comm_interface_line_attr7    IN VARCHAR2  DEFAULT NULL,
485                  p_comm_interface_line_attr8    IN VARCHAR2  DEFAULT NULL,
486                  p_comm_interface_line_attr9    IN VARCHAR2  DEFAULT NULL,
487                  p_comm_interface_line_attr10   IN VARCHAR2  DEFAULT NULL,
488                  p_comm_interface_line_attr11   IN VARCHAR2  DEFAULT NULL,
489                  p_comm_interface_line_attr12   IN VARCHAR2  DEFAULT NULL,
490                  p_comm_interface_line_attr13   IN VARCHAR2  DEFAULT NULL,
491                  p_comm_interface_line_attr14   IN VARCHAR2  DEFAULT NULL,
492                  p_comm_interface_line_attr15   IN VARCHAR2  DEFAULT NULL,
493 
494              -- ******* Global Flexfield parameters *******
495                  p_global_attr_cust_lines_rec
496                                   IN global_attr_rec_type
497                                   DEFAULT g_attr_cust_lines_rec_const,
498                  p_org_id                       IN  NUMBER   DEFAULT NULL,
499                  p_payment_trxn_extension_id    IN  NUMBER   DEFAULT NULL,
500             --   ** OUT NOCOPY variables
501                  X_new_trx_number           OUT NOCOPY
502                                 ra_customer_trx.trx_number%type,
503                  X_new_customer_trx_id      OUT NOCOPY
504                                 ra_customer_trx.customer_trx_id%type,
505                  X_new_customer_trx_line_id OUT NOCOPY
506                                 ra_customer_trx_lines.customer_trx_line_id%type,
507                  X_new_rowid                OUT NOCOPY  VARCHAR2 ) IS
508 
509 /*-----------------------------------------------------------------------+
510  | Local Variable Declarations and initializations                       |
511  +-----------------------------------------------------------------------*/
512 
513     l_api_name       CONSTANT VARCHAR2(20) := 'Create_Deposit';
514     l_api_version    CONSTANT NUMBER       := 1.0;
515 
516     l_deposit_number             ra_customer_trx_all.trx_number%type;
517     l_default_batch_source_id     ra_batch_sources.batch_source_id%type;
518     l_default_batch_source_name   ra_batch_sources.name%type;
519     l_auto_trx_numbering_flag     ra_batch_sources.auto_trx_numbering_flag%type;
520     l_batch_source_type           ra_batch_sources.batch_source_type%type;
521     l_copy_doc_number_flag 	  ra_batch_sources.copy_doc_number_flag%type;
522     l_bs_default_cust_trx_type_id
523                                   ra_cust_trx_types.cust_trx_type_id%type;
524     l_default_cust_trx_type_id    ra_cust_trx_types.cust_trx_type_id%type;
525     l_default_type_name           ra_cust_trx_types.name%type;
526     l_class                       ra_cust_trx_types.type%type;
527     l_open_receivables_flag       ra_cust_trx_types.accounting_affect_flag%type;
528     l_post_to_gl_flag             ra_cust_trx_types.post_to_gl%type;
529     l_allow_freight_flag          ra_cust_trx_types.allow_freight_flag%type;
530     l_creation_sign               ra_cust_trx_types.creation_sign%type;
531     l_dft_tax_calculation_flag    ra_cust_trx_types.tax_calculation_flag%type;
532     l_tax_calculation_flag        ra_cust_trx_types.tax_calculation_flag%type;
533     l_default_status_code         ar_lookups.lookup_code%type;
534     l_default_status              ar_lookups.meaning%type;
535     l_status_trx                  ar_lookups.meaning%type;
536     l_default_printing_option     ar_lookups.meaning%type;
537     l_printing_option             ar_lookups.lookup_code%type;
538     l_default_term_id             ra_terms.term_id%type;
539     l_default_term_name           ra_terms.name%type;
540     l_number_of_due_dates         number;
541     l_term_due_date               date;
542     l_default_gl_date             date;
543     l_gd_default_gl_date          date;
544     l_ctt_default_ctrx_type_id    ra_cust_trx_types.cust_trx_type_id%type;
545     l_ctt_default_type_name       ra_cust_trx_types.name%type;
546     l_ctt_bs_default_type_name    ra_cust_trx_types.name%type;
547     l_batch_source_id             ra_batch_sources.batch_source_id%type;
548     l_cust_trx_type_id            ra_cust_trx_types.cust_trx_type_id%type;
549     l_term_id                     ra_terms.term_id%type;
550     l_salesrep_id                 ra_salesreps.salesrep_id%type;
551     l_default_salesrep_id         ra_salesreps.salesrep_id%type;
552     l_dft_bill_to_contact_id      Number;
553     l_printing_pending            ra_customer_trx_all.printing_pending%type;
554     l_doc_sequence_id             NUMBER;
555     l_doc_sequence_value          VARCHAR2(50);
556     l_attribute_rec               attr_rec_type;
557     l_hd_attribute_rec            attr_rec_type;
558     l_in_comm_attribute_rec       attr_rec_type;
559     l_new_trx_number              ra_customer_trx.trx_number%type;
560     l_new_customer_trx_id         ra_customer_trx.customer_trx_id%type;
561     l_new_rowid                   varchar(18);
562     l_bill_to_customer_id         ra_customer_trx.bill_to_customer_id%type;
563     l_bill_to_customer_name       hz_parties.party_name%type;
564     l_bill_to_customer_number     hz_cust_accounts.account_number%type;
565     l_bill_to_location            hz_cust_site_uses.location%type;
566     l_bill_to_site_use_id         ra_customer_trx.bill_to_site_use_id%type;
567     l_bill_to_contact_id          ra_customer_trx.bill_to_contact_id%type;
568     l_bill_to_contact_first_name  hz_parties.person_first_name%type;
569     l_bill_to_contact_last_name   hz_parties.person_last_name%type;
570     l_ship_to_customer_id         ra_customer_trx.ship_to_customer_id%type;
571     l_ship_to_customer_name       hz_parties.party_name%type;
572     l_ship_to_customer_number     hz_cust_accounts.account_number%type;
573     l_ship_to_location            hz_cust_site_uses.location%type;
574     l_ship_to_site_use_id         ra_customer_trx.ship_to_site_use_id%type;
575     l_ship_to_contact_id          ra_customer_trx.ship_to_contact_id%type;
576     l_ship_to_contact_first_name  hz_parties.person_first_name%type;
577     l_ship_to_contact_last_name   hz_parties.person_last_name%type;
578     l_usr_currency_code           ra_customer_trx.invoice_currency_code%type;
579     l_usr_exchange_rate_type      ra_customer_trx.exchange_rate_type%type;
580     l_currency_code               ra_customer_trx.invoice_currency_code%type;
581     l_exchange_rate_type          ra_customer_trx.exchange_rate_type%type;
582     l_exchange_rate               ra_customer_trx.exchange_rate%type;
583     l_exchange_rate_date          ra_customer_trx.exchange_date%type;
584     l_amount                      NUMBER;
585     l_memo_line_id                NUMBER;
586     l_memo_line_name              VARCHAR2(240);
587     l_inventory_id                NUMBER;
588     l_deposit_date                Date;
589     l_gl_date                     Date;
590     l_remit_to_address_id         ra_customer_trx.remit_to_address_id%type;
591     l_cust_location_site_num      hz_cust_acct_sites.cust_acct_site_id%type;
592     l_sold_to_customer_id         ra_customer_trx.bill_to_customer_id%type;
593     l_sold_to_customer_name       hz_parties.party_name%type;
594     l_sold_to_customer_number     hz_cust_accounts.account_number%type;
595     l_start_date_commitmenmt      DATE;
596     l_end_date_commitmenmt        DATE;
597     l_paying_customer_id          ra_customer_trx.ship_to_customer_id%type;
598     l_paying_customer_name        hz_parties.party_name%type;
599     l_paying_customer_number      hz_cust_accounts.account_number%type;
600     l_paying_location             hz_cust_site_uses.location%type;
601     l_paying_site_use_id          ra_customer_trx.ship_to_site_use_id%type;
602     l_receipt_method_id           ra_customer_trx.receipt_method_id%type;
603     l_receipt_method_name         ar_receipt_methods.name%type;
604     l_cust_bank_account_id        ra_customer_trx.customer_bank_account_id%type;
605     l_cust_bank_account_name      ap_bank_accounts.bank_account_name%type;
606     l_cust_bank_account_number    ap_bank_accounts.bank_account_num%type;
607     l_agreement_id                ra_customer_trx.agreement_id%type;
608     l_fin_payment_method_name     ar_receipt_methods.name%type;
609     l_fin_receipt_method_id       ra_customer_trx.receipt_method_id%type;
610     l_fin_creation_method_code    ar_receipt_classes.creation_method_code%type;
611     l_fin_bank_account_num        ap_bank_accounts.bank_account_num%type;
612     l_fin_bank_name               ce_bank_branches_v.bank_name%type;
613     l_fin_bank_branch_name        ce_bank_branches_v.bank_branch_name%type;
614     l_fin_bank_branch_id          ce_bank_branches_v.branch_party_id%TYPE;
615     l_financial_charges           ra_customer_trx.finance_charges%type;
616 
617     --*******status
618     l_receipt_method_status       VARCHAR2(1000);
619     l_bank_acct_status            VARCHAR2(1000);
620     l_post_commit_status          VARCHAR2(1000);
621     l_return_val_status           VARCHAR2(1000);
622     l_new_status                  VARCHAR2(1000);
623     l_return_status               VARCHAR2(1000);
624     l_doc_seq_status              VARCHAR2(1000);
625     l_cdflex_val_return_status    VARCHAR2(1000);
626     l_dflex_val_return_status     VARCHAR2(1000);
627     l_intflex_val_return_status   VARCHAR2(1000);  /* Bug 4895995 FP Bug 5467022 */
628     l_id_return_status            VARCHAR2(1000);
629     l_dft_return_status           VARCHAR2(1000);
630     l_dummy                       NUMBER;
631     l_fin_customer_bank_account_id
632                    ra_customer_trx.customer_bank_account_id%type;
633     l_new_customer_trx_line_id
634                    ra_customer_trx_lines.customer_trx_line_id%type;
635     l_ctt_bs_deflt_ctrx_type_id
636                    ra_cust_trx_types.cust_trx_type_id%type;
637     l_allow_overapplication_flag
638                          ra_cust_trx_types.allow_overapplication_flag%type;
639     l_natural_app_only_flag
640                          ra_cust_trx_types.natural_application_only_flag%type;
641     l_default_printing_option_code
642                          ar_lookups.lookup_code%type;
643     l_org_return_status VARCHAR2(1);
644     l_org_id                           NUMBER;
645     l_payment_trxn_extension_id                           NUMBER;
646     l_legal_entity_id		NUMBER;
647 BEGIN
648          --assignment to local variables
649 arp_util.debug('AR_DEPOSIT_API_PUB.Create_Deposit()+ ');
650 arp_util.debug('initialize local variable ');
651 /*-----------------------------------------------------------------------+
652  | Local Variable initializations		                         |
653  +-----------------------------------------------------------------------*/
654 
655 
656 
657        l_hd_attribute_rec.attribute_category  :=   p_interface_header_context;
658        l_hd_attribute_rec.attribute1          :=   p_interface_header_attribute1;
659        l_hd_attribute_rec.attribute2          :=   p_interface_header_attribute2;
660        l_hd_attribute_rec.attribute3          :=   p_interface_header_attribute3;
661        l_hd_attribute_rec.attribute4          :=   p_interface_header_attribute4;
662        l_hd_attribute_rec.attribute5          :=   p_interface_header_attribute5;
663        l_hd_attribute_rec.attribute6          :=   p_interface_header_attribute6;
664        l_hd_attribute_rec.attribute7          :=   p_interface_header_attribute7;
665        l_hd_attribute_rec.attribute8          :=   p_interface_header_attribute8;
666        l_hd_attribute_rec.attribute9          :=   p_interface_header_attribute9;
667        l_hd_attribute_rec.attribute10         :=   p_interface_header_attribute10;
668        l_hd_attribute_rec.attribute11         :=   p_interface_header_attribute11;
669        l_hd_attribute_rec.attribute12         :=   p_interface_header_attribute12;
670        l_hd_attribute_rec.attribute13         :=   p_interface_header_attribute13;
671        l_hd_attribute_rec.attribute14         :=   p_interface_header_attribute14;
672        l_hd_attribute_rec.attribute15         :=   p_interface_header_attribute15;
673 
674 
675 
676        l_attribute_rec.attribute_category  :=   p_attribute_category;
677        l_attribute_rec.attribute1          :=   p_attribute1;
678        l_attribute_rec.attribute2          :=   p_attribute2;
679        l_attribute_rec.attribute3          :=   p_attribute3;
680        l_attribute_rec.attribute4          :=   p_attribute4;
681        l_attribute_rec.attribute5          :=   p_attribute5;
682        l_attribute_rec.attribute6          :=   p_attribute6;
683        l_attribute_rec.attribute7          :=   p_attribute7;
684        l_attribute_rec.attribute8          :=   p_attribute8;
685        l_attribute_rec.attribute9          :=   p_attribute9;
686        l_attribute_rec.attribute10         :=   p_attribute10;
687        l_attribute_rec.attribute11         :=   p_attribute11;
688        l_attribute_rec.attribute12         :=   p_attribute12;
689        l_attribute_rec.attribute13         :=   p_attribute13;
690        l_attribute_rec.attribute14         :=   p_attribute14;
691        l_attribute_rec.attribute15         :=   p_attribute15;
692 
693        l_in_comm_attribute_rec.attribute_category  :=   p_comm_interface_line_context;
694        l_in_comm_attribute_rec.attribute1          :=   p_comm_interface_line_attr1;
695        l_in_comm_attribute_rec.attribute2          :=   p_comm_interface_line_attr2;
696        l_in_comm_attribute_rec.attribute3          :=   p_comm_interface_line_attr3;
697        l_in_comm_attribute_rec.attribute4          :=   p_comm_interface_line_attr4;
698        l_in_comm_attribute_rec.attribute5          :=   p_comm_interface_line_attr5;
699        l_in_comm_attribute_rec.attribute6          :=   p_comm_interface_line_attr6;
700        l_in_comm_attribute_rec.attribute7          :=   p_comm_interface_line_attr7;
701        l_in_comm_attribute_rec.attribute8          :=   p_comm_interface_line_attr8;
702        l_in_comm_attribute_rec.attribute9          :=   p_comm_interface_line_attr9;
703        l_in_comm_attribute_rec.attribute10         :=   p_comm_interface_line_attr10;
704        l_in_comm_attribute_rec.attribute11         :=   p_comm_interface_line_attr11;
705        l_in_comm_attribute_rec.attribute12         :=   p_comm_interface_line_attr12;
706        l_in_comm_attribute_rec.attribute13         :=   p_comm_interface_line_attr13;
707        l_in_comm_attribute_rec.attribute14         :=   p_comm_interface_line_attr14;
708        l_in_comm_attribute_rec.attribute15         :=   p_comm_interface_line_attr15;
709 
710 
711        l_doc_sequence_value                :=   p_document_number;
712        l_bill_to_customer_id        := p_bill_to_customer_id;
713        l_bill_to_customer_name      := p_bill_to_customer_name;
714        l_bill_to_customer_number    := p_bill_to_customer_number;
715        l_bill_to_location           := p_bill_to_location;
716        l_bill_to_site_use_id        := null;
717        l_bill_to_contact_id         := p_bill_to_contact_id;
718        l_bill_to_contact_first_name := p_bill_to_contact_first_name;
719        l_bill_to_contact_last_name  := p_bill_to_contact_last_name;
720 
721        l_ship_to_customer_id        := p_ship_to_customer_id;
722        l_ship_to_customer_name      := p_ship_to_customer_name;
723        l_ship_to_customer_number    := p_ship_to_customer_number;
724        l_ship_to_location           := p_ship_to_location;
725        l_ship_to_site_use_id        := null;
726        l_ship_to_contact_id         := p_ship_to_contact_id;
727        l_ship_to_contact_first_name := p_ship_to_contact_first_name;
728        l_ship_to_contact_last_name  := p_ship_to_contact_last_name;
729        l_agreement_id               := p_agreement_id;
730 
731        l_usr_currency_code          := p_usr_currency_code;
732        l_usr_exchange_rate_type     := p_usr_exchange_rate_type;
733        l_currency_code              := p_currency_code;
734        l_exchange_rate_type         := p_exchange_rate_type;
735        l_exchange_rate              := p_exchange_rate ;
736        l_exchange_rate_date         := p_exchange_rate_date;
737        l_start_date_commitmenmt     := p_start_date_commitment;
738        l_end_date_commitmenmt       := p_end_date_commitment;
739        l_amount                     := p_amount;
740        /*l_item                       :=  p_item;
741        l_memo_line                  :=  p_memo_line;
742        l_description                :=  p_description;*/
743        l_memo_line_id               :=  p_memo_line_id;
744        l_memo_line_name             :=  p_memo_line_name;
745 
746        l_inventory_id               :=  p_inventory_id;
747        l_deposit_date               := p_deposit_date;
748        l_gl_date                    := p_gl_date;
749 
750 
751        l_remit_to_address_id        := p_remit_to_address_id;
752        l_cust_location_site_num     := null;
753 
754        l_sold_to_customer_id        :=p_sold_to_customer_id;
755        l_sold_to_customer_name      :=p_sold_to_customer_name;
756        l_sold_to_customer_number    :=p_sold_to_customer_number;
757 
758        l_paying_customer_id        := p_paying_customer_id;
759        l_paying_customer_name      := p_paying_customer_name;
760        l_paying_customer_number    := p_paying_customer_number;
761        l_paying_location           := p_paying_location;
762        l_paying_site_use_id        := null;
763 
764        l_receipt_method_id         := p_receipt_method_id;
765        l_receipt_method_name       := p_receipt_method_name;
766 
767        l_cust_bank_account_id      :=p_cust_bank_account_id;
768        l_cust_bank_account_name    :=p_cust_bank_account_name;
769        l_cust_bank_account_number  :=p_cust_bank_account_number;
770 
771        l_batch_source_id      := p_batch_source_id;
772        l_cust_trx_type_id     := p_cust_trx_type_id;
773        l_printing_option      := p_printing_option;
774        l_status_trx           := p_status_trx;
775        l_tax_calculation_flag := p_default_tax_exempt_flag;
776        l_financial_charges    := p_financial_charges;
777        l_salesrep_id          := p_salesrep_id;
778        l_term_id              := p_term_id;
779        l_payment_trxn_extension_id  := p_payment_trxn_extension_id;
780 
781        /*------------------------------------+
782         |   Standard start of API savepoint  |
783         +------------------------------------*/
784 
785       SAVEPOINT Create_Deposit_PVT;
786        arp_util.debug('Save point defined and calling compatible API call ');
787        /*--------------------------------------------------+
788         |   Standard call to check for call compatibility  |
789         +--------------------------------------------------*/
790 
791         IF NOT FND_API.Compatible_API_Call(
792                                             l_api_version,
793                                             p_api_version,
794                                             l_api_name,
795                                             G_PKG_NAME
796                                           )
797         THEN
798               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
799         END IF;
800 
801        /*--------------------------------------------------------------+
802         |   Initialize message list if p_init_msg_list is set to TRUE  |
803         +--------------------------------------------------------------*/
804 
805         IF FND_API.to_Boolean( p_init_msg_list )
806           THEN
807               FND_MSG_PUB.initialize;
808         END IF;
809 
810        /*-----------------------------------------+
811         |   Initialize return status to SUCCESS   |
812         +-----------------------------------------*/
813 
814         x_return_status     := FND_API.G_RET_STS_SUCCESS;
815         l_doc_seq_status    := FND_API.G_RET_STS_SUCCESS;
816 
817         l_id_return_status          := FND_API.G_RET_STS_SUCCESS;
818         l_cdflex_val_return_status  := FND_API.G_RET_STS_SUCCESS;
819         l_dflex_val_return_status   := FND_API.G_RET_STS_SUCCESS;
820 	    l_intflex_val_return_status := FND_API.G_RET_STS_SUCCESS; /* Bug 4895995 FP Bug 5467022 */
821         l_dft_return_status         := FND_API.G_RET_STS_SUCCESS;
822         l_receipt_method_status     := FND_API.G_RET_STS_SUCCESS;
823         l_return_val_status         := FND_API.G_RET_STS_SUCCESS;
824         l_bank_acct_status          := FND_API.G_RET_STS_SUCCESS;
825 
826 
827 
828 /* SSA change */
829        l_org_id            := p_org_id;
830        l_org_return_status := FND_API.G_RET_STS_SUCCESS;
831        ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
832                                                 p_return_status =>l_org_return_status);
833  IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
834        x_return_status := FND_API.G_RET_STS_ERROR;
835  ELSE
836         /*-------------------------------------------------+
837          | Initialize the profile option package variables |
838          +-------------------------------------------------*/
839            arp_util.debug('Before initialize_profile_globals ');
840            initialize_profile_globals;
841           arp_util.debug('After initialize_profile_globals');
842 
843 
844 /*--------------------------------------------------------------------------+
845 | Getting all id 's required for commitment creation from name or number    |
846 | comibination  it ll also be validated inside the called routine           |
847 +---------------------------------------------------------------------------*/
848 
849     AR_DEPOSIT_LIB_PVT.Default_deposit_ids
850                              (l_salesrep_id,
851                               p_salesrep_name,
852                               l_term_id,
853                               p_term_name,
854                               l_batch_source_id,
855                               p_batch_source_name,
856                               l_cust_trx_type_id,
857                               p_cust_trx_type,
858                               l_bill_to_customer_id,
859                               l_bill_to_site_use_id,
860                               l_bill_to_customer_name,
861                               l_bill_to_customer_number,
862                               l_bill_to_location,
863                               l_bill_to_contact_id,
864                               l_bill_to_contact_first_name,
865                               l_bill_to_contact_last_name,
866 
867                               l_ship_to_customer_id,
868                               l_ship_to_site_use_id,
869                               l_ship_to_customer_name,
870                               l_ship_to_customer_number,
871                               l_ship_to_location,
872                               l_ship_to_contact_id,
873                               l_ship_to_contact_first_name,
874                               l_ship_to_contact_last_name,
875 
876                               l_usr_currency_code,
877                               l_usr_exchange_rate_type,
878                               l_currency_code,
879                               l_exchange_rate_type,
880 
881                               l_remit_to_address_id,
882                               l_cust_location_site_num,
883 
884                               l_sold_to_customer_id,
885                               l_sold_to_customer_name,
886                               l_sold_to_customer_number,
887 
888                               l_paying_customer_id,
889                               l_paying_site_use_id,
890                               l_paying_customer_name,
891                               l_paying_customer_number,
892                               l_paying_location,
893 
894                               l_receipt_method_id,
895                               l_receipt_method_name,
896 
897                               l_cust_bank_account_id,
898                               l_cust_bank_account_name,
899                               l_cust_bank_account_number,
900                               l_memo_line_id ,
901                               l_memo_line_name,
902                               l_inventory_id,
903                               p_deposit_number ,
904                               l_deposit_date,
905                               l_id_return_status --out
906                               );
907 
908 arp_util.debug('l_receipt_method_id'||to_char(l_receipt_method_id));
909 /*----------------------------------------------------------------------------+
910 | Getting some of the defaulted values for depsoit creations		     |
911 +----------------------------------------------------------------------------*/
912 
913          AR_DEPOSIT_LIB_PVT.Get_deposit_Defaults
914                                         (l_currency_code,
915                                          l_exchange_rate_type,
916                                          l_exchange_rate ,
917                                          l_exchange_rate_date,
918                                          l_start_date_commitmenmt,
919                                          l_end_date_commitmenmt,
920                                          l_amount,
921                                          l_deposit_date,
922                                          l_gl_date,
923                                          l_bill_to_customer_id,
924                                          l_bill_to_site_use_id,
925                                          l_ship_to_customer_id,
926                                          l_ship_to_site_use_id,
927                                          l_default_salesrep_id,
928                                          l_dft_bill_to_contact_id,
929                                          'AR_DEPOSIT_API_PUB',
930                                          l_dft_return_status);
931 
932 
933 
934  -- **** default the salesrep id,bill to contact if id's is not passed ****
935 
936 	IF l_salesrep_id is null then
937  		l_salesrep_id := l_default_salesrep_id;
938 	END IF;
939 	IF l_bill_to_contact_id is null then
940  		l_bill_to_contact_id := l_dft_bill_to_contact_id;
941 	END IF;
942 
943 /*----------------------------------------------------------------------------+
944 |Only do  main validation before creating the deposit			     |
945 +----------------------------------------------------------------------------*/
946         ar_deposit_val_pvt.Validate_Deposit(l_batch_source_id,
947                                             l_deposit_date,
948                                             l_gl_date,
949                                             l_doc_sequence_value,
950                                             l_amount,
951                                             l_currency_code,
952                                             l_exchange_rate_type,
953                                             l_exchange_rate,
954                                             l_exchange_rate_date,
955                                             l_printing_option,
956                                             l_status_trx,
957                                             l_tax_calculation_flag,
958                                             l_financial_charges,
959                                             l_return_val_status);
960 
961 /*----------------------------------------------------------------------+
962 |Only do the check if either the batch_source_id or		       |
963 |ar_ra_batch_source are not null 				       |
964 +-----------------------------------------------------------------------*/
965 
966        IF   l_batch_source_id IS NOT NULL OR
967             ar_deposit_lib_pvt.pg_profile_batch_source IS NOT NULL
968        THEN
969 
970                  arp_trx_defaults.get_header_defaults(
971                     l_batch_source_id,
972                     NULL,
973                     ar_deposit_lib_pvt.pg_profile_batch_source,
974                     NULL,
975                     l_cust_trx_type_id,
976                     l_term_id,
977                     NULL,
978                     'DEP',
979                     l_deposit_date,
980                     NULL,--p_deposit_number,
981                     NULL,
982                     NULL,
983                     'N',
984                     'N',
985                     'Y',
986                     l_bill_to_customer_id,
987                     l_bill_to_site_use_id,
988                     l_gl_date,
989                     NULL,
990                     NULL,
991                     NULL,
992                     l_default_batch_source_id,
993                     l_default_batch_source_name,
994                     l_auto_trx_numbering_flag,
995                     l_batch_source_type,
996 		    l_copy_doc_number_flag,
997                     l_bs_default_cust_trx_type_id,
998                     l_default_cust_trx_type_id,
999                     l_default_type_name,
1000                     l_class,
1001                     l_open_receivables_flag,
1002                     l_post_to_gl_flag,
1003                     l_allow_freight_flag,
1004                     l_creation_sign,
1005                     l_allow_overapplication_flag,
1006                     l_natural_app_only_flag,
1007                     l_dft_tax_calculation_flag,
1008                     l_default_status_code,
1009                     l_default_status,
1010                     l_default_printing_option_code,
1011                     l_default_printing_option,
1012                     l_default_term_id,
1013                     l_default_term_name,
1014                     l_number_of_due_dates,
1015                     l_term_due_date,
1016                     l_default_gl_date,
1017                     'N',
1018                     'N',
1019                     'N',
1020                     'Y'
1021              );
1022        END IF;
1023        arp_util.debug('l_term_id := '||to_char(l_term_id));
1024        arp_util.debug('l_default_term_id := '||to_char(l_default_term_id));
1025 
1026        IF l_cust_trx_type_id is NULL and
1027           l_default_cust_trx_type_id is NULL THEN
1028 
1029          FND_MESSAGE.SET_NAME('AR','AR_DAPI_TRANS_TYPE_NULL');
1030          FND_MSG_PUB.Add;
1031          x_return_status := FND_API.G_RET_STS_ERROR;
1032        ELSIF l_cust_trx_type_id is NULL and l_default_cust_trx_type_id is NOT NULL THEN
1033           BEGIN
1034             SELECT  cust_trx_type_id
1035             INTO l_cust_trx_type_id
1036             FROM  ra_cust_trx_types
1037             where type = 'DEP' and
1038                   nvl(p_deposit_date, trunc(sysdate)) between
1039                       nvl(start_date(+), nvl(p_deposit_date, trunc(sysdate)))   and
1040                       nvl(end_date(+), nvl(p_deposit_date, trunc(sysdate)))  and
1041                   cust_trx_type_id = l_default_cust_trx_type_id;
1042           EXCEPTION
1043 
1044             WHEN NO_DATA_FOUND THEN
1045                   FND_MESSAGE.SET_NAME('AR','AR_DAPI_TRANS_TYPE_NULL');
1046                   FND_MSG_PUB.Add;
1047                   x_return_status := FND_API.G_RET_STS_ERROR;
1048            WHEN OTHERS THEN
1049              RAISE;
1050           END;
1051 
1052        END IF;
1053 
1054       --**** Passed deposit number will not be passed if l_auto_trx_numbering_flag
1055       --  it set to Y, a new deposit number will be generated
1056          IF nvl(l_auto_trx_numbering_flag,'N') = 'Y' then
1057              l_deposit_number := null;
1058          else
1059             l_deposit_number := p_deposit_number;
1060          end IF;
1061       --****overriding defaulted term_id
1062 	IF l_term_id is not null
1063 	THEN
1064   		 l_default_term_id := l_term_id;
1065 	END IF;
1066 
1067 /*----------------------------------------------------------------------------+
1068 |  Only do the check if either the payment method or bank fields are not null |
1069 +-----------------------------------------------------------------------------*/
1070 
1071    IF l_receipt_method_id is  null or
1072       l_cust_bank_account_id is  null THEN
1073 
1074       ARP_TRX_VALIDATE.val_and_dflt_pay_mthd_and_bank
1075                                     ( l_deposit_date ,
1076                                       l_currency_code ,
1077                                       l_paying_customer_id,
1078                                       l_paying_site_use_id,
1079                                       l_bill_to_customer_id,
1080                                       l_bill_to_site_use_id,
1081                                       l_receipt_method_id,
1082                                       l_cust_bank_account_id,
1083                                       NULL, -- *p_payment_type_code***
1084                                       l_fin_payment_method_name,
1085                                       l_fin_receipt_method_id,
1086                                       l_fin_creation_method_code,
1087                                       l_fin_customer_bank_account_id,
1088                                       l_fin_bank_account_num,
1089                                       l_fin_bank_name,
1090                                       l_fin_bank_branch_name,
1091                                       l_fin_bank_branch_id);
1092   	arp_util.debug('l_receipt_method_id'||
1093                                to_char(l_receipt_method_id));
1094   	arp_util.debug('l_cust_bank_account_id'||
1095                                to_char(l_cust_bank_account_id));
1096   	arp_util.debug('l_fin_receipt_method_id'||
1097                                to_char(l_fin_receipt_method_id));
1098   	arp_util.debug('l_fin_customer_bank_account_id'||
1099                                to_char(l_fin_customer_bank_account_id));
1100 
1101    END IF;
1102 
1103    IF l_printing_option is NULL
1104    THEN
1105          l_printing_option := l_default_printing_option;
1106    END IF;
1107 
1108    IF    (l_printing_option  = 'NOT' )
1109    THEN
1110         l_printing_pending :='N';
1111    ELSE
1112          l_printing_pending := 'Y';
1113    END IF;
1114 
1115    IF l_status_trx is NULL THEN
1116         l_status_trx := l_default_status_code;
1117    END IF;
1118 
1119    IF l_tax_calculation_flag is NULL THEN
1120         l_tax_calculation_flag := l_dft_tax_calculation_flag;
1121    END IF;
1122 
1123 /*-----------------------------------------------------------------------------+
1124 |  Validating Descriptive Flex Fields 					     |
1125 +-----------------------------------------------------------------------------*/
1126 
1127         ar_deposit_lib_pvt.Validate_Desc_Flexfield(
1128                                             l_attribute_rec,
1129                                             'RA_CUSTOMER_TRX',
1130                                             l_dflex_val_return_status
1131                                             );
1132         ar_deposit_lib_pvt.Validate_Desc_Flexfield(
1133                                             l_hd_attribute_rec,
1134                                             'RA_INTERFACE_HEADER',
1135                                        --   l_dflex_val_return_status
1136 					    					l_intflex_val_return_status  /* Bug 4895995 FP Bug 5467022 */
1137                                             );
1138         ar_deposit_lib_pvt.Validate_Desc_Flexfield(
1139                                             l_in_comm_attribute_rec,
1140                                            'RA_INTERFACE_LINES',
1141                                             l_cdflex_val_return_status
1142                                             );
1143 END IF;
1144 
1145       IF l_id_return_status          <> FND_API.G_RET_STS_SUCCESS OR
1146          l_cdflex_val_return_status  <> FND_API.G_RET_STS_SUCCESS OR
1147          l_dflex_val_return_status   <> FND_API.G_RET_STS_SUCCESS OR
1148 	 	 l_intflex_val_return_status <> FND_API.G_RET_STS_SUCCESS OR    /* Bug 4895995 FP Bug 5467022*/
1149          l_dft_return_status         <> FND_API.G_RET_STS_SUCCESS OR
1150          l_return_val_status         <> FND_API.G_RET_STS_SUCCESS OR
1151          l_receipt_method_status     <> FND_API.G_RET_STS_SUCCESS OR
1152          l_bank_acct_status          <> FND_API.G_RET_STS_SUCCESS
1153 
1154 
1155       THEN
1156 
1157             x_return_status := FND_API.G_RET_STS_ERROR;
1158 
1159       END IF;
1160 
1161 /*-----------------------------------------------------------------------------+
1162 | Call the document sequence routine only there have been no errors reported   |
1163 | so far.								       |
1164 +-----------------------------------------------------------------------------*/
1165 
1166         IF x_return_status = FND_API.G_RET_STS_SUCCESS  THEN
1167 
1168            ar_deposit_lib_pvt.get_doc_seq(222,
1169                                           l_default_type_name,
1170                                             --l_receipt_method_name,
1171                                           arp_global.set_of_books_id,
1172                                           'M',
1173                                           l_deposit_date,
1174                                           l_doc_sequence_value,
1175                                           l_doc_sequence_id,
1176                                           l_doc_seq_status
1177                                           );
1178         END IF;
1179 
1180 
1181        /*------------------------------------------------------------+
1182         |  If any errors - including validation failures - occurred, |
1183         |  rollback any changes and return an error status.          |
1184         +------------------------------------------------------------*/
1185       arp_util.debug('x_return_status : '||x_return_status);
1186       arp_util.debug('l_doc_seq_status : '||l_doc_seq_status);
1187 	 IF (
1188               x_return_status         <> FND_API.G_RET_STS_SUCCESS
1189               OR l_doc_seq_status     <> FND_API.G_RET_STS_SUCCESS
1190              )
1191              THEN
1192 
1193               ROLLBACK TO Create_Deposit_PVT;
1194 
1195 
1196        /*-------------------------------------------------------+
1197         | FND_MSG_PUB.Count_And_Get used  get the count of mesg.|
1198         | in the message stack. If there is only one message in |
1199         | the stack it retrieves this message                   |
1200         +-------------------------------------------------------*/
1201               x_return_status := FND_API.G_RET_STS_ERROR ;
1202 
1203               FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
1204                                         p_count => x_msg_count,
1205                                         p_data  => x_msg_data);
1206 
1207              arp_util.debug('Error(s) occurred.
1208                              Rolling back and setting status to ERROR');
1209              Return;
1210         END IF;
1211           arp_util.debug('x_return_status '||x_return_status);
1212 
1213 /*---------------------------------------------------------------------+
1214  |   Bug 6620785 Get and validate default legal entity id              |
1215  +--------------------------------------------------------------------*/
1216     BEGIN
1217     IF pg_debug = 'Y' THEN
1218         arp_util.debug ('AR_DEPOSIT_API_PUB.populate_legal_entity(+)' );
1219     END IF;
1220 
1221 	l_legal_entity_id := arp_legal_entity_util.get_default_le(
1222 				l_sold_to_customer_id,
1223 				l_bill_to_customer_id,
1224 				l_cust_trx_type_id,
1225 				l_batch_source_id);
1226     IF NVL(l_legal_entity_id, -1) = -1 then
1227 	ROLLBACK TO Create_Deposit_PVT;
1228 	x_return_status := FND_API.G_RET_STS_ERROR ;
1229 	Return;
1230     END IF;
1231 
1232     IF pg_debug = 'Y' THEN
1233 	arp_util.debug ('AR_DEPOSIT_API_PUB.populate_legal_entity(-)' );
1234     END IF;
1235 
1236     EXCEPTION
1237             WHEN Others THEN
1238                 FND_MESSAGE.SET_NAME('AR','AR_LE_NAME_MANDATORY');
1239                 FND_MSG_PUB.Add;
1240                 x_return_status := FND_API.G_RET_STS_ERROR ;
1241                 ROLLBACK TO Create_Deposit_PVT;
1242                FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
1243                                         p_count => x_msg_count,
1244 					p_data  => x_msg_data);
1245 		return;
1246     END;
1247 
1248 /*-----------------------------------------------------------------------------+
1249 |   Inserting Header and line for commitment calling the routine ,             |
1250 |   arp_process_header_insrt_cover.insert_header_cover                         |
1251 +-----------------------------------------------------------------------------*/
1252    BEGIN
1253    arp_process_header_insrt_cover.insert_header_cover(
1254                       G_PKG_NAME,
1255                       p_api_version,
1256                       'DEP', -- p_class,  --p_class can be used for future enhancement
1257                       l_default_gl_date,
1258                       NULL,
1259                       NULL,
1260                       NULL,
1261                       l_deposit_number,
1262                       NULL,
1263                       'Y',
1264                       NULL,
1265                       NULL,
1266                       NULL,
1267                       NULL,
1268                       l_default_cust_trx_type_id,
1269                       NULL,
1270                       l_default_batch_source_id,
1271                       l_agreement_id,
1272 	              trunc(l_deposit_date), /*Bug 4065254*/
1273                       l_bill_to_customer_id,
1274                       l_bill_to_contact_id,
1275                       l_bill_to_site_use_id,
1276                       l_ship_to_customer_id,
1277                       l_ship_to_contact_id,
1278                       l_ship_to_site_use_id,
1279                       l_sold_to_customer_id ,
1280                       NULL,
1281                       NULL,
1282                       NULL,
1283                       NULL,
1284                       NULL,
1285                       NULL,
1286                       trunc(l_start_date_commitmenmt), /*Bug 4065254*/
1287                       trunc(l_end_date_commitmenmt), /*Bug 4065254*/
1288                       trunc(l_exchange_rate_date), /*Bug 4065254*/
1289                       l_exchange_rate,
1290                       l_exchange_rate_type,
1291                       nvl(l_cust_bank_account_id,
1292                           l_fin_customer_bank_account_id),
1293                       l_financial_charges,
1294                       ar_deposit_lib_pvt.Get_FOB_POINT(l_bill_to_customer_id,
1295                                                        l_bill_to_location,
1296                                                        l_ship_to_customer_id,
1297                                                        l_ship_to_location,
1298                                                        x_return_status),
1299                       p_comments,
1300                       p_special_instructions,
1301                       l_currency_code,
1302                       NULL,
1303                       NULL,
1304                       NULL,
1305                       l_salesrep_id,
1306                       NULL,
1307                       NULL,
1308                       l_printing_option,
1309                       NULL,
1310                       l_printing_pending,
1311                       p_purchase_order,
1312                       p_purchase_order_date,
1313                       p_purchase_order_revision,
1314                       nvl(l_receipt_method_id,l_fin_receipt_method_id),
1315                       l_remit_to_address_id ,
1316                       NULL,
1317                       NULL,
1318                       NULL, /*Bug 4065254*/
1319                       trunc(l_term_due_date), /*Bug 4065254*/
1320                       l_default_term_id,
1321                       ar_deposit_lib_pvt.Get_Territory_id(l_bill_to_customer_id,						          l_bill_to_location,
1322                                                           l_ship_to_customer_id,							  l_ship_to_location,
1323                                                           l_salesrep_id,
1324 							  l_deposit_date,
1325 							  x_return_status),
1326                       NULL,
1327                       l_status_trx,
1328                       NUll,
1329                       l_doc_sequence_id,
1330                       l_doc_sequence_value,
1331                       l_paying_customer_id,
1332                       l_paying_site_use_id,
1333                       NULL,
1334                       l_tax_calculation_flag,
1335                       'ARXCDEPB' ,
1336                       p_ussgl_transaction_code,
1337                       NULL,
1338                       p_interface_header_context,
1339                       p_interface_header_attribute1,
1340                       p_interface_header_attribute2,
1341                       p_interface_header_attribute3,
1342                       p_interface_header_attribute4,
1343                       p_interface_header_attribute5,
1344                       p_interface_header_attribute6,
1345                       p_interface_header_attribute7,
1346                       p_interface_header_attribute8,
1347                       p_interface_header_attribute9,
1348                       p_interface_header_attribute10,
1349                       p_interface_header_attribute11,
1350                       p_interface_header_attribute12,
1351                       p_interface_header_attribute13,
1352                       p_interface_header_attribute14,
1353                       p_interface_header_attribute15,
1354                       l_attribute_rec.attribute_category,
1355                       l_attribute_rec.attribute1,
1356                       l_attribute_rec.attribute2,
1357                       l_attribute_rec.attribute3,
1358                       l_attribute_rec.attribute4,
1359                       l_attribute_rec.attribute5,
1360                       l_attribute_rec.attribute6,
1361                       l_attribute_rec.attribute7,
1362                       l_attribute_rec.attribute8,
1363                       l_attribute_rec.attribute9,
1364                       l_attribute_rec.attribute10,
1365                       l_attribute_rec.attribute11,
1366                       l_attribute_rec.attribute12,
1367                       l_attribute_rec.attribute13,
1368                       l_attribute_rec.attribute14,
1369                       l_attribute_rec.attribute15,
1370                       NULL,
1371                       l_inventory_id,
1372 		      l_memo_line_id,
1373                       p_description,
1374                       l_amount,
1375                       p_comm_interface_line_attr1,
1376                       p_comm_interface_line_attr2,
1377                       p_comm_interface_line_attr3,
1378                       p_comm_interface_line_attr4,
1379                       p_comm_interface_line_attr5,
1380                       p_comm_interface_line_attr6,
1381                       p_comm_interface_line_attr7,
1382                       p_comm_interface_line_attr8,
1383                       p_comm_interface_line_attr9,
1384                       p_comm_interface_line_attr10,
1385                       p_comm_interface_line_attr11,
1386                       p_comm_interface_line_attr12,
1387                       p_comm_interface_line_attr13,
1388                       p_comm_interface_line_attr14,
1389                       p_comm_interface_line_attr15,
1390                       p_comm_interface_line_context,
1391                       null,
1392                       null,
1393                       null,
1394                       null,
1395                       null,
1396                       null,
1397                       null,
1398                       null,
1399                       null,
1400                       null,
1401                       null,
1402                       null,
1403                       null,
1404                       null,
1405                       null,
1406                       null,
1407                       NULL,
1408                       l_new_trx_number,
1409                       l_new_customer_trx_id,
1410                       l_new_customer_trx_line_id,
1411                       l_new_rowid,
1412                       l_new_status,
1413 		      l_legal_entity_id);
1414 
1415      X_new_trx_number           := l_new_trx_number;
1416      X_new_customer_trx_id      := l_new_customer_trx_id;
1417      X_new_customer_trx_line_id := l_new_customer_trx_line_id;
1418      X_new_rowid                := l_new_rowid;
1419 arp_util.debug('arp_process_header_insrt_cover.insert_header_cover: l_new_status'||l_new_status );
1420    EXCEPTION
1421             WHEN Others THEN
1422              FND_MESSAGE.SET_NAME('AR','AR_DAPI_INSERT_HEADER_ST');
1423              FND_MSG_PUB.Add;
1424              FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
1425              FND_MESSAGE.SET_TOKEN('GENERIC_TEXT',SQLERRM);
1426              FND_MSG_PUB.Add;
1427              x_return_status := FND_API.G_RET_STS_ERROR ;
1428              ROLLBACK TO Create_Deposit_PVT;
1429              FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
1430                                        p_count => x_msg_count,
1431                                        p_data  => x_msg_data);
1432              Return;
1433    END;
1434 
1435 
1436 /* PAYMENT UPTAKE */
1437 
1438       IF l_new_customer_trx_id IS NOT NULL
1439       THEN
1440            BEGIN
1441 
1442              copy_trxn_extension (
1443                      p_customer_trx_id => l_new_customer_trx_id,
1444                      p_payment_trxn_extension_id =>l_payment_trxn_extension_id,
1445                      p_return_status =>l_return_status);
1446 
1447    /*       EXCEPTION
1448             WHEN Others THEN */
1449 
1450 
1451 
1452 
1453          IF l_return_status = FND_API.G_RET_STS_ERROR THEN
1454              FND_MESSAGE.SET_NAME('AR','AR_CC_AUTH_FAILED');
1455              FND_MSG_PUB.Add;
1456              FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
1457              FND_MESSAGE.SET_TOKEN('GENERIC_TEXT',SQLERRM);
1458              FND_MSG_PUB.Add;
1459              x_return_status := FND_API.G_RET_STS_ERROR ;
1460              ROLLBACK TO Create_Deposit_PVT;
1461              FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
1462                                        p_count => x_msg_count,
1463                                        p_data  => x_msg_data);
1464              Return;
1465          END IF;
1466 
1467              EXCEPTION
1468              WHEN OTHERS THEN
1469 
1470              FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
1471              FND_MESSAGE.SET_TOKEN('GENERIC_TEXT',SQLERRM);
1472              FND_MSG_PUB.Add;
1473              x_return_status := FND_API.G_RET_STS_ERROR ;
1474              ROLLBACK TO Create_Deposit_PVT;
1475              FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
1476                                        p_count => x_msg_count,
1477                                        p_data  => x_msg_data);
1478             return;
1479 
1480           END;
1481       END IF;
1482 
1483 /* PAYMENT UPTAKE END */
1484 
1485 
1486 
1487   -- ****update ra_customer_trx and line for globalization felx
1488 
1489 /*-----------------------------------------------------------------------------+
1490 |   Posting commit activities i.e completing the deposit create by routine ,  |
1491 |   arp_process_header_insrt_cover.insert_header_cover  using                 |
1492 |   arp_process_header.post_commit  			                      |
1493 +-----------------------------------------------------------------------------*/
1494 
1495 
1496       IF l_new_customer_trx_id IS NOT NULL
1497       THEN
1498            BEGIN
1499            arp_process_header.post_commit( 'AR_DEPOSIT_API_PUB',
1500                                            1.0,
1501                                            l_new_customer_trx_id,
1502                                            NULL,
1503                                            'Y',
1504                                            l_open_receivables_flag,
1505                                            NULL,
1506                                            l_creation_sign,
1507                                            l_allow_overapplication_flag,
1508                                            l_natural_app_only_flag,
1509                                            NULL
1510                                          );
1511           EXCEPTION
1512             WHEN Others THEN
1513              FND_MESSAGE.SET_NAME('AR','AR_DAPI_POST_COMMIT_ST');
1514              FND_MSG_PUB.Add;
1515              FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
1516              FND_MESSAGE.SET_TOKEN('GENERIC_TEXT',SQLERRM);
1517              FND_MSG_PUB.Add;
1518              x_return_status := FND_API.G_RET_STS_ERROR ;
1519              ROLLBACK TO Create_Deposit_PVT;
1520              FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
1521                                        p_count => x_msg_count,
1522                                        p_data  => x_msg_data);
1523              Return;
1524 
1525           END;
1526       END IF;
1527 
1528 -- Bug # 3177345
1529     IF NVL(l_copy_doc_number_flag, 'N') = 'Y' AND
1530          (l_doc_sequence_value IS NOT NULL)
1531     THEN
1532        update ra_customer_trx
1533        set  old_trx_number = l_new_trx_number ,
1534             trx_number = l_doc_sequence_value
1535        where customer_trx_id = l_new_customer_trx_id ;
1536        --Bug # 3515882 -also updatingh trx_number in payment schedule
1537        update ar_payment_schedules
1538        set   trx_number = l_doc_sequence_value
1539        where customer_trx_id = l_new_customer_trx_id ;
1540 
1541        X_new_trx_number           := l_doc_sequence_value;
1542      END IF;
1543  --bug 3177345
1544 
1545        /*--------------------------------+
1546         |   Standard check of p_commit   |
1547         +--------------------------------*/
1548 
1549         IF FND_API.To_Boolean( p_commit )
1550         THEN
1551             arp_util.debug('committing');
1552             Commit;
1553         END IF;
1554 
1555 arp_util.debug('AR_DEPOSIT_API_PUB.Create_Deposit()- ');
1556 END CREATE_DEPOSIT;
1557 /*========================================================================
1558  | PUBLIC PROCEDURE insert_non_rev_salescredit
1559  |
1560  | DESCRIPTION
1561  |      Enter a brief description of what the package procedure does.
1562  |      ----------------------------------------
1563  |        This routine is called to assign non revenue sales credit to
1564  |        salesreps of  to deposit, commitment. You can  create as many
1565  |        of the non-revenue credit assignment.
1566  |        This API routine has  4 output and 22 input parameters in total.
1567  |
1568  | CALLED FROM PROCEDURES/FUNCTIONS (local to this package body)
1569  |      Enter a list of all local procedures and functions which
1570  |      are call this package.
1571  |      AR_DEPOSIT_API_PUB.insert_non_rev_salescredit
1572  |      Parameter
1573  |      p_deposit_number
1574  |      p_customer_trx_id
1575  |      p_salesrep_number
1576  |      p_salesrep_id
1577  |      p_non_revenue_amount_split
1578  |      p_non_revenue_percent_split
1579  |      p_attribute_category
1580  |      p_attribute1 to p_attribute15
1581  |
1582  | CALLS PROCEDURES/FUNCTIONS (local to this package body)
1583  |
1584  | PARAMETERS
1585  |
1586  |          None
1587  |
1588  | KNOWN ISSUES
1589  |
1590  | NOTES
1591  |
1592  | MODIFICATION HISTORY
1593  | Date                  Author            Description of Changes
1594  | 08-JUL-2003           Anuj              Created
1595  | DD-MON-YYYY           Name              Bug #####, modified amount ..
1596  |
1597  *=======================================================================*/
1598 
1599 PROCEDURE insert_non_rev_salescredit
1600 
1601 (
1602  -- Standard API parameters.
1603  p_api_version                  IN  NUMBER,
1604  p_init_msg_list                IN  VARCHAR2 := FND_API.G_TRUE,
1605  p_commit                       IN  VARCHAR2 := FND_API.G_TRUE,
1606  p_validation_level             IN  NUMBER   := FND_API.G_VALID_LEVEL_FULL,
1607  x_return_status                OUT NOCOPY VARCHAR2,
1608  x_msg_count                    OUT NOCOPY NUMBER,
1609  x_msg_data                     OUT NOCOPY VARCHAR2,
1610  p_deposit_number               IN  VARCHAR2 DEFAULT NULL,
1611  p_customer_trx_id              IN  NUMBER DEFAULT NULL,
1612  p_salesrep_number              IN  VARCHAR2  DEFAULT NULL,
1613  p_salesrep_id                  IN  NUMBER  DEFAULT NULL,
1614  p_non_revenue_amount_split     IN  NUMBER  DEFAULT NULL,
1615  p_non_revenue_percent_split    IN  NUMBER  DEFAULT NULL,
1616  p_attribute_category           IN  VARCHAR2 DEFAULT NULL ,
1617  p_attribute1                   IN  VARCHAR2 DEFAULT NULL ,
1618  p_attribute2                   IN  VARCHAR2 DEFAULT NULL ,
1619  p_attribute3                   IN  VARCHAR2 DEFAULT NULL ,
1620  p_attribute4                   IN  VARCHAR2 DEFAULT NULL ,
1621  p_attribute5                   IN  VARCHAR2 DEFAULT NULL ,
1622  p_attribute6                   IN  VARCHAR2 DEFAULT NULL ,
1623  p_attribute7                   IN  VARCHAR2 DEFAULT NULL ,
1624  p_attribute8                   IN  VARCHAR2 DEFAULT NULL ,
1625  p_attribute9                   IN  VARCHAR2 DEFAULT NULL ,
1626  p_attribute10                  IN  VARCHAR2 DEFAULT NULL ,
1627  p_attribute11                  IN  VARCHAR2 DEFAULT NULL ,
1628  p_attribute12                  IN  VARCHAR2 DEFAULT NULL ,
1629  p_attribute13                  IN  VARCHAR2 DEFAULT NULL ,
1630  p_attribute14                  IN  VARCHAR2 DEFAULT NULL ,
1631  p_attribute15                  IN  VARCHAR2 DEFAULT NULL ,
1632  p_org_id                       IN  NUMBER   DEFAULT NULL )
1633 
1634 IS
1635 
1636 
1637  l_api_name       CONSTANT VARCHAR2(100) := 'insert_non_rev_salescredit';
1638  l_api_version    CONSTANT NUMBER       := 1.0;
1639 
1640  l_deposit_number            ra_customer_trx.trx_number%type;
1641  l_deposit_date           ra_customer_trx.trx_date%type;
1642  l_customer_trx_id           ra_cust_trx_line_salesreps.customer_trx_id%type;
1643  l_salesrep_number             ra_salesreps.salesrep_number%type;
1644  l_salesrep_id               ra_cust_trx_line_salesreps.salesrep_id%type;
1645  l_non_revenue_amount_split  ra_cust_trx_line_salesreps.non_revenue_amount_split%type;
1646  l_non_revenue_percent_split ra_cust_trx_line_salesreps.non_revenue_percent_split%type;
1647  l_desc_flex_rec             ar_deposit_api_pub.attr_rec_type;
1648  l_dflex_val_return_status   varchar2(1000);
1649  l_nosales_val_return_status varchar2(1000);
1650  l_dept_no_return_status     varchar2(1000);
1651  l_sales_val_return_status   varchar2(1000);
1652  l_nonrev_amt_pct_return_status varchar2(1000);
1653  l_dummy_return_status       varchar2(1000);
1654  l_INVOICE_CURRENCY_CODE     ra_customer_trx.INVOICE_CURRENCY_CODE%type;
1655 
1656  l_cust_trx_line_salesrep_id number;
1657  l_customer_trx_line_id      number;
1658  l_status                    varchar2(100);
1659  l_amount                    number;
1660  l_dummy_number              number;
1661  l_org_return_status VARCHAR2(1);
1662  l_org_id                           NUMBER;
1663 BEGIN
1664 
1665 --assignment to local variables
1666 arp_util.debug('AR_DEPOSIT_API_PUB.insert_non_rev_salescredit()+ ');
1667 arp_util.debug('initialize local variable ');
1668 
1669        /*------------------------------------+
1670         |   Standard start of API savepoint  |
1671         +------------------------------------*/
1672 
1673       SAVEPOINT Create_non_rev_sales_PVT;
1674        arp_util.debug('Save point defined and calling compatible API call ');
1675        /*--------------------------------------------------+
1676         |   Standard call to check for call compatibility  |
1677         +--------------------------------------------------*/
1678 
1679         IF NOT FND_API.Compatible_API_Call(
1680                                             l_api_version,
1681                                             p_api_version,
1682                                             l_api_name,
1683                                             G_PKG_NAME
1684                                           )
1685         THEN
1686               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1687         END IF;
1688 
1689        /*--------------------------------------------------------------+
1690         |   Initialize message list if p_init_msg_list is set to TRUE  |
1691         +--------------------------------------------------------------*/
1692 
1693         IF FND_API.to_Boolean( p_init_msg_list )
1694           THEN
1695               FND_MSG_PUB.initialize;
1696         END IF;
1697 
1698 
1699        /*-----------------------------------------+
1700         |   Initialize return status to SUCCESS   |
1701         +-----------------------------------------*/
1702 
1703         x_return_status             := FND_API.G_RET_STS_SUCCESS;
1704         l_dflex_val_return_status   := FND_API.G_RET_STS_SUCCESS;
1705         l_dummy_return_status       := FND_API.G_RET_STS_SUCCESS;
1706         l_sales_val_return_status   := FND_API.G_RET_STS_SUCCESS;
1707         l_nosales_val_return_status := FND_API.G_RET_STS_SUCCESS;
1708         l_nonrev_amt_pct_return_status := FND_API.G_RET_STS_SUCCESS;
1709         l_dept_no_return_status        := FND_API.G_RET_STS_SUCCESS;
1710 
1711 
1712 
1713 
1714 /* SSA change */
1715        l_org_id            := p_org_id;
1716        l_org_return_status := FND_API.G_RET_STS_SUCCESS;
1717        ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
1718                                                 p_return_status =>l_org_return_status);
1719  IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1720        x_return_status := FND_API.G_RET_STS_ERROR;
1721  ELSE
1722 
1723         /*-------------------------------------------------+
1724          | Initialize the profile option package variables |
1725          +-------------------------------------------------*/
1726            arp_util.debug('Before initialize_profile_globals ');
1727            initialize_profile_globals;
1728           arp_util.debug('After initialize_profile_globals');
1729 
1730 
1731        l_amount  := 0;
1732 
1733      If  ( p_deposit_number IS  NULL AND
1734            p_customer_trx_id IS  NULL  ) then
1735 
1736          FND_MESSAGE.SET_NAME('AR','AR_DAPI_DEP_NO_ID_REQ');
1737          FND_MSG_PUB.Add;
1738          l_dept_no_return_status := FND_API.G_RET_STS_ERROR;
1739 
1740     elsif ( p_deposit_number IS  NOT NULL AND
1741            p_customer_trx_id IS  NOT NULL  ) then
1742        begin
1743            SELECT customer_trx_id,INVOICE_CURRENCY_CODE,trx_date
1744            INTO   l_customer_trx_id,l_INVOICE_CURRENCY_CODE,l_deposit_date
1745            FROM    ra_customer_trx
1746            WHERE  customer_trx_id = p_customer_trx_id;
1747 
1748            FND_MESSAGE.SET_NAME('AR','AR_DAPI_DEP_NO_ING');
1749            FND_MSG_PUB.Add;
1750 
1751            SELECT customer_trx_id into l_dummy_number
1752            FROM   ra_customer_trx cust_trx ,
1753                   ra_cust_trx_types cust_trx_type
1754            WHERE  cust_trx.cust_trx_type_id =cust_trx_type.cust_trx_type_id
1755                   and customer_trx_id = l_customer_trx_id
1756                   and cust_trx_type.TYPE = 'DEP';
1757         exception
1758            when no_data_found then
1759                  FND_MESSAGE.SET_NAME('AR','AR_DAPI_DEP_ID_INVALID');
1760                  FND_MSG_PUB.Add;
1761                  l_dept_no_return_status := FND_API.G_RET_STS_ERROR;
1762 
1763         end;
1764     elsif ( p_deposit_number IS  NULL AND
1765            p_customer_trx_id IS  NOT NULL  ) then
1766        begin
1767            SELECT customer_trx_id,INVOICE_CURRENCY_CODE,trx_date
1768            INTO   l_customer_trx_id,l_INVOICE_CURRENCY_CODE,l_deposit_date
1769            FROM    ra_customer_trx
1770            WHERE  customer_trx_id = p_customer_trx_id;
1771 
1772            SELECT customer_trx_id into l_dummy_number
1773            FROM   ra_customer_trx cust_trx ,
1774                   ra_cust_trx_types cust_trx_type
1775            WHERE  cust_trx.cust_trx_type_id =cust_trx_type.cust_trx_type_id
1776                   and customer_trx_id = l_customer_trx_id and
1777                    cust_trx_type.TYPE = 'DEP';
1778         exception
1779            when no_data_found then
1780                  FND_MESSAGE.SET_NAME('AR','AR_DAPI_DEP_ID_INVALID');
1781                  FND_MSG_PUB.Add;
1782                  l_dept_no_return_status := FND_API.G_RET_STS_ERROR;
1783 
1784         end;
1785       elsif ( p_deposit_number IS  NOT NULL AND
1786             p_customer_trx_id IS   NULL  ) then
1787        begin
1788            SELECT customer_trx_id,INVOICE_CURRENCY_CODE,trx_date
1789            INTO   l_customer_trx_id,l_INVOICE_CURRENCY_CODE,l_deposit_date
1790            FROM    ra_customer_trx
1791            WHERE  trx_number = p_deposit_number;
1792 
1793            SELECT customer_trx_id into l_dummy_number
1794            FROM   ra_customer_trx cust_trx ,
1795                   ra_cust_trx_types cust_trx_type
1796            WHERE  cust_trx.cust_trx_type_id =cust_trx_type.cust_trx_type_id
1797                   and customer_trx_id = l_customer_trx_id and
1798                    cust_trx_type.TYPE = 'DEP';
1799         exception
1800            when no_data_found then
1801                  FND_MESSAGE.SET_NAME('AR','AR_DAPI_DEP_NO_INVALID');
1802                  FND_MSG_PUB.Add;
1803                  l_dept_no_return_status := FND_API.G_RET_STS_ERROR;
1804 
1805         end;
1806     end if;
1807 
1808     if l_dept_no_return_status  =  FND_API.G_RET_STS_SUCCESS THEN
1809      begin
1810        select sum(EXTENDED_AMOUNT)
1811        into l_amount
1812        from ra_customer_trx_lines
1813        where customer_trx_id = l_customer_trx_id;
1814      end;
1815     end if;
1816 
1817     if l_dept_no_return_status  =  FND_API.G_RET_STS_SUCCESS THEN
1818      begin
1819        select customer_trx_line_id
1820        into l_customer_trx_line_id
1821        from ra_customer_trx_lines
1822        where customer_trx_id = l_customer_trx_id; --only line per deposit
1823      exception when others  then raise;
1824      end;
1825     end if;
1826     if ( p_salesrep_id IS  NULL AND
1827          p_salesrep_number IS  NULL  ) then
1828 
1829          FND_MESSAGE.SET_NAME('AR','AR_DAPI_SALESREP_NO_ID_NAME');
1830          FND_MSG_PUB.Add;
1831          l_nosales_val_return_status := FND_API.G_RET_STS_ERROR;
1832 
1833     end if;
1834 
1835 
1836 
1837        IF   p_salesrep_id IS  NULL AND
1838             p_salesrep_number IS NOT NULL
1839        THEN
1840 
1841         begin
1842           SELECT salesrep_id
1843           INTO   l_salesrep_id
1844           FROM   ra_salesreps
1845           WHERE  SALESREP_NUMBER = p_salesrep_number and
1846                  NVL(status,'A') ='A' and
1847                  l_deposit_date between nvl(start_date_active, l_deposit_date) and
1848                                         nvl(end_date_active, l_deposit_date);
1849 
1850 
1851         exception
1852            when no_data_found then
1853                  FND_MESSAGE.SET_NAME('AR','AR_DAPI_SALESREP_NAME_INVALID');
1854                   FND_MSG_PUB.Add;
1855                   l_sales_val_return_status := FND_API.G_RET_STS_ERROR;
1856 
1857         end;
1858        ELSIF (p_salesrep_id IS  NOT NULL) THEN
1859 
1860         begin
1861           SELECT salesrep_id
1862           INTO   l_salesrep_id
1863           FROM   ra_salesreps
1864           WHERE  salesrep_id = p_salesrep_id and
1865                  NVL(status,'A') ='A' and
1866                  l_deposit_date between nvl(start_date_active, l_deposit_date) and
1867                                         nvl(end_date_active, l_deposit_date);
1868 
1869 
1870         exception
1871            when no_data_found then
1872                  FND_MESSAGE.SET_NAME('AR','AR_DAPI_SALESREP_ID_INVALID');
1873                  FND_MSG_PUB.Add;
1874                  l_sales_val_return_status := FND_API.G_RET_STS_ERROR;
1875 
1876         end;
1877        END IF;
1878 if l_sales_val_return_status =  FND_API.G_RET_STS_SUCCESS  and
1879    l_dept_no_return_status   =  FND_API.G_RET_STS_SUCCESS THEN
1880 
1881    If  ( p_non_revenue_amount_split IS  NULL AND
1882          p_non_revenue_percent_split IS  NULL  ) then
1883 
1884          FND_MESSAGE.SET_NAME('AR','AR_DAPI_NON_REV_AMT_PCT');
1885          FND_MSG_PUB.Add;
1886          l_nonrev_amt_pct_return_status := FND_API.G_RET_STS_ERROR;
1887     elsif ( p_non_revenue_amount_split IS  NOT NULL AND
1888             p_non_revenue_percent_split IS  NULL  ) then
1889       l_non_revenue_amount_split  := p_non_revenue_amount_split;
1890       l_non_revenue_percent_split := ROUND(p_non_revenue_amount_split /l_amount,4 )*100;
1891    elsif ( p_non_revenue_amount_split IS   NULL AND
1892             p_non_revenue_percent_split IS  NOT NULL  ) then
1893       l_non_revenue_percent_split  := p_non_revenue_percent_split ;
1894       l_non_revenue_amount_split   := CurrRound(
1895                                         ( l_non_revenue_percent_split / 100 ) * l_amount ,l_INVOICE_CURRENCY_CODE);
1896    elsif ( p_non_revenue_amount_split IS   NOT NULL AND
1897             p_non_revenue_percent_split IS  NOT NULL  ) then
1898       l_non_revenue_percent_split  := p_non_revenue_percent_split ;
1899       l_non_revenue_amount_split   := CurrRound(
1900                                         ( l_non_revenue_percent_split / 100 ) * l_amount,l_INVOICE_CURRENCY_CODE );
1901 
1902        FND_MESSAGE.SET_NAME('AR','AR_DAPI_REV_AMT_IGN');
1903        FND_MSG_PUB.Add;
1904     end if;
1905 
1906       l_desc_flex_rec.attribute_category := p_attribute_category;
1907       l_desc_flex_rec.attribute1 := p_attribute1;
1908       l_desc_flex_rec.attribute2 := p_attribute2;
1909       l_desc_flex_rec.attribute3 := p_attribute3;
1910       l_desc_flex_rec.attribute4 := p_attribute4;
1911       l_desc_flex_rec.attribute5 := p_attribute5;
1912       l_desc_flex_rec.attribute6 := p_attribute6;
1913       l_desc_flex_rec.attribute7 := p_attribute7;
1914       l_desc_flex_rec.attribute8 := p_attribute8;
1915       l_desc_flex_rec.attribute9 := p_attribute9;
1916       l_desc_flex_rec.attribute10 := p_attribute10;
1917       l_desc_flex_rec.attribute11 := p_attribute11;
1918       l_desc_flex_rec.attribute12 := p_attribute12;
1919       l_desc_flex_rec.attribute13 := p_attribute13;
1920       l_desc_flex_rec.attribute14 := p_attribute14;
1921       l_desc_flex_rec.attribute15 := p_attribute15;
1922 /*-----------------------------------------------------------------------------+
1923 |  Validating Descriptive Flex Fields 					     |
1924 +-----------------------------------------------------------------------------*/
1925 
1926          ar_deposit_lib_pvt.Validate_Desc_Flexfield(
1927                                             l_desc_flex_rec,
1928                                             'RA_CUST_TRX_LINE_SALESREPS',
1929                                             l_dflex_val_return_status
1930                                             );
1931 
1932 
1933  END IF;
1934 END IF;
1935       IF  l_dflex_val_return_status   <> FND_API.G_RET_STS_SUCCESS OR
1936           l_sales_val_return_status   <> FND_API.G_RET_STS_SUCCESS OR
1937           l_nosales_val_return_status <> FND_API.G_RET_STS_SUCCESS OR
1938           l_nonrev_amt_pct_return_status <> FND_API.G_RET_STS_SUCCESS OR
1939           l_dept_no_return_status  <> FND_API.G_RET_STS_SUCCESS
1940       THEN
1941             x_return_status := FND_API.G_RET_STS_ERROR;
1942       END IF;
1943 
1944  IF (  x_return_status  <> FND_API.G_RET_STS_SUCCESS  )  THEN
1945            ROLLBACK TO Create_non_rev_sales_PVT;
1946        /*-------------------------------------------------------+
1947         | FND_MSG_PUB.Count_And_Get used  get the count of mesg.|
1948         | in the message stack. If there is only one message in |
1949         | the stack it retrieves this message                   |
1950         +-------------------------------------------------------*/
1951               x_return_status := FND_API.G_RET_STS_ERROR ;
1952 
1953               FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
1954                                         p_count => x_msg_count,
1955                                         p_data  => x_msg_data);
1956 
1957              arp_util.debug('Error(s) occurred.
1958                              Rolling back and setting status to ERROR');
1959 
1960              Return;
1961  END IF;
1962 
1963  arp_util.debug('x_return_status '||x_return_status);
1964 
1965       BEGIN
1966       arp_process_salescredit.insert_salescredit_cover(
1967                              l_api_name,
1968                              l_api_version,
1969                              FALSE, --l_rerun_autoaccounting_flag,
1970                              l_customer_trx_id , -- ak1 art_context.pg_customer_trx_id,
1971                              l_customer_trx_line_id, -- derive based on p_customer_trx_id
1972                              l_salesrep_id , -- ak2 Name_In('tscr_lines.salesrep_id'),
1973                              null, -- l_revenue_amount_split,
1974                              l_non_revenue_amount_split, --ak3 l_non_revenue_amount_split,
1975                              l_non_revenue_percent_split, --ak4 Name_In('tscr_lines.non_revenue_percent_split'),
1976                              null, --Name_In('tscr_lines.revenue_percent_split'),
1977                              null, --Name_In('tscr_lines.prev_cust_trx_line_salesrep_id'),
1978                              l_desc_flex_rec.attribute_category ,
1979                              l_desc_flex_rec.attribute1,
1980                              l_desc_flex_rec.attribute2,
1981                              l_desc_flex_rec.attribute3,
1982                              l_desc_flex_rec.attribute4,
1983                              l_desc_flex_rec.attribute5,
1984                              l_desc_flex_rec.attribute6,
1985                              l_desc_flex_rec.attribute7,
1986                              l_desc_flex_rec.attribute8,
1987                              l_desc_flex_rec.attribute9,
1988                              l_desc_flex_rec.attribute10,
1989                              l_desc_flex_rec.attribute11,
1990                              l_desc_flex_rec.attribute12,
1991                              l_desc_flex_rec.attribute13,
1992                              l_desc_flex_rec.attribute14,
1993                              l_desc_flex_rec.attribute15,
1994                              l_cust_trx_line_salesrep_id,
1995                              l_status );
1996        IF ( l_status <> 'OK' )
1997        THEN
1998            FND_MESSAGE.SET_NAME('AR','AR_DAPI_SALESREP_ST');
1999            FND_MESSAGE.RAISE_ERROR;
2000 
2001 
2002        END IF;
2003 
2004     EXCEPTION
2005             WHEN Others THEN
2006              FND_MESSAGE.SET_NAME('AR','AR_DAPI_SALESREP_ST');
2007              FND_MSG_PUB.Add;
2008              FND_MESSAGE.SET_NAME('AR', 'GENERIC_MESSAGE');
2009              FND_MESSAGE.SET_TOKEN('GENERIC_TEXT',SQLERRM);
2010              FND_MSG_PUB.Add;
2011              x_return_status := FND_API.G_RET_STS_ERROR ;
2012              ROLLBACK TO Create_non_rev_sales_PVT;
2013              FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
2014                                        p_count => x_msg_count,
2015                                        p_data  => x_msg_data);
2016              return;
2017     END;
2018 
2019        /*--------------------------------+
2020         |   Standard check of p_commit   |
2021         +--------------------------------*/
2022 
2023         IF FND_API.To_Boolean( p_commit )
2024         THEN
2025             arp_util.debug('committing');
2026             Commit;
2027         END IF;
2028 
2029 arp_util.debug('AR_DEPOSIT_API_PUB.insert_non_rev_salescredit()- ');
2030 
2031 END insert_non_rev_salescredit;
2032 
2033 
2034 /*========================================================================
2035  |  PROCEDURE set_profile_for_testing
2036  |
2037  | DESCRIPTION
2038  |      Enter a brief description of what the package procedure does.
2039  |      ----------------------------------------
2040  |      This procedure does the following: Set the value of profile options
2041  |
2042  | CALLED FROM PROCEDURES/FUNCTIONS (local to this package body)
2043  |      Enter a list of all local procedures and functions which
2044  |      are call this package.
2045  |
2046  |
2047  | CALLS PROCEDURES/FUNCTIONS (local to this package body)
2048  |      Enter a list of all local procedures and funtions which
2049  |      this package calls.
2050  |      fnd_profile.value
2051  |
2052  | PARAMETERS
2053  |
2054  |          None
2055  |
2056  | KNOWN ISSUES
2057  |
2058  | NOTES
2059  |
2060  | MODIFICATION HISTORY
2061  | Date                  Author            Description of Changes
2062  | 21-MAY-2001           Anuj              Created
2063  | DD-MON-YYYY           Name              Bug #####, modified amount ..
2064  |
2065  *=======================================================================*/
2066 
2067 PROCEDURE set_profile_for_testing(p_profile_batch_source      NUMBER,
2068                                   p_profile_doc_seq           VARCHAR2,
2069                                   p_profile_trxln_excpt       VARCHAR2,
2070                                   p_profile_enable_cc         VARCHAR2,
2071                                   p_profile_cc_rate_type      VARCHAR2,
2072 
2073                                   p_profile_dsp_inv_rate      VARCHAR2,
2074                                   p_profile_def_x_rate_type   VARCHAR2
2075                                   ) IS
2076 BEGIN
2077   arp_util.debug('AR_DEPOSIT_API_PUB.set_profile_for_testing()+ ');
2078 
2079   ar_deposit_lib_pvt.pg_profile_batch_source       := p_profile_batch_source;
2080   ar_deposit_lib_pvt.pg_profile_doc_seq            := p_profile_doc_seq;
2081   ar_deposit_lib_pvt.pg_profile_trxln_excpt_flag   := p_profile_trxln_excpt;
2082   ar_deposit_lib_pvt.pg_profile_enable_cc          := p_profile_enable_cc;
2083   ar_deposit_lib_pvt.pg_profile_cc_rate_type       := p_profile_cc_rate_type;
2084   ar_deposit_lib_pvt.pg_profile_dsp_inv_rate       := p_profile_dsp_inv_rate;
2085   ar_deposit_lib_pvt.pg_profile_def_x_rate_type    := p_profile_def_x_rate_type;
2086 
2087   arp_util.debug('AR_DEPOSIT_API_PUB.set_profile_for_testing()- ');
2088 
2089 END set_profile_for_testing;
2090 
2091 
2092 /*========================================================================
2093  |  PROCEDURE create_trxn_extension
2094  |
2095  | DESCRIPTION
2096  |      Enter a brief description of what the package procedure does.
2097  |      ----------------------------------------
2098  |      This procedure does the following: updates pmt_trx_extn
2099  |
2100  | CALLED FROM PROCEDURES/FUNCTIONS (local to this package body)
2101  |      Enter a list of all local procedures and functions which
2102  |      are call this package.
2103  |
2104  |
2105  | CALLS PROCEDURES/FUNCTIONS (local to this package body)
2106  |      Enter a list of all local procedures and funtions which
2107  |      this package calls.
2108  |      fnd_profile.value
2109  |
2110  | PARAMETERS
2111  |
2112  |          None
2113  |
2114  | KNOWN ISSUES
2115  |
2116  | NOTES
2117  |
2118  | MODIFICATION HISTORY
2119  | Date                  Author            Description of Changes
2120  | 26-sep-2005           bichatte           created
2121  |
2122  *=======================================================================*/
2123 
2124   PROCEDURE copy_trxn_extension( p_customer_trx_id  IN  NUMBER,
2125                                p_payment_trxn_extension_id IN NUMBER,
2126                                p_return_status  OUT NOCOPY VARCHAR2 ) IS
2127 
2128 
2129              l_payer_rec                     IBY_FNDCPT_COMMON_PUB.PayerContext_rec_type;
2130              l_cpy_msg_data                  VARCHAR2(2000);
2131              l_trxn_attribs_rec              IBY_FNDCPT_TRXN_PUB.TrxnExtension_rec_type;
2132              p_trxn_entity_id                RA_CUSTOMER_TRX.PAYMENT_TRXN_EXTENSION_ID%TYPE;
2133              l_response_rec                  IBY_FNDCPT_COMMON_PUB.Result_rec_type;
2134              l_pmt_trxn_extension_id          IBY_FNDCPT_COMMON_PUB.Id_tbl_type;
2135              o_payment_trxn_extension_id         RA_CUSTOMER_TRX.PAYMENT_TRXN_EXTENSION_ID%TYPE;
2136 
2137              l_return_status VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2138              l_assignment_id                 NUMBER;
2139 
2140              l_msg_count                     NUMBER;
2141              l_msg_data                      VARCHAR2(2000);
2142 
2143 
2144             l_payment_channel       ar_receipt_methods.payment_channel_code%type;
2145             l_customer_id           ra_customer_trx.paying_customer_id%type;
2146             l_customer_site_use_id  ra_customer_trx.paying_site_use_id%type;
2147             l_org_id                ra_customer_trx.org_id%type;
2148             l_trx_number            ra_customer_trx.trx_number%type;
2149             l_customer_trx_id       ra_customer_trx.customer_trx_id%type;
2150             l_party_id              hz_parties.party_id%type;
2151 
2152 
2153     BEGIN
2154 
2155 arp_util.debug('AR_DEPOSIT_API_PUB.create_trxn_extension()'|| SQLERRM);
2156 arp_util.debug('customer_trx_id'|| p_customer_trx_id);
2157 arp_util.debug('payment_trxn_extension_id'|| p_payment_trxn_extension_id);
2158 
2159 
2160 
2161 
2162    IF p_payment_trxn_extension_id is NOT NULL THEN
2163 
2164              select trx.paying_customer_id,
2165                     trx.paying_site_use_id,
2166                     trx.org_id,
2167                     party.party_id,
2168                     trx.trx_number,
2169                     rm.payment_channel_code,
2170                     trx.customer_trx_id
2171              into   l_customer_id,
2172                     l_customer_site_use_id,
2173                     l_org_id,
2174                     l_party_id,
2175                     l_trx_number,
2176                     l_payment_channel,
2177                     l_customer_trx_id
2178              FROM   hz_cust_accounts hca,
2179                     hz_parties    party,
2180                     ra_customer_trx trx,
2181                     ar_receipt_methods rm
2182              WHERE  trx.customer_trx_id = p_customer_trx_id
2183              AND    hca.party_id = party.party_id
2184              AND    hca.cust_account_id = trx.paying_customer_id
2185              AND    trx.receipt_method_id = rm.receipt_method_id(+) ;
2186 
2187 
2188 
2189      SELECT INSTR_ASSIGNMENT_ID
2190      INTO  l_assignment_id
2191      from  iby_fndcpt_tx_extensions
2192      where trxn_extension_id = p_payment_trxn_extension_id;
2193 
2194 
2195 
2196 arp_util.debug('AR_DEPOSIT_API_PUB.create_trxn_extension()'|| SQLERRM);
2197 arp_util.debug('customer_trx_id'|| p_customer_trx_id);
2198 
2199 
2200      /* pouplate values into the variables */
2201 
2202         l_payer_rec.Payment_Function := 'CUSTOMER_PAYMENT';
2203         l_payer_rec.Party_Id :=  l_party_id;                  -- receipt customer party id mandatory
2204         l_payer_rec.org_id   := l_org_id;
2205         l_payer_rec.org_type := 'OPERATING_UNIT';
2206         l_payer_rec.Cust_Account_Id :=l_customer_id ;         -- receipt customer account_id
2207         l_payer_rec.Account_Site_Id :=l_customer_site_use_id; -- receipt customer site_id
2208 
2209         if l_customer_site_use_id is NULL  THEN
2210 
2211           l_payer_rec.org_id := NULL;
2212           l_payer_rec.org_type := NULL;
2213 
2214         end if;
2215 
2216         l_trxn_attribs_rec.Originating_Application_Id := arp_standard.application_id;
2217         l_trxn_attribs_rec.order_id :=  l_trx_number;
2218         l_trxn_attribs_rec.Trxn_Ref_Number1 := 'TRANSACTION';
2219         l_trxn_attribs_rec.Trxn_Ref_Number2 := l_customer_trx_id;
2220         l_assignment_id := l_assignment_id;
2221 
2222 
2223         l_pmt_trxn_extension_id(1) := p_payment_trxn_extension_id;
2224 
2225 
2226 
2227              IBY_FNDCPT_TRXN_PUB.Copy_Transaction_Extension
2228                      ( p_api_version        => 1.0,
2229                        p_init_msg_list      => FND_API.G_TRUE,
2230                        p_commit             => FND_API.G_FALSE,
2231                        x_return_status      => l_return_status,
2232                        x_msg_count          => l_msg_count,
2233                        x_msg_data           => l_msg_data,
2234                        p_payer              => l_payer_rec,
2235                        p_payer_equivalency  => IBY_FNDCPT_COMMON_PUB.G_PAYER_EQUIV_UPWARD,
2236                        p_entities           => l_pmt_trxn_extension_id,
2237                        p_trxn_attribs       => l_trxn_attribs_rec,
2238                        x_entity_id          => p_trxn_entity_id,          -- out parm
2239                        x_response           => l_response_rec             -- out
2240                       );
2241 
2242 
2243                 IF l_return_status = FND_API.G_RET_STS_SUCCESS  THEN
2244 
2245                          o_payment_trxn_extension_id  := p_trxn_entity_id ;
2246 
2247                      arp_standard.debug('the copied value of trx_entn is ' || o_payment_trxn_extension_id );
2248 
2249 
2250                         update ra_customer_trx
2251                         set payment_trxn_extension_id = o_payment_trxn_extension_id
2252                         where customer_trx_id = p_customer_trx_id ;
2253 
2254 
2255                  END IF;
2256 
2257            IF l_return_status <> FND_API.G_RET_STS_SUCCESS  THEN
2258 
2259                    arp_util.debug('FAILED: ' ||l_response_rec.result_code,0);
2260 
2261                 p_return_status := FND_API.G_RET_STS_ERROR ;
2262 
2263            END IF;
2264 
2265 
2266   END IF ; /* payment_trxn_extension_id is not null */
2267 
2268      arp_util.debug('AR_DEPOSIT_API_PUB.create_trxn_extension()'|| SQLERRM);
2269      EXCEPTION
2270         WHEN OTHERS THEN
2271                 p_return_status := FND_API.G_RET_STS_ERROR ;
2272 
2273 arp_util.debug('AR_DEPOSIT_API_PUB.create_trxn_extension()'|| SQLERRM);
2274 END copy_trxn_extension;
2275 
2276 
2277 
2278 
2279 
2280 
2281 
2282 
2283 
2284 BEGIN
2285 
2286    ar_deposit_lib_pvt.pg_profile_batch_source := FND_API.G_MISS_NUM;
2287    ar_deposit_lib_pvt.pg_profile_doc_seq := FND_API.G_MISS_CHAR;
2288    ar_deposit_lib_pvt.pg_profile_trxln_excpt_flag := FND_API.G_MISS_CHAR;
2289    ar_deposit_lib_pvt.pg_profile_enable_cc := FND_API.G_MISS_CHAR;
2290    ar_deposit_lib_pvt.pg_profile_cc_rate_type := FND_API.G_MISS_CHAR;
2291    ar_deposit_lib_pvt.pg_profile_dsp_inv_rate := FND_API.G_MISS_CHAR;
2292    ar_deposit_lib_pvt.pg_profile_def_x_rate_type := FND_API.G_MISS_CHAR;
2293 
2294 
2295 END AR_DEPOSIT_API_PUB;