Sei sulla pagina 1di 49

CREATE OR REPLACE PACKAGE BODY APPS.

cust_adi_customer_v3_pkg IS
PROCEDURE cust_vaildate_upload_data(p_validate_or_process_entry VARCHAR2,
---Validation---(1.54)
p_receivables_responsibility VARCHAR2,
---Validation---(1.52)
p_oracle_user_name VARCHAR2,
---Validation---(1.53)
p_new_or_existing_cust VARCHAR2,
---Validation---(1.13)
p_cust_no_if_exists VARCHAR2,
---Validation---(1.14, 1.15)
p_ou_name VARCHAR2,
---Party Level Field--- ---Validation---(1.1)
p_organization_name VARCHAR2,
---Party Level Field--- ---Validation---(1.11)
p_principal_name VARCHAR2,
---Party Level Field---
p_organization_name_phonetic VARCHAR2,
---Party Level Field---
p_tax_reference VARCHAR2,
---Party Level Field---
p_jgzz_fiscal_code VARCHAR2,
---Party Level Field---
p_known_as VARCHAR2,
---Party Level Field---
p_internal_flag VARCHAR2,
---Party Level Field--- ---Validation---(1.2)
p_customer_attribute_category VARCHAR2,
---Party Level Field---
p_customer_attribute1 VARCHAR2,
---Party Level Field---
p_customer_attribute2 VARCHAR2,
---Party Level Field---
p_customer_attribute3 VARCHAR2,
---Party Level Field---
p_customer_attribute4 VARCHAR2,
---Party Level Field---
p_customer_attribute5 VARCHAR2,
---Party Level Field---
p_customer_attribute6 VARCHAR2,
---Party Level Field---
p_customer_attribute7 VARCHAR2,
---Party Level Field---
p_customer_attribute8 VARCHAR2,
---Party Level Field---
p_customer_attribute9 VARCHAR2,
---Party Level Field---
p_customer_attribute10 VARCHAR2,
---Party Level Field---
p_customer_attribute11 VARCHAR2,
---Party Level Field---
p_customer_attribute12 VARCHAR2,
---Party Level Field---
p_customer_attribute13 VARCHAR2,
---Party Level Field---
p_customer_attribute14 VARCHAR2,
---Party Level Field---
p_customer_attribute15 VARCHAR2,
---Party Level Field---
p_new_or_existing_account VARCHAR2,
---Validation---(1.16, 1.17)
p_account_no_if_exists VARCHAR2,
---Validation---(1.18, 1.19, 1.20)
p_account_name VARCHAR2,
---Account Level Field--- ---Validation---(1.12)
p_customer_class_code VARCHAR2,
---Account Level Field--- ---Validation---(1.3)
p_account_price_list_name VARCHAR2,
---Account Level Field--- ---Validation---(1.6)
p_account_tax_code_name VARCHAR2,
---Account Level Field--- ---Validation---(1.7)
p_account_tax_name VARCHAR2,
---Account Level Field--- ---Validation---(1.7)
p_account_tax_regime_name VARCHAR2,
---Account Level Field--- ---Validation---(1.7)
p_account_freight_term VARCHAR2,
---Account Level Field--- ---Validation---(1.8)
p_ship_partial VARCHAR2,
---Account Level Field--- ---Validation---(1.2)
p_account_warehouse_name VARCHAR2,
---Account Level Field--- ---Validation---(1.9)
p_over_shipment_tol VARCHAR2,
---Account Level Field--- ---Validation---(1.10)
p_under_shipment_tol VARCHAR2,
---Account Level Field--- ---Validation---(1.10)
p_over_return_tol VARCHAR2,
---Account Level Field--- ---Validation---(1.10)
p_under_return_tol VARCHAR2,
---Account Level Field--- ---Validation---(1.10)
p_account_attribute_category VARCHAR2,
---Account Level Field---
p_account_attribute1 VARCHAR2,
---Account Level Field---
p_account_attribute2 VARCHAR2,
---Account Level Field---
p_account_attribute3 VARCHAR2,
---Account Level Field---
p_account_attribute4 VARCHAR2,
---Account Level Field---
p_account_attribute5 VARCHAR2,
---Account Level Field---
p_account_attribute6 VARCHAR2,
---Account Level Field---
p_account_attribute7 VARCHAR2,
---Account Level Field---
p_account_attribute8 VARCHAR2,
---Account Level Field---
p_account_attribute9 VARCHAR2,
---Account Level Field---
p_account_attribute10 VARCHAR2,
---Account Level Field---
p_account_attribute11 VARCHAR2,
---Account Level Field---
p_account_attribute12 VARCHAR2,
---Account Level Field---
p_account_attribute13 VARCHAR2,
---Account Level Field---
p_account_attribute14 VARCHAR2,
---Account Level Field---
p_account_attribute15 VARCHAR2,
---Account Level Field---
p_acc_prof_credit_checking VARCHAR2,
---Account Profile Level Field--- ---Validation---(1.2, 1.57, 1.60)
p_acc_prof_currency_code VARCHAR2,
---Account Profile Amount Level Field--- ---Validation---(1.55)
p_acc_prof_trx_credit_limit VARCHAR2,
---Account Profile Amount Level Field--- ---Validation---(1.10)
p_acc_prof_overal_credit_limit VARCHAR2,
---Account Profile Amount Level Field--- ---Validation---(1.10)
p_country VARCHAR2,
---Location Level Field--- ---Validation---(1.21)
p_address1 VARCHAR2,
---Location Level Field--- ---Validation---(1.24)
p_address2 VARCHAR2,
---Location Level Field---
p_address3 VARCHAR2,
---Location Level Field---
p_city VARCHAR2,
---Location Level Field---
p_postal_code VARCHAR2,
---Location Level Field---
p_state VARCHAR2,
---Location Level Field---
p_province VARCHAR2,
---Location Level Field---
p_county VARCHAR2,
---Location Level Field---
p_loc_attribute_category VARCHAR2,
---Location Level Field---
p_loc_attribute1 VARCHAR2,
---Location Level Field---
p_loc_attribute2 VARCHAR2,
---Location Level Field---
p_loc_attribute3 VARCHAR2,
---Location Level Field---
p_loc_attribute4 VARCHAR2,
---Location Level Field---
p_loc_attribute5 VARCHAR2,
---Location Level Field---
p_loc_attribute6 VARCHAR2,
---Location Level Field---
p_loc_attribute7 VARCHAR2,
---Location Level Field---
p_loc_attribute8 VARCHAR2,
---Location Level Field---
p_loc_attribute9 VARCHAR2,
---Location Level Field---
p_loc_attribute10 VARCHAR2,
---Location Level Field---
p_new_or_existing_site VARCHAR2,
---Validation---(1.22, 1.23)
p_site_no_if_exists VARCHAR2,
---Validation---(1.27, 1.28)
p_site_customer_category_code VARCHAR2,
---Account Site Level Field--- ---Validation---(1.25)
p_site_territory VARCHAR2,
---Account Site Level Field--- ---Validation---(1.26)
p_site_attribute_category VARCHAR2,
---Account Site Level Field---
p_site_attribute1 VARCHAR2,
---Account Site Level Field---
p_site_attribute2 VARCHAR2,
---Account Site Level Field---
p_site_attribute3 VARCHAR2,
---Account Site Level Field---
p_site_attribute4 VARCHAR2,
---Account Site Level Field---
p_site_attribute5 VARCHAR2,
---Account Site Level Field---
p_site_attribute6 VARCHAR2,
---Account Site Level Field---
p_site_attribute7 VARCHAR2,
---Account Site Level Field---
p_site_attribute8 VARCHAR2,
---Account Site Level Field---
p_site_attribute9 VARCHAR2,
---Account Site Level Field---
p_site_attribute10 VARCHAR2,
---Account Site Level Field---
p_site_use_site_use_code VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.29)
p_bill_to_site_use_id VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.49)
p_site_use_primary_flag VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.2)
p_site_use_payment_term_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.30)
p_site_use_ship_partial VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.2)
p_site_use_ship_via VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.51)
p_site_use_fob_point VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.47)
p_site_use_order_type_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.31)
p_site_use_price_list_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.32)
p_site_use_freight_term VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.33)
p_site_use_warehouse_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.34)
p_site_use_territory_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.35)
p_site_use_attribute_category VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute1 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute2 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute3 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute4 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute5 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute6 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute7 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute8 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute9 VARCHAR2,
---Account Site Use Level Field---
p_site_use_attribute10 VARCHAR2,
---Account Site Use Level Field---
p_site_use_tax_code_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.45)
p_site_use_tax_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.45)
p_site_use_tax_regime_name VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.45)
p_site_use_primary_salesrep_no VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.46)
p_site_use_over_shipment_tol VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.10)
p_site_use_under_shipment_tol VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.10)
p_site_use_over_return_tol VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.10)
p_site_use_under_return_tol VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.10)
p_site_use_shipset_inc_ln_flag VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.2)
p_site_use_pricing_event VARCHAR2,
---Account Site Use Level Field--- ---Validation---()
p_site_use_gl_code_rec VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.36, 1.50)
p_site_use_gl_code_rev VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.37, 1.50)
p_site_use_gl_code_tax VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.38, 1.50)
p_site_use_gl_code_freight VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.39, 1.50)
p_site_use_gl_code_clearing VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.40, 1.50)
p_site_use_gl_code_unbilled VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.41, 1.50)
p_site_use_gl_code_unearned VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.42, 1.50)
p_site_use_gl_code_unpaid_rec VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.43, 1.50)
p_site_use_gl_code_remittance VARCHAR2,
---Account Site Use Level Field--- ---Validation---(1.44, 1.50)
p_site_prof_credit_checking VARCHAR2,
---Site Profile Level Field--- ---Validation---(1.2, 1.58, 1.59, 1.61)
p_site_prof_currency_code VARCHAR2,
---Site Profile Amount Level Field--- ---Validation---(1.56)
p_site_prof_trx_credit_limit VARCHAR2,
---Site Profile Amount Level Field--- ---Validation---(1.10)
p_site_prof_overal_credit_limt VARCHAR2
---Site Profile Amount Level Field--- ---Validation---(1.10)
) IS

l_error_message VARCHAR2(3000);
l_error_code VARCHAR2(3000);
l_rec_resp_id NUMBER;
l_resp_application_id NUMBER;
l_user_id NUMBER;
l_org_id NUMBER;
l_organization_name VARCHAR2(3000);
l_cust_no_party_name VARCHAR2(3000);
l_account_no_acc_name VARCHAR2(3000);
l_account_no_party_num VARCHAR2(3000);
l_account_name VARCHAR2(3000);
l_customer_class_code VARCHAR2(200);
l_account_price_list_id NUMBER;
l_account_freight_term VARCHAR2(200);
l_account_tax_code VARCHAR2(200);
l_account_warehouse_id NUMBER;
l_numeric_validation VARCHAR2(200);
l_flag_validation VARCHAR2(200);
l_country VARCHAR2(200);
l_site_customer_category_code VARCHAR2(200);
l_site_territory_id NUMBER;
l_site_no_account_no VARCHAR2(200);
l_site_use_payment_term_id NUMBER;
l_site_use_order_type_id NUMBER;
l_site_use_price_list_id NUMBER;
l_site_use_freight_term VARCHAR2(200);
l_site_use_warehouse_id NUMBER;
l_site_use_territory_id NUMBER;
l_site_use_gl_id_rec NUMBER;
l_site_use_gl_id_rev NUMBER;
l_site_use_gl_id_tax NUMBER;
l_site_use_gl_id_freight NUMBER;
l_site_use_gl_id_clearing NUMBER;
l_site_use_gl_id_unbilled NUMBER;
l_site_use_gl_id_unearned NUMBER;
l_site_use_gl_id_unpaid_rec NUMBER;
l_site_use_gl_id_remittance NUMBER;
l_site_use_tax_code VARCHAR2(200);
l_site_use_primary_salesrep_id VARCHAR2(200);
l_site_use_fob_point VARCHAR2(200);
l_gl_ids_validation VARCHAR2(1000);
l_site_use_ship_via VARCHAR2(500);
l_acc_prof_currency_code VARCHAR2(100);
l_site_prof_currency_code VARCHAR2(100);
l_cust_newaccount_profile_id NUMBER;
p_cust_account_rec HZ_CUST_ACCOUNT_V2PUB.CUST_ACCOUNT_REC_TYPE;
p_organization_rec HZ_PARTY_V2PUB.ORGANIZATION_REC_TYPE;
p_customer_profile_rec
HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
p_customer_site_profile_rec
HZ_CUSTOMER_PROFILE_V2PUB.CUSTOMER_PROFILE_REC_TYPE;
p_location_rec HZ_LOCATION_V2PUB.LOCATION_REC_TYPE;
p_party_site_rec HZ_PARTY_SITE_V2PUB.PARTY_SITE_REC_TYPE;
p_cust_acct_site_rec
hz_cust_account_site_v2pub.cust_acct_site_rec_type;
p_cust_site_use_rec
HZ_CUST_ACCOUNT_SITE_V2PUB.CUST_SITE_USE_REC_TYPE;
p_cust_prof_amt_rec
HZ_CUSTOMER_PROFILE_V2PUB.CUST_PROFILE_AMT_REC_TYPE;
p_cust_site_prof_amt_rec
HZ_CUSTOMER_PROFILE_V2PUB.CUST_PROFILE_AMT_REC_TYPE;
x_site_use_id NUMBER;
x_cust_acct_site_id NUMBER;
x_party_site_id NUMBER;
x_party_site_number VARCHAR2(2000);
x_location_id NUMBER;
x_cust_account_id NUMBER;
x_account_number VARCHAR2(2000);
x_party_id NUMBER;
x_party_number VARCHAR2(2000);
x_profile_id NUMBER;
x_cust_acc_site_profile_id NUMBER;
x_cust_acct_profile_amt_id NUMBER;
x_return_status VARCHAR2(2000);
x_msg_count NUMBER;
x_msg_data VARCHAR2(2000);

BEGIN

-------------------------------------------------------------
----------1.13 New or Existing Customer Flag is Mandatory----
-------------------------------------------------------------
BEGIN

IF NVL(p_new_or_existing_cust, 'A') not in ('NEW', 'EXISTING') THEN


l_error_message := l_error_message || ',' ||
'Please indicate whether this is a NEW or EXISTING
customer.';
l_error_code := 'E';

END IF;

END;

-------------------------------------------------------------
----------1.16 New or Existing Account Flag is Mandatory-----
-------------------------------------------------------------
BEGIN

IF NVL(p_new_or_existing_account, 'A') not in ('NEW', 'EXISTING') THEN


l_error_message := l_error_message || ',' ||
'Please indicate whether this is a NEW or EXISTING
Account.';
l_error_code := 'E';

END IF;

END;

-------------------------------------------------------------
----------1.22 New or Existing Site Flag is Mandatory--------
-------------------------------------------------------------
BEGIN

IF NVL(p_new_or_existing_site, 'A') not in ('NEW', 'EXISTING') THEN


l_error_message := l_error_message || ',' ||
'Please indicate whether this is a NEW or EXISTING
Site.';
l_error_code := 'E';
END IF;

END;

---------------------------------------------------------------
----------1.54 Validate or Process entry field is Mandatory----
---------------------------------------------------------------
BEGIN

IF NVL(p_validate_or_process_entry, 'A') not in


('VALIDATE', 'PROCESS') THEN
l_error_message := l_error_message || ',' ||
'Please indicate whether you want to VALIDATE or PROCESS
this entry.';
l_error_code := 'E';

END IF;

END;

-----------------------------------------------------------------------------------
------------
----------1.17 p_new_or_existing_cust is 'NEW' and p_new_or_existing_account is
'EXISTING'-----

-----------------------------------------------------------------------------------
------------
BEGIN

IF NVL(p_new_or_existing_cust, 'A') = 'NEW' AND


NVL(p_new_or_existing_account, 'A') = 'EXISTING' THEN
l_error_message := l_error_message || ',' ||
'NEW_OR_EXISTING_ACCOUNT Field cannot be EXISTING when
the NEW_OR_EXISTING_CUSTOMER field is NEW.';
l_error_code := 'E';

END IF;

END;

-----------------------------------------------------------------------------------
------------
----------1.23 p_new_or_existing_account is 'NEW' and p_new_or_existing_site is
'EXISTING'-----

-----------------------------------------------------------------------------------
------------
BEGIN

IF NVL(p_new_or_existing_account, 'A') = 'NEW' AND


NVL(p_new_or_existing_site, 'A') = 'EXISTING' THEN
l_error_message := l_error_message || ',' ||
'NEW_OR_EXISTING_SITE Field cannot be EXISTING when the
NEW_OR_EXISTING_ACCOUNT field is NEW.';
l_error_code := 'E';

END IF;
END;

-----------------------------------------------------------------------------------
--------------------
----------1.14 "CUSTOMER_NUMBER_IF_EXISTING" field is Mandatory when entry is
marked as EXISTING-------

-----------------------------------------------------------------------------------
--------------------
BEGIN

IF NVL(p_new_or_existing_cust, 'A') = 'EXISTING' AND


p_cust_no_if_exists is null THEN
l_error_message := l_error_message || ',' ||
'Please enter a customer number as you have marked this
customer as EXISTING.';
l_error_code := 'E';

END IF;

END;

-----------------------------------------------------------------------------------
---------------------
----------1.18 "ACCOUNT_NUMBER_IF_EXISTING" field is Mandatory when entry is
marked as is EXISTING-----

-----------------------------------------------------------------------------------
---------------------
BEGIN

IF NVL(p_new_or_existing_account, 'A') = 'EXISTING' AND


p_account_no_if_exists is null THEN
l_error_message := l_error_message || ',' ||
'Please enter an account number as you have marked this
account as EXISTING.';
l_error_code := 'E';

END IF;

END;

-----------------------------------------------------------------------------------
---------------------
----------1.27 "SITE_NUMBER_IF_EXISTING" field is Mandatory when entry is
marked as is EXISTING--------

-----------------------------------------------------------------------------------
---------------------
BEGIN

IF NVL(p_new_or_existing_site, 'A') = 'EXISTING' AND


p_site_no_if_exists is null THEN
l_error_message := l_error_message || ',' ||
'Please enter a site number as you have marked this site
as EXISTING.';
l_error_code := 'E';

END IF;

END;

-----------------------------------------------------------------------------------
----------
----------1.15 Customer Name against Customer Number does not match Customer
Name entered----

-----------------------------------------------------------------------------------
----------

IF NVL(p_new_or_existing_cust, 'A') = 'EXISTING'

THEN

BEGIN

select hp.party_name
into l_cust_no_party_name
from hz_parties hp
where 1 = 1
and hp.party_number = p_cust_no_if_exists;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a customer number that exists in the
system.';
l_error_code := 'E';

IF l_cust_no_party_name <> p_organization_name THEN


l_error_message := l_error_message || ',' ||
'The Customer opened against the Customer no.
provided does not match the organization name entered.';
l_error_code := 'E';

END IF;

END;

END IF;

-----------------------------------------------------------------------------------
----------
----------1.19 Account Name against Account Number does not match Account Name
entered-------

-----------------------------------------------------------------------------------
----------

IF NVL(p_new_or_existing_account, 'A') = 'EXISTING'

THEN
BEGIN

select hca.account_name
into l_account_no_acc_name
from hz_cust_accounts_all hca
where 1 = 1
and hca.account_number = p_account_no_if_exists;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter an account number that exists in the
system.';
l_error_code := 'E';

IF l_account_no_acc_name <> p_account_name THEN


l_error_message := l_error_message || ',' ||
'The Account name opened against the Account no.
provided does not match the Account name entered.';
l_error_code := 'E';

END IF;

END;

END IF;

-----------------------------------------------------------------------------------
------
----------1.20 Ensure Account No provided exists under Customer
Provided-----------------

-----------------------------------------------------------------------------------
------
IF NVL(p_new_or_existing_account, 'A') = 'EXISTING'

THEN

BEGIN

SELECT hp.party_number
INTO l_account_no_party_num
FROM hz_parties hp, hz_cust_accounts_all hca
WHERE 1 = 1
AND hp.party_id = hca.party_id
AND hca.account_number = p_account_no_if_exists;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter an account number that exists in the
system.';
l_error_code := 'E';

IF l_account_no_party_num <> p_cust_no_if_exists THEN


l_error_message := l_error_message || ',' ||
'The Account no. provided does not exist under the
Customer no. provided.';
l_error_code := 'E';

END IF;

END;

END IF;

-----------------------------------------------------------------------------------
------
----------1.28 Ensure Site No provided exists under Account
Provided---------------------

-----------------------------------------------------------------------------------
------
IF NVL(p_new_or_existing_site, 'A') = 'EXISTING'

THEN

BEGIN

SELECT hca.account_number
INTO l_site_no_account_no
FROM hz_party_sites hps,
hz_cust_accounts_all hca,
hz_cust_acct_sites_all hcasa
WHERE 1 = 1
AND hca.cust_account_id = hcasa.cust_account_id
AND hcasa.party_site_id = hps.party_site_id
AND hps.party_site_number = p_site_no_if_exists;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a site number that exists in the
system.';
l_error_code := 'E';

IF l_site_no_account_no <> p_account_no_if_exists THEN


l_error_message := l_error_message || ',' ||
'The Site no. provided does not exist under the
Account no. provided.';
l_error_code := 'E';

END IF;

END;

END IF;

-----------------------------------------------------------------------------------
-----
--------------------1.55 Curreny Code Check Validation (Account
Level)------------------

-----------------------------------------------------------------------------------
-----

IF p_acc_prof_currency_code is not null

THEN

BEGIN

select fct.currency_code
into l_acc_prof_currency_code
from FND_CURRENCIES_TL fct
where 1 = 1
and fct.currency_code = p_acc_prof_currency_code;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a currency code that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--
--------------------1.56 Curreny Code Check Validation (Site
Level)------------------

-----------------------------------------------------------------------------------
--

IF p_site_prof_currency_code is not null

THEN

BEGIN

select fct.currency_code
into l_site_prof_currency_code
from FND_CURRENCIES_TL fct
where 1 = 1
and fct.currency_code = p_site_prof_currency_code;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a currency code that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------
--------------------1.57 Curreny Code is mandatory if
p_acc_prof_credit_checking is 'Y'------------------

-----------------------------------------------------------------------------------
----------------------

IF p_acc_prof_credit_checking = 'Y' AND


p_acc_prof_currency_code is null

THEN

l_error_message := l_error_message || ',' ||


'Please enter a currency code as you have set account
level credit checking as Y.';
l_error_code := 'E';

END IF;

-----------------------------------------------------------------------------------
----------------------
--------------------1.58 Curreny Code is mandatory if
p_site_prof_credit_checking is 'Y'-----------------

-----------------------------------------------------------------------------------
----------------------

IF p_site_prof_credit_checking = 'Y' AND


p_site_prof_currency_code is null

THEN

l_error_message := l_error_message || ',' ||


'Please enter a currency code as you have set site credit
checking as Y.';
l_error_code := 'E';

END IF;

-----------------------------------------------------------------------------------
-----------------------------------------
--------------------1.59 p_site_prof_credit_checking cannot be 'Y' if
p_site_use_site_use_code is 'SHIP_TO'-----------------

-----------------------------------------------------------------------------------
-----------------------------------------

IF p_site_prof_credit_checking = 'Y' AND


p_site_use_site_use_code = 'SHIP_TO'

THEN

l_error_message := l_error_message || ',' ||


'You cannot set site level credit checking as Y for a
SHIP_TO entry.';
l_error_code := 'E';
END IF;

-----------------------------------------------------------------------------------
------------------------------------------
--------------------1.60 p_acc_prof_credit_checking is null or NO and
p_acc_prof_currency_code is not null-------------------

-----------------------------------------------------------------------------------
------------------------------------------

IF NVL(p_acc_prof_credit_checking, 'N') = 'N' AND


p_acc_prof_currency_code is not null

THEN

l_error_message := l_error_message || ',' ||


'Please set Account level credit checking to Y as you have
provided a Currency Code.';
l_error_code := 'E';

END IF;

-----------------------------------------------------------------------------------
------------------------------------------
--------------------1.61 p_acc_prof_credit_checking is null or NO and
p_acc_prof_currency_code is not null-------------------

-----------------------------------------------------------------------------------
------------------------------------------

IF NVL(p_site_prof_credit_checking, 'N') = 'N' AND


p_site_prof_currency_code is not null

THEN

l_error_message := l_error_message || ',' ||


'Please set site level credit checking to Y as you have
provided a Currency Code.';
l_error_code := 'E';

END IF;

------------------------------------------------------------------------
----------1.11 Organization (Customer) Name is Mandatory----------------
------------------------------------------------------------------------

BEGIN

select p_organization_name
into l_organization_name
from dual
where 1 = 1;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter an organization name.';
l_error_code := 'E';

END;

--------------------------------------------
----------1.1 Select Org ID-----------------
--------------------------------------------
BEGIN
select hou.ORGANIZATION_ID
into l_org_id
from hr_organization_units hou
where hou.NAME = p_ou_name;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter an operating unit defined in the system.';
l_error_code := 'E';

END;

------------------------------------------------------------------------
----------1.52 Receivables Responsibility ID is Mandatory----------------
------------------------------------------------------------------------

BEGIN

select frl.RESPONSIBILITY_ID, frl.APPLICATION_ID


into l_rec_resp_id, l_resp_application_id
from fnd_responsibility_tl frl
where 1 = 1
and frl.RESPONSIBILITY_NAME = p_receivables_responsibility
and frl.APPLICATION_ID = 222;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a receivables responsibility name.';
l_error_code := 'E';

END;

------------------------------------------------------------------------
-----------------------1.53 User ID is Mandatory------------------------
------------------------------------------------------------------------

BEGIN

select fu.USER_ID
into l_user_id
from fnd_user fu
where 1 = 1
and fu.USER_NAME = p_oracle_user_name;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter an oracle user name.';
l_error_code := 'E';
END;

-----------------------------------------------------------------
----------Set Org ID for Customer Account & Site-----------------
-----------------------------------------------------------------

-- Fnd_client_info.set_org_context(l_org_id);

fnd_global.apps_initialize(user_id => NVL(l_user_id, -1),


resp_id => NVL(l_rec_resp_id, 20678),
resp_appl_id => NVL(l_resp_application_id,
222));
mo_global.init('AR');
mo_global.set_policy_context('S', l_org_id);

--------------------------------------------
---------1.2 Validate Flags entered---------
--------------------------------------------

BEGIN

select TRIM(TRANSLATE(NVL(p_internal_flag, 'Y') ||


NVL(p_site_use_primary_flag, 'Y') ||
NVL(p_site_use_shipset_inc_ln_flag, 'Y') ||
NVL(p_ship_partial, 'Y') ||
NVL(p_site_use_ship_partial, 'Y') ||
NVL(p_acc_prof_credit_checking, 'Y') ||
NVL(p_site_prof_credit_checking, 'Y'),
'YN',
' '))
into l_flag_validation
from dual;

IF l_flag_validation is not null THEN


l_error_message := l_error_message || ',' ||
'Please enter your relevant flags as either Y or N.';
l_error_code := 'E';
END IF;
END;

-------------------------------------------------------------
----------1.12 Account Name is Mandatory---------------------
-------------------------------------------------------------
BEGIN
select p_account_name into l_account_name from dual where 1 = 1;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter an account name.';
l_error_code := 'E';

END;

---------------------------------------------------------------------
-----------------1.3 Customer Class Code Validation------------------
---------------------------------------------------------------------
IF p_customer_class_code is not null

THEN

BEGIN

SELECT lookup_code
INTO l_customer_class_code
FROM ar_lookups
WHERE lookup_type = 'CUSTOMER CLASS'
AND enabled_flag = 'Y'
AND lookup_code = p_customer_class_code;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a class lookup code setup in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------1.6 Account level Price List
Validation------------------------

-----------------------------------------------------------------------------------

IF p_account_price_list_name is not null

THEN

BEGIN

SELECT qll.LIST_HEADER_ID
INTO l_account_price_list_id
FROM qp_list_headers_tl qll
WHERE 1 = 1
AND qll.NAME = p_account_price_list_name;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a price list that is setup in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------1.7 Account level Tax Code
Validation--------------------------
-----------------------------------------------------------------------------------

IF p_account_tax_code_name is not null

THEN

BEGIN

select zrb.TAX_RATE_CODE
into l_account_tax_code
from zx_rates_b zrb
where 1 = 1
and zrb.TAX_RATE_CODE = p_account_tax_code_name
and zrb.TAX = p_account_tax_name
and zrb.TAX_REGIME_CODE = p_account_tax_regime_name
and zrb.RATE_TYPE_CODE in ('PERCENTAGE', 'QUANTITY');

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a tax code that is setup in the system
against the provided Tax and Regime.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------1.8 Account level Freight Term
Validation----------------------

-----------------------------------------------------------------------------------

IF p_account_freight_term is not null

THEN

BEGIN

SELECT ol.lookup_code
INTO l_account_freight_term
FROM oe_lookups ol
WHERE 1 = 1
AND ol.LOOKUP_TYPE = 'FREIGHT_TERMS'
AND ol.lookup_code = p_account_freight_term
AND ol.enabled_flag = 'Y';

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a freight term lookup code that is setup
in the system.';
l_error_code := 'E';

END;

END IF;
-----------------------------------------------------------------------------------
--------------------1.9 Account level Warehouse
Validation-------------------------

-----------------------------------------------------------------------------------

IF p_account_warehouse_name is not null

THEN

BEGIN

SELECT hou.ORGANIZATION_ID
INTO l_account_warehouse_id
FROM hr_organization_units hou
WHERE hou.NAME = p_account_warehouse_name;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a warehouse that is setup in the
system.';
l_error_code := 'E';

END;

END IF;

------------------------------------------------------
---------1.10 Validate Numeric fields entered---------
------------------------------------------------------

BEGIN

select TRIM(TRANSLATE(NVL(p_over_shipment_tol, 1) ||
--NVL(p_under_shipment_tol,1)||
NVL(p_over_return_tol, 1) ||
NVL(p_under_return_tol, 1) ||
NVL(p_site_use_over_shipment_tol, 1) ||
NVL(p_site_use_under_shipment_tol, 1) ||
NVL(p_site_use_over_return_tol, 1) ||
NVL(p_site_use_under_return_tol, 1) ||
NVL(p_acc_prof_trx_credit_limit, 1) ||
NVL(p_acc_prof_overal_credit_limit, 1) ||
NVL(p_site_prof_trx_credit_limit, 1) ||
NVL(p_site_prof_overal_credit_limt, 1),
'1234567890',
' '))
into l_numeric_validation
from dual;

IF l_numeric_validation is not null THEN


l_error_message := l_error_message || ',' ||
'Please ensure that all numeric fields are correctly
entered.';
l_error_code := 'E';
END IF;
END;

-----------------------------------------------------------------------------------
-------------------------------1.21 Country Code
Validation------------------------

-----------------------------------------------------------------------------------

IF p_new_or_existing_site = 'NEW'

THEN

BEGIN

SELECT TERRITORY_CODE
INTO l_country
FROM FND_TERRITORIES
WHERE TERRITORY_CODE = p_country;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a correct country code.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
---------------
-------------------------------1.24 Address Line 1 is Mandatory if Site is
NEW--------------------

-----------------------------------------------------------------------------------
---------------

IF p_new_or_existing_site = 'NEW' AND p_address1 is NULL

THEN
l_error_message := l_error_message || ',' ||
'Please enter an ADDRESS1 as the site is NEW.';
l_error_code := 'E';

END IF;

-----------------------------------------------------------------------------------
-----------
-------------------------------1.25 Customer Category Code
Validation-------------------------

-----------------------------------------------------------------------------------
-----------

IF p_site_customer_category_code is not null


THEN

BEGIN

SELECT lookup_code
INTO l_site_customer_category_code
FROM ar_lookups
WHERE lookup_type = 'CUSTOMER_CATEGORY'
AND enabled_flag = 'Y'
AND lookup_code = p_site_customer_category_code;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a customer category code defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
-----------
-------------------------------1.26 Territory ID
Validation-----------------------------------

-----------------------------------------------------------------------------------
-----------

IF p_site_territory is not null

THEN

BEGIN

SELECT rt.territory_id
INTO l_site_territory_id
FROM ra_territories_kfv rt
WHERE 1 = 1
AND rt.CONCATENATED_SEGMENTS = p_site_territory;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a territory defined in the system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
-----------
-------------------------------1.29 SITE USE CODE
Validation----------------------------------
-----------------------------------------------------------------------------------
-----------

IF p_site_use_site_use_code not in ('BILL_TO', 'SHIP_TO')

THEN
l_error_message := l_error_message || ',' ||
'Please enter a site use code as either BILL_TO or
SHIP_TO.';
l_error_code := 'E';

END IF;

/* --- Check removed to Allow creation of Independent SHIP_TO sites --- */


/*

--------------------------------------------------------------------------------
------1.48 BILL_TO_SITE_USE_ID Must be entered if Site Use Code is
SHIP_TO------

--------------------------------------------------------------------------------

IF p_site_use_site_use_code = 'SHIP_TO' AND p_bill_to_site_use_id is null

THEN
l_error_message :=l_error_message
||','||
'Please enter the BILL_TO site use ID in order to
link it to this SHIP_TO entry.';
l_error_code := 'E';

END IF;
*/

--------------------------------------------------------------------------------
------1.49 BILL_TO_SITE_USE_ID cannot be entered if Site Use Code is
BILL_TO----

--------------------------------------------------------------------------------

IF p_site_use_site_use_code = 'BILL_TO' AND


p_bill_to_site_use_id is not null

THEN
l_error_message := l_error_message || ',' ||
'Please remove the BILL_TO site use ID as this is not a
SHIP_TO entry.';
l_error_code := 'E';

END IF;

-----------------------------------------------------------------------------------
----------------------------
-------------------------------1.30 Payment Term ID (Site Use Level)
Validation--------------------------------
-----------------------------------------------------------------------------------
----------------------------

IF p_site_use_payment_term_name is not null

THEN

BEGIN

SELECT rt.term_id
INTO l_site_use_payment_term_id
FROM ra_terms rt
WHERE 1 = 1
AND rt.NAME = p_site_use_payment_term_name;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Payment Term defined in the system for
the provided Operating Unit.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------------
-------------------------------1.31 Order Type ID Account Site Use
Validation--------------------------------

-----------------------------------------------------------------------------------
--------------------------

IF p_site_use_order_type_name is not null

THEN

BEGIN

SELECT ott.transaction_type_id
INTO l_site_use_order_type_id
FROM oe_transaction_types_all ott, oe_transaction_types_tl ottl
WHERE 1 = 1
AND ott.TRANSACTION_TYPE_ID = ottl.TRANSACTION_TYPE_ID
AND ottl.NAME = p_site_use_order_type_name
AND ott.ORG_ID = l_org_id;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Order Type defined in the system for
the provided Operating Unit.';
l_error_code := 'E';

END;
END IF;

-----------------------------------------------------------------------------------
--------------------------
-------------------------------1.32 Price List ID Account Site Use
Validation--------------------------------

-----------------------------------------------------------------------------------
--------------------------

IF p_site_use_price_list_name is not null

THEN

BEGIN

SELECT qll.LIST_HEADER_ID
INTO l_site_use_price_list_id
FROM qp_list_headers_tl qll
WHERE 1 = 1
AND qll.NAME = p_site_use_price_list_name;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Price List defined in the system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------------
-------------------------------1.33 Freight Term Account Site Use
Validation---------------------------------

-----------------------------------------------------------------------------------
--------------------------

IF p_site_use_freight_term is not null

THEN

BEGIN

SELECT ol.lookup_code
INTO l_site_use_freight_term
FROM oe_lookups ol
WHERE 1 = 1
AND ol.LOOKUP_TYPE = 'FREIGHT_TERMS'
AND ol.lookup_code = p_site_use_freight_term
AND ol.enabled_flag = 'Y';

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a freight term defined in the system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------------
-------------------------------1.34 Warehouse ID Account Site Use
Validation---------------------------------

-----------------------------------------------------------------------------------
--------------------------

IF p_site_use_warehouse_name is not null

THEN

BEGIN

SELECT hou.ORGANIZATION_ID
INTO l_site_use_warehouse_id
FROM hr_organization_units hou
WHERE hou.NAME = p_site_use_warehouse_name;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Warehouse that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------------
-------------------------------1.35 Territory ID Account Site Use
Validation---------------------------------

-----------------------------------------------------------------------------------
--------------------------

IF p_site_use_territory_name is not null

THEN

BEGIN

SELECT rt.territory_id
INTO l_site_use_territory_id
FROM ra_territories_kfv rt
WHERE 1 = 1
AND rt.CONCATENATED_SEGMENTS = p_site_use_territory_name;
EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Territory that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.36 Receivable Account- Account Site Use
Validation---------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_rec is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_rec
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_rec;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Receivable Account that is defined in
the system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.37 Revenue Account- Account Site Use
Validation------------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_rev is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_rev
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_rev;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Revenue Account that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.38 Tax Account- Account Site Use
Validation----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_tax is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_tax
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_tax;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Tax Account that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.39 Freight Account- Account Site Use
Validation------------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_freight is not null


THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_freight
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_freight;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Freight Account that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.40 Clearing Account- Account Site Use
Validation-----------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_clearing is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_clearing
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_clearing;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Clearing Account that is defined in
the system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.41 Unbilled Account- Account Site Use
Validation-----------------------------------
-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_unbilled is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_unbilled
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_unbilled;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Unbilled Account that is defined in
the system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.42 Unearned Account- Account Site Use
Validation-----------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_unearned is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_unearned
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_unearned;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Unearned Account that is defined in
the system.';
l_error_code := 'E';

END;

END IF;
-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.43 Unpaid Account- Account Site Use
Validation-------------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_unpaid_rec is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_unpaid_rec
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_unpaid_rec;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Unpaid Account that is defined in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------
-------------------------------1.44 Remittance Account- Account Site Use
Validation---------------------------------

-----------------------------------------------------------------------------------
----------------------------------

IF p_site_use_gl_code_remittance is not null

THEN

BEGIN

SELECT gcc.code_combination_id
INTO l_site_use_gl_id_remittance
FROM gl_code_combinations_kfv gcc
WHERE 1 = 1
AND gcc.CONCATENATED_SEGMENTS = p_site_use_gl_code_remittance;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a Remittance Account that is defined in
the system.';
l_error_code := 'E';
END;

END IF;

-----------------------------------------------------------------------------------
--------------------1.45 Account Use level Tax Code
Validation---------------------

-----------------------------------------------------------------------------------

IF p_site_use_tax_code_name is not null

THEN

BEGIN

select zrb.TAX_RATE_CODE
into l_account_tax_code
from zx_rates_b zrb
where 1 = 1
and zrb.TAX_RATE_CODE = p_site_use_tax_code_name
and zrb.TAX = p_site_use_tax_name
and zrb.TAX_REGIME_CODE = p_site_use_tax_regime_name
and zrb.RATE_TYPE_CODE in ('PERCENTAGE', 'QUANTITY');

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a tax code that is setup in the system
against the provided Tax and Regime.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
--------------------1.46 Account Use level Sales Rep Name
Validation---------------

-----------------------------------------------------------------------------------

IF p_site_use_primary_salesrep_no is not null

THEN

BEGIN

SELECT jsl.SALESREP_ID
INTO l_site_use_primary_salesrep_id
FROM jtf_rs_resource_extns jrr, JTF_RS_SALESREPS jsl
WHERE 1 = 1
AND jrr.RESOURCE_ID = jsl.RESOURCE_ID
AND jsl.ORG_ID = l_org_id
AND jrr.RESOURCE_NUMBER = p_site_use_primary_salesrep_no;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a sales rep that is setup in the
system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
-
--------------------1.47 Account Use level FOB Point
Validation---------------------

-----------------------------------------------------------------------------------
-

IF p_site_use_fob_point is not null

THEN

BEGIN

SELECT lookup_code
INTO l_site_use_fob_point
FROM ar_lookups
WHERE 1 = 1
AND lookup_type = 'FOB'
AND enabled_flag = 'Y'
AND lookup_code = p_site_use_fob_point;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter an FOB point that is setup in the
system.';
l_error_code := 'E';

END;

END IF;

--------------------------------------------------------------------------
---------1.50 GL IDs cannot be entered if SITE USE is not BILL_TO---------
--------------------------------------------------------------------------

IF p_site_use_site_use_code <> 'BILL_TO'

THEN

BEGIN

select TRIM(p_site_use_gl_code_rec || p_site_use_gl_code_rev ||


p_site_use_gl_code_tax || p_site_use_gl_code_freight ||
p_site_use_gl_code_clearing ||
p_site_use_gl_code_unbilled ||
p_site_use_gl_code_unearned ||
p_site_use_gl_code_unpaid_rec ||
p_site_use_gl_code_remittance)
into l_gl_ids_validation
from dual;

IF l_gl_ids_validation is not null THEN


l_error_message := l_error_message || ',' ||
'You cannot enter any GL account as the SITE use code
is not BILL_TO.';
l_error_code := 'E';
END IF;
END;

END IF;

-----------------------------------------------------------------------------------
--------------------1.51 Account Use level Shipment Method
Validation--------------

-----------------------------------------------------------------------------------

IF p_site_use_ship_via is not null

THEN

BEGIN

SELECT lookup_code
INTO l_site_use_ship_via
FROM fnd_lookup_values
WHERE 1 = 1
AND lookup_type = 'SHIP_METHOD'
AND enabled_flag = 'Y'
AND lookup_code = p_site_use_ship_via;

EXCEPTION
WHEN no_data_found THEN
l_error_message := l_error_message || ',' ||
'Please enter a shipment method code (Ship Via) that
is setup in the system.';
l_error_code := 'E';

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-----------------------------****** PARTY AND ACCOUNT CREATION API BLOCK
******--------------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------
-------- i. Condition to evaluate any error existing at this stage and
stopping the API-----------------------------------
-------- ii. If no error exists, a sub condition will evaluate weather the
party and Account exists------------------------
--------iii. party and Account exists for provided details, the API in this
block will be skipped--------------------------
-------- iv. If party and account doesnt exist for the provided details, a new
customer will be created--------------------
-------- v. If party exists and account doesnt exist for the provided details,
only a new account will be created---------

-----------------------------------------------------------------------------------
----------------------------------------

IF l_error_code = 'E'

THEN
raise_application_error(-20101, l_error_message);

ELSIF NVL(l_error_code, 'A') <> 'E'

THEN

IF p_new_or_existing_cust = 'EXISTING' AND


p_new_or_existing_account = 'EXISTING'

THEN

BEGIN

SELECT hp.party_id, hca.cust_account_id


INTO x_party_id, x_cust_account_id
FROM hz_parties hp, hz_cust_accounts_all hca
WHERE 1 = 1
AND hp.party_id = hca.party_id
AND hp.party_number = p_cust_no_if_exists
AND hca.account_number = p_account_no_if_exists;

END;

ELSIF p_new_or_existing_cust = 'NEW' AND


p_new_or_existing_account = 'NEW'

THEN

BEGIN

p_organization_rec.organization_name := p_organization_name;
p_organization_rec.principal_name := p_principal_name;
p_organization_rec.organization_name_phonetic :=
p_organization_name_phonetic;
p_organization_rec.tax_reference := p_tax_reference;
p_organization_rec.jgzz_fiscal_code := p_jgzz_fiscal_code;
p_organization_rec.known_as := p_known_as;
p_organization_rec.internal_flag := p_internal_flag;
p_organization_rec.party_rec.attribute_category :=
p_customer_attribute_category;
p_organization_rec.party_rec.attribute1 := p_customer_attribute1;
p_organization_rec.party_rec.attribute2 := p_customer_attribute2;
p_organization_rec.party_rec.attribute3 := p_customer_attribute3;
p_organization_rec.party_rec.attribute4 := p_customer_attribute4;
p_organization_rec.party_rec.attribute5 := p_customer_attribute5;
p_organization_rec.party_rec.attribute6 := p_customer_attribute6;
p_organization_rec.party_rec.attribute7 := p_customer_attribute7;
p_organization_rec.party_rec.attribute8 := p_customer_attribute8;
p_organization_rec.party_rec.attribute9 := p_customer_attribute9;
p_organization_rec.party_rec.attribute10 :=
p_customer_attribute10;
p_organization_rec.party_rec.attribute11 :=
p_customer_attribute11;
p_organization_rec.party_rec.attribute12 :=
p_customer_attribute12;
p_organization_rec.party_rec.attribute13 :=
p_customer_attribute13;
p_organization_rec.party_rec.attribute14 :=
p_customer_attribute14;
p_organization_rec.party_rec.attribute15 :=
p_customer_attribute15;
/* p_organization_rec.attribute_category:=
p_customer_attribute_category;
p_organization_rec.attribute1:= p_customer_attribute1;
p_organization_rec.attribute2:= p_customer_attribute2;
p_organization_rec.attribute3:= p_customer_attribute3;
p_organization_rec.attribute4:= p_customer_attribute4;
p_organization_rec.attribute5:= p_customer_attribute5;
p_organization_rec.attribute6:= p_customer_attribute6;
p_organization_rec.attribute7:= p_customer_attribute7;
p_organization_rec.attribute8:= p_customer_attribute8;
p_organization_rec.attribute9:= p_customer_attribute9;
p_organization_rec.attribute10:= p_customer_attribute10;
p_organization_rec.attribute11:= p_customer_attribute11;
p_organization_rec.attribute12:= p_customer_attribute12;
p_organization_rec.attribute13:= p_customer_attribute13;
p_organization_rec.attribute14:= p_customer_attribute14;
p_organization_rec.attribute15:= p_customer_attribute15; */
p_organization_rec.created_by_module := 'TCA_V2_API';
p_cust_account_rec.account_name := p_account_name;
p_cust_account_rec.customer_class_code := p_customer_class_code;
p_cust_account_rec.price_list_id := l_account_price_list_id;
p_cust_account_rec.tax_code := p_account_tax_code_name;
p_cust_account_rec.freight_term := p_account_freight_term;
p_cust_account_rec.ship_partial := p_ship_partial;
p_cust_account_rec.warehouse_id := l_account_warehouse_id;
-- p_cust_account_rec.over_shipment_tolerance :=
p_over_shipment_tol;
--p_cust_account_rec.under_shipment_tolerance := p_under_shipment_tol;
p_cust_account_rec.account_number := p_under_shipment_tol;
p_cust_account_rec.sales_channel_code := p_account_attribute15;
p_cust_account_rec.over_return_tolerance := p_over_return_tol;
p_cust_account_rec.under_return_tolerance := p_under_return_tol;
p_cust_account_rec.attribute_category :=
p_account_attribute_category;
p_cust_account_rec.attribute1 := p_account_attribute1;
p_cust_account_rec.attribute2 := p_account_attribute2;
p_cust_account_rec.attribute3 := p_account_attribute3;
p_cust_account_rec.attribute4 := p_account_attribute4;
p_cust_account_rec.attribute5 := p_account_attribute5;
p_cust_account_rec.attribute6 := p_account_attribute6;
p_cust_account_rec.attribute7 := p_account_attribute7;
p_cust_account_rec.attribute8 := p_account_attribute8;
p_cust_account_rec.attribute9 := p_account_attribute9;
p_cust_account_rec.attribute10 := p_account_attribute10;
p_cust_account_rec.attribute11 := p_account_attribute11;
p_cust_account_rec.attribute12 := p_account_attribute12;
p_cust_account_rec.attribute13 := p_account_attribute13;
p_cust_account_rec.attribute14 := p_account_attribute14;
p_cust_account_rec.attribute15 := p_account_attribute15;
p_customer_profile_rec.credit_checking := p_acc_prof_credit_checking;
p_cust_account_rec.created_by_module := 'TCA_V2_API';

hz_cust_account_v2pub.create_cust_account('T',
p_cust_account_rec,
p_organization_rec,
p_customer_profile_rec,
'F',
x_cust_account_id,
x_account_number,
x_party_id,
x_party_number,
x_profile_id,
x_return_status,
x_msg_count,
x_msg_data);

dbms_output.put_line('x_return_status = ' ||
SUBSTR(x_return_status, 1, 255));
dbms_output.put_line('x_msg_count = ' || TO_CHAR(x_msg_count));
dbms_output.put_line('Party Id = ' || TO_CHAR(x_party_id));
dbms_output.put_line('Party Number = ' || x_party_number);
dbms_output.put_line('Profile Id = ' || TO_CHAR(x_profile_id));
dbms_output.put_line('x_msg_data = ' ||
SUBSTR(x_msg_data, 1, 255));

IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || x_msg_count ||


' : Customer Account : ' || 'x_msg_data = ' ||
SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;

END;

ELSIF p_new_or_existing_cust = 'EXISTING' AND


p_new_or_existing_account = 'NEW'

THEN

SELECT hp.party_id
INTO x_party_id
FROM hz_parties hp
WHERE 1 = 1
AND hp.party_number = p_cust_no_if_exists;

BEGIN

p_organization_rec.party_rec.party_id := x_party_id;
p_cust_account_rec.account_name := p_account_name;
p_cust_account_rec.account_number := p_under_shipment_tol;
p_cust_account_rec.sales_channel_code := p_account_attribute15;
p_cust_account_rec.customer_class_code := p_customer_class_code;
p_cust_account_rec.price_list_id := l_account_price_list_id;
p_cust_account_rec.tax_code := p_account_tax_code_name;
p_cust_account_rec.freight_term := p_account_freight_term;
p_cust_account_rec.ship_partial := p_ship_partial;
p_cust_account_rec.warehouse_id := l_account_warehouse_id;
-- p_cust_account_rec.over_shipment_tolerance :=
p_over_shipment_tol;
--p_cust_account_rec.under_shipment_tolerance := p_under_shipment_tol;
p_cust_account_rec.over_return_tolerance := p_over_return_tol;
p_cust_account_rec.under_return_tolerance := p_under_return_tol;
p_cust_account_rec.attribute_category :=
p_account_attribute_category;
p_cust_account_rec.attribute1 := p_account_attribute1;
p_cust_account_rec.attribute2 := p_account_attribute2;
p_cust_account_rec.attribute3 := p_account_attribute3;
p_cust_account_rec.attribute4 := p_account_attribute4;
p_cust_account_rec.attribute5 := p_account_attribute5;
p_cust_account_rec.attribute6 := p_account_attribute6;
p_cust_account_rec.attribute7 := p_account_attribute7;
p_cust_account_rec.attribute8 := p_account_attribute8;
p_cust_account_rec.attribute9 := p_account_attribute9;
p_cust_account_rec.attribute10 := p_account_attribute10;
p_cust_account_rec.attribute11 := p_account_attribute11;
p_cust_account_rec.attribute12 := p_account_attribute12;
p_cust_account_rec.attribute13 := p_account_attribute13;
p_cust_account_rec.attribute14 := p_account_attribute14;
p_cust_account_rec.attribute15 := p_account_attribute15;
p_customer_profile_rec.credit_checking := p_acc_prof_credit_checking;
p_cust_account_rec.created_by_module := 'TCA_V2_API';

hz_cust_account_v2pub.create_cust_account('T',
p_cust_account_rec,
p_organization_rec,
p_customer_profile_rec,
'F',
x_cust_account_id,
x_account_number,
x_party_id,
x_party_number,
x_profile_id,
x_return_status,
x_msg_count,
x_msg_data);

dbms_output.put_line('x_return_status = ' ||
SUBSTR(x_return_status, 1, 255));
dbms_output.put_line('x_msg_count = ' || TO_CHAR(x_msg_count));
dbms_output.put_line('Party Id = ' || TO_CHAR(x_party_id));
dbms_output.put_line('Party Number = ' || x_party_number);
dbms_output.put_line('Profile Id = ' || TO_CHAR(x_profile_id));
dbms_output.put_line('x_msg_data = ' ||
SUBSTR(x_msg_data, 1, 255));

IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || 'x_msg_data = ' ||


SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;

END;

END IF;
END IF;

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
------------------------------****** ACCOUNT LEVEL PROFILE AMOUNT CREATION API
BLOCK ******--------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-------------------- i. If Account Level Credit Checking is Set to 'Y', then
Credit Limit will be created-----------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

IF p_acc_prof_credit_checking = 'Y' AND


p_new_or_existing_account = 'NEW'

THEN

BEGIN

/*Selection of newly created cust account profile into variable*/


select hcp.CUST_ACCOUNT_PROFILE_ID
into l_cust_newaccount_profile_id
from hz_customer_profiles hcp
where hcp.CUST_ACCOUNT_ID = x_cust_account_id;

p_cust_prof_amt_rec.cust_account_id := x_cust_account_id;
p_cust_prof_amt_rec.cust_account_profile_id :=
l_cust_newaccount_profile_id;
--p_cust_prof_amt_rec.site_use_id := xxx;
p_cust_prof_amt_rec.currency_code := p_acc_prof_currency_code;
p_cust_prof_amt_rec.overall_credit_limit := p_acc_prof_overal_credit_limit;
p_cust_prof_amt_rec.trx_credit_limit := p_acc_prof_trx_credit_limit;
p_cust_prof_amt_rec.created_by_module := 'TCA_V2_API';

hz_customer_profile_v2pub.create_cust_profile_amt('T',
'T',
p_cust_prof_amt_rec,

x_cust_acct_profile_amt_id,
x_return_status,
x_msg_count,
x_msg_data);
IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || 'x_msg_data = ' ||


SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
--------------------------------------****** LOCATION CREATION API BLOCK
******--------------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-------------------- i. If Party Site to be Created is NEW, the a new location
will be created----------------------------
-------------------- ii. If Party Site to be Created is EXISTING, the API in
this block will be skipped--------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

IF p_new_or_existing_account in ('NEW', 'EXISTING') AND


p_new_or_existing_site = 'NEW'

THEN
BEGIN

p_location_rec.country := p_country;
p_location_rec.address1 := p_address1;
p_location_rec.address2 := p_address2;
p_location_rec.address3 := p_address3;
p_location_rec.city := p_city;
p_location_rec.postal_code := p_postal_code;
p_location_rec.state := p_state;
p_location_rec.province := p_province;
p_location_rec.county := p_county;
p_location_rec.attribute_category := p_loc_attribute_category;
p_location_rec.attribute1 := p_loc_attribute1;
p_location_rec.attribute2 := p_loc_attribute2;
p_location_rec.attribute3 := p_loc_attribute3;
p_location_rec.attribute4 := p_loc_attribute4;
p_location_rec.attribute5 := p_loc_attribute5;
p_location_rec.attribute6 := p_loc_attribute6;
p_location_rec.attribute7 := p_loc_attribute7;
p_location_rec.attribute8 := p_loc_attribute8;
p_location_rec.attribute9 := p_loc_attribute9;
p_location_rec.attribute10 := p_loc_attribute10;
p_location_rec.created_by_module := 'TCA_V2_API';

hz_location_v2pub.create_location('T',
p_location_rec,
x_location_id,
x_return_status,
x_msg_count,
x_msg_data);

dbms_output.put_line('x_return_status = ' ||
SUBSTR(x_return_status, 1, 255));
dbms_output.put_line('x_msg_count = ' || TO_CHAR(x_msg_count));
dbms_output.put_line('Location Id = ' || TO_CHAR(x_location_id));
dbms_output.put_line('Country = ' ||
SUBSTR(p_location_rec.country, 1, 255));
dbms_output.put_line('Address1 = ' ||
SUBSTR(p_location_rec.Address1, 1, 255));
dbms_output.put_line('State = ' ||
SUBSTR(p_location_rec.state, 1, 255));
dbms_output.put_line('Created By = ' ||
SUBSTR(p_location_rec.created_by_module,
1,
255));
dbms_output.put_line('x_msg_data = ' || SUBSTR(x_msg_data, 1, 255));

IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || 'x_msg_data = ' ||


SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;

END;
END IF;

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
--------------------------------------****** PARTY SITE CREATION API BLOCK
******------------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-------------------- i. If Party Site to be Created is NEW, the a new party
site will be created--------------------------
-------------------- ii. If Party Site to be Created is EXISTING, the API in
this block will be skipped--------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

IF p_new_or_existing_account in ('NEW', 'EXISTING') AND


p_new_or_existing_site = 'NEW'

THEN

BEGIN

p_party_site_rec.party_id := x_party_id;
p_party_site_rec.location_id := x_location_id;
p_party_site_rec.identifying_address_flag := 'Y';
p_party_site_rec.attribute_category := p_site_attribute_category;
p_party_site_rec.attribute1 := p_site_attribute1;
p_party_site_rec.attribute2 := p_site_attribute2;
p_party_site_rec.attribute3 := p_site_attribute3;
p_party_site_rec.attribute4 := p_site_attribute4;
p_party_site_rec.attribute5 := p_site_attribute5;
p_party_site_rec.attribute6 := p_site_attribute6;
p_party_site_rec.attribute7 := p_site_attribute7;
p_party_site_rec.attribute8 := p_site_attribute8;
p_party_site_rec.attribute9 := p_site_attribute9;
p_party_site_rec.attribute10 := p_site_attribute10;
p_party_site_rec.created_by_module := 'TCA_V2_API';

hz_party_site_v2pub.create_party_site('T',
p_party_site_rec,
x_party_site_id,
x_party_site_number,
x_return_status,
x_msg_count,
x_msg_data);
dbms_output.put_line('x_return_status = ' ||
SUBSTR(x_return_status, 1, 255));
dbms_output.put_line('x_msg_count = ' || TO_CHAR(x_msg_count));
dbms_output.put_line('Party Site Id = ' ||
TO_CHAR(x_party_site_id));
dbms_output.put_line('Party Site Number = ' ||
SUBSTR(x_party_site_number, 1, 255));
dbms_output.put_line('x_msg_data = ' || SUBSTR(x_msg_data, 1, 255));

IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || 'x_msg_data = ' ||


SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
--------------------------------------****** ACCOUNT SITE CREATION API BLOCK
******----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-------------------- i. If Party Site to be Created is NEW, the a new account
site will be created------------------------
-------------------- ii. If Party Site to be Created is EXISTING, the API in
this block will be skipped--------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

IF p_new_or_existing_account in ('NEW', 'EXISTING') AND


p_new_or_existing_site = 'EXISTING'

THEN

BEGIN

SELECT hcasa.cust_acct_site_id
INTO x_cust_acct_site_id
FROM hz_cust_acct_sites_all hcasa, hz_party_sites hps
WHERE hcasa.party_site_id = hps.party_site_id
AND hps.party_site_number = p_site_no_if_exists;

END;

ELSIF p_new_or_existing_account in ('NEW', 'EXISTING') AND


p_new_or_existing_site = 'NEW'

THEN

BEGIN
p_cust_acct_site_rec.cust_account_id := x_cust_account_id;
p_cust_acct_site_rec.party_site_id := x_party_site_id;
p_cust_acct_site_rec.customer_category_code :=
p_site_customer_category_code;
p_cust_acct_site_rec.territory_id := l_site_territory_id;
/* p_cust_acct_site_rec.attribute_category := p_site_attribute_category;
p_cust_acct_site_rec.attribute1 := p_site_attribute1;
p_cust_acct_site_rec.attribute2 := p_site_attribute2;
p_cust_acct_site_rec.attribute3 := p_site_attribute3;
p_cust_acct_site_rec.attribute4 := p_site_attribute4;
p_cust_acct_site_rec.attribute5 := p_site_attribute5;
p_cust_acct_site_rec.attribute6 := p_site_attribute6;
p_cust_acct_site_rec.attribute7 := p_site_attribute7;
p_cust_acct_site_rec.attribute8 := p_site_attribute8;
p_cust_acct_site_rec.attribute9 := p_site_attribute9;
p_cust_acct_site_rec.attribute10 := p_site_attribute10; */
p_cust_acct_site_rec.org_id := l_org_id;
p_cust_acct_site_rec.created_by_module := 'TCA_V2_API';

hz_cust_account_site_v2pub.create_cust_acct_site('T',
p_cust_acct_site_rec,
x_cust_acct_site_id,
x_return_status,
x_msg_count,
x_msg_data);

dbms_output.put_line('x_return_status = ' ||
SUBSTR(x_return_status, 1, 255));
dbms_output.put_line('x_msg_count = ' || TO_CHAR(x_msg_count));
dbms_output.put_line('Customer Account Site Id is = ' ||
TO_CHAR(x_cust_acct_site_id));
dbms_output.put_line('x_msg_data = ' || SUBSTR(x_msg_data, 1, 255));

IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || 'x_msg_data = ' ||


SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;

END;

END IF;
-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
--------------------------------------****** ACCOUNT SITE USE CREATION API
BLOCK ******------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-------------------- i. If Party Site to be Created is NEW, the a new account
site will be created------------------------
-------------------- ii. If Party Site to be Created is EXISTING, the API in
this block will be skipped--------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

IF 1 = 1

THEN

BEGIN

p_cust_site_use_rec.cust_acct_site_id := x_cust_acct_site_id;
p_cust_site_use_rec.site_use_code :=
p_site_use_site_use_code;
p_cust_site_use_rec.bill_to_site_use_id := p_bill_to_site_use_id;
p_cust_site_use_rec.primary_flag :=
p_site_use_primary_flag;
p_cust_site_use_rec.payment_term_id :=
l_site_use_payment_term_id;
p_cust_site_use_rec.ship_partial :=
p_site_use_ship_partial;
p_cust_site_use_rec.ship_via := p_site_use_ship_via;
p_cust_site_use_rec.fob_point := p_site_use_fob_point;
p_cust_site_use_rec.order_type_id :=
l_site_use_order_type_id;
p_cust_site_use_rec.price_list_id :=
l_site_use_price_list_id;
p_cust_site_use_rec.freight_term :=
p_site_use_freight_term;
p_cust_site_use_rec.warehouse_id :=
l_site_use_warehouse_id;
p_cust_site_use_rec.territory_id :=
l_site_use_territory_id;
p_cust_site_use_rec.attribute_category :=
p_site_use_attribute_category;
p_cust_site_use_rec.attribute1 := p_site_use_attribute1;
p_cust_site_use_rec.attribute2 := p_site_use_attribute2;
p_cust_site_use_rec.attribute3 := p_site_use_attribute3;
p_cust_site_use_rec.attribute4 := p_site_use_attribute4;
p_cust_site_use_rec.attribute5 := p_site_use_attribute5;
p_cust_site_use_rec.attribute6 := p_site_use_attribute6;
p_cust_site_use_rec.attribute7 := p_site_use_attribute7;
p_cust_site_use_rec.attribute8 := p_site_use_attribute8;
p_cust_site_use_rec.attribute9 := p_site_use_attribute9;
p_cust_site_use_rec.attribute10 := p_site_use_attribute10;
p_cust_site_use_rec.tax_code :=
p_site_use_tax_code_name;
p_cust_site_use_rec.primary_salesrep_id :=
l_site_use_primary_salesrep_id;
p_cust_site_use_rec.over_shipment_tolerance :=
p_site_use_over_shipment_tol;
p_cust_site_use_rec.under_shipment_tolerance :=
p_site_use_under_shipment_tol;
p_cust_site_use_rec.over_return_tolerance :=
p_site_use_over_return_tol;
p_cust_site_use_rec.under_return_tolerance :=
p_site_use_under_return_tol;
p_cust_site_use_rec.ship_sets_include_lines_flag :=
p_site_use_shipset_inc_ln_flag;
p_cust_site_use_rec.pricing_event :=
p_site_use_pricing_event;
p_cust_site_use_rec.gl_id_rec := l_site_use_gl_id_rec;
p_cust_site_use_rec.gl_id_rev := l_site_use_gl_id_rev;
p_cust_site_use_rec.gl_id_tax := l_site_use_gl_id_tax;
p_cust_site_use_rec.gl_id_freight :=
l_site_use_gl_id_freight;
p_cust_site_use_rec.gl_id_clearing :=
l_site_use_gl_id_clearing;
p_cust_site_use_rec.gl_id_unbilled :=
l_site_use_gl_id_unbilled;
p_cust_site_use_rec.gl_id_unearned :=
l_site_use_gl_id_unearned;
p_cust_site_use_rec.gl_id_unpaid_rec :=
l_site_use_gl_id_unpaid_rec;
p_cust_site_use_rec.gl_id_remittance :=
l_site_use_gl_id_remittance;
p_cust_site_use_rec.created_by_module := 'TCA_V2_API';

hz_cust_account_site_v2pub.create_cust_site_use('T',
p_cust_site_use_rec,
p_customer_profile_rec,
'',
'',
x_site_use_id,
x_return_status,
x_msg_count,
x_msg_data);

dbms_output.put_line('x_return_status = ' ||
SUBSTR(x_return_status, 1, 255));
dbms_output.put_line('x_msg_count = ' || TO_CHAR(x_msg_count));
dbms_output.put_line('Site Use Id = ' || TO_CHAR(x_site_use_id));
dbms_output.put_line('Site Use = ' ||
SUBSTR(p_cust_site_use_rec.site_use_code,
1,
255));
dbms_output.put_line('x_msg_data = ' || SUBSTR(x_msg_data, 1, 255));
IF x_msg_count > 0

THEN
IF x_msg_count > 0 THEN
FOR I IN 1 .. x_msg_count LOOP
l_error_message := I || '.' || SUBSTR(FND_MSG_PUB.Get(p_encoded =>
FND_API.G_FALSE),
1,
255);
END LOOP;
END IF;

/*FOR i IN 1 .. x_msg_count LOOP


l_error_message := i || '.' || Substr(fnd_msg_pub.Get(p_encoded =>
fnd_api.g_false),
1,
255);
END LOOP;*/
/*l_error_message := l_error_message || ',' || x_msg_count ||
' : Site : ' || x_cust_acct_site_id || ' :
x_msg_data = ' ||
SUBSTR(x_msg_data, 1, 255);
*/
raise_application_error(-20101, l_error_message);

END IF;

END;

END IF;

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
------------------------------****** SITE LEVEL PROFILE & PROFILE AMOUNT
CREATION API BLOCK ******-------------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------
-------------------- i. If Site Level Credit Checking is Set to 'Y', then
Credit Limit will be created--------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------------------------------------------------------------
----------------------------------------

-----------------------------SITE LEVEL PROFILE


CREATION--------------------------------

IF p_site_prof_credit_checking = 'Y'
THEN

BEGIN

p_customer_site_profile_rec.site_use_id := x_site_use_id;
p_customer_site_profile_rec.cust_account_id := x_cust_account_id;
p_customer_site_profile_rec.status := 'A';
p_customer_site_profile_rec.credit_checking :=
p_site_prof_credit_checking;
p_customer_site_profile_rec.created_by_module := 'TCA_V2_API';

HZ_CUSTOMER_PROFILE_V2PUB.create_customer_profile('T',

p_customer_site_profile_rec,
'F',

x_cust_acc_site_profile_id,
x_return_status,
x_msg_count,
x_msg_data);

IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || x_msg_count || ' : ' ||


'x_msg_data = ' || SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;
END;

END IF;

-----------------------------CREDIT LIMIT
CREATION--------------------------------

IF p_site_prof_credit_checking = 'Y'

THEN

BEGIN

p_cust_site_prof_amt_rec.cust_account_id := x_cust_account_id;
p_cust_site_prof_amt_rec.cust_account_profile_id :=
x_cust_acc_site_profile_id;
p_cust_site_prof_amt_rec.site_use_id := x_site_use_id;
p_cust_site_prof_amt_rec.currency_code :=
p_site_prof_currency_code;
p_cust_site_prof_amt_rec.overall_credit_limit :=
p_site_prof_overal_credit_limt;
p_cust_site_prof_amt_rec.trx_credit_limit :=
p_site_prof_trx_credit_limit;
p_cust_site_prof_amt_rec.created_by_module := 'TCA_V2_API';

hz_customer_profile_v2pub.create_cust_profile_amt('T',
'T',
p_cust_site_prof_amt_rec,
x_cust_acct_profile_amt_id,
x_return_status,
x_msg_count,
x_msg_data);
IF x_msg_count > 0

THEN

l_error_message := l_error_message || ',' || x_msg_count || ' : ' ||


'x_msg_data = ' || SUBSTR(x_msg_data, 1, 255);

raise_application_error(-20101, l_error_message);

END IF;

END;

END IF;

IF p_validate_or_process_entry = 'VALIDATE'

THEN

ROLLBACK;

ELSIF p_validate_or_process_entry = 'PROCESS'

THEN

COMMIT;

END IF;

END cust_vaildate_upload_data;

END cust_adi_customer_v3_pkg;
/

Potrebbero piacerti anche