客戶信息一覽

SELECT 
        hca.account_number             customer_number,
        hp.party_name                  customer_name,
        fcv.currency_code              currency_code,
        hcsu.tax_code                  tax_rate_code,
        hcpa.trx_credit_limit          credit_limit,
        hcsu.tax_reference             tax_registration_number,
        rt.name                        payment_term,
        hcsu.location                  location,
        --hcas.status                    status,
        flvv.meaning                   status,
        hcsu.site_use_code             site_use_code,
        hl.address_lines_phonetic      address_lines_phonetic,
        hl.address1                    address_line1,
        hl.address2                    address_line2,
        hl.address3                    address_line3,
        hl.address4                    address_line4,
        hl.postal_code                 postal_code,
        hl.city                        city,
        hl.county                      county,
        hl.country                     country,
        rtt.name                       region,
        ood.organization_name          warehouse,
        pl.name                        price_list,
        arm.name                       payment_method,
        gcc_rec.concatenated_segments  receivable_account,
        gcc_rev.concatenated_segments  revenue_account,
        res.resource_name              sales_person,
        hp.attribute1                  customer_main_group,
        hp.attribute2                  customer_group,
        ott.name                       order_type,
        --
        --'=T("' || hcp_phone.phone_number || '")'              phone_number,
        --'=T("' || hcp_fax.phone_number   || '")'              fax_number,
        --hcp_mail.email_address              email_address,
        ibybanks.bank_name                  bank_name,
        ibybanks.bank_branch_name           bank_branch_name,
        ibybanks.bank_account_number        bank_account_number,
        ibybanks.bank_account_name          bank_account_name,
        ibybanks.eft_swift_code             eft_swift_code,
        ibybanks.iban_number                iban_number,
        ida.authorization_reference_number  authorization_reference_number,
        ida.auth_sign_date                  auth_sign_date,
        ida.creditor_le_name                creditor_le_name,
        ida.payment_type_code               payment_type_code,
        hps.party_site_id
        --
    FROM 
        hz_cust_accounts             hca,
        hz_cust_acct_sites_all       hcas,
        hz_cust_site_uses_all        hcsu,
        ra_terms_vl                  rt,
        jtf_rs_salesreps             jrs,
        jtf_rs_resource_extns_vl     res,
        ra_territories               rtt,
        org_organization_definitions ood,
        hz_party_sites               hps,
        hz_parties                   hp,
        hz_locations                 hl,
        gl_code_combinations_kfv     gcc_rec,
        gl_code_combinations_kfv     gcc_rev,
        hz_customer_profiles         hcp,
        hz_cust_profile_amts         hcpa,
        fnd_currencies_vl            fcv,
        ra_cust_receipt_methods      rcrm,
        ar_receipt_methods           arm,
        qp_list_headers_vl           pl,
        oe_order_types_v             ott,
        --
        --hz_contact_points        hcp_phone,
        --hz_contact_points        hcp_fax,
        --hz_contact_points        hcp_mail,
        iby_external_payers_all  iepa,
        iby_pmt_instr_uses_all   ipiua,
        iby_ext_bank_accounts_v  ibybanks,
        iby_debit_authorizations ida,
        fnd_lookup_values_vl     flvv
        --
    WHERE 
        hca.cust_account_id = hcas.cust_account_id
    --
    AND hcas.status = flvv.lookup_code(+)
    AND flvv.lookup_type(+) = 'CODE_STATUS'
    AND flvv.enabled_flag(+) = 'Y'
    AND flvv.VIEW_APPLICATION_ID(+) = 222
    AND sysdate between nvl(flvv.start_date_active, sysdate - 1) and
        nvl(flvv.end_date_active, sysdate + 1)
    --    
    AND hcas.cust_acct_site_id = hcsu.cust_acct_site_id
    AND hcas.org_id = hcsu.org_id
    AND hcas.party_site_id = hps.party_site_id
    AND hps.party_id = hp.party_id
    AND hcsu.site_use_id = hcp.site_use_id(+)
    AND hcp.cust_account_profile_id = hcpa.cust_account_profile_id(+)
    AND hcpa.currency_code = fcv.currency_code(+)
    AND hcsu.site_use_id = rcrm.site_use_id(+)
    AND rcrm.receipt_method_id = arm.receipt_method_id(+)
    AND hcsu.price_list_id = pl.LIST_HEADER_ID(+)
    AND sysdate between nvl(pl.start_date_active, sysdate) and
        nvl(pl.end_date_active, sysdate)
    AND nvl(pl.list_type_code, 'PRL') = ('PRL')
    AND hps.location_id = hl.location_id
    AND hcas.org_id = hcsu.org_id
    AND hcsu.payment_term_id = rt.term_id(+)
    AND hcsu.primary_salesrep_id = jrs.salesrep_id(+)
    AND hcsu.org_id = jrs.org_id(+)
    AND jrs.resource_id = res.resource_id(+)
    AND nvl(RES.CATEGORY, 'EMPLOYEE') IN
        ('EMPLOYEE', 'OTHER', 'PARTY', 'PARTNER', 'SUPPLIER_CONTACT')
    AND hcsu.territory_id = rtt.territory_id(+)
    AND hcsu.warehouse_id = ood.organization_id(+)
    AND hcsu.gl_id_rec = gcc_rec.code_combination_id(+)
    AND hcsu.gl_id_rev = gcc_rev.code_combination_id(+)
    AND hcsu.order_type_id = ott.order_type_id(+)
    --
    --AND hps.party_site_id = HCP_phone.OWNER_TABLE_ID(+)
    --AND HCP_phone.OWNER_TABLE_NAME(+) = 'HZ_PARTY_SITES'
    --AND HCP_phone.CONTACT_POINT_TYPE(+) = 'PHONE'
    --AND HCP_phone.PHONE_LINE_TYPE(+) = 'GEN'
    --AND HCP_phone.STATUS(+) = 'A'
    --AND hcp_fax.OWNER_TABLE_ID(+) = hps.party_site_id
    --AND hcp_fax.OWNER_TABLE_NAME(+) = 'HZ_PARTY_SITES'
    --AND hcp_fax.CONTACT_POINT_TYPE(+) = 'PHONE'
    --AND hcp_fax.PHONE_LINE_TYPE(+) = 'FAX'
    --AND hcp_fax.STATUS(+) = 'A'
    --AND hcp_mail.OWNER_TABLE_ID(+) = hps.party_site_id
    --AND hcp_mail.OWNER_TABLE_NAME(+) = 'HZ_PARTY_SITES'
    --AND hcp_mail.CONTACT_POINT_TYPE(+) = 'EMAIL'
    --AND hcp_mail.STATUS(+) = 'A'
    AND hcsu.site_use_id = iepa.acct_site_use_id(+)
    AND iepa.payment_function(+) = 'CUSTOMER_PAYMENT'
    AND iepa.ext_payer_id = ipiua.ext_pmt_party_id(+)
    AND ipiua.instrument_type(+) = 'BANKACCOUNT'
    AND ipiua.instrument_id = ibybanks.bank_account_id(+)
    AND ipiua.payment_function(+) = 'CUSTOMER_PAYMENT'
    AND ipiua.instrument_payment_use_id = ida.EXTERNAL_BANK_ACCOUNT_USE_ID(+)
    AND hcsu.org_id = g_org_id
    AND hca.account_number BETWEEN NVL(p_customer_num_from,hca.account_number) 
    AND NVL(p_customer_num_to,hca.account_number)
    ORDER BY account_number;
發佈了73 篇原創文章 · 獲贊 4 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章