create or replace procedure XIU_BPA_TO_ASL_PROC(errbuf out varchar2,
errcode out number,
p_vendor in NUMBER,
p_blanket in VARCHAR2) as
l_vendor_id PO_HEADERS_ALL.vendor_id%type;
l_document_id PO_HEADERS_ALL.po_header_id%type;
l_purchasing_org_id PO_HEADERS_ALL.org_id%type;
l_vendor_site_id PO_HEADERS_ALL.vendor_site_id%type;
l_select_agreement_lines VARCHAR2(10);
l_assignment_set MRP_ASSIGNMENT_SETS.assignment_set_id%type;
l_sourcing_level VARCHAR2(20) := 'ITEM-ORGANIZATION';
l_inv_org HR_ALL_ORGANIZATION_UNITS.organization_id%type;
l_sourcing_rule_name MRP_SOURCING_RULES.sourcing_rule_name%type;
l_release_generation_method PO_ASL_ATTRIBUTES.release_generation_method%type;
l_api_version NUMBER := 1.0;
l_init_msg_list VARCHAR2(5) := FND_API.G_FALSE;
l_commit VARCHAR2(5) := FND_API.G_FALSE;
l_validation_level NUMBER := FND_API.G_VALID_LEVEL_FULL;
l_return_status VARCHAR2(5);
l_msg_count NUMBER;
l_msg_data VARCHAR2(2000);
l_progress VARCHAR2(3) := '000';
v_count number;
x_row_id VARCHAR2(30);
x_asl_id NUMBER;
x_using_organization_id NUMBER;
x_owning_organization_id NUMBER;
x_vendor_business_type VARCHAR2(30);
x_asl_status_id NUMBER;
x_last_update_date DATE;
x_last_updated_by NUMBER := fnd_profile.VALUE('USER_ID');
x_creation_date DATE;
x_created_by NUMBER;
x_manufacturer_id NUMBER;
x_vendor_id NUMBER;
x_item_id NUMBER;
x_category_id NUMBER;
x_vendor_site_id NUMBER;
x_primary_vendor_item VARCHAR2(30);
x_manufacturer_asl_id NUMBER;
x_comments VARCHAR2(30);
x_review_by_date DATE;
x_attribute_category VARCHAR2(30);
x_attribute1 VARCHAR2(150);
x_attribute2 VARCHAR2(150);
x_attribute3 VARCHAR2(150);
x_attribute4 VARCHAR2(150);
x_attribute5 VARCHAR2(150);
x_attribute6 VARCHAR2(150);
x_attribute7 VARCHAR2(150);
x_attribute8 VARCHAR2(150);
x_attribute9 VARCHAR2(150);
x_attribute10 VARCHAR2(150);
x_attribute11 VARCHAR2(150);
x_attribute12 VARCHAR2(150);
x_attribute13 VARCHAR2(150);
x_attribute14 VARCHAR2(150);
x_attribute15 VARCHAR2(150);
x_last_update_login NUMBER := fnd_profile.VALUE('LOGIN_ID');
x_disable_flag VARCHAR2(1);
v_min_rank number;
v_err_flag varchar2(1) := 'N';
v_head_err_flag VARCHAR2(1) := 'N';
x_err_flag VARCHAR2(1);
BEGIN
fnd_global.apps_initialize(user_id => 1110,
resp_id => 50597,
resp_appl_id => 20003);
-- Call the procedure to create Document Sourcing Rules
l_inv_org := 81; --fnd_profile.VALUE('MFG_ORGANIZATION_ID');
fnd_file.PUT_LINE(fnd_file.LOG, '==>l_inv_org' || l_inv_org);
if p_blanket is not null then
select count(*)
into v_count
from po_headers_all ph
WHERE PH.TYPE_LOOKUP_CODE = 'BLANKET'
AND PH.AUTHORIZATION_STATUS = 'APPROVED'
AND NVL(PH.closed_code, 'OPEN') not in ('CLOSED', 'FINALLY CLOSED')
and ph.segment1 = p_blanket;
if v_count = 0 then
fnd_file.PUT_LINE(fnd_file.LOG,
'==>' || p_blanket || '不符合条件,请返回检查');
return;
end if;
end if;
for v_head_rec in (SELECT PH.PO_HEADER_ID,
PH.SEGMENT1,
PH.VENDOR_ID,
PH.VENDOR_SITE_ID,
PH.ORG_ID,
NVL(PH.ATTRIBUTE1, 'N') CONSIGN_FLAG
FROM PO_HEADERS_ALL PH
WHERE PH.TYPE_LOOKUP_CODE = 'BLANKET'
AND PH.AUTHORIZATION_STATUS = 'APPROVED'
AND NVL(PH.closed_code, 'OPEN') not in
('CLOSED', 'FINALLY CLOSED')
/*and PH.SEGMENT1 in ('100559')*/ /*TEST*/
AND EXISTS
(SELECT NULL
FROM PO_LINES_ALL PL
WHERE PL.PO_HEADER_ID = PH.PO_HEADER_ID
AND NVL(PL.ATTRIBUTE15, 'N') = 'N'
/*test*/
AND (PH.VENDOR_ID = p_vendor or
p_vendor is null)
AND (ph.segment1 = p_blanket or
p_blanket is null))
/*test*/
) LOOP
if v_head_rec.vendor_id is not null and
v_head_rec.vendor_site_id is not null then
BEGIN
v_head_err_flag := 'N';
fnd_file.PUT_LINE(fnd_file.LOG,
'==>一揽子采购协议' || v_head_rec.segment1 ||
'开始生成ASL......');
PO_CREATE_SR_ASL.create_autosource_rules(p_api_version => l_api_version,
p_init_msg_list => l_init_msg_list,
p_commit => l_commit,
x_return_status => l_return_status,
X_msg_count => l_msg_count,
x_msg_data => l_msg_data,
p_document_id => v_head_rec.po_header_id,
p_vendor_id => v_head_rec.vendor_id,
p_purchasing_org_id => v_head_rec.org_id,
p_vendor_site_id => v_head_rec.vendor_site_id,
p_create_sourcing_rule => 'Y',
p_update_sourcing_rule => 'Y',
p_agreement_lines_selection => null,
p_sourcing_level => l_sourcing_level,
p_inv_org => l_inv_org,
p_sourcing_rule_name => null,
p_release_gen_method => null,
p_assignment_set_id => null);
l_progress := '001';
fnd_file.PUT_LINE(fnd_file.LOG,
'==>l_return_status' || l_return_status ||
'开始生成ASL返回状态......');
if l_return_status = 'U' then
for v_line_rec in (select pl.po_header_id,
pl.po_line_id,
pl.item_id,
pl.vendor_product_num vendor_item
from po_lines_all pl
where pl.po_header_id =
v_head_rec.po_header_id
and nvl(pl.attribute15, 'N') = 'N'
order by pl.last_update_date) LOOP
v_err_flag := 'N';
if v_head_rec.consign_flag = 'Y' THEN
update po_asl_attributes paa
set paa.consigned_from_supplier_flag = 'Y',
paa.last_billing_date = trunc(sysdate)
where paa.vendor_id = v_head_rec.vendor_id
and paa.vendor_site_id = v_head_rec.vendor_site_id
and paa.item_id = v_line_rec.item_id;
else
update po_asl_attributes paa
set paa.consigned_from_supplier_flag = 'N',
paa.last_billing_date = NULL
where paa.vendor_id = v_head_rec.vendor_id
and paa.vendor_site_id = v_head_rec.vendor_site_id
and paa.item_id = v_line_rec.item_id;
end if;
begin
select rowid,
ps.asl_id,
ps.using_organization_id,
ps.owning_organization_id,
ps.vendor_business_type,
ps.asl_status_id,
sysdate,
nvl(x_last_updated_by, 0),
ps.creation_date,
ps.created_by,
ps.manufacturer_id,
ps.vendor_id,
ps.item_id,
ps.category_id,
ps.vendor_site_id,
ps.primary_vendor_item,
ps.manufacturer_asl_id,
ps.comments,
ps.review_by_date,
ps.attribute_category,
ps.attribute1,
ps.attribute2,
ps.attribute3,
ps.attribute4,
ps.attribute5,
ps.attribute6,
ps.attribute7,
ps.attribute8,
ps.attribute9,
ps.attribute10,
ps.attribute11,
ps.attribute12,
ps.attribute13,
ps.attribute14,
ps.attribute15,
nvl(x_last_update_login, ps.last_update_login),
ps.disable_flag
into x_row_id,
x_asl_id,
x_using_organization_id,
x_owning_organization_id,
x_vendor_business_type,
x_asl_status_id,
x_last_update_date,
x_last_updated_by,
x_creation_date,
x_created_by,
x_manufacturer_id,
x_vendor_id,
x_item_id,
x_category_id,
x_vendor_site_id,
x_primary_vendor_item,
x_manufacturer_asl_id,
x_comments,
x_review_by_date,
x_attribute_category,
x_attribute1,
x_attribute2,
x_attribute3,
x_attribute4,
x_attribute5,
x_attribute6,
x_attribute7,
x_attribute8,
x_attribute9,
x_attribute10,
x_attribute11,
x_attribute12,
x_attribute13,
x_attribute14,
x_attribute15,
x_last_update_login,
x_disable_flag
from po_approved_supplier_list ps
where ps.item_id = v_line_rec.item_id
and ps.vendor_id = v_head_rec.vendor_id
and nvl(ps.vendor_site_id, 0) =
NVL(v_head_rec.vendor_site_id, 0);
x_primary_vendor_item := v_line_rec.vendor_item;
/* select nvl(min(ps.attribute1)-1,99)
into x_attribute1
from po_approved_supplier_list ps
where ps.item_id = v_line_rec.item_id;*/
PO_ASL_THS1.update_row(x_row_id => x_row_id,
x_asl_id => x_asl_id,
x_using_organization_id => x_using_organization_id,
x_owning_organization_id => x_owning_organization_id,
x_vendor_business_type => x_vendor_business_type,
x_asl_status_id => x_asl_status_id,
x_last_update_date => x_last_update_date,
x_last_updated_by => x_last_updated_by,
x_creation_date => x_creation_date,
x_created_by => x_created_by,
x_manufacturer_id => x_manufacturer_id,
x_vendor_id => x_vendor_id,
x_item_id => x_item_id,
x_category_id => x_category_id,
x_vendor_site_id => x_vendor_site_id,
x_primary_vendor_item => x_primary_vendor_item,
x_manufacturer_asl_id => x_manufacturer_asl_id,
x_comments => x_comments,
x_review_by_date => x_review_by_date,
x_attribute_category => x_attribute_category,
x_attribute1 => x_attribute1,
x_attribute2 => x_attribute2,
x_attribute3 => x_attribute3,
x_attribute4 => x_attribute4,
x_attribute5 => x_attribute5,
x_attribute6 => x_attribute6,
x_attribute7 => x_attribute7,
x_attribute8 => x_attribute8,
x_attribute9 => x_attribute9,
x_attribute10 => x_attribute10,
x_attribute11 => x_attribute11,
x_attribute12 => x_attribute12,
x_attribute13 => x_attribute13,
x_attribute14 => x_attribute14,
x_attribute15 => x_attribute15,
x_last_update_login => x_last_update_login,
x_disable_flag => x_disable_flag);
exception
when no_data_found then
v_err_flag := 'Y';
v_head_err_flag := 'Y';
fnd_file.PUT_LINE(fnd_file.LOG,
'==>exception789' || 'no_data_found' ||
'错误......');
end;
fnd_file.PUT_LINE(fnd_file.LOG,
'==>v_err_flag123' || v_err_flag ||
'错误状态......');
if v_err_flag <> 'Y' then
xiu_blanket_to_source_rule_pkg.generate_sourcing_rule(p_header_id => v_line_rec.po_header_id,
p_line_id => v_line_rec.po_line_id,
x_err_flag => x_err_flag);
end if;
fnd_file.PUT_LINE(fnd_file.LOG,
'==>x_err_flag456' || x_err_flag ||
'错误状态......');
if x_err_flag = 'Y' then
v_err_flag := 'Y';
v_head_err_flag := 'Y';
end if;
if v_err_flag = 'N' then
update po_lines_all pla
set pla.attribute15 = 'Y'
where pla.po_header_id = v_head_rec.po_header_id
and pla.po_line_id = v_line_rec.po_line_id;
end if;
end loop;
-- commit;
end if;
-- if l_return_status = 'U' then
fnd_file.PUT_LINE(fnd_file.LOG,
'==>v_head_err_flag' || v_head_err_flag ||
'返回头状态......');
if v_head_err_flag = 'N' then
fnd_file.PUT_LINE(fnd_file.LOG,
'==>一揽子采购协议' || v_head_rec.segment1 ||
'成功生成ASL');
commit;
else
fnd_file.PUT_LINE(fnd_file.LOG,
'==>一揽子采购协议' || v_head_rec.segment1 ||
'生成ASL失败:' || l_msg_data);
rollback;
end if;
-- fnd_file.PUT_LINE(fnd_file.LOG,'==>状态:'||l_return_status);
EXCEPTION
WHEN OTHERS THEN
po_message_s.sql_error('POASLGEN', l_progress, sqlcode);
po_message_s.sql_show_error;
RAISE;
END;
else
fnd_file.PUT_LINE(fnd_file.LOG,
'==>一揽子采购协议' || v_head_rec.segment1 || '供应商和地点不能为空');
end if;
END LOOP;
-- commit;
END xiu_bpa_to_asl_proc;
/
EBS开发_BPA生成ASL列表
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013711561/article/details/79274884
猜你喜欢
转载自blog.csdn.net/u013711561/article/details/79274884
今日推荐
周排行