create or replace PACKAGE BODY XX_AP_EMP_TYPE_SUPP_PKG AS
PROCEDURE main(errbuf OUT VARCHAR2,
retcode OUT NUMBER,
p_emp_id IN number,
p_pay_method IN varchar2,
p_org_id IN number
) AS
CURSOR c_empdet(p_emp_id IN VARCHAR2) IS
SELECT PAPF.FULL_NAME, PAPF.PERSON_ID, PAPF.EMPLOYEE_NUMBER
FROM PER_ALL_PEOPLE_F PAPF
WHERE PAPF.BUSINESS_GROUP_ID = g_business_group_id
AND PAPF.PERSON_ID = p_emp_id;
cursor lcu_accoutdet(p_org_id In NUMBER) IS
SELECT UPPER(flv.tag) SITE_CODE, attribute2, attribute3
FROM FND_LOOKUP_VALUES FLV
where flv.lookup_type = 'XX_AP_EMP_SUP_SITE'
AND p_org_id = to_number(flv.attribute1);
cursor c_hou IS
select hou.name
from hr_operating_units hou
where hou.organization_id = p_org_id;
cursor c_vendor(v_vendor_name IN varchar2) IS
select pv.vendor_id, pv.vendor_type_lookup_code
from po_vendors pv
where UPPER(vendor_name) = UPPER(v_vendor_name);
cursor c_vensite(p_vendor_id IN NUMBER,p_org_id IN NUMBER) IS
SELECT COUNT(1)
FROM ap_supplier_sites_all
WHERE vendor_id = p_vendor_id
AND UPPER(VENDOR_SITE_CODE) IN ('HOME','OFFICE','PROVISIONAL')
AND ORG_ID = p_org_id;
l_vendor_rec ap_vendor_pub_pkg.r_vendor_rec_type;
l_vendor_site_rec ap_vendor_pub_pkg.r_vendor_site_rec_type;
ext_payee_rec IBY_DISBURSEMENT_SETUP_PUB.external_payee_rec_type;
l_return_status VARCHAR2(10);
l_msg_count NUMBER;
l_msg_data VARCHAR2(1000);
l_vendor_id NUMBER;
l_party_id NUMBER;
v_empname VARCHAR2(50);
v_empid NUMBER;
p_count number;
l_vendor_site_id NUMBER;
l_party_site_id NUMBER;
l_location_id NUMBER;
l_liability_id NUMBER;
l_prepay_id NUMBER;
v_error varchar2(1000);
v_org_name varchar2(50);
l_vendor_type_code varchar2(20);
v_employee_number varchar2(20);
ln_sup_site_cnt number;
BEGIN
v_error := 'S';
apps.fnd_file.put_line(apps.fnd_file.output,
'***************Employee Type Supplier Creation***********************');
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
OPEN c_hou;
FETCH c_hou
INTO v_org_name;
CLOSE c_hou;
apps.fnd_file.put_line(apps.fnd_file.output,
' Organization : ' || v_org_name);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
OPEN c_empdet(p_emp_id);
FETCH c_empdet
INTO v_empname, v_empid, v_employee_number;
CLOSE c_empdet;
IF v_empname IS NULL THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Employee does not exist for Employee Number#' ||
v_employee_number);
ELSE
OPEN c_vendor(v_empname);
FETCH c_vendor
INTO l_vendor_id, l_vendor_type_code;
CLOSE c_vendor;
IF l_vendor_id IS NOT NULL THEN
v_error := 'Supp_Exists';
apps.fnd_file.put_line(apps.fnd_file.output,
' Supplier Already Exists with Vendor Id#' ||
l_vendor_id || ' and Type ' ||
l_vendor_type_code);
OPEN c_vensite(l_vendor_id,p_org_id);
FETCH c_vensite INTO ln_sup_site_cnt;
CLOSE c_vensite;
IF ln_sup_site_cnt = 3 THEN
retcode := '2';
errbuf := ' Error - Supplier and Sites have already been created. ';
END IF;
END IF;
IF v_error <> 'Supp_Exists' THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Creating Employee Type Supplier for :' ||
v_empname);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
-- --------------
-- Required
-- --------------
l_vendor_rec.vendor_name := v_empname;
l_vendor_rec.VENDOR_TYPE_LOOKUP_CODE := 'EMPLOYEE';
l_vendor_rec.employee_id := v_empid;
apps.fnd_file.put_line(apps.fnd_file.output,
' Calling CREATE_VENDOR API....');
pos_vendor_pub_pkg.create_vendor( -- -------------------------
-- Input Parameters
-- -------------------------
p_vendor_rec => l_vendor_rec,
-- ----------------------------
-- Output Parameters
-- ----------------------------
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
x_vendor_id => l_vendor_id,
x_party_id => l_party_id);
IF (l_return_status <> 'S') THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Error in Creating Employee Type Supplier..');
IF (l_msg_count = 1) THEN
apps.fnd_file.put_line(apps.fnd_file.output,
'x_msg_data ' || l_msg_data);
ELSIF (l_msg_count > 1) THEN
LOOP
p_count := p_count + 1;
l_msg_data := fnd_msg_pub.get(fnd_msg_pub.g_next,
fnd_api.g_false);
IF (l_msg_data IS NULL) THEN
EXIT;
END IF;
apps.fnd_file.put_line(apps.fnd_file.output,
' Error Message' || p_count || ' ---' ||
l_msg_data);
END LOOP;
END IF;
ELSE
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
apps.fnd_file.put_line(apps.fnd_file.output,
' Successfully Cretaed Supplier with below details,');
apps.fnd_file.put_line(apps.fnd_file.output,
' Supplier Name :' || v_empname);
apps.fnd_file.put_line(apps.fnd_file.output,
' Vendor Id :' || l_vendor_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Party Id :' || l_party_id);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
apps.fnd_file.put_line(apps.fnd_file.output,
' Creating Supplier Sites...');
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
END IF;
END IF;
IF l_vendor_id IS NOT NULL AND NVL(ln_sup_site_cnt,0) <> 3 THEN
BEGIN
FOR i_rec IN lcu_accoutdet(p_org_id) LOOP
l_liability_id := f_ccid(p_org_id, i_rec.attribute2);
l_prepay_id := f_ccid(p_org_id, i_rec.attribute3);
IF l_liability_id IS NULL OR l_prepay_id IS NULL THEN
v_error := 'E';
apps.fnd_file.put_line(apps.fnd_file.output,
' Liability Account/Prepayment Account does not exists for bewlow segments,');
apps.fnd_file.put_line(apps.fnd_file.output,
' Liability Account :' ||
i_rec.attribute2);
apps.fnd_file.put_line(apps.fnd_file.output,
' Prepayment Account :' ||
i_rec.attribute3);
END IF;
IF v_error <> 'E' THEN
l_vendor_site_rec.vendor_id := l_vendor_id;
l_vendor_site_rec.vendor_site_code := i_rec.site_code;
l_vendor_site_rec.org_id := p_org_id;
l_vendor_site_rec.ACCTS_PAY_CODE_COMBINATION_ID := l_liability_id;
l_vendor_site_rec.PREPAY_CODE_COMBINATION_ID := l_prepay_id;
l_vendor_site_rec.TERMS_DATE_BASIS := 'Invoice';
ext_payee_rec.default_pmt_method := p_pay_method;
l_vendor_site_rec.ext_payee_rec.default_pmt_method:= p_pay_method;
pos_vendor_pub_pkg.create_vendor_site(
-- ------------------------------
-- Input data elements
-- ------------------------------
p_vendor_site_rec => l_vendor_site_rec,
-- ---------------------------------
-- Output data elements
-- ---------------------------------
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
x_vendor_site_id => l_vendor_site_id,
x_party_site_id => l_party_site_id,
x_location_id => l_location_id);
IF (l_return_status <> 'S') THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Error in Creating Employee Type Supplier..');
retcode := '1';
errbuf := ' Error in Supplier Site Creation-';
IF (l_msg_count = 1) THEN
apps.fnd_file.put_line(apps.fnd_file.output,
'x_msg_data ' || l_msg_data);
ELSIF (l_msg_count > 1) THEN
LOOP
p_count := p_count + 1;
l_msg_data := fnd_msg_pub.get(fnd_msg_pub.g_next,
fnd_api.g_false);
IF (l_msg_data IS NULL) THEN
EXIT;
END IF;
apps.fnd_file.put_line(apps.fnd_file.output,
' Error Message' || p_count ||
' ---' || l_msg_data);
END LOOP;
END IF;
ELSE
apps.fnd_file.put_line(apps.fnd_file.output,
' Successfully Cretaed Supplier Site with below details,');
apps.fnd_file.put_line(apps.fnd_file.output,
' Supplier Site :' ||
i_rec.site_code);
apps.fnd_file.put_line(apps.fnd_file.output,
' Vendor Site Id :' ||
l_vendor_site_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Party Site Id :' ||
l_party_site_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Location Id :' ||
l_location_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Liability Account :' ||
i_rec.attribute2);
apps.fnd_file.put_line(apps.fnd_file.output,
' Prepayment Account :' ||
i_rec.attribute3);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
END IF;
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Error - ' || SQLERRM);
END;
END IF;
END IF;
apps.fnd_file.put_line(apps.fnd_file.output,
'*************** END ***********************');
EXCEPTION
WHEN OTHERS THEN
retcode := '2';
errbuf := ' Error in Main- ' || SQLERRM;
apps.fnd_file.put_line(apps.fnd_file.output,
' Error in Main- ' || SQLERRM);
END main;
FUNCTION f_ccid(p_org_id IN NUMBER, p_segments IN VARCHAR2) RETURN NUMBER IS
v_ccid NUMBER;
BEGIN
SELECT gcc.code_combination_id
INTO v_ccid
FROM apps.gl_code_combinations_kfv gcc,
apps.hr_operating_units hou,
apps.gl_Sets_of_books sob
WHERE NVL(gcc.end_date_active, SYSDATE + 1) >= TRUNC(sysdate)
AND NVL(gcc.enabled_flag, 'N') = 'Y'
AND hou.organization_id = p_org_id
AND sob.set_of_books_id = hou.set_of_books_id
AND sob.chart_of_accounts_id = gcc.chart_of_accounts_id
AND UPPER(gcc.concatenated_segments) = UPPER(p_segments);
RETURN v_ccid;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END f_ccid;
END XX_AP_EMP_TYPE_SUPP_PKG;
PROCEDURE main(errbuf OUT VARCHAR2,
retcode OUT NUMBER,
p_emp_id IN number,
p_pay_method IN varchar2,
p_org_id IN number
) AS
CURSOR c_empdet(p_emp_id IN VARCHAR2) IS
SELECT PAPF.FULL_NAME, PAPF.PERSON_ID, PAPF.EMPLOYEE_NUMBER
FROM PER_ALL_PEOPLE_F PAPF
WHERE PAPF.BUSINESS_GROUP_ID = g_business_group_id
AND PAPF.PERSON_ID = p_emp_id;
cursor lcu_accoutdet(p_org_id In NUMBER) IS
SELECT UPPER(flv.tag) SITE_CODE, attribute2, attribute3
FROM FND_LOOKUP_VALUES FLV
where flv.lookup_type = 'XX_AP_EMP_SUP_SITE'
AND p_org_id = to_number(flv.attribute1);
cursor c_hou IS
select hou.name
from hr_operating_units hou
where hou.organization_id = p_org_id;
cursor c_vendor(v_vendor_name IN varchar2) IS
select pv.vendor_id, pv.vendor_type_lookup_code
from po_vendors pv
where UPPER(vendor_name) = UPPER(v_vendor_name);
cursor c_vensite(p_vendor_id IN NUMBER,p_org_id IN NUMBER) IS
SELECT COUNT(1)
FROM ap_supplier_sites_all
WHERE vendor_id = p_vendor_id
AND UPPER(VENDOR_SITE_CODE) IN ('HOME','OFFICE','PROVISIONAL')
AND ORG_ID = p_org_id;
l_vendor_rec ap_vendor_pub_pkg.r_vendor_rec_type;
l_vendor_site_rec ap_vendor_pub_pkg.r_vendor_site_rec_type;
ext_payee_rec IBY_DISBURSEMENT_SETUP_PUB.external_payee_rec_type;
l_return_status VARCHAR2(10);
l_msg_count NUMBER;
l_msg_data VARCHAR2(1000);
l_vendor_id NUMBER;
l_party_id NUMBER;
v_empname VARCHAR2(50);
v_empid NUMBER;
p_count number;
l_vendor_site_id NUMBER;
l_party_site_id NUMBER;
l_location_id NUMBER;
l_liability_id NUMBER;
l_prepay_id NUMBER;
v_error varchar2(1000);
v_org_name varchar2(50);
l_vendor_type_code varchar2(20);
v_employee_number varchar2(20);
ln_sup_site_cnt number;
BEGIN
v_error := 'S';
apps.fnd_file.put_line(apps.fnd_file.output,
'***************Employee Type Supplier Creation***********************');
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
OPEN c_hou;
FETCH c_hou
INTO v_org_name;
CLOSE c_hou;
apps.fnd_file.put_line(apps.fnd_file.output,
' Organization : ' || v_org_name);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
OPEN c_empdet(p_emp_id);
FETCH c_empdet
INTO v_empname, v_empid, v_employee_number;
CLOSE c_empdet;
IF v_empname IS NULL THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Employee does not exist for Employee Number#' ||
v_employee_number);
ELSE
OPEN c_vendor(v_empname);
FETCH c_vendor
INTO l_vendor_id, l_vendor_type_code;
CLOSE c_vendor;
IF l_vendor_id IS NOT NULL THEN
v_error := 'Supp_Exists';
apps.fnd_file.put_line(apps.fnd_file.output,
' Supplier Already Exists with Vendor Id#' ||
l_vendor_id || ' and Type ' ||
l_vendor_type_code);
OPEN c_vensite(l_vendor_id,p_org_id);
FETCH c_vensite INTO ln_sup_site_cnt;
CLOSE c_vensite;
IF ln_sup_site_cnt = 3 THEN
retcode := '2';
errbuf := ' Error - Supplier and Sites have already been created. ';
END IF;
END IF;
IF v_error <> 'Supp_Exists' THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Creating Employee Type Supplier for :' ||
v_empname);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
-- --------------
-- Required
-- --------------
l_vendor_rec.vendor_name := v_empname;
l_vendor_rec.VENDOR_TYPE_LOOKUP_CODE := 'EMPLOYEE';
l_vendor_rec.employee_id := v_empid;
apps.fnd_file.put_line(apps.fnd_file.output,
' Calling CREATE_VENDOR API....');
pos_vendor_pub_pkg.create_vendor( -- -------------------------
-- Input Parameters
-- -------------------------
p_vendor_rec => l_vendor_rec,
-- ----------------------------
-- Output Parameters
-- ----------------------------
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
x_vendor_id => l_vendor_id,
x_party_id => l_party_id);
IF (l_return_status <> 'S') THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Error in Creating Employee Type Supplier..');
IF (l_msg_count = 1) THEN
apps.fnd_file.put_line(apps.fnd_file.output,
'x_msg_data ' || l_msg_data);
ELSIF (l_msg_count > 1) THEN
LOOP
p_count := p_count + 1;
l_msg_data := fnd_msg_pub.get(fnd_msg_pub.g_next,
fnd_api.g_false);
IF (l_msg_data IS NULL) THEN
EXIT;
END IF;
apps.fnd_file.put_line(apps.fnd_file.output,
' Error Message' || p_count || ' ---' ||
l_msg_data);
END LOOP;
END IF;
ELSE
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
apps.fnd_file.put_line(apps.fnd_file.output,
' Successfully Cretaed Supplier with below details,');
apps.fnd_file.put_line(apps.fnd_file.output,
' Supplier Name :' || v_empname);
apps.fnd_file.put_line(apps.fnd_file.output,
' Vendor Id :' || l_vendor_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Party Id :' || l_party_id);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
apps.fnd_file.put_line(apps.fnd_file.output,
' Creating Supplier Sites...');
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
END IF;
END IF;
IF l_vendor_id IS NOT NULL AND NVL(ln_sup_site_cnt,0) <> 3 THEN
BEGIN
FOR i_rec IN lcu_accoutdet(p_org_id) LOOP
l_liability_id := f_ccid(p_org_id, i_rec.attribute2);
l_prepay_id := f_ccid(p_org_id, i_rec.attribute3);
IF l_liability_id IS NULL OR l_prepay_id IS NULL THEN
v_error := 'E';
apps.fnd_file.put_line(apps.fnd_file.output,
' Liability Account/Prepayment Account does not exists for bewlow segments,');
apps.fnd_file.put_line(apps.fnd_file.output,
' Liability Account :' ||
i_rec.attribute2);
apps.fnd_file.put_line(apps.fnd_file.output,
' Prepayment Account :' ||
i_rec.attribute3);
END IF;
IF v_error <> 'E' THEN
l_vendor_site_rec.vendor_id := l_vendor_id;
l_vendor_site_rec.vendor_site_code := i_rec.site_code;
l_vendor_site_rec.org_id := p_org_id;
l_vendor_site_rec.ACCTS_PAY_CODE_COMBINATION_ID := l_liability_id;
l_vendor_site_rec.PREPAY_CODE_COMBINATION_ID := l_prepay_id;
l_vendor_site_rec.TERMS_DATE_BASIS := 'Invoice';
ext_payee_rec.default_pmt_method := p_pay_method;
l_vendor_site_rec.ext_payee_rec.default_pmt_method:= p_pay_method;
pos_vendor_pub_pkg.create_vendor_site(
-- ------------------------------
-- Input data elements
-- ------------------------------
p_vendor_site_rec => l_vendor_site_rec,
-- ---------------------------------
-- Output data elements
-- ---------------------------------
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
x_vendor_site_id => l_vendor_site_id,
x_party_site_id => l_party_site_id,
x_location_id => l_location_id);
IF (l_return_status <> 'S') THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Error in Creating Employee Type Supplier..');
retcode := '1';
errbuf := ' Error in Supplier Site Creation-';
IF (l_msg_count = 1) THEN
apps.fnd_file.put_line(apps.fnd_file.output,
'x_msg_data ' || l_msg_data);
ELSIF (l_msg_count > 1) THEN
LOOP
p_count := p_count + 1;
l_msg_data := fnd_msg_pub.get(fnd_msg_pub.g_next,
fnd_api.g_false);
IF (l_msg_data IS NULL) THEN
EXIT;
END IF;
apps.fnd_file.put_line(apps.fnd_file.output,
' Error Message' || p_count ||
' ---' || l_msg_data);
END LOOP;
END IF;
ELSE
apps.fnd_file.put_line(apps.fnd_file.output,
' Successfully Cretaed Supplier Site with below details,');
apps.fnd_file.put_line(apps.fnd_file.output,
' Supplier Site :' ||
i_rec.site_code);
apps.fnd_file.put_line(apps.fnd_file.output,
' Vendor Site Id :' ||
l_vendor_site_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Party Site Id :' ||
l_party_site_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Location Id :' ||
l_location_id);
apps.fnd_file.put_line(apps.fnd_file.output,
' Liability Account :' ||
i_rec.attribute2);
apps.fnd_file.put_line(apps.fnd_file.output,
' Prepayment Account :' ||
i_rec.attribute3);
apps.fnd_file.put_line(apps.fnd_file.output, ' ');
END IF;
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
apps.fnd_file.put_line(apps.fnd_file.output,
' Error - ' || SQLERRM);
END;
END IF;
END IF;
apps.fnd_file.put_line(apps.fnd_file.output,
'*************** END ***********************');
EXCEPTION
WHEN OTHERS THEN
retcode := '2';
errbuf := ' Error in Main- ' || SQLERRM;
apps.fnd_file.put_line(apps.fnd_file.output,
' Error in Main- ' || SQLERRM);
END main;
FUNCTION f_ccid(p_org_id IN NUMBER, p_segments IN VARCHAR2) RETURN NUMBER IS
v_ccid NUMBER;
BEGIN
SELECT gcc.code_combination_id
INTO v_ccid
FROM apps.gl_code_combinations_kfv gcc,
apps.hr_operating_units hou,
apps.gl_Sets_of_books sob
WHERE NVL(gcc.end_date_active, SYSDATE + 1) >= TRUNC(sysdate)
AND NVL(gcc.enabled_flag, 'N') = 'Y'
AND hou.organization_id = p_org_id
AND sob.set_of_books_id = hou.set_of_books_id
AND sob.chart_of_accounts_id = gcc.chart_of_accounts_id
AND UPPER(gcc.concatenated_segments) = UPPER(p_segments);
RETURN v_ccid;
EXCEPTION
WHEN OTHERS THEN
RETURN 0;
END f_ccid;
END XX_AP_EMP_TYPE_SUPP_PKG;
This comment has been removed by the author.
ReplyDeletehow to update ap_suppliers, supplier number and name as employee number and name?
ReplyDeleteAPI