You are on page 1of 3

PROCEDURE PAICHENG_MPS(errbuf OUT VARCHAR2,

retcode OUT NUMBER,


p_organization_id in number) is
l_return BOOLEAN;
l_iface_rec mrp.mrp_schedule_interface%ROWTYPE;
l_mds_name varchar2(240);
l_mps_name varchar2(240);

cursor cux_data is
select p.ORGANIZATION_ID,
p.INVENTORY_ITEM_ID,
p.PROJECT_ID,
p.paicheng_date,
p.quantity,
p.mps_transaction_id,
p.schedule_level,
p.supply_demand_type
from CUX_MPS_PAICHENG p
where p.schedule_designator = l_mds_name
and p.organization_id = p_organization_id
and p.paicheng_type = 1
and p.quantity > 0
--2018.11.14 add by hulei � � � � ɵ IJ � � � � �
and not exists
(select 1
from cux_mds_wancheng cmw
where cmw.mps_transaction_id = p.mps_transaction_id
and cmw.schedule_level = p.SCHEDULE_LEVEL
and cmw.supply_demand_type = p.SUPPLY_DEMAND_TYPE);

--� � � � δ � ¹ � � � � ģ‫��װ‬MPS
� � � ����
cursor cux_data2 is
select p.ORGANIZATION_ID,
p.INVENTORY_ITEM_ID,
p.PROJECT_ID,
p.paicheng_date,
p.quantity,
p.mps_transaction_id,
p.schedule_level,
p.supply_demand_type
from CUX_MPS_PAICHENG_v p
where p.schedule_designator = l_mds_name
and p.organization_id = p_organization_id
and p.paicheng_type = 2
and p.quantity > 0
--2018.11.19 add by hulei � � � � ɵ IJ �‫� �װ‬
and not exists
(select 1
from cux_mds_wancheng cmw
where cmw.mps_transaction_id = p.mps_transaction_id
and cmw.schedule_level = p.SCHEDULE_LEVEL
and cmw.supply_demand_type = p.SUPPLY_DEMAND_TYPE)
and not exists
(select 1
from wip_discrete_jobs wdj
where wdj.organization_id = p.organization_id
and wdj.primary_item_id = p.inventory_item_id
and wdj.attribute15 = p.project_number
and wdj.status_type <> 7
and trunc(wdj.scheduled_completion_date) = p.paicheng_date);

BEGIN
begin
select mds.mds_name, mds.mps_name
into l_mds_name, l_mps_name
from cux_mps_paicheng_mds_v mds
where mds.organization_id = p_organization_id
and rownum = 1;
exception
when no_data_found then
l_mds_name := null;
l_mps_name := null;
return;
when others then
l_mds_name := null;
l_mps_name := null;
return;
end;
--
delete from mrp.mrp_schedule_dates t
where t.organization_id = p_organization_id
and t.schedule_designator = l_mps_name;
commit;
--����Ԥ�ų̵�̬‫��������״‬MRP�����¹�����2��3
update_mps_paicheng_type(l_mds_name,
p_organization_id,
trunc(sysdate) - 1000,
trunc(sysdate) + 1000);
--���¹���δ��ɵ�̬‫״‬
update_mps_paicheng_type2(l_mds_name,
p_organization_id,
trunc(sysdate) - 1000,
trunc(sysdate) + 1000);
--
for c in cux_data loop

l_iface_rec.last_update_date := SYSDATE;
l_iface_rec.last_updated_by := fnd_global.USER_ID;
l_iface_rec.creation_date := SYSDATE;
l_iface_rec.created_by := fnd_global.USER_ID;
l_iface_rec.last_update_login := fnd_global.LOGIN_ID;
--
l_iface_rec.process_status := 2;
l_iface_rec.organization_id := c.organization_id;
l_iface_rec.schedule_designator := l_mps_name;
l_iface_rec.inventory_item_id := c.inventory_item_id;
l_iface_rec.schedule_date := c.paicheng_date;
l_iface_rec.schedule_quantity := c.quantity;
l_iface_rec.project_id := c.project_id;
l_iface_rec.workday_control := 1;
l_iface_rec.transaction_id := NULL;
l_iface_rec.source_code := 'CUX_TDE';
l_iface_rec.source_line_id := 987654321;
--
INSERT INTO mrp.mrp_schedule_interface VALUES l_iface_rec;
end loop;
commit;
--����δ�¹����ģ�������MPS
for c in cux_data2 loop

l_iface_rec.last_update_date := SYSDATE;
l_iface_rec.last_updated_by := fnd_global.USER_ID;
l_iface_rec.creation_date := SYSDATE;
l_iface_rec.created_by := fnd_global.USER_ID;
l_iface_rec.last_update_login := fnd_global.LOGIN_ID;
--
l_iface_rec.process_status := 2;
l_iface_rec.organization_id := c.organization_id;
l_iface_rec.schedule_designator := l_mps_name;
l_iface_rec.inventory_item_id := c.inventory_item_id;
l_iface_rec.schedule_date := c.paicheng_date;
l_iface_rec.schedule_quantity := c.quantity;
l_iface_rec.project_id := c.project_id;
l_iface_rec.workday_control := 1;
l_iface_rec.transaction_id := NULL;
l_iface_rec.source_code := 'CUX_TDE';
l_iface_rec.source_line_id := 987654321;
--
INSERT INTO mrp.mrp_schedule_interface VALUES l_iface_rec;
end loop;
commit;
--
update CUX_MPS_PAICHENG p
set p.paicheng_type = 2
where p.schedule_designator = l_mds_name
and p.organization_id = p_organization_id
and p.paicheng_type = 1
and p.quantity > 0
--2018.11.14 add by hulei ����ɵIJ�����
and not exists
(select 1
from cux_mds_wancheng cmw
where cmw.mps_transaction_id = p.mps_transaction_id
and cmw.schedule_level = p.SCHEDULE_LEVEL
and cmw.supply_demand_type = p.SUPPLY_DEMAND_TYPE);
commit;

EXCEPTION
WHEN OTHERS THEN
fnd_file.put_line(fnd_file.LOG,
'����MPS-��������ִ ���:' || substr(SQLERRM, 1, 200));
errbuf := SQLERRM;
retcode := 1;
l_return := fnd_concurrent.set_completion_status('WARNING', 'WARNING');
END;

You might also like