Sei sulla pagina 1di 5

CREATE OR REPLACE PACKAGE BODY APPS.

XX_SUPPLIER_CREATE_PKG1 AS
PROCEDURE XX_SUPPLIER_CREATE_PROC1(ERRBUF OUT VARCHAR2,RETCODE OUT NUMBER) IS
l_vendor_rec AP_VENDOR_PUB_PKG.r_vendor_rec_type;
l_vendor_site_rec AP_VENDOR_PUB_PKG.r_vendor_site_rec_type;
x_return_status VARCHAR2(2000);
x_msg_count NUMBER;
x_msg_data VARCHAR2(2000);
l_upd number := 0;
x_vendor_id number;
x_party_id number;
x_vendor_site_id number;
x_party_site_id number;
x_location_id number;
l_party_site_id number;
l_organization_id number;
--============================================================================
================================
l_country_code VARCHAR2(20);
l_error_flag varchar2(1):='N';
l_error_mesg varchar2(2000);
l_concat_error_mesg varchar2(4000);
l_rec_count number :=0;
l_rec_cnt_success number:=0;
l_rec_cnt_failed number:=0;
VENDOR_NAME varchar2(240);
l_ship_to_location_code VARCHAR2(255);
l_bill_to_location_code VARCHAR2(255);
l_terms_disp VARCHAR2(255);
l_country_of_origin_code VARCHAR2(255);
SUMMARY_FLAG varchar2(10);
ENABLED_FLAG varchar2(10);
vat_registration_num varchar2(100);
invoice_currency_code varchar2(100);
vendor_id varchar2(100);
L_PAYMENT_TERMS NUMBER;
L_INVOICE_CURRENCY VARCHAR2(3);
cursor c1 is select * from XX_SUPPLIER_STG where STATUS_CODE='N';
begin
FOR C_REC in c1 loop
L_ERROR_FLAG :='N';
L_ERROR_MESG := NULL;
L_CONCAT_ERROR_MESG := NULL;
-- L_PAYMENT_TERMS := NULL;
L_INVOICE_CURRENCY := NULL;
l_country_code :=NULL;
l_rec_count:=l_rec_count+1;
-- =====================================================
-- CURRENCY VALIDATION STARTS --
-- =====================================================
FND_FILE.PUT_LINE ( fnd_file.LOG,'Currency Validation - Starts ');
BEGIN
SELECT CURRENCY_CODE
INTO L_INVOICE_CURRENCY
FROM FND_CURRENCIES
WHERE UPPER(CURRENCY_CODE)=UPPER(TRIM(C_REC.INVOICE_CURRENCY))
AND ENABLED_FLAG='Y';
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg:='Currency not Defined';
l_concat_error_mesg:=l_concat_error_mesg ||l_error_mesg;
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_error_flag:='Y';
WHEN OTHERS
THEN
l_error_mesg:= SUBSTR(SQLERRM,1,255);
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_concat_error_mesg:=l_concat_error_mesg||'~'||l_error_mesg;
l_error_flag:='Y';
END;
FND_FILE.PUT_LINE(FND_FILE.LOG,'Currency is '||L_INVOICE_CURRENCY);
FND_FILE.PUT_LINE ( fnd_file.LOG,'Currency is '||L_INVOICE_CURRENCY);
FND_FILE.PUT_LINE ( fnd_file.LOG,'Currency Validation - Ends ');
-- =====================================================
-- CURRENCY VALIDATION ENDS --
-- =====================================================
-- =====================================================
-- PAYMENT TERMS VALIDATION STARTS --
-- =====================================================
FND_FILE.PUT_LINE ( fnd_file.LOG,'PAYMENT Validation - Starts ');
IF C_REC.PAYMENT_TERMS IS NOT NULL THEN
BEGIN
SELECT ap_terms.term_id
INTO L_PAYMENT_TERMS
FROM ap_terms
WHERE UPPER(ap_terms.NAME)=UPPER(TRIM(C_REC.PAYMENT_TERMS))
AND ENABLED_FLAG='Y';
EXCEPTION
WHEN NO_DATA_FOUND
THEN
L_PAYMENT_TERMS:=10001;
l_error_mesg:='PAYMENT not Defined';
l_concat_error_mesg:=l_concat_error_mesg ||l_error_mesg;
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_error_flag:='Y';

WHEN OTHERS
THEN
L_PAYMENT_TERMS:=10001;
l_error_mesg:= SUBSTR(SQLERRM,1,255);
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_concat_error_mesg:=l_concat_error_mesg||'~'||l_error_mesg;
l_error_flag:='Y';
END;
FND_FILE.PUT_LINE(FND_FILE.LOG,'PAYMENT is '||L_PAYMENT_TERMS);
FND_FILE.PUT_LINE ( fnd_file.LOG,'PAYMENT is '||L_PAYMENT_TERMS);
FND_FILE.PUT_LINE ( fnd_file.LOG,'PAYMENT Validation - Ends ');
END IF;
-- =====================================================
-- PAYMENT TERMS VALIDATION ENDS --
-- =====================================================
--country validation
--================================================================
FND_FILE.PUT_LINE ( fnd_file.LOG,'country Validation - Starts ');
begin
select LOOKUP_CODE
into l_country_code
from fnd_lookup_values where lookup_type='GHR_US_CNTRY_WRLD_CTZN'
and meaning=trim(C_REC.COUNTRY)
AND ENABLED_FLAG='Y';
EXCEPTION
WHEN NO_DATA_FOUND
THEN
l_error_mesg:='PAYMENT not Defined';
l_concat_error_mesg:=l_concat_error_mesg ||l_error_mesg;
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_error_flag:='Y';
WHEN OTHERS
THEN
l_error_mesg:= SUBSTR(SQLERRM,1,255);
FND_FILE.PUT_LINE ( fnd_file.LOG,l_error_mesg);
l_concat_error_mesg:=l_concat_error_mesg||'~'||l_error_mesg;
l_error_flag:='Y';
end;
FND_FILE.PUT_LINE(FND_FILE.LOG,'country is '||l_country_code);
FND_FILE.PUT_LINE ( fnd_file.LOG,'country is '||l_country_code);
FND_FILE.PUT_LINE ( fnd_file.LOG,'country Validation - Ends ');
--==========================================================================
================
BEGIN
IF l_error_flag ='N' THEN
l_vendor_rec.VENDOR_NAME := trim(C_REC.supplier_name);
l_vendor_rec.SUMMARY_FLAG := 'N';
l_vendor_rec.ENABLED_FLAG := 'Y';
l_vendor_rec.invoice_currency_code:=TRIM(L_INVOICE_CURRENCY);
--l_vendor_rec.TERMS_ID:=10001;--TRIM(nvl(L_PAYMENT_TERMS,10001));
IF C_REC.PAYMENT_TERMS IS NOT NULL THEN
l_vendor_rec.TERMS_ID:=L_PAYMENT_TERMS;--TRIM(nvl(L_PAYMENT_TERMS,1000
1));
ELSE
l_vendor_rec.TERMS_ID:=10001;
END IF;
if C_REC.ALIAS is not null then
l_vendor_rec.VENDOR_NAME_ALT := TRIM(C_REC.ALIAS );
end if;

FND_FILE.PUT_LINE ( fnd_file.LOG,'STARTING API');

AP_VENDOR_PUB_PKG.Create_Vendor
( p_api_version => 1,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data,
p_vendor_rec => l_vendor_rec,
x_vendor_id => x_vendor_id,
x_party_id => x_party_id
);
if (x_return_status <> 'S') then
FND_FILE.PUT_LINE(FND_FILE.LOG,'Encountered ERROR in supplie
r creation!!!');
FND_FILE.PUT_LINE(FND_FILE.LOG,SQLCODE||' '||SQLERRM);
FND_FILE.PUT_LINE(FND_FILE.LOG,'----------------------------
----------');
FND_FILE.PUT_LINE(FND_FILE.LOG,x_msg_data);
IF x_msg_count > 1 THEN
FOR i IN 1..x_msg_count LOOP
FND_FILE.PUT_LINE(FND_FILE.LOG,substr(FND_MSG_PUB.G
et( p_encoded => FND_API.G_FALSE ),1,255));
END LOOP;
END IF;
else
FND_FILE.PUT_LINE ( fnd_file.LOG,'SUPPLIER CREATED SUCCESSFULLY AND
VENDOR ID IS '||x_vendor_id);
l_vendor_site_rec.vendor_id := x_vendor_id;
l_vendor_site_rec.org_id :=187;
l_vendor_site_rec.PURCHASING_SITE_FLAG := 'Y';
l_vendor_site_rec.PAY_SITE_FLAG := 'Y';
l_vendor_site_rec.city :=TRIM(C_REC.CITY);
l_vendor_site_rec.state := TRIM(C_REC.STATE);
l_vendor_site_rec.zip :=TRIM(C_REC.POSTAL_CODE);
l_vendor_site_rec.country:=l_country_code;
l_vendor_site_rec.county:=TRIM(C_REC.COUNTY);
l_vendor_site_rec.address_line1:=TRIM(C_REC.ADDRESS_LINE1);
l_vendor_site_rec.vendor_site_code:=upper(TRIM(substr(C_REC.ADDRESS_
NAME,1,15)));
l_vendor_site_rec.country_of_origin_code:=l_country_code;
if C_REC.tax_registration_number is not null then
l_vendor_site_rec.vat_registration_num:=trim(C_REC.tax_registrati
on_number);
end if;

AP_VENDOR_PUB_PKG.Create_Vendor_Site
( p_api_version => 1,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data,
p_vendor_site_rec => l_vendor_site_rec,
x_vendor_site_id => x_vendor_site_id,
x_party_site_id => x_party_site_id,
x_location_id => x_location_id
);
FND_FILE.PUT_LINE ( fnd_file.LOG,'API ENDS ');
if (x_return_status <> 'S') then
l_rec_cnt_failed:=l_rec_cnt_failed+1;
FND_FILE.PUT_LINE(FND_FILE.LOG,'Encountered ERROR in supplie
r site creation!!!');
FND_FILE.PUT_LINE(FND_FILE.LOG,SQLCODE||' '||SQLERRM);
FND_FILE.PUT_LINE(FND_FILE.LOG,'-----------------------------
---------');
FND_FILE.PUT_LINE(FND_FILE.LOG,x_msg_data);
IF x_msg_count > 1 THEN
FOR i IN 1..x_msg_count LOOP
dbms_output.put_line(substr(FND_MSG_PUB.
Get( p_encoded => FND_API.G_FALSE ),1,255));
END LOOP;
END IF;
ELSE
l_rec_cnt_success:=l_rec_cnt_success+1;
FND_FILE.PUT_LINE(FND_FILE.LOG,'Supplier Site Created!!!
and x_vendor_site_id is'||x_vendor_site_id);
end if;
end if;
UPDATE XX_SUPPLIER_STG SET STATUS_CODE='R'where supplier_name=c_rec.
supplier_name;
ELSE
FND_FILE.PUT_LINE ( fnd_file.LOG,'ERROR FLAG IS '||l_error_flag ||' '|| l
_concat_error_mesg);
UPDATE XX_SUPPLIER_STG SET STATUS_CODE='E'where supplier_name=c_rec.suppl
ier_name;
END IF;
END;
END LOOP;
FND_FILE.PUT_LINE(FND_FILE.LOG,'Total Record Count Is '||l_rec_count);
FND_FILE.PUT_LINE(FND_FILE.LOG,' No of Records Read '||l_rec
_count);
FND_FILE.PUT_LINE(FND_FILE.LOG,' No of Records Successfully Completed '||l_rec
_cnt_success);
FND_FILE.PUT_LINE(FND_FILE.LOG, 'No of Records Errored Out '||l_rec
_cnt_failed);
END XX_SUPPLIER_CREATE_PROC1;
END XX_SUPPLIER_CREATE_PKG1;
/