CREATE OR REPLACE PROCEDURE APPS.Xx_customer_api_723 (
Retcode OUT VARCHAR2
,Errorbuf OUT VARCHAR2
)
AS
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;
X_cust_account_id NUMBER;
X_account_number VARCHAR2 (2000);
P_party_usage_code VARCHAR2 (240);
X_party_id NUMBER;
X_party_number VARCHAR2 (2000);
X_profile_id NUMBER;
P_location_rec Hz_location_v2pub.Location_rec_type;
X_location_id NUMBER;
P_party_site_rec Hz_party_site_v2pub.Party_site_rec_type;
X_party_site_id NUMBER;
X_party_site_number VARCHAR2 (2000);
P_cust_acct_site_rec Hz_cust_account_site_v2pub.Cust_acct_site_rec_type;
X_cust_acct_site_id NUMBER;
P_cust_site_use_rec Hz_cust_account_site_v2pub.Cust_site_use_rec_type;
X_site_use_id NUMBER;
P_contact_point_rec Hz_contact_point_v2pub.Contact_point_rec_type;
P_phone_rec Hz_contact_point_v2pub.Phone_rec_type;
P_edi_rec_type Hz_contact_point_v2pub.Edi_rec_type;
P_email_rec_type Hz_contact_point_v2pub.Email_rec_type;
P_telex_rec_type Hz_contact_point_v2pub.Telex_rec_type;
P_web_rec_type Hz_contact_point_v2pub.Web_rec_type;
L_bill VARCHAR2 (240);
L_ship VARCHAR2 (240);
L_country VARCHAR2 (240);
X_contact_point_id NUMBER;
X_return_status VARCHAR2 (2000);
L_party VARCHAR2 (240);
L_salesrep_id NUMBER := NULL;
X_api_error VARCHAR2 (4000);
X_msg_count NUMBER;
X_msg_data VARCHAR2 (2000);
P_init_msg_list VARCHAR2 (200);
L_user_id NUMBER := 1318;
--Fnd_global.User_id;
--1318,50559,222
L_resp_id NUMBER := 50559;
--Fnd_global.Resp_id;
L_appl_id NUMBER := 222;
--Fnd_global.Resp_appl_id;
L_error_details VARCHAR2 (4000) := NULL;
L_error_flag VARCHAR2 (2000) := NULL;
L_total_count NUMBER := 0;
L_total_count1 NUMBER := 0;
L_success_count NUMBER := 0;
L_failure_count NUMBER := 0;
V_customer_name NUMBER;
V_customer_name1 NUMBER;
V_profile_id NUMBER;
V_currecy_code VARCHAR2 (50);
V_address NUMBER;
V_phone_number NUMBER;
V_master NUMBER;
v_party_site number;
CURSOR C1
IS
SELECT *
FROM Xx_master_723;
CURSOR C2 (Cust_name VARCHAR2)
IS
SELECT *
FROM Xx_address_723;
BEGIN
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
FOR I IN C1
LOOP
L_error_details := NULL;
L_error_flag := NULL;
L_total_count := L_total_count + 1;
L_error_details := NULL;
BEGIN
SELECT COUNT(*)
INTO V_MASTER
FROM XX_address_723
where A_CUSTOMER_NAME = i.customer_name;
END;
BEGIN
SELECT COUNT (*)
INTO V_customer_name
FROM Hz_parties Hp, Hz_cust_accounts_all Hca
WHERE Hp.Party_id = Hca.Party_id AND Hp.Party_name = I.Customer_name;
IF V_customer_name > 0
THEN
GOTO Second_loop;
ELSE
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'customer Error'
|| ' \ '
|| SUBSTR (SQLERRM, 1, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name);
END;
BEGIN
SELECT Profile_class_id
INTO V_profile_id
FROM Hz_cust_profile_classes
WHERE NAME = I.Profile_class;
IF V_profile_id = 0
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'PROFILE ID ERROR'
|| ' \ '
|| SUBSTR (SQLERRM, 2, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name);
END;
BEGIN
SELECT Currency_code
INTO V_currecy_code
FROM Fnd_currencies
WHERE Currency_code = I.Currency_code AND Enabled_flag = 'Y';
IF V_currecy_code <> 'USD'
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'CURRENCY CODE ERROR'
|| ' \ '
|| SUBSTR (SQLERRM, 3, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name);
END;
--create the customer organization--
IF I.Customer_name IS NOT NULL AND V_customer_name = 0
THEN
BEGIN
X_party_id := NULL;
X_msg_data := NULL;
X_msg_count := NULL;
P_init_msg_list := 'T';
-- p_party_usage_code := 'Organization';
P_organization_rec.Organization_name := I.Customer_name;
-- p_organization_rec.organization_TYPE := 'External';
P_organization_rec.Created_by_module := I.Created_by_module;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
Hz_party_v2pub.Create_organization (P_init_msg_list
,P_organization_rec
,P_party_usage_code
,X_return_status
,X_msg_count
,X_msg_data
,X_party_id
,X_party_number
,X_profile_id
);
DBMS_OUTPUT.Put_line ('***************************');
DBMS_OUTPUT.Put_line ('Output information ....');
DBMS_OUTPUT.Put_line ('x_party_id: ' || X_party_id);
DBMS_OUTPUT.Put_line ('x_party_number: ' || X_party_number);
DBMS_OUTPUT.Put_line ('x_profile_id: ' || X_profile_id);
DBMS_OUTPUT.Put_line ('x_return_status: ' || X_return_status);
DBMS_OUTPUT.Put_line ('x_msg_count: ' || X_msg_count);
DBMS_OUTPUT.Put_line ('x_msg_data: ' || X_msg_data);
DBMS_OUTPUT.Put_line ('***************************');
--FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Failure Records Count : '||l_failure_count);
Fnd_file.Put_line (Fnd_file.Output, 'x_party_id: ' || X_party_id);
Fnd_file.Put_line (Fnd_file.Output
, 'x_party_number: ' || X_party_number
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_profile_id: ' || X_profile_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_return_status: ' || X_return_status
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_count: ' || X_msg_count);
Fnd_file.Put_line (Fnd_file.Output, 'x_msg_data: ' || X_msg_data);
Fnd_file.Put_line (Fnd_file.Output, '***************************');
-- commit;
-- dbms_output.put_line(x_party_id);
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details || X_api_error || 'CUSTOMER PARTY API ';
ELSE
L_error_details := X_api_error || 'CUSTOMER PARTY API ';
END IF;
END;
END IF;
--create the customer accounts --
IF I.Account_number IS NULL
THEN
BEGIN
X_msg_data := NULL;
X_api_error := NULL;
P_cust_account_rec.Account_name := I.Account_name;
-- p_cust_account_rec.account_number := I.ACCOUNT_NUMBER;
P_cust_account_rec.Customer_type := 'R';
--P_cust_account_rec.Primary_salesrep_id := L_salesrep_id;
-- P_cust_account_rec.Fob_point := I.Fob;
--P_cust_account_rec.Warehouse_id := I.Warehouse;
--P_cust_account_rec.Freight_term := I.Freight_terms;
P_cust_account_rec.Created_by_module := I.Created_by_module;
P_organization_rec.Party_rec.Party_id := X_party_id;
P_organization_rec.Created_by_module := I.Created_by_module;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
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 ('***************************');
DBMS_OUTPUT.Put_line ('Output information ....');
DBMS_OUTPUT.Put_line ('x_cust_account_id: ' || X_cust_account_id);
DBMS_OUTPUT.Put_line ('x_account_number: ' || X_account_number);
DBMS_OUTPUT.Put_line ('x_party_id: ' || X_party_id);
DBMS_OUTPUT.Put_line ('x_party_number: ' || X_party_number);
DBMS_OUTPUT.Put_line ('x_profile_id: ' || X_profile_id);
DBMS_OUTPUT.Put_line ('x_return_status: ' || X_return_status);
DBMS_OUTPUT.Put_line ('x_msg_count: ' || X_msg_count);
DBMS_OUTPUT.Put_line ('x_msg_data: ' || X_msg_data);
DBMS_OUTPUT.Put_line ('***************************');
Fnd_file.Put_line (Fnd_file.Output
, 'x_cust_account_id: ' || X_cust_account_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_account_number: ' || X_account_number
);
Fnd_file.Put_line (Fnd_file.Output, 'x_party_id: ' || X_party_id);
Fnd_file.Put_line (Fnd_file.Output
, 'x_party_number: ' || X_party_number
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_profile_id: ' || X_profile_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_return_status: ' || X_return_status
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_count: ' || X_msg_count);
Fnd_file.Put_line (Fnd_file.Output, 'x_msg_data: ' || X_msg_data);
Fnd_file.Put_line (Fnd_file.Output, '***************************');
-- dbms_output.put_line(x_cust_account_id);
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details || X_api_error || 'CUSTOMER ACCOUNT API ';
ELSE
L_error_details := X_api_error || 'CUSTOMER ACCOUNT API ';
END IF;
END;
END IF;
<<Second_loop>>
FOR J IN C2 (I.Customer_name)
LOOP
L_total_count1 := L_total_count + 1;
BEGIN
-- SELECT COUNT (*)
-- INTO V_customer_name1
-- FROM Hz_parties Hp, Hz_cust_accounts_all Hca
-- WHERE Hp.Party_id = Hca.Party_id AND Hp.Party_name = I.Customer_name;
IF V_customer_name > V_master
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'customer Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 4, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name1);
END;
BEGIN
SELECT COUNT (*)
INTO V_address
FROM Hz_locations
WHERE Address1 = J.A_address_line1;
IF V_address > 0
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'address Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 5, 100);
END IF;
END;
begin
SELECT COUNT (*)
into v_party_site
FROM Hz_locations Hl, Hz_parties Hp
WHERE Hp.Party_name = i.customer_name
AND Hl.Address1 = j.A_ADDRESS_LINE1;
if v_party_site > 0
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'party_site Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 6, 100);
END IF;
END;
BEGIN
select
count(*)
into V_PHONE_NUMBER
from
hz_contact_points hcp,
hz_parties hp
where
hcp.OWNER_TABLE_ID=hp.PARTY_ID
and hp.party_name=i.customer_name
and hcp.PHONE_NUMBER=j.C_TELEPHONE_NUM;
IF V_PHONE_NUMBER > 0
then
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'PHONE NUMBER Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 6, 100);
END IF;
end;
---create the customer location --
IF J.A_address_line1 IS NOT NULL AND V_address = 0
THEN
--IF I.CUSTOMER_COUNTRY IS NOT NULL THEN
BEGIN
X_msg_data := NULL;
X_api_error := NULL;
X_msg_count := NULL;
P_location_rec.Country := J.A_country;
P_location_rec.Address1 := J.A_address_line1;
-- P_LOCATION_REC.ADDRESS2 := I.ADDRESS2;
--P_LOCATION_REC.ADDRESS3 := I.ADDRESS3;
--P_location_rec.City := I.City;
--P_location_rec.Postal_code := I.Postal_code;
P_location_rec.Created_by_module := I.Created_by_module;
P_init_msg_list := 'T';
--P_location_rec.State := I.State;
--P_location_rec.County := NULL;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
Hz_location_v2pub.Create_location (P_init_msg_list
,P_location_rec
,X_location_id
,X_return_status
,X_msg_count
,X_msg_data
);
DBMS_OUTPUT.Put_line ('***************************');
DBMS_OUTPUT.Put_line ('Output information ....');
DBMS_OUTPUT.Put_line ('x_location_id: ' || X_location_id);
DBMS_OUTPUT.Put_line ('x_return_status: ' || X_return_status);
DBMS_OUTPUT.Put_line ('x_msg_count: ' || X_msg_count);
DBMS_OUTPUT.Put_line ('x_msg_data: ' || X_msg_data);
DBMS_OUTPUT.Put_line ('***************************');
Fnd_file.Put_line (Fnd_file.Output, 'Output information ....');
Fnd_file.Put_line (Fnd_file.Output
, 'x_location_id: ' || X_location_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_return_status: ' || X_return_status
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_count: ' || X_msg_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_data: ' || X_msg_data
);
Fnd_file.Put_line (Fnd_file.Output
,'***************************'
);
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details || X_api_error
|| 'CUSTOMER LOCATION API ';
ELSE
L_error_details := X_api_error || 'CUSTOMER LOCATION API ';
END IF;
END;
END IF;
IF X_location_id IS NOT NULL and v_party_site = 0
THEN
BEGIN
X_msg_data := NULL;
X_api_error := NULL;
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 :=I.Identifying_address;
P_party_site_rec.Created_by_module := i.created_by_module;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
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('***************************');
dbms_output.put_line('Output information ....');
dbms_output.put_line('x_party_site_id: '||x_party_site_id);
dbms_output.put_line('x_party_site_number: '||x_party_site_number);
dbms_output.put_line('x_return_status: '||x_return_status);
dbms_output.put_line('x_msg_count: '||x_msg_count);
dbms_output.put_line('x_msg_data: '||x_msg_data);
dbms_output.put_line('***************************');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_party_site_id: '||x_party_site_id);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_party_site_number: '||x_party_site_number);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_return_status: '||x_return_status);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_msg_count: '||x_msg_count);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_msg_data: '||x_msg_data);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'***************************');
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details
|| X_api_error
|| 'CUSTOMER PARTY SITE API ';
ELSE
L_error_details :=
X_api_error || 'CUSTOMER PARTY SITE API ';
END IF;
END;
END IF;
-- IF X_cust_acct_site_id IS NOT NULL
-- THEN
-- BEGIN
-- X_msg_data := NULL;
-- X_api_error := NULL;
-- P_cust_site_use_rec.Cust_acct_site_id :=
-- X_cust_acct_site_id;
-- p_cust_site_use_rec.site_use_code := j.B_BUSINESS_PURPOSE;
-- P_cust_site_use_rec.Created_by_module :=
-- i.created_by_module;
-- 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('***************************');
-- dbms_output.put_line('Output information ....');
-- dbms_output.put_line('x_site_use_id: '||x_site_use_id);
-- dbms_output.put_line('x_return_status: '||x_return_status);
-- dbms_output.put_line('x_msg_count: '||x_msg_count);
-- dbms_output.put_line('x_msg_data: '||x_msg_count);
-- dbms_output.put_line('***************************');
-- IF X_msg_count > 1
-- THEN
-- FOR I IN 1 .. X_msg_count
-- LOOP
-- X_api_error :=
-- ( I
-- || '. '
-- || SUBSTR
-- (Fnd_msg_pub.Get
-- (P_encoded => Fnd_api.G_false)
-- ,1
-- ,255
-- )
-- );
-- END LOOP;
-- ELSIF X_msg_count = 1
-- THEN
-- X_api_error := X_msg_data;
-- END IF;
-- IF X_api_error IS NOT NULL
-- THEN
-- IF L_error_details IS NOT NULL
-- AND X_api_error IS NOT NULL
-- THEN
-- L_error_details :=
-- L_error_details
-- || X_api_error
-- || 'CUSTOMER ACCOUNT SITE USE API2 ';
-- ELSE
-- L_error_details :=
-- X_api_error || 'CUSTOMER ACCOUNT SITE USE API2 ';
-- END IF;
-- END IF;
-- END;
-- end if;
IF j.C_TELEPHONE_NUM IS NOT NULL and V_PHONE_NUMBER =0
THEN
BEGIN
X_api_error := NULL;
X_msg_data := NULL;
P_contact_point_rec.Contact_point_type := j.CONTACT_POINT_TYPE;
P_contact_point_rec.Owner_table_name := 'HZ_PARTIES';
P_contact_point_rec.Owner_table_id := X_party_id;
--<value for party_id from step 8>
P_contact_point_rec.Created_by_module :=
i.created_by_module;
P_phone_rec.Phone_number :=j.C_TELEPHONE_NUM;
--p_phone_rec.Phone_EXTENSION := I.PHONE_EXTENSION;
p_phone_rec.Phone_AREA_CODE := j.C_AREA_CODE;
P_phone_rec.Phone_line_type :=j.PHONE_LINE_TYPE;
Hz_contact_point_v2pub.Create_contact_point
('T'
,P_contact_point_rec
,P_edi_rec_type
,P_email_rec_type
,P_phone_rec
,P_telex_rec_type
,P_web_rec_type
,X_contact_point_id
,X_return_status
,X_msg_count
,X_msg_data
);
dbms_output.put_line('***************************');
dbms_output.put_line('Output information ....');
dbms_output.put_line('X_contact_point_id: '||X_contact_point_id);
dbms_output.put_line('x_return_status: '||x_return_status);
dbms_output.put_line('x_msg_count: '||x_msg_count);
dbms_output.put_line('x_msg_data: '||x_msg_count);
dbms_output.put_line('***************************');
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF X_api_error IS NOT NULL
THEN
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details
|| X_api_error
|| 'COMMUNICATION API PHONE';
ELSE
L_error_details :=
X_api_error || 'COMMUNICATION API PHONE ';
END IF;
END IF;
END;
END IF;
END LOOP;
END LOOP;
Fnd_file.Put_line (Fnd_file.LOG
, 'Successful Records Count : ' || L_success_count
);
Fnd_file.Put_line (Fnd_file.LOG
, 'Failure Records Count : ' || L_failure_count
);
Fnd_file.Put_line (Fnd_file.LOG, 'Total Records Count : ' || L_total_count);
Fnd_file.Put_line (Fnd_file.Output
, 'Successful Records Count : ' || L_success_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'Failure Records Count : ' || L_failure_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'Total Records Count : ' || L_total_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'Total Records Count : ' || L_total_count1
);
EXCEPTION
WHEN OTHERS
THEN
Fnd_file.Put_line (Fnd_file.LOG, 'Error : ' || L_error_details);
COMMIT;
END;
/
Retcode OUT VARCHAR2
,Errorbuf OUT VARCHAR2
)
AS
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;
X_cust_account_id NUMBER;
X_account_number VARCHAR2 (2000);
P_party_usage_code VARCHAR2 (240);
X_party_id NUMBER;
X_party_number VARCHAR2 (2000);
X_profile_id NUMBER;
P_location_rec Hz_location_v2pub.Location_rec_type;
X_location_id NUMBER;
P_party_site_rec Hz_party_site_v2pub.Party_site_rec_type;
X_party_site_id NUMBER;
X_party_site_number VARCHAR2 (2000);
P_cust_acct_site_rec Hz_cust_account_site_v2pub.Cust_acct_site_rec_type;
X_cust_acct_site_id NUMBER;
P_cust_site_use_rec Hz_cust_account_site_v2pub.Cust_site_use_rec_type;
X_site_use_id NUMBER;
P_contact_point_rec Hz_contact_point_v2pub.Contact_point_rec_type;
P_phone_rec Hz_contact_point_v2pub.Phone_rec_type;
P_edi_rec_type Hz_contact_point_v2pub.Edi_rec_type;
P_email_rec_type Hz_contact_point_v2pub.Email_rec_type;
P_telex_rec_type Hz_contact_point_v2pub.Telex_rec_type;
P_web_rec_type Hz_contact_point_v2pub.Web_rec_type;
L_bill VARCHAR2 (240);
L_ship VARCHAR2 (240);
L_country VARCHAR2 (240);
X_contact_point_id NUMBER;
X_return_status VARCHAR2 (2000);
L_party VARCHAR2 (240);
L_salesrep_id NUMBER := NULL;
X_api_error VARCHAR2 (4000);
X_msg_count NUMBER;
X_msg_data VARCHAR2 (2000);
P_init_msg_list VARCHAR2 (200);
L_user_id NUMBER := 1318;
--Fnd_global.User_id;
--1318,50559,222
L_resp_id NUMBER := 50559;
--Fnd_global.Resp_id;
L_appl_id NUMBER := 222;
--Fnd_global.Resp_appl_id;
L_error_details VARCHAR2 (4000) := NULL;
L_error_flag VARCHAR2 (2000) := NULL;
L_total_count NUMBER := 0;
L_total_count1 NUMBER := 0;
L_success_count NUMBER := 0;
L_failure_count NUMBER := 0;
V_customer_name NUMBER;
V_customer_name1 NUMBER;
V_profile_id NUMBER;
V_currecy_code VARCHAR2 (50);
V_address NUMBER;
V_phone_number NUMBER;
V_master NUMBER;
v_party_site number;
CURSOR C1
IS
SELECT *
FROM Xx_master_723;
CURSOR C2 (Cust_name VARCHAR2)
IS
SELECT *
FROM Xx_address_723;
BEGIN
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
FOR I IN C1
LOOP
L_error_details := NULL;
L_error_flag := NULL;
L_total_count := L_total_count + 1;
L_error_details := NULL;
BEGIN
SELECT COUNT(*)
INTO V_MASTER
FROM XX_address_723
where A_CUSTOMER_NAME = i.customer_name;
END;
BEGIN
SELECT COUNT (*)
INTO V_customer_name
FROM Hz_parties Hp, Hz_cust_accounts_all Hca
WHERE Hp.Party_id = Hca.Party_id AND Hp.Party_name = I.Customer_name;
IF V_customer_name > 0
THEN
GOTO Second_loop;
ELSE
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'customer Error'
|| ' \ '
|| SUBSTR (SQLERRM, 1, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name);
END;
BEGIN
SELECT Profile_class_id
INTO V_profile_id
FROM Hz_cust_profile_classes
WHERE NAME = I.Profile_class;
IF V_profile_id = 0
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'PROFILE ID ERROR'
|| ' \ '
|| SUBSTR (SQLERRM, 2, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name);
END;
BEGIN
SELECT Currency_code
INTO V_currecy_code
FROM Fnd_currencies
WHERE Currency_code = I.Currency_code AND Enabled_flag = 'Y';
IF V_currecy_code <> 'USD'
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'CURRENCY CODE ERROR'
|| ' \ '
|| SUBSTR (SQLERRM, 3, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name);
END;
--create the customer organization--
IF I.Customer_name IS NOT NULL AND V_customer_name = 0
THEN
BEGIN
X_party_id := NULL;
X_msg_data := NULL;
X_msg_count := NULL;
P_init_msg_list := 'T';
-- p_party_usage_code := 'Organization';
P_organization_rec.Organization_name := I.Customer_name;
-- p_organization_rec.organization_TYPE := 'External';
P_organization_rec.Created_by_module := I.Created_by_module;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
Hz_party_v2pub.Create_organization (P_init_msg_list
,P_organization_rec
,P_party_usage_code
,X_return_status
,X_msg_count
,X_msg_data
,X_party_id
,X_party_number
,X_profile_id
);
DBMS_OUTPUT.Put_line ('***************************');
DBMS_OUTPUT.Put_line ('Output information ....');
DBMS_OUTPUT.Put_line ('x_party_id: ' || X_party_id);
DBMS_OUTPUT.Put_line ('x_party_number: ' || X_party_number);
DBMS_OUTPUT.Put_line ('x_profile_id: ' || X_profile_id);
DBMS_OUTPUT.Put_line ('x_return_status: ' || X_return_status);
DBMS_OUTPUT.Put_line ('x_msg_count: ' || X_msg_count);
DBMS_OUTPUT.Put_line ('x_msg_data: ' || X_msg_data);
DBMS_OUTPUT.Put_line ('***************************');
--FND_FILE.PUT_LINE(FND_FILE.OUTPUT, 'Failure Records Count : '||l_failure_count);
Fnd_file.Put_line (Fnd_file.Output, 'x_party_id: ' || X_party_id);
Fnd_file.Put_line (Fnd_file.Output
, 'x_party_number: ' || X_party_number
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_profile_id: ' || X_profile_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_return_status: ' || X_return_status
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_count: ' || X_msg_count);
Fnd_file.Put_line (Fnd_file.Output, 'x_msg_data: ' || X_msg_data);
Fnd_file.Put_line (Fnd_file.Output, '***************************');
-- commit;
-- dbms_output.put_line(x_party_id);
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details || X_api_error || 'CUSTOMER PARTY API ';
ELSE
L_error_details := X_api_error || 'CUSTOMER PARTY API ';
END IF;
END;
END IF;
--create the customer accounts --
IF I.Account_number IS NULL
THEN
BEGIN
X_msg_data := NULL;
X_api_error := NULL;
P_cust_account_rec.Account_name := I.Account_name;
-- p_cust_account_rec.account_number := I.ACCOUNT_NUMBER;
P_cust_account_rec.Customer_type := 'R';
--P_cust_account_rec.Primary_salesrep_id := L_salesrep_id;
-- P_cust_account_rec.Fob_point := I.Fob;
--P_cust_account_rec.Warehouse_id := I.Warehouse;
--P_cust_account_rec.Freight_term := I.Freight_terms;
P_cust_account_rec.Created_by_module := I.Created_by_module;
P_organization_rec.Party_rec.Party_id := X_party_id;
P_organization_rec.Created_by_module := I.Created_by_module;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
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 ('***************************');
DBMS_OUTPUT.Put_line ('Output information ....');
DBMS_OUTPUT.Put_line ('x_cust_account_id: ' || X_cust_account_id);
DBMS_OUTPUT.Put_line ('x_account_number: ' || X_account_number);
DBMS_OUTPUT.Put_line ('x_party_id: ' || X_party_id);
DBMS_OUTPUT.Put_line ('x_party_number: ' || X_party_number);
DBMS_OUTPUT.Put_line ('x_profile_id: ' || X_profile_id);
DBMS_OUTPUT.Put_line ('x_return_status: ' || X_return_status);
DBMS_OUTPUT.Put_line ('x_msg_count: ' || X_msg_count);
DBMS_OUTPUT.Put_line ('x_msg_data: ' || X_msg_data);
DBMS_OUTPUT.Put_line ('***************************');
Fnd_file.Put_line (Fnd_file.Output
, 'x_cust_account_id: ' || X_cust_account_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_account_number: ' || X_account_number
);
Fnd_file.Put_line (Fnd_file.Output, 'x_party_id: ' || X_party_id);
Fnd_file.Put_line (Fnd_file.Output
, 'x_party_number: ' || X_party_number
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_profile_id: ' || X_profile_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_return_status: ' || X_return_status
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_count: ' || X_msg_count);
Fnd_file.Put_line (Fnd_file.Output, 'x_msg_data: ' || X_msg_data);
Fnd_file.Put_line (Fnd_file.Output, '***************************');
-- dbms_output.put_line(x_cust_account_id);
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details || X_api_error || 'CUSTOMER ACCOUNT API ';
ELSE
L_error_details := X_api_error || 'CUSTOMER ACCOUNT API ';
END IF;
END;
END IF;
<<Second_loop>>
FOR J IN C2 (I.Customer_name)
LOOP
L_total_count1 := L_total_count + 1;
BEGIN
-- SELECT COUNT (*)
-- INTO V_customer_name1
-- FROM Hz_parties Hp, Hz_cust_accounts_all Hca
-- WHERE Hp.Party_id = Hca.Party_id AND Hp.Party_name = I.Customer_name;
IF V_customer_name > V_master
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'customer Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 4, 100);
END IF;
--dbms_output.put_line('error_for_customer:'||V_customer_name1);
END;
BEGIN
SELECT COUNT (*)
INTO V_address
FROM Hz_locations
WHERE Address1 = J.A_address_line1;
IF V_address > 0
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'address Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 5, 100);
END IF;
END;
begin
SELECT COUNT (*)
into v_party_site
FROM Hz_locations Hl, Hz_parties Hp
WHERE Hp.Party_name = i.customer_name
AND Hl.Address1 = j.A_ADDRESS_LINE1;
if v_party_site > 0
THEN
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'party_site Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 6, 100);
END IF;
END;
BEGIN
select
count(*)
into V_PHONE_NUMBER
from
hz_contact_points hcp,
hz_parties hp
where
hcp.OWNER_TABLE_ID=hp.PARTY_ID
and hp.party_name=i.customer_name
and hcp.PHONE_NUMBER=j.C_TELEPHONE_NUM;
IF V_PHONE_NUMBER > 0
then
L_error_flag := 'Y';
L_error_details :=
L_error_details
|| ' \ '
|| 'PHONE NUMBER Error1'
|| ' \ '
|| SUBSTR (SQLERRM, 6, 100);
END IF;
end;
---create the customer location --
IF J.A_address_line1 IS NOT NULL AND V_address = 0
THEN
--IF I.CUSTOMER_COUNTRY IS NOT NULL THEN
BEGIN
X_msg_data := NULL;
X_api_error := NULL;
X_msg_count := NULL;
P_location_rec.Country := J.A_country;
P_location_rec.Address1 := J.A_address_line1;
-- P_LOCATION_REC.ADDRESS2 := I.ADDRESS2;
--P_LOCATION_REC.ADDRESS3 := I.ADDRESS3;
--P_location_rec.City := I.City;
--P_location_rec.Postal_code := I.Postal_code;
P_location_rec.Created_by_module := I.Created_by_module;
P_init_msg_list := 'T';
--P_location_rec.State := I.State;
--P_location_rec.County := NULL;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
Hz_location_v2pub.Create_location (P_init_msg_list
,P_location_rec
,X_location_id
,X_return_status
,X_msg_count
,X_msg_data
);
DBMS_OUTPUT.Put_line ('***************************');
DBMS_OUTPUT.Put_line ('Output information ....');
DBMS_OUTPUT.Put_line ('x_location_id: ' || X_location_id);
DBMS_OUTPUT.Put_line ('x_return_status: ' || X_return_status);
DBMS_OUTPUT.Put_line ('x_msg_count: ' || X_msg_count);
DBMS_OUTPUT.Put_line ('x_msg_data: ' || X_msg_data);
DBMS_OUTPUT.Put_line ('***************************');
Fnd_file.Put_line (Fnd_file.Output, 'Output information ....');
Fnd_file.Put_line (Fnd_file.Output
, 'x_location_id: ' || X_location_id
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_return_status: ' || X_return_status
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_count: ' || X_msg_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'x_msg_data: ' || X_msg_data
);
Fnd_file.Put_line (Fnd_file.Output
,'***************************'
);
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details || X_api_error
|| 'CUSTOMER LOCATION API ';
ELSE
L_error_details := X_api_error || 'CUSTOMER LOCATION API ';
END IF;
END;
END IF;
IF X_location_id IS NOT NULL and v_party_site = 0
THEN
BEGIN
X_msg_data := NULL;
X_api_error := NULL;
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 :=I.Identifying_address;
P_party_site_rec.Created_by_module := i.created_by_module;
Fnd_global.Apps_initialize (L_user_id, L_resp_id, L_appl_id);
Mo_global.Init ('AR');
Mo_global.Set_policy_context ('S', 204);
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('***************************');
dbms_output.put_line('Output information ....');
dbms_output.put_line('x_party_site_id: '||x_party_site_id);
dbms_output.put_line('x_party_site_number: '||x_party_site_number);
dbms_output.put_line('x_return_status: '||x_return_status);
dbms_output.put_line('x_msg_count: '||x_msg_count);
dbms_output.put_line('x_msg_data: '||x_msg_data);
dbms_output.put_line('***************************');
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_party_site_id: '||x_party_site_id);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_party_site_number: '||x_party_site_number);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_return_status: '||x_return_status);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_msg_count: '||x_msg_count);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'x_msg_data: '||x_msg_data);
FND_FILE.PUT_LINE(FND_FILE.OUTPUT,'***************************');
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details
|| X_api_error
|| 'CUSTOMER PARTY SITE API ';
ELSE
L_error_details :=
X_api_error || 'CUSTOMER PARTY SITE API ';
END IF;
END;
END IF;
-- IF X_cust_acct_site_id IS NOT NULL
-- THEN
-- BEGIN
-- X_msg_data := NULL;
-- X_api_error := NULL;
-- P_cust_site_use_rec.Cust_acct_site_id :=
-- X_cust_acct_site_id;
-- p_cust_site_use_rec.site_use_code := j.B_BUSINESS_PURPOSE;
-- P_cust_site_use_rec.Created_by_module :=
-- i.created_by_module;
-- 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('***************************');
-- dbms_output.put_line('Output information ....');
-- dbms_output.put_line('x_site_use_id: '||x_site_use_id);
-- dbms_output.put_line('x_return_status: '||x_return_status);
-- dbms_output.put_line('x_msg_count: '||x_msg_count);
-- dbms_output.put_line('x_msg_data: '||x_msg_count);
-- dbms_output.put_line('***************************');
-- IF X_msg_count > 1
-- THEN
-- FOR I IN 1 .. X_msg_count
-- LOOP
-- X_api_error :=
-- ( I
-- || '. '
-- || SUBSTR
-- (Fnd_msg_pub.Get
-- (P_encoded => Fnd_api.G_false)
-- ,1
-- ,255
-- )
-- );
-- END LOOP;
-- ELSIF X_msg_count = 1
-- THEN
-- X_api_error := X_msg_data;
-- END IF;
-- IF X_api_error IS NOT NULL
-- THEN
-- IF L_error_details IS NOT NULL
-- AND X_api_error IS NOT NULL
-- THEN
-- L_error_details :=
-- L_error_details
-- || X_api_error
-- || 'CUSTOMER ACCOUNT SITE USE API2 ';
-- ELSE
-- L_error_details :=
-- X_api_error || 'CUSTOMER ACCOUNT SITE USE API2 ';
-- END IF;
-- END IF;
-- END;
-- end if;
IF j.C_TELEPHONE_NUM IS NOT NULL and V_PHONE_NUMBER =0
THEN
BEGIN
X_api_error := NULL;
X_msg_data := NULL;
P_contact_point_rec.Contact_point_type := j.CONTACT_POINT_TYPE;
P_contact_point_rec.Owner_table_name := 'HZ_PARTIES';
P_contact_point_rec.Owner_table_id := X_party_id;
--<value for party_id from step 8>
P_contact_point_rec.Created_by_module :=
i.created_by_module;
P_phone_rec.Phone_number :=j.C_TELEPHONE_NUM;
--p_phone_rec.Phone_EXTENSION := I.PHONE_EXTENSION;
p_phone_rec.Phone_AREA_CODE := j.C_AREA_CODE;
P_phone_rec.Phone_line_type :=j.PHONE_LINE_TYPE;
Hz_contact_point_v2pub.Create_contact_point
('T'
,P_contact_point_rec
,P_edi_rec_type
,P_email_rec_type
,P_phone_rec
,P_telex_rec_type
,P_web_rec_type
,X_contact_point_id
,X_return_status
,X_msg_count
,X_msg_data
);
dbms_output.put_line('***************************');
dbms_output.put_line('Output information ....');
dbms_output.put_line('X_contact_point_id: '||X_contact_point_id);
dbms_output.put_line('x_return_status: '||x_return_status);
dbms_output.put_line('x_msg_count: '||x_msg_count);
dbms_output.put_line('x_msg_data: '||x_msg_count);
dbms_output.put_line('***************************');
IF X_msg_count > 1
THEN
FOR I IN 1 .. X_msg_count
LOOP
X_api_error :=
( I
|| '. '
|| SUBSTR
(Fnd_msg_pub.Get (P_encoded => Fnd_api.G_false)
,1
,255
)
);
END LOOP;
ELSIF X_msg_count = 1
THEN
X_api_error := X_msg_data;
END IF;
IF X_api_error IS NOT NULL
THEN
IF L_error_details IS NOT NULL
THEN
L_error_details :=
L_error_details
|| X_api_error
|| 'COMMUNICATION API PHONE';
ELSE
L_error_details :=
X_api_error || 'COMMUNICATION API PHONE ';
END IF;
END IF;
END;
END IF;
END LOOP;
END LOOP;
Fnd_file.Put_line (Fnd_file.LOG
, 'Successful Records Count : ' || L_success_count
);
Fnd_file.Put_line (Fnd_file.LOG
, 'Failure Records Count : ' || L_failure_count
);
Fnd_file.Put_line (Fnd_file.LOG, 'Total Records Count : ' || L_total_count);
Fnd_file.Put_line (Fnd_file.Output
, 'Successful Records Count : ' || L_success_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'Failure Records Count : ' || L_failure_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'Total Records Count : ' || L_total_count
);
Fnd_file.Put_line (Fnd_file.Output
, 'Total Records Count : ' || L_total_count1
);
EXCEPTION
WHEN OTHERS
THEN
Fnd_file.Put_line (Fnd_file.LOG, 'Error : ' || L_error_details);
COMMIT;
END;
/
No comments:
Post a Comment