Showing posts with label PO Conversion. Show all posts
Showing posts with label PO Conversion. Show all posts

Wednesday, 11 May 2011

PO Conversion


PO Conversion

CREATE OR REPLACE PROCEDURE PO_Int12(Errbuf  OUT VARCHAR2,
                                      Retcode OUT VARCHAR2) AS
CURSOR c1 IS SELECT * FROM XX_TEMP_HEADERS;
CURSOR c2 IS SELECT * FROM XX_TEMP_LINES;
l_vendor_id   number(10);
l_item        varchar2(150);
l_flag        varchar2(4) default 'A';
l_msg         varchar2(200);
l_site_code     varchar2(100);
l_curr_code     varchar2(10);
l_org_id     number(6);
BEGIN
DELETE FROM PO_HEADERS_INTERFACE;
DELETE FROM PO_LINES_INTERFACE;
COMMIT;
FOR x1 IN c1 LOOP
 BEGIN
   SELECT vendor_id
   INTO   l_vendor_id
   FROM   po_vendors
   WHERE  vendor_name = x1.VENDOR_NAME;
  EXCEPTION
   WHEN OTHERS THEN
    l_flag        := 'E';
    l_msg       := 'Vendor id is Not in SYSTEM';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
 END;
--Vendor Site code  Validation
 begin
    select  vendor_site_code
    into    l_site_code
    from    po_vendor_sites_all
    where   vendor_site_code = x1.vendor_site_code;
    EXCEPTION
       WHEN OTHERS THEN
        l_flag        := 'E';
        l_msg         := 'Vendor Site Code is Not in SYSTEM';
Fnd_FIle.Put_line(Fnd_File.log,'Error Occured'||l_msg);
    END;
--End of Site Code Validation
--Currency Code Validation
  Begin
   select currency_code
   into   l_curr_code
   from   fnd_currencies
   where  currency_code = x1.CURRENCY_CODE;
EXCEPTION
      WHEN OTHERS THEN
        l_flag        := 'E';
        l_msg         := 'Currency Code is Invalid';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
    END;
--End of te Currency Validation
--Operating Unit ID Validation
Begin
   select organization_id
   into   l_org_id
   from   hr_operating_units
   where  organization_id = x1.org_id;
   EXCEPTION
      WHEN OTHERS THEN
        l_flag        := 'E';
        l_msg         := 'Invalid Organization ID';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
    END;
--End of the ORG ID Validation
  IF l_flag != 'E' THEN
     INSERT INTO po_headers_interface
   (
   INTERFACE_HEADER_ID
  ,BATCH_ID
  ,ACTION
   ,ORG_ID
  ,DOCUMENT_TYPE_CODE
  ,CURRENCY_CODE
  ,AGENT_NAME
  ,VENDOR_NAME
  ,VENDOR_SITE_CODE
  ,SHIP_TO_LOCATION
  ,BILL_TO_LOCATION
  ,creation_date
  ,APPROVAL_STATUS
  ,APPROVED_DATE
  ,FREIGHT_TERMS
)
VALUES
(
   x1.INTERFACE_HEADER_ID
  ,x1.batch_id
  ,x1.action
  ,x1.org_id
  ,x1.document_type_code
  ,x1.CURRENCY_CODE
  ,x1.AGENT_NAME
  ,x1.VENDOR_NAME
  ,x1.VENDOR_SITE_CODE
  ,x1.SHIP_TO_LOCATION
  ,x1.BILL_TO_LOCATION
  ,SYSDATE-10
  ,x1.APPROVAL_STATUS
  ,SYSDATE
 ,x1.FREIGHT_TERMS
 );
end if;
END LOOP;
FOR x2 IN c2  LOOP
l_flag := 'A';
--Item Validation
begin
  select segment1
  into   l_item
  from   mtl_system_items_b
     where  segment1        = x2.item
     AND    ORGANIZATION_ID = fnd_profile.value('ORG_ID');
exception
when others then
    l_flag        := 'E';
    l_msg       := 'Item is not valid Item';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
 END;
--End of the Item Validation
 if  l_flag != 'E' then
 INSERT INTO PO_LINES_INTERFACE
 (
  INTERFACE_LINE_ID
  ,INTERFACE_HEADER_ID
  ,LINE_NUM
  ,SHIPMENT_NUM
  ,LINE_TYPE
  ,ITEM
  ,ITEM_DESCRIPTION
  ,item_id
  ,UOM_CODE
  ,QUANTITY
  ,UNIT_PRICE
  ,SHIP_TO_ORGANIZATION_CODE
  ,SHIP_TO_LOCATION
  ,NEED_BY_DATE
  ,PROMISED_DATE
  ,list_price_per_unit
)
VALUES
(
   x2.INTERFACE_LINE_ID
  ,x2.INTERFACE_HEADER_ID
  ,x2.LINE_NUM
  ,x2.SHIPMENT_NUM
  ,x2.LINE_TYPE
  ,x2.ITEM
  ,x2.ITEM_DESCRIPTION
  ,x2.item_id
  ,x2.UOM_CODE
  ,x2.QUANTITY,
   X2.UNIT_PRICE,
  X2.SHIP_TO_ORGANIZATION_CODE,
  X2.SHIP_TO_LOCATION,
  sysdate,
  sysdate,
  X2.LIST_PRICE_PER_UNIT);
END IF;
END LOOP;
COMMIT;
END PO_INT12;
/

PO Conversion


PO Conversion

CREATE OR REPLACE PROCEDURE PO_Int12(Errbuf  OUT VARCHAR2,
                                      Retcode OUT VARCHAR2) AS
CURSOR c1 IS SELECT * FROM XX_TEMP_HEADERS;
CURSOR c2 IS SELECT * FROM XX_TEMP_LINES;
l_vendor_id   number(10);
l_item        varchar2(150);
l_flag        varchar2(4) default 'A';
l_msg         varchar2(200);
l_site_code     varchar2(100);
l_curr_code     varchar2(10);
l_org_id     number(6);
BEGIN
DELETE FROM PO_HEADERS_INTERFACE;
DELETE FROM PO_LINES_INTERFACE;
COMMIT;
FOR x1 IN c1 LOOP
 BEGIN
   SELECT vendor_id
   INTO   l_vendor_id
   FROM   po_vendors
   WHERE  vendor_name = x1.VENDOR_NAME;
  EXCEPTION
   WHEN OTHERS THEN
    l_flag        := 'E';
    l_msg       := 'Vendor id is Not in SYSTEM';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
 END;
--Vendor Site code  Validation
 begin
    select  vendor_site_code
    into    l_site_code
    from    po_vendor_sites_all
    where   vendor_site_code = x1.vendor_site_code;
    EXCEPTION
       WHEN OTHERS THEN
        l_flag        := 'E';
        l_msg         := 'Vendor Site Code is Not in SYSTEM';
Fnd_FIle.Put_line(Fnd_File.log,'Error Occured'||l_msg);
    END;
--End of Site Code Validation
--Currency Code Validation
  Begin
   select currency_code
   into   l_curr_code
   from   fnd_currencies
   where  currency_code = x1.CURRENCY_CODE;
EXCEPTION
      WHEN OTHERS THEN
        l_flag        := 'E';
        l_msg         := 'Currency Code is Invalid';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
    END;
--End of te Currency Validation
--Operating Unit ID Validation
Begin
   select organization_id
   into   l_org_id
   from   hr_operating_units
   where  organization_id = x1.org_id;
   EXCEPTION
      WHEN OTHERS THEN
        l_flag        := 'E';
        l_msg         := 'Invalid Organization ID';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
    END;
--End of the ORG ID Validation
  IF l_flag != 'E' THEN
     INSERT INTO po_headers_interface
   (
   INTERFACE_HEADER_ID
  ,BATCH_ID
  ,ACTION
   ,ORG_ID
  ,DOCUMENT_TYPE_CODE
  ,CURRENCY_CODE
  ,AGENT_NAME
  ,VENDOR_NAME
  ,VENDOR_SITE_CODE
  ,SHIP_TO_LOCATION
  ,BILL_TO_LOCATION
  ,creation_date
  ,APPROVAL_STATUS
  ,APPROVED_DATE
  ,FREIGHT_TERMS
)
VALUES
(
   x1.INTERFACE_HEADER_ID
  ,x1.batch_id
  ,x1.action
  ,x1.org_id
  ,x1.document_type_code
  ,x1.CURRENCY_CODE
  ,x1.AGENT_NAME
  ,x1.VENDOR_NAME
  ,x1.VENDOR_SITE_CODE
  ,x1.SHIP_TO_LOCATION
  ,x1.BILL_TO_LOCATION
  ,SYSDATE-10
  ,x1.APPROVAL_STATUS
  ,SYSDATE
 ,x1.FREIGHT_TERMS
 );
end if;
END LOOP;
FOR x2 IN c2  LOOP
l_flag := 'A';
--Item Validation
begin
  select segment1
  into   l_item
  from   mtl_system_items_b
     where  segment1        = x2.item
     AND    ORGANIZATION_ID = fnd_profile.value('ORG_ID');
exception
when others then
    l_flag        := 'E';
    l_msg       := 'Item is not valid Item';
Fnd_FIle.Put_line(Fnd_File.Log,'Error Occured'||l_msg);
 END;
--End of the Item Validation
 if  l_flag != 'E' then
 INSERT INTO PO_LINES_INTERFACE
 (
  INTERFACE_LINE_ID
  ,INTERFACE_HEADER_ID
  ,LINE_NUM
  ,SHIPMENT_NUM
  ,LINE_TYPE
  ,ITEM
  ,ITEM_DESCRIPTION
  ,item_id
  ,UOM_CODE
  ,QUANTITY
  ,UNIT_PRICE
  ,SHIP_TO_ORGANIZATION_CODE
  ,SHIP_TO_LOCATION
  ,NEED_BY_DATE
  ,PROMISED_DATE
  ,list_price_per_unit
)
VALUES
(
   x2.INTERFACE_LINE_ID
  ,x2.INTERFACE_HEADER_ID
  ,x2.LINE_NUM
  ,x2.SHIPMENT_NUM
  ,x2.LINE_TYPE
  ,x2.ITEM
  ,x2.ITEM_DESCRIPTION
  ,x2.item_id
  ,x2.UOM_CODE
  ,x2.QUANTITY,
   X2.UNIT_PRICE,
  X2.SHIP_TO_ORGANIZATION_CODE,
  X2.SHIP_TO_LOCATION,
  sysdate,
  sysdate,
  X2.LIST_PRICE_PER_UNIT);
END IF;
END LOOP;
COMMIT;
END PO_INT12;
/