首页 > 代码库 > 客户地点分配多OU

客户地点分配多OU

DECLARE
   l_num_user_id            NUMBER;
   l_num_appl_id            NUMBER;
   l_num_resp_id            NUMBER;
   cust_account_rec_type    hz_cust_account_v2pub.cust_account_rec_type;
   l_num_obj_ver_num        NUMBER;
   l_chr_return_status      VARCHAR2(2000);
   l_num_msg_count          NUMBER;
   l_chr_msg_data           VARCHAR2(500);
   l_num_profile_id         NUMBER;
   l_organization_rec       hz_party_v2pub.organization_rec_type;
   l_customer_profile_rec   hz_customer_profile_v2pub.customer_profile_rec_type;
   l_num_cust_id            NUMBER;
   l_chr_acct_num           VARCHAR2(500);
   l_num_party_id           NUMBER;
   l_chr_party_number       VARCHAR2(500);
   l_cust_acct_site_use_rec hz_cust_account_site_v2pub.cust_site_use_rec_type;
   l_cust_acct_site_rec     hz_cust_account_site_v2pub.cust_acct_site_rec_type;
   l_chr_sit_return_status  VARCHAR2(500);
   l_num_sit_msg_count      NUMBER;
   l_chr_sit_msg_data       VARCHAR2(500);
   l_chr_situ_return_status VARCHAR2(500);
   l_num_situ_msg_count     NUMBER;
   l_chr_situ_msg_data      VARCHAR2(500);
   l_num_site_use_id        NUMBER;
   CURSOR update_base_tables_cur IS
      SELECT DISTINCT a.party_number,
                      ps.party_site_number,
                      a.party_id,
                      'CUST-' || a.party_id || '-' || ass.org_id AS customer_ref,
                      'ADD-' || ps.party_site_id || '-' || ass.org_id AS address_ref,
                      ps.party_site_id,
                      ass.address_line1,
                      ass.city,
                      ass.state,
                      ass.zip,
                      ass.country,
                      'N' primary_site_use_flag,
                      a.orig_system_reference AS party_ref,
                      a.party_name AS customer_name,
                      ass.org_id
        FROM apps.ap_suppliers          ap,
             apps.ap_supplier_sites_all ass,
             apps.hz_parties            a,
             apps.hz_party_sites        ps
       WHERE ap.vendor_id = ass.vendor_id
         AND a.party_id = ap.party_id
         AND ps.party_id = ap.party_id
         AND ass.party_site_id = ps.party_site_id
         AND a.party_name = ap.vendor_name
         AND a.party_id = 12465 -- modify this part/query
            --and ass.org_id = 204
         AND NOT EXISTS
       (SELECT 1 FROM hz_cust_accounts a WHERE a.party_id = a.party_id);
BEGIN
   fnd_global.apps_initialize(&user_id, &responsibility_id, 222); -- input from 1st sql
   dbms_output.put_line('***************************');
   FOR update_base_tables_rec IN update_base_tables_cur LOOP
      NULL;
      cust_account_rec_type.cust_account_id       := fnd_api.g_miss_num;
      cust_account_rec_type.account_name          := update_base_tables_rec.customer_name;
      l_organization_rec.party_rec.party_id       := update_base_tables_rec.party_id;
      l_organization_rec.party_rec.party_number   := update_base_tables_rec.party_number;
      l_organization_rec.organization_name        := update_base_tables_rec.customer_name;
      cust_account_rec_type.orig_system_reference := update_base_tables_rec.customer_ref;
      l_customer_profile_rec.party_id             := update_base_tables_rec.party_id;
      l_customer_profile_rec.profile_class_id     := 0; -- use DEFAULT profile with id=0
      l_customer_profile_rec.created_by_module    := 'HZ_CPUI';
      cust_account_rec_type.created_by_module     := 'HZ_CPUI';
      hz_cust_account_v2pub.create_cust_account(p_init_msg_list        => fnd_api.g_false,
                                                p_cust_account_rec     => cust_account_rec_type,
                                                p_organization_rec     => l_organization_rec,
                                                p_customer_profile_rec => l_customer_profile_rec,
                                                p_create_profile_amt   => fnd_api.g_true,
                                                x_cust_account_id      => l_num_cust_id,
                                                x_account_number       => l_chr_acct_num,
                                                x_party_id             => l_num_party_id,
                                                x_party_number         => l_chr_party_number,
                                                x_profile_id           => l_num_profile_id,
                                                x_return_status        => l_chr_return_status,
                                                x_msg_count            => l_num_msg_count,
                                                x_msg_data             =http://www.mamicode.com/> l_chr_msg_data);>

客户地点分配多OU