Pages

Friday, November 22, 2013

Supplier site creation api (ap_vendor_pub_pkg.create_vendor_site)

This below script used for Roll out project & creating supplier site in new OU for which details avail and copied from existing OU.
======================================================================


CREATE TABLE APPS.XXEEC_SUPPLIER_SITE_API_ECIHC
(
  VENDOR_ID                      NUMBER         NOT NULL,
  VENDOR_SITE_CODE               VARCHAR2(15 BYTE) NOT NULL,
  ADDRESS_LINE1                  VARCHAR2(240 BYTE),
  ADDRESS_LINE2                  VARCHAR2(240 BYTE),
  ADDRESS_LINE3                  VARCHAR2(240 BYTE),
  CITY                           VARCHAR2(60 BYTE),
  STATE                          VARCHAR2(150 BYTE),
  ZIP                            VARCHAR2(60 BYTE),
  PROVINCE                       VARCHAR2(150 BYTE),
  COUNTRY                        VARCHAR2(60 BYTE),
  ACCTS_PAY_CODE_COMBINATION_ID  NUMBER,
  PURCHASING_SITE_FLAG           VARCHAR2(1 BYTE),
  PAY_SITE_FLAG                  VARCHAR2(1 BYTE),
  RFQ_ONLY_SITE_FLAG             VARCHAR2(1 BYTE),
  "Supplier Num"                 VARCHAR2(30 BYTE) NOT NULL,
  "Supplier Name"                VARCHAR2(240 BYTE),
  SEGMENT1                       VARCHAR2(30 BYTE) NOT NULL,
  CREATION_DATE                  DATE           NOT NULL,
  SITE_CREATION_DATE             DATE           NOT NULL,
  CREATION_STATUS                VARCHAR2(150 BYTE),
  ERROR_MESSAGE                  VARCHAR2(150 BYTE),
  ORG                            NUMBER
)

--========================================================================================


DECLARE
   p_api_version        NUMBER;
   p_init_msg_list      VARCHAR2 (200);
   p_commit             VARCHAR2 (200);
   p_validation_level   NUMBER;
   x_return_status      VARCHAR2 (200);
   x_msg_count          NUMBER;
   x_msg_data           VARCHAR2 (200);
   p_vendor_site_rec    apps.ap_vendor_pub_pkg.r_vendor_site_rec_type;
   x_vendor_site_id     NUMBER;
   x_party_site_id      NUMBER;
   x_location_id        NUMBER;
   v_msg_index_out    NUMBER;
 
cursor c1 is

--select * from xxeec_supplier_site_api where CREATION_STATUS='N'; --and vendor_id in(2019); --and rownum=1;
select * from xxeec_supplier_site_api_ecihc where CREATION_STATUS='Y'-- and vendor_id in(6,8)
order by segment1; --and rownum=1; --This table contains below query data only
 /*select
 asp.VENDOR_ID
,aspa.VENDOR_SITE_CODE
,nvl(aspa.ADDRESS_LINE1,'ECIHC')ADDRESS_LINE1
,aspa.ADDRESS_LINE2
,aspa.ADDRESS_LINE3
,aspa.city
,aspa.state
,aspa.zip
,aspa.PROVINCE
,nvl(aspa.COUNTRY,'SA')COUNTRY
,aspa.ACCTS_PAY_CODE_COMBINATION_ID
,aspa.purchasing_site_flag
,aspa.pay_site_flag
,aspa.rfq_only_site_flag
,asp.segment1 "Supplier Num"
,asp.vendor_name "Supplier Name"
,asp.segment1
,asp.CREATION_DATE
,asp.last_update_date "SITE_CREATION_DATE"
,asp.ATTRIBUTE1"CREATION_STATUS"
,asp.ATTRIBUTE2"ERROR_MESSAGE"
,aspa.ORG_ID"ORG"
--,asp.VENDOR_TYPE_LOOKUP_CODE
FROM ap_suppliers asp
,ap_supplier_sites_all aspa where 1=1
and asp.vendor_id = aspa.vendor_id
--and asp.vendor_id=2
and org_id =102
and asp.VENDOR_TYPE_LOOKUP_CODE='VENDOR'*/

 
BEGIN
for rec in c1
loop
   p_api_version := 1.0;
   p_init_msg_list := FND_API.G_TRUE;
   p_commit := FND_API.G_TRUE;
   p_validation_level := FND_API.G_VALID_LEVEL_FULL;
   x_return_status := NULL;
   x_msg_count := NULL;
   x_msg_data := NULL;
   P_VENDOR_SITE_REC.AREA_CODE := '';
   P_VENDOR_SITE_REC.PHONE := '';
   P_VENDOR_SITE_REC.FAX_AREA_CODE := '';
   P_VENDOR_SITE_REC.FAX := '';
   P_VENDOR_SITE_REC.VENDOR_ID :=rec.vendor_id;
   P_VENDOR_SITE_REC.VENDOR_SITE_CODE := rec.VENDOR_SITE_CODE; --'HOME';
   --P_VENDOR_SITE_REC.ORG_ID := 204;
   P_VENDOR_SITE_REC.address_line1 := nvl(rec.address_line1,'ECIHC'); --'Ammam Kovil Street';
   P_VENDOR_SITE_REC.address_line2 :=rec.address_line2; --'Vadapalani';
   P_VENDOR_SITE_REC.address_line3 := rec.address_line3; --'Chennai';    
--   P_VENDOR_SITE_REC.org_name := 'Vision Operations';
   P_VENDOR_SITE_REC.org_id := 861;
   P_VENDOR_SITE_REC.country := nvl(rec.country,'SA');
   P_VENDOR_SITE_REC.purchasing_site_flag  :=rec.purchasing_site_flag;
   P_VENDOR_SITE_REC.pay_site_flag         :=rec.pay_site_flag;
   P_VENDOR_SITE_REC.rfq_only_site_flag    :=rec.rfq_only_site_flag;      
   x_vendor_site_id := NULL;
   x_party_site_id := NULL;
   x_location_id := NULL;
   apps.ap_vendor_pub_pkg.create_vendor_site (p_api_version,
                                              p_init_msg_list,
                                              p_commit,
                                              p_validation_level,
                                              x_return_status,
                                              x_msg_count,
                                              x_msg_data,
                                              p_vendor_site_rec,
                                              x_vendor_site_id,
                                              x_party_site_id,
                                              x_location_id
                                             );
   DBMS_OUTPUT.put_line ('X_RETURN_STATUS = ' || x_return_status);
   DBMS_OUTPUT.put_line ('X_MSG_COUNT = ' || TO_CHAR (x_msg_count));
   DBMS_OUTPUT.put_line ('X_MSG_DATA = ' || x_msg_data);
   DBMS_OUTPUT.put_line ('X_VENDOR_SITE_ID = ' || TO_CHAR (x_vendor_site_id));
   DBMS_OUTPUT.put_line ('X_PARTY_SITE_ID = ' || TO_CHAR (x_party_site_id));
   DBMS_OUTPUT.put_line ('X_LOCATION_ID = ' || TO_CHAR (x_location_id));
   DBMS_OUTPUT.put_line ('');
   COMMIT;
 
 
  IF x_return_status = 'S' THEN
  UPDATE
  --xxeec_supplier_site_api
  xxeec_supplier_site_api_ecihc
               SET creation_status = 'Y',
                   error_message = rec.vendor_id ||'---Supplier Site Created',
                   site_creation_date=sysdate
             WHERE vendor_id = rec.vendor_id;
    COMMIT;
  ELSE
    ROLLBACK;
  END IF;
  IF x_msg_count > 0 THEN
    FOR v_index IN 1 .. x_msg_count
    LOOP
      fnd_msg_pub.get (p_msg_index => v_index, p_encoded => 'F', p_data => x_msg_data, p_msg_index_out => v_msg_index_out);
      x_msg_data := SUBSTR (x_msg_data, 1, 100);
      DBMS_OUTPUT.put_line (rec.vendor_id||'--'||x_msg_data);
      UPDATE
      --xxeec_supplier_site_api
      xxeec_supplier_site_api_ecihc
               SET creation_status = 'N',
                   error_message = rec.vendor_id ||'-'||x_msg_data||'---Supplier Site NOT AT ALL Created',
                   site_creation_date=sysdate
             WHERE vendor_id = rec.vendor_id;
     
    END LOOP;
  END IF;
  end loop;

EXCEPTION
WHEN OTHERS THEN
      DBMS_OUTPUT.put_line ('SQL Error' || SQLERRM);
END;

Customer site creation API ( hz_cust_account_site_v2pub.create_cust_acct_site)

This below script used for Roll out project & creating customer site in new OU for which details avail and copied from existing OU.
======================================================================

CREATE TABLE APPS.XXEEC_CUST_SITE_API
(
  CUST_ACCOUNT_ID     NUMBER(15)                NOT NULL,
  PARTY_SITE_ID       NUMBER(15)                NOT NULL,
  PARTY_NAME          VARCHAR2(360 BYTE)        NOT NULL,
  CUST_ACCT_SITE_ID   NUMBER(15)                NOT NULL,
  ADDRESS1            VARCHAR2(240 BYTE)        NOT NULL,
  ADDRESS2            VARCHAR2(240 BYTE),
  ADDRESS3            VARCHAR2(240 BYTE),
  ADDRESS4            VARCHAR2(240 BYTE),
  POSTAL_CODE         VARCHAR2(60 BYTE),
  STATE               VARCHAR2(60 BYTE),
  COUNTRY             VARCHAR2(80 BYTE),
  BILL_TO_LOCATION    VARCHAR2(40 BYTE),
  SHIP_TO_LOCATION    VARCHAR2(40 BYTE),
  ACCOUNT_NUMBER      VARCHAR2(30 BYTE)         NOT NULL,
  SITE_CREATION_DATE  DATE,
  CREATION_STATUS     VARCHAR2(10 BYTE),
  ERROR_MESSAGE       VARCHAR2(240 BYTE)
)

--==========================================================================================================

CREATE OR REPLACE PROCEDURE APPS.XXEEC_CUST_SITE_CREATION_PROC(
      errbuff       OUT   VARCHAR2,
      retcode       OUT   VARCHAR2,
      p_orgid       in    number
   )
   IS
--Created by Senthil Kalvarayapillai 10-Mar-2013
--Creating only CUSTOMER site , for existing CUSTOMER from old OU TO nEW OU.

   p_cust_acct_site_rec         hz_cust_account_site_v2pub.cust_acct_site_rec_type;
   p_cust_site_use_rec          hz_cust_account_site_v2pub.cust_site_use_rec_type;
   p_customer_profile_rec       hz_customer_profile_v2pub.customer_profile_rec_type;
   x_return_status              VARCHAR2 ( 2000 );
   x_msg_count                  NUMBER;
   x_msg_data                   VARCHAR2 ( 2000 ) ;
   x_cust_acct_site_id          NUMBER;
   p_site_use_id                NUMBER;
   po_return_status1            VARCHAR2 (100);
   po_msg_count1                NUMBER;
   po_msg_data1                 VARCHAR2 (1000);
   x_site_use_id                NUMBER;
   ln_business_group_id         number;
   ln_user_id                   number;
   ln_org_id                    number;
   ln_resp_id                   number;
   v_error_message              varchar2(240);
 
cursor c1 is

--select * from xxeec_cust_site_api where CREATION_STATUS='N'order by account_number; --and vendor_id in(326173);--This table contains below query data only

select * from xxeec_cust_site_api where CREATION_STATUS='N' order by account_number;
--and ACCOUNT_NUMBER in(1000,1001);--This table contains below query data only

/*select distinct hcas.CUST_ACCOUNT_ID,hcas.PARTY_SITE_ID,hp.PARTY_NAME,CUST_ACCT_SITE_ID
,hl.ADDRESS1,hl.ADDRESS2,hl.ADDRESS3,hl.ADDRESS4,hl.POSTAL_CODE,hl.STATE
,(SELECT ftt.territory_short_name
          FROM fnd_territories_tl ftt, hz_locations hl
         WHERE hl.country = ftt.territory_code
           AND hl.location_id = hps.location_id and rownum=1) country
,(SELECT DISTINCT hcsua.LOCATION
                   FROM hz_cust_site_uses_all hcsua
                  WHERE hcsua.cust_acct_site_id = hcas.cust_acct_site_id
                    AND hcsua.site_use_code = 'BILL_TO') bill_to_location,
       (SELECT DISTINCT hcsua.LOCATION
                   FROM hz_cust_site_uses_all hcsua
                  WHERE hcsua.cust_acct_site_id = hcas.cust_acct_site_id
                    AND hcsua.site_use_code = 'SHIP_TO'
  and hcsua.status='A') ship_to_location,HCA.account_number
from
hz_cust_accounts hca
,HZ_CUST_ACCT_SITES_ALL hcas
,hz_parties hp
,hz_party_sites hps
,hz_locations hl
where 1=1
and hca.cust_account_id=hcas.cust_account_id
--and hcas.ORG_ID=801
and hca.PARTY_ID=hp.PARTY_ID
and hca.PARTY_ID=hps.PARTY_ID
and hps.LOCATION_ID=hl.LOCATION_ID
and hcas.ORG_ID=102
order by HCA.account_number
;*/
 
BEGIN
            ln_user_id := fnd_profile.VALUE ('USER_ID');-- Get the user_id
            ln_org_id  := fnd_profile.VALUE ('ORG_ID');  -- Get the Org_id
            ln_resp_id := fnd_profile.VALUE ('RESP_ID');-- Get the Resp_id
           
            FND_FILE.put_line(FND_FILE.output,'user id '||ln_user_id);
            FND_FILE.put_line(FND_FILE.output,'org id ' ||ln_org_id);
            FND_FILE.put_line(FND_FILE.output,'resp id '||ln_resp_id);
            --Initializing the variables
            fnd_global.apps_initialize (user_id           => ln_user_id,
                                        resp_id           => ln_resp_id, --50639,
                                        resp_appl_id      => 800
                                             );
            --mo_global.init ('PER');
            mo_global.set_policy_context ('S', ln_org_id);
           
For REC IN C1
    Loop
    begin  
               
   p_cust_acct_site_rec.cust_account_id   := REC.cust_account_id; --219251;
   p_cust_acct_site_rec.party_site_id     := rec.party_site_id; --212126;
   p_cust_acct_site_rec.org_id            := P_ORGID;
   --p_cust_acct_site_rec.location_id       := 6640;
   --p_cust_acct_site_rec.language          := 'US';
   --The Above Language Column is Obsolete in R12
   p_cust_acct_site_rec.created_by_module := 'TCA_V2_API';
 
 
   p_cust_site_use_rec.site_use_code        :='BILL_TO';
   p_cust_site_use_rec.cust_acct_site_id    :=REC.cust_account_id; --219251; --p_cust_acct_site_id;
   p_cust_site_use_rec.created_by_module    :='HZ_IMPORT';
                                                                 
                                                                 
 
   mo_global.init ( 'AR' ) ;
   mo_global.set_org_context ( P_ORGID, NULL, 'AR' ) ;
   fnd_global.set_nls_context ( 'AMERICAN' ) ;
   mo_global.set_policy_context ( 'S', P_ORGID ) ;
   hz_cust_account_site_v2pub.create_cust_acct_site (    'T'                   ,
                                                         p_cust_acct_site_rec  ,
                                                         x_cust_acct_site_id   ,
                                                         x_return_status       ,
                                                         x_msg_count           ,
                                                         x_msg_data
                                                    ) ;
                                                   
    dbms_output.put_line ( 'x_return_status = '||SUBSTR ( x_return_status, 1, 255 ) );
   dbms_output.put_line ( 'x_msg_count = '||TO_CHAR ( x_msg_count ) ) ;
   dbms_output.put_line ( 'Customer Account Site Id is = '||TO_CHAR ( x_cust_acct_site_id ) ) ;
   dbms_output.put_line ( 'x_msg_data = '|| SUBSTR ( x_msg_data, 1, 255 ) ) ;
   IF x_msg_count >1 THEN
      FOR I      IN 1..x_msg_count
      LOOP
         dbms_output.put_line ( I||'.'||SUBSTR ( FND_MSG_PUB.Get ( p_encoded=> FND_API.G_FALSE ), 1, 255 ) ) ;
         fnd_file.put_line (fnd_file.output,rec.cust_account_id ||'ERROR in customer site creation'||fnd_msg_pub.get(fnd_msg_pub.g_next,fnd_api.g_false));
         v_error_message :=rec.cust_account_id ||'orgid -'||P_ORGID||'-ERROR in customer site creation----'||fnd_msg_pub.get(fnd_msg_pub.g_next,fnd_api.g_false);
       
         UPDATE xxeec_cust_site_api
               SET creation_status = 'N',
                   error_message = v_error_message,
                   site_creation_date=sysdate
             WHERE CUST_ACCOUNT_ID = rec.cust_account_id;
             commit;
       
      END LOOP;
   ----END IF;
 
   else    
                   dbms_output.put_line('customer Site Created!');
                   fnd_file.put_line (fnd_file.output,'customer Site Created for--'||rec.cust_account_id);
                 
                   UPDATE xxeec_cust_site_api
               SET creation_status = 'Y',
                   error_message = rec.cust_account_id ||'orgid-'||P_ORGID||'---customer Site Created',
                   site_creation_date=sysdate
             WHERE CUST_ACCOUNT_ID = rec.cust_account_id;

            COMMIT;
            end if;
 

      ------------------------------------------------------------
    begin
   p_cust_site_use_rec.cust_acct_site_id := x_cust_acct_site_id;
   p_cust_site_use_rec.site_use_code     := 'BILL_TO';
   p_cust_site_use_rec.location          := REC.BILL_TO_LOCATION; --'NEW INV LOCATION-6582';
   p_cust_site_use_rec.created_by_module := 'TCA_V2_API';
 
   hz_cust_account_site_v2pub.create_cust_site_use (  p_init_msg_list          =>   'T'                     ,
                                                      p_cust_site_use_rec      =>   p_cust_site_use_rec     ,
                                                      p_customer_profile_rec  =>   p_customer_profile_rec  ,
                                                      p_create_profile         =>   ''                      ,
                                                      p_create_profile_amt     =>   ''                      ,
                                                      x_site_use_id            =>   x_site_use_id           ,
                                                      x_return_status          =>   x_return_status         ,
                                                      x_msg_count              =>   x_msg_count             ,
                                                      x_msg_data               =>   x_msg_data
                                                   );
                                                 
    dbms_output.put_line ( 'x_return_status = '||SUBSTR ( x_return_status, 1, 255 ) ) ;
   dbms_output.put_line ( 'x_msg_count = '||TO_CHAR ( x_msg_count ) ) ;
   dbms_output.put_line ( 'Site Use Id = '||TO_CHAR ( x_site_use_id ) ) ;
   dbms_output.put_line ( 'Site Use = '|| SUBSTR ( p_cust_site_use_rec.site_use_code, 1, 255 ) ) ;
   dbms_output.put_line ( 'x_msg_data = '|| SUBSTR ( x_msg_data, 1, 255 ) ) ;
   IF x_msg_count >1 THEN
      FOR I      IN 1..x_msg_count
      LOOP
         dbms_output.put_line ( I||'.'||SUBSTR ( FND_MSG_PUB.Get ( p_encoded=> FND_API.G_FALSE ), 1, 255 ) ) ;
      END LOOP;
   END IF;                                                  
 
 
   END LOOP;
 
EXCEPTION
WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE ( 'Error: '||SQLERRM ) ;
END;
END LOOP;
end XXEEC_CUST_SITE_CREATION_PROC;
/