Mass Upload of Items to Quote
Script to upload items for a given quote and vendor:
--SET SERVEROUTPUT ON;
DECLARE
V_ITEM_ID mtl_system_items_b.inventory_item_id%TYPE;
V_PRICE PO_LINES_ALL.UNIT_PRICE%TYPE;
V_ITEM_DESC mtl_system_items_b.DESCRIPTION%TYPE;
V_line_num PO_LINES_ALL.LINE_NUM%TYPE := 0;
V_organization_id mtl_system_items_b.organization_id%TYPE;
CURSOR C1 IS
select msib.inventory_item_id,msib.segment1 ITEM_NUM,
msib.DESCRIPTION,
msib.PRIMARY_UNIT_OF_MEASURE UOM
,msib.organization_id,mic.category_id,
(select ITEM_COST
from cst_item_costs
where INVENTORY_ITEM_ID = msib.INVENTORY_ITEM_ID
and ORGANIZATION_ID = msib.ORGANIZATION_ID
and COST_TYPE_ID =1) price
from mtl_system_items_b msib,
mtl_item_categories mic
where msib.INVENTORY_ITEM_ID = mic.INVENTORY_ITEM_ID
and msib.ORGANIZATION_ID = mic.ORGANIZATION_ID
and msib.organization_id = 12
and mic .CATEGORY_SET_ID = 1001
AND msib.segment1 in ('2017',);
BEGIN
FOR SR IN C1 LOOP
BEGIN
select max(l.line_num) INTO V_line_num
from po_lines_all l
where l.po_header_id = 1402017 ;
--DBMS_OUTPUT.PUT_LINE ('Po header is null'||'-'||V_line_num);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Po header is null'||'-'||V_line_num);
END;
V_line_num := V_line_num +1;
V_organization_id := SR.organization_id ;
IF V_organization_id = 12 THEN
BEGIN
INSERT INTO PO_LINES_ALL POL
(PO_LINE_ID ,
PO_HEADER_ID ,
LINE_TYPE_ID ,
LINE_NUM,
LAST_UPDATE_DATE,
LAST_UPDATED_BY ,
CREATION_DATE,
CREATED_BY,
ITEM_ID,
CATEGORY_ID,
ITEM_DESCRIPTION,
UNIT_MEAS_LOOKUP_CODE,
UNIT_PRICE,
ORG_ID,
ORDER_TYPE_LOOKUP_CODE,
PURCHASE_BASIS ,
MATCHING_BASIS
)
VALUES
( PO_LINES_S.NEXTVAL,
1402017, --po_header_id
1, --line_type_id
V_line_num, -- line_num
SYSDATE, --last_update_date
1, -- last_updated_by
SYSDATE, -- creation_date
1, -- created_by opera id,
SR.INVENTORY_ITEM_ID, --item_id
sr.CATEGORY_ID, --category_id
SR.DESCRIPTION, --item_desc
sr.UOM , ---UOM
sr.price,--unit_price
12,
'QUANTITY', --ORDER_TYPE_LOOKUP_CODE,
'GOODS', -- PURCHASE_BASIS ,
'QUANTITY' -- MATCHING_BASIS
);
DBMS_OUTPUT.PUT_LINE ('ITEMS Quotation INSERTED'||'-'||SR.ITEM_NUM);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Inseration failed'||'-'||SQLERRM);
END;
ELSE
DBMS_OUTPUT.PUT_LINE ('Organization id is not 12 org'||'-'||V_organization_id);
END IF;
END LOOP;
END;
--SET SERVEROUTPUT ON;
DECLARE
V_ITEM_ID mtl_system_items_b.inventory_item_id%TYPE;
V_PRICE PO_LINES_ALL.UNIT_PRICE%TYPE;
V_ITEM_DESC mtl_system_items_b.DESCRIPTION%TYPE;
V_line_num PO_LINES_ALL.LINE_NUM%TYPE := 0;
V_organization_id mtl_system_items_b.organization_id%TYPE;
CURSOR C1 IS
select msib.inventory_item_id,msib.segment1 ITEM_NUM,
msib.DESCRIPTION,
msib.PRIMARY_UNIT_OF_MEASURE UOM
,msib.organization_id,mic.category_id,
(select ITEM_COST
from cst_item_costs
where INVENTORY_ITEM_ID = msib.INVENTORY_ITEM_ID
and ORGANIZATION_ID = msib.ORGANIZATION_ID
and COST_TYPE_ID =1) price
from mtl_system_items_b msib,
mtl_item_categories mic
where msib.INVENTORY_ITEM_ID = mic.INVENTORY_ITEM_ID
and msib.ORGANIZATION_ID = mic.ORGANIZATION_ID
and msib.organization_id = 12
and mic .CATEGORY_SET_ID = 1001
AND msib.segment1 in ('2017',);
BEGIN
FOR SR IN C1 LOOP
BEGIN
select max(l.line_num) INTO V_line_num
from po_lines_all l
where l.po_header_id = 1402017 ;
--DBMS_OUTPUT.PUT_LINE ('Po header is null'||'-'||V_line_num);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Po header is null'||'-'||V_line_num);
END;
V_line_num := V_line_num +1;
V_organization_id := SR.organization_id ;
IF V_organization_id = 12 THEN
BEGIN
INSERT INTO PO_LINES_ALL POL
(PO_LINE_ID ,
PO_HEADER_ID ,
LINE_TYPE_ID ,
LINE_NUM,
LAST_UPDATE_DATE,
LAST_UPDATED_BY ,
CREATION_DATE,
CREATED_BY,
ITEM_ID,
CATEGORY_ID,
ITEM_DESCRIPTION,
UNIT_MEAS_LOOKUP_CODE,
UNIT_PRICE,
ORG_ID,
ORDER_TYPE_LOOKUP_CODE,
PURCHASE_BASIS ,
MATCHING_BASIS
)
VALUES
( PO_LINES_S.NEXTVAL,
1402017, --po_header_id
1, --line_type_id
V_line_num, -- line_num
SYSDATE, --last_update_date
1, -- last_updated_by
SYSDATE, -- creation_date
1, -- created_by opera id,
SR.INVENTORY_ITEM_ID, --item_id
sr.CATEGORY_ID, --category_id
SR.DESCRIPTION, --item_desc
sr.UOM , ---UOM
sr.price,--unit_price
12,
'QUANTITY', --ORDER_TYPE_LOOKUP_CODE,
'GOODS', -- PURCHASE_BASIS ,
'QUANTITY' -- MATCHING_BASIS
);
DBMS_OUTPUT.PUT_LINE ('ITEMS Quotation INSERTED'||'-'||SR.ITEM_NUM);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ('Inseration failed'||'-'||SQLERRM);
END;
ELSE
DBMS_OUTPUT.PUT_LINE ('Organization id is not 12 org'||'-'||V_organization_id);
END IF;
END LOOP;
END;
Comments
Post a Comment