Showing posts with label customer Item interface. Show all posts
Showing posts with label customer Item interface. Show all posts

Thursday, 20 April 2017

CUSTOMER ITEM INTERFACE ORACLE APPS

CUSTOMER ITEM INTERFACE ORACLE APPS CODE:

PACKAGE SPEC:
CREATE OR REPLACE PACKAGE xxrs_cust_item_int_pkg
AS
PROCEDURE main(retcode OUT NUMBER
              ,errbuff OUT VARCHAR2
 ,p_cust_no IN NUMBER);
PROCEDURE cust_item_iface(p_cust_no IN NUMBER);
PROCEDURE cust_item_iface_xref(p_cust_no IN NUMBER);
END xxrs_cust_item_int_pkg;

PACKAGE BODY:

create or replace PACKAGE BODY xxrs_cust_item_int_pkg
AS
 PROCEDURE main( retcode   OUT NUMBER
                ,errbuff   OUT VARCHAR2
         ,p_cust_no  IN NUMBER
)
 AS
  --local variables
  l_req_id            NUMBER;
  lc_phase            VARCHAR2(50);
  lc_status           VARCHAR2(50);
  lc_dev_phase        VARCHAR2(50);
  lc_dev_status       VARCHAR2(50);
  lc_message          VARCHAR2(50);
  l_req_return_status BOOLEAN;
 BEGIN

   l_req_id := fnd_request.submit_request( application   => 'XXRS'
                                          ,program       => 'XXRSCUITEL'
                                          ,description   => ''
                                          ,start_time    => SYSDATE
                                          ,sub_request   => FALSE
                       );

      fnd_file.put_line(fnd_file.log,'Request Id for loading Customer Items to temp table'||l_req_id);

      COMMIT;

     l_req_return_status :=fnd_concurrent.wait_for_request (request_id      => l_req_id
                                                           ,INTERVAL        => 5
                                                           ,max_wait        => 1
                                                           ,phase           => lc_phase
                                                           ,STATUS          => lc_status
                                                           ,dev_phase       => lc_dev_phase
                                                           ,dev_status      => lc_dev_status
                                                           ,message         => lc_message
                                                          );
        xxrs_cust_item_int_pkg.cust_item_iface(p_cust_no);
        xxrs_cust_item_int_pkg.cust_item_iface_xref(p_cust_no);
 EXCEPTION
  WHEN OTHERS THEN
   fnd_File.put_line(fnd_file.log,'Unhandled exception occurred in package.procedure'||SQLERRM);
   retcode :=2;
 END main;

 PROCEDURE cust_item_iface(p_cust_no IN NUMBER
                          )
 AS
 --local variables
  v_user_id           NUMBER;
  v_acct_id           NUMBER :=p_cust_no;
  l_req_id            NUMBER;
  lc_phase            VARCHAR2(50);
  lc_status           VARCHAR2(50);
  lc_dev_phase        VARCHAR2(50);
  lc_dev_status       VARCHAR2(50);
  lc_message          VARCHAR2(50);
  l_req_return_status BOOLEAN;
  -- cursor is fetching the data from staging table to validate
 CURSOR c1 IS
 SELECT vendor_item
       ,medline_item
 FROM xx_cus_item_temp;

 BEGIN
  fnd_file.put_line(fnd_file.log,'v_acct_id '||v_acct_id);
   select user_id
   into v_user_id
   from fnd_user
   where user_name='ANONYMOUS';

   FOR i IN c1
   LOOP
   INSERT INTO mtl_ci_interface(process_flag
                                ,process_mode
                                ,lock_flag
                                ,last_updated_by
                                ,last_update_date
                                ,last_update_login
                                ,created_by
                                ,creation_date
                                ,transaction_type
                                ,customer_id
                                ,address_id
                                ,customer_item_number
                                ,customer_item_desc
                                ,item_definition_level
                                ,commodity_code_id
                                ,inactive_flag
                                )
                       VALUES (1              
                              ,1              
                              ,'N'            
                              ,v_user_id      
                              ,SYSDATE        
                              ,v_user_id      
                              ,v_user_id      
                              ,SYSDATE
                              ,'CREATE'
                              ,v_acct_id
                              ,NULL
                              ,i.medline_item
                              ,NULL
                              ,'1'
                              ,1
                              ,2
                              );
                       COMMIT;
   END LOOP;
             
l_req_id := fnd_request.submit_request(application    => 'INV'
                                           ,program       => 'INVCIINT'
                                           ,description   => ''
                                           ,start_time    => SYSDATE
                                           ,sub_request   => FALSE
                                           ,argument1  => 'N'
                                           ,argument2  => 'Y'
  );
     fnd_file.put_line(fnd_file.log,'request id for import customer items '||l_req_id);

     COMMIT;
      l_req_return_status :=fnd_concurrent.wait_for_request (request_id      => l_req_id
                                                            ,INTERVAL        => 5
                                                            ,max_wait        => 1
                                                            ,phase           => lc_phase
                                                            ,STATUS          => lc_status
                                                            ,dev_phase       => lc_dev_phase
                                                            ,dev_status      => lc_dev_status
                                                            ,message         => lc_message
                                                            );
 END cust_item_iface;
 

 PROCEDURE cust_item_iface_xref(p_cust_no IN NUMBER
                               )
 AS

  v_user_id    NUMBER;
  V_ITEM_ID    NUMBER;
  l_req_id     NUMBER;
  V_ACCT_ID    NUMBER :=p_cust_no;

   -- cursor is fetching the data from staging table to validate
  CURSOR c1 IS
  SELECT vendor_item
        ,medline_item
  FROM xx_cus_item_temp;

  BEGIN
    select user_id
    into v_user_id
    from fnd_user
    where user_name='ANONYMOUS';


   FOR i IN c1
   LOOP
     BEGIN
      SELECT DISTINCT inventory_item_id
      INTO v_item_id
      FROM mtl_system_items_b
      WHERE segment1=i.vendor_item;--'040-00';
     EXCEPTION
      WHEN no_data_found THEN
       v_item_id:=NULL;
       fnd_file.put_line(fnd_file.log,'for vendor_item'||i.vendor_item ||'inventory_item_id doesnot exists');
     END;

             INSERT INTO mtl_ci_xrefs_interface (process_flag
                                                ,process_mode
                                                ,lock_flag
                                                ,last_update_date
                                                ,last_updated_by
                                                ,creation_date
                                                ,created_by
                                                ,last_update_login
                                                ,transaction_type
                                                ,customer_id
                                                ,address_id
                                                ,customer_item_number
                                                ,item_definition_level
                                                ,inventory_item_id
                                                ,master_organization_id
                                                ,preference_number
                                                ,inactive_flag
                                                )
                                        VALUES (1
                                               ,1
                                               ,'N'
                                               ,SYSDATE
                                               ,v_user_id
                                               ,SYSDATE
                                               ,v_user_id
                                               ,v_user_id
                                               ,'CREATE'
                                               ,v_acct_id
                                               ,NULL
                                               ,i.medline_item
                                               ,'1'
                                               ,v_item_id
                                               ,83
                                               ,1
                                               ,2
                                              );
                                      COMMIT;

  END LOOP;

l_req_id := fnd_request.submit_request(application   => 'INV'
                                          ,program       => 'INVCIINTX'
                                          ,description   => ''
                                          ,start_time    => SYSDATE
                                          ,sub_request   => FALSE
                                          ,argument1   => 'N'
                                          ,argument2 => 'Y'
 );
    fnd_file.put_line(fnd_file.log,'request id for import customer item cross references'||l_req_id);
COMMIT;
 END cust_item_iface_xref;


end xxrs_cust_item_int_pkg;