You are on page 1of 7

/*Formattedon271020162:22:00PM(QP5v5.215.12089.

38647)*/
SELECTDISTINCT

hl.location_id,

hcas.CUST_ACCT_SITE_ID,
(SELECTDISTINCTsite_use_id
FROMhz_cust_site_uses_allhcsua
WHEREhcas.cust_acct_site_id=hcsua.cust_acct_site_id
ANDhcsua.site_use_code='SHIP_TO')
SHIP_site_use_id

,(SELECTDISTINCTsite_use_id
FROMhz_cust_site_uses_allhcsua
WHEREhcas.cust_acct_site_id=hcsua.cust_acct_site_id
ANDhcsua.site_use_code='BILL_TO')
BILL_site_use_id,
PartyInformation

hp.party_number"RegistryID",
hp.party_name"PartyName",
hp.party_type"PartyType",
DECODE(hp.status,'A','Active','I','Inactive',hp.status)
"PartyStatus",
hp.PRIMARY_PHONE_NUMBER"PhoneNumber",

AccountInformation

hca.account_number"AccountNumber",
DECODE(hca.status,'A','Active','I','Inactive',hca.status)
"AccountStatus",
hca.account_name"AccountDescription",
hca.customer_class_code"Classification",
DECODE(hca.customer_type,
'R','External',
'I','Internal',
hca.customer_type)
"AccountType",

SiteInformation

hps.party_site_number"CustomerSiteNumber",
DECODE(hcas.status,'A','Active','Inactive')"SiteStatus",
DECODE(hcas.bill_to_flag,
'P','Primary',
'Y','Yes',
hcas.bill_to_flag)
"BillToFlag",
DECODE(hcas.ship_to_flag,
'P','Primary',
'Y','Yes',

hcas.ship_to_flag)
"ShipToFlag",
hcas.cust_acct_site_id"CustomerAcctSiteID",

AddressInformation

hl.address1"Address1",
hl.address2"Address2",
hl.address3"Address3",
hl.address4"Address4",
hl.city"City",
hl.state"State",
hl.postal_code"ZipCode",
ter.name"Territory",

DFFInformation(specifictoclient)

hcas.attribute4"SMGKey",
hcas.attribute8"GLNKey",
hca.attribute3"CreditApprovalDate",
hca.attribute7"CreditApprovedBy",
hca.attribute4"AcctOpenedDate",
hca.attribute5"CreditCollectionStatus",
hca.attribute1"BPCSLastTrxDate",
hca.attribute2"BPCSAvgPayDays",
hca.attribute6"BPCSRCMReference",

CollectorInformation

col.name"CollectorName",

AccountProfileInformation

hcp.credit_checking"CreditCheckFlag",
hcp.credit_hold"CreditHoldFlag",
hcpa.auto_rec_min_receipt_amount"MinReceiptAmount",
hcpa.overall_credit_limit"CreditLimit",
hcpa.trx_credit_limit"OrderCreditLimit",

AttachmentFlag

NVL(
(SELECT'Y'
FROMfnd_documents_vldoc,
fnd_lobsblo,
fnd_attached_documentsatt
WHEREdoc.media_id=blo.file_id
ANDdoc.document_id=att.document_id
ANDatt.entity_name='AR_CUSTOMERS'
ANDatt.pk1_value=hca.cust_account_id
ANDROWNUM=1),
'N')
"AttachmentFlag",

PartyRelationshipFlag

NVL(
(SELECT'Y'
FROMhz_cust_acct_relate_allhzcar
WHEREhzcar.cust_account_id=hca.cust_account_id
ANDhzcar.relationship_type='ALL'
ANDROWNUM=1),
'N')
"PartyRelationshipFlag",

AccountRelationshipFlag

NVL(
(SELECT'Y'
FROMhz_cust_acct_relate_allhzcar
WHEREhzcar.cust_account_id=hca.cust_account_idANDROWNUM=
1),
'N')
"AccountRelationshipFlag",

PartyContactFlag

NVL(
(SELECT'Y'
FROMhz_partieshp2
WHERE1=1
ANDhp2.party_id=hp.party_id
AND(hp2.urlISNOTNULL
ORLENGTH(TRIM(hp.email_address))>
5
INSTR(hp2.email_address,'@')>0
ORhp2.primary_phone_purposeISNOTNULL)),
'N')
"PartyContactFlag",

AccountContactFlag

NVL(
(SELECT'Y'
FROMhz_contact_points
WHEREstatus='A'
ANDowner_table_id=
(SELECThcar.party_id
FROMhz_cust_account_roleshcar,
ar_contacts_vacv
WHEREhcar.cust_account_id=
hca.cust_account_id
ANDhcar.cust_account_role_id=
acv.contact_id
ANDhcar.cust_acct_site_idISNULLlook
foraccountlevelonly
ANDROWNUM=1addthisrowtoshow
inactivesites(i.e.withnositeid)

)
ANDROWNUM=1),
'N')
"AccountContactFlag",

SiteContactFlag

NVL(
(SELECT'Y'
FROMhz_contact_points
WHEREstatus='A'
ANDowner_table_id=
(SELECThcar.party_id
FROMhz_cust_account_roleshcar,
ar_contacts_vacv
WHEREhcar.cust_acct_site_id=
hcas.cust_acct_site_id
ANDhcar.cust_account_role_id=
acv.contact_id
ANDROWNUM=1addthisrowtoshow
inactivesites(i.e.withnositeid)
)
ANDROWNUM=1),
'N'anycontact(email,phone,fax)wouldsufficethis
condition
)
"SiteContactFlag"

,
(SELECTDISTINCTNAME
FROMhz_cust_site_uses_allsu,hr_operating_unitsop
WHERE1=1
ANDsu.cust_acct_site_id=hcas.cust_acct_site_id
ANDop.ORGANIZATION_ID=su.ORG_ID)
"OrganizationName"

FROMhz_partieshp,
hz_cust_accounts_allhca,
hz_cust_acct_sites_allhcas,
hz_party_siteshps,
hz_customer_profileshcp,
hz_locationshl,
hz_cust_profile_amtshcpa,
ar_collectorscol
WHERE1=1
ANDhp.party_id=hca.party_id
ANDhca.cust_account_id=hcas.cust_account_id

ANDhps.party_site_id=hcas.party_site_id
ANDhp.party_id=hcp.party_id
ANDhca.cust_account_id=hcp.cust_account_id
ANDhps.location_id=hl.location_id
(+)

ANDhcp.cust_account_profile_id=hcpa.cust_account_profile_id(+)
ANDcol.collector_id=hcp.collector_id
ANDhp.party_type='ORGANIZATION'onlyORGANIZATIONParty
types
ANDhp.status='A'onlyActive
Parties/Customers
andhca.account_number='20005'
ORDERBYTO_NUMBER(hp.party_number),hp.party_name,hca.account_number;

DECLARE
p_cust_site_use_rec
hz_cust_account_site_v2pub.cust_site_use_rec_type;
p_customer_profile_rec
hz_customer_profile_v2pub.customer_profile_rec_type;
x_site_use_idNUMBER;
x_return_statusVARCHAR2(2000);
x_msg_countNUMBER;
x_msg_dataVARCHAR2(2000);
l_created_by_moduleVARCHAR2(240);
l_error_messageVARCHAR2(2000);
l_msg_index_outNUMBER;
BEGIN

SELECTlookup_code
INTOl_created_by_module
FROMfnd_lookup_values
WHERElookup_type='HZ_CREATED_BY_MODULES'
ANDROWNUM=1
ANDenabled_flag='Y'
ANDNVL(end_date_active,SYSDATE)>=SYSDATE;
mo_global.init('AR');
fnd_global.apps_initialize(1523,50758,222);
mo_global.set_policy_context('S',82);

p_cust_site_use_rec.cust_acct_site_id:=1660;
p_cust_site_use_rec.site_use_code:='SHIP_TO';

p_cust_site_use_rec.created_by_module:='HZ_CPUI';
p_cust_site_use_rec.org_id:=82;
hz_cust_account_site_v2pub.create_cust_site_use(p_init_msg_list
=>fnd_api.g_true
,p_cust_site_use_rec
=>p_cust_site_use_rec
,p_customer_profile_rec
=>p_customer_profile_rec
,p_create_profile
=>fnd_api.g_false
,p_create_profile_amt
=>fnd_api.g_false
,x_site_use_id
=>x_site_use_id
,x_return_status
=>x_return_status
,x_msg_count
=>x_msg_count
,x_msg_data
=>x_msg_data
);
IFx_return_status<>fnd_api.g_ret_sts_success
THEN
FORiIN1..x_msg_count
LOOP
apps.fnd_msg_pub.get(p_msg_index=>i
,p_encoded=>
fnd_api.g_false
,p_data=>x_msg_data
,p_msg_index_out=>
l_msg_index_out
);
IFl_error_messageISNULL
THEN
l_error_message:=SUBSTR
(x_msg_data,1,250);
ELSE
l_error_message:=

l_error_message||'/'||SUBSTR(x_msg_data,1,250);
ENDIF;
ENDLOOP;
DBMS_OUTPUT.put_line('*****************************************');
DBMS_OUTPUT.put_line('APIError:'||l_error_message);
DBMS_OUTPUT.put_line('*****************************************');
ROLLBACK;
ELSE
DBMS_OUTPUT.put_line('*****************************************');
DBMS_OUTPUT.put_line('AccountSiteUseCreatedSuccessfully');
DBMS_OUTPUT.put_line('SiteUseid:'||x_site_use_id);

DBMS_OUTPUT.put_line('*****************************************');
COMMIT;
ENDIF;
EXCEPTION
WHENOTHERS
THEN
DBMS_OUTPUT.put_line('UnexpectedError'||SUBSTR(SQLERRM,1,250));
END;

You might also like