EBS R12 客戶表結構

R12客戶進行了翻天覆地的變化

剛接觸客戶表結構的時候,可能會感覺非常亂

但整理一凡過後,會感覺倒是有點道理

現發筆記出來,不對的地方希望各位高手指正


客戶表/聯繫人/PARTY關聯
   HZ_PARTIES

客戶賬戶表
   HZ_CUST_ACCOUNTS

例子:

SELECT hp.party_number                       --客戶註冊標識
        , hp.party_name                         --組織名/客戶
        , hp.known_as                           --別名
        , hp.organization_name_phonetic         --名稱拼音
        , acc.account_number                    --帳號
        , flv_sale.meaning   sales_channel_code --銷售渠道
        , acc.account_name                      --賬記說明
        , flv_customer.meaning customer_class_code  --分類
        , acc.orig_system_reference             --參考
        , flv_status.meaning      status        --狀態
        , flv_type.meaning customer_type        --賬戶類型
        , acc.attribute_category                --上下文
        , acc.attribute1                        --註冊
        , acc.attribute2                        --人員推廣
        , acc.attribute3                        --特殊要求
        , acc.Attribute4                        --發貨單是否打印價格
        , acc.Attribute5                        --所屬利潤
     FROM hz_parties        hp
        , hz_cust_accounts  acc
        , fnd_lookup_values flv_sale      --銷售渠道
        , fnd_lookup_values flv_customer  --分類
        , fnd_lookup_values flv_status    --狀態
        , fnd_lookup_values flv_type      --賬戶類型
    WHERE hp.party_id              = acc.party_id
      AND acc.sales_channel_code   = flv_sale.lookup_code
      AND flv_sale.lookup_type     = 'SALES_CHANNEL'
      AND flv_sale.LANGUAGE        = userenv('LANG')
      AND acc.customer_class_code  = flv_customer.lookup_code
      AND flv_customer.lookup_type = 'CUSTOMER CLASS'
      AND flv_customer.LANGUAGE    = userenv('LANG')
      AND acc.status               = flv_status.lookup_code
      AND flv_status.lookup_type   = 'HZ_CPUI_REGISTRY_STATUS'
      AND flv_status.LANGUAGE      = userenv('LANG')
      AND acc.customer_type        = flv_type.lookup_code
      AND flv_type.lookup_type     = 'CUSTOMER_TYPE'
      AND flv_type.LANGUAGE        = userenv('LANG')
      AND hp.party_id              = hz_parties.party_id;

帳戶配置文件
   HZ_CUSTOMER_PROFILES
   字段
   cust_account_role_id  --oe_order_headers.sold_to_contract_id
   cust_account_id
   site_use_id    --客戶頭的該字段爲空
                  --客戶地點層爲hz_cust_site_uses_all.site_use_id

配置文件金額
   HZ_CUST_PROFILE_AMTS   --客戶頭層/客戶地點層
   關聯:hz_customer_profiles.cust_account_profile_id

客戶聯繫人
   HZ_CUST_ACCOUNT_ROLES    --客戶頭層/地點層
   cust_account_id
   cust_acct_site_id    --頭層該字段爲空
   party_id             --類型爲 PARTY_RELATIONSHIP 的 PARTY_ID
   role_type            --CONTACT

   以頭層的聯繫人爲例

SELECT hp_per.*
     FROM hz_cust_account_roles rol
        , hz_parties            hp_rel
        , hz_relationships      rel
        , hz_parties            hp_per
    WHERE rol.party_id          = hp_rel.party_id
      AND hp_rel.party_id       = rel.party_id
      AND rel.object_type       = 'PERSON'
      AND rel.relationship_code = 'CONTACT'
      AND rel.object_id         = hp_per.party_id
      AND rol.cust_acct_site_id IS NULL              --頭層
      AND rol.cust_account_id   = hz_cust_accounts.cust_account_id;

聯繫方式
   HZ_CONTACT_POINTS
   字段
   owner_table_name   HZ_PARTIES/HZ_PARTY_SITES
   owner_table_id     PARTY_ID/PARTY_SITE_ID
   客戶地點層的聯繫方式,直接用party_site_id 關聯 owner_table_id 即可
   客戶頭層的聯繫方式,要用 HZ_RELATIONSHIPS 錶轉換一下,與 hz_relationships.party_id 關聯
   客戶聯繫人下面的聯繫方式,要用HZ_CUST_ACCOUNT_ROLES的PARTY_ID關聯owner_table_id
   例子:
--客戶頭層
   SELECT con.*
     FROM hz_parties        hp
        , hz_relationships  rel
        , hz_contact_points con
     WHERE hp.party_id          = rel.subject_id
      AND rel.subject_type     = 'ORGANIZATION'
      AND rel.party_id         = con.owner_table_id
      AND con.owner_table_name = 'HZ_PARTIES'
      AND hp.party_id          = hz_parties.party_id;
   --客戶地點層
   SELECT *
     FROM hz_contact_points con
     WHERE con.owner_table_id = hz_party_sites.party_site_id;   
   --客戶聯繫人下的聯繫方式
   SELECT *
     FROM hz_contact_points c
    WHERE c.owner_table_id = hz_cust_account_roles.party_id

客戶的稅
   HZ_CODE_ASSIGNMENTS    會計分類/客戶頭層/地點層
   字段
   OWNER_TABLE_NAME   關聯表名/'ZX_PARTY_TAX_PROFILE'
   OWNER_TABLE_ID     關聯表主鍵/PARTY_TAX_PROFILE_ID
   CLASS_CODE         會計分類代碼
   
   ZX_PARTY_TAX_PROFILE   供應商的稅的配置文件
   字段
   PARTY_TYPE_CODE         類型   THIRD_PARTY/THIRD_PARTY_SITE
   PARTY_ID                關聯表 HZ_PARTIES/HZ_PARTY_SITES
                            頭層: PARTY_TYPE_CODE = 'THIRD_PARTY'
                             AND PARTY_ID = HZ_PARTIES.PARTY_ID
                          地點層: PARTY_TYPE_CODE = 'THIRD_PARTY_SITE'
                             AND PARTY_ID = HZ_PARTY_SITES.PARTY_SITE_ID
   REP_REGISTRATION_NUMBER 納稅登記編號  
   PARTY_TAX_PROFILE_ID    主鍵
   HZ_CLASS_CODE_DENORM   會計分類描述
   
   ZX_EXEMPTIONS          客戶免稅/ 客戶頭層/地點層
   字段
   PARTY_TAX_PROFILE_ID   關聯  ZX_PARTY_TAX_PROFILE.PARTY_TAX_PROFILE_ID

客戶地點
   HZ_PARTY_SITES

地點地址
   HZ_LOCATIONS

客戶地點帳戶表
   HZ_CUST_ACCT_SITES_ALL

客戶地點業務目的
   HZ_CUST_SITE_USES_ALL

滯納費用
   HZ_CUSTOMER_PROFILES

由銷售訂單分析客戶結構

SELECT h.sold_from_org_id     --業務實體/ORG ID
     , h.sold_to_org_id       --客戶
     , h.ship_from_org_id     --發貨倉庫
     , h.ship_to_org_id       --收貨方
     , h.invoice_to_org_id
     , h.sold_to_contact_id
  FROM oe_order_headers_all h ;

--業務實體
SELECT org.NAME
  FROM hr_organization_units org
WHERE org.organization_id = oe_order_headers_all.sold_from_org_id;
   
--客戶
SELECT hz.party_name
  FROM hz_cust_accounts acc
     , hz_parties       hz
WHERE acc.party_id = hz.party_id
   AND acc.cust_account_id = oe_order_headers_all.sold_to_org_id;
   
--發貨倉庫
SELECT para.Organization_Code,para.*
  FROM mtl_parameters para
WHERE para.organization_id = oe_order_headers_all.ship_from_org_id;
SELECT *
  FROM org_organization_definitions org
WHERE org.organization_id = oe_order_headers_all.ship_from_org_id;

--地點詳細信息
SELECT loc.*
  FROM hz_parties     hp
     , hz_party_sites hps
     , hz_locations   loc
WHERE hp.party_id     = hps.party_id
   AND hps.location_id = loc.location_id
   AND hp.party_id     = 5042;

--業務目的
SELECT hp.party_name                 --客戶
     , hp.party_number               --註冊表標識
     , uses.site_use_code
     , acnt.account_number           --賬號
     , flv.meaning businesspurpose   --業務目的
     , uses.location                 --地點
     , acnt.account_name             --帳戶說明
     , decode(loc.address1,NULL,loc.address1,loc.address1 || ',') ||
       decode(loc.city,NULL,loc.city,loc.city || ',') ||
       decode(loc.state,NULL,loc.state,loc.state || ',') ||
       decode(loc.postal_code,NULL,' ',loc.postal_code) address   --地點地址
     , hps.party_site_number         --地點說明
     , uses.payment_term_id          --付款條件
     , site.cust_acct_site_id
     , acnt.cust_account_id
     , uses.site_use_id      
  FROM hz_parties             hp
     , hz_cust_accounts       acnt
     , hz_cust_acct_sites_all site
     , hz_cust_site_uses_all  uses
     , hz_party_sites         hps
     , hz_locations           loc
     , fnd_lookup_values      flv
WHERE hp.party_id            = acnt.party_id
   AND acnt.cust_account_id   = site.cust_account_id
   AND site.cust_acct_site_id = uses.cust_acct_site_id
   AND hps.party_site_id      = site.party_site_id
   AND loc.location_id        = hps.location_id
   AND uses.site_use_code     = flv.lookup_code
   AND flv.lookup_type        = 'SITE_USE_CODE'
   AND flv.LANGUAGE           = userenv('LANG')
   AND hp.party_id            = 5042
   AND hps.party_site_id      = 3023;

--聯繫人電話/地點層
SELECT phone.phone_number
  FROM hz_contact_points phone
WHERE phone.owner_table_name = 'HZ_PARTY_SITES'
   AND phone.owner_table_id   = :hz_party_sites.party_sites_id
         
--聯繫人/地點層
SELECT hpsub.party_name
  FROM hz_cust_account_roles  hcar
     , hz_relationships       hr
     , hz_parties             hpsub
WHERE hcar.party_id             = hr.party_id
   AND hr.subject_id             = hpsub.party_id
   AND hcar.role_type            = 'CONTACT'
   AND hr.directional_flag       = 'F'
   AND hcar.cust_account_role_id = :oe_order_headers_all.sold_to_contact_id
   AND hpsub.status              = 'A';



發佈了1 篇原創文章 · 獲贊 3 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章