应收发票相关脚本

--应收发票主表
SELECT *
  FROM RA_CUSTOMER_TRX_ALL A
 WHERE A.TRX_NUMBER = '156640'
   AND A.ORG_ID = 236;

--应收发票行表
SELECT B.EXTENDED_AMOUNT --不含税原币金额
      ,B.EXTENDED_ACCTD_AMOUNT --不含税本币金额
      ,B.GROSS_UNIT_SELLING_PRICE -- 含税单价
      ,B.GROSS_EXTENDED_AMOUNT --含税金额
      ,B.REVENUE_AMOUNT --收入金额
      ,B.UNIT_SELLING_PRICE --不含税单价
      ,B.UNIT_STANDARD_PRICE
      ,B.*
  FROM RA_CUSTOMER_TRX_LINES_ALL B
 WHERE B.CUSTOMER_TRX_ID = 1449740;
--发票分配表
SELECT C.AMOUNT --不含税原原币金额
      ,C.ACCTD_AMOUNT --不含税本币金额
      ,C.*
  FROM RA_CUST_TRX_LINE_GL_DIST_ALL C
 WHERE C.CUSTOMER_TRX_ID = 1449519;

--发票应收科目
SELECT RCTLGDA.*
  FROM RA_CUSTOMER_TRX_ALL          RCA
      ,RA_CUST_TRX_LINE_GL_DIST_ALL RCTLGDA
 WHERE RCA.CUSTOMER_TRX_ID = RCTLGDA.CUSTOMER_TRX_ID
   AND RCTLGDA.ACCOUNT_CLASS = 'REC'
   AND RCA.CUSTOMER_TRX_ID = 1337786;

--发票收入和税科目
SELECT RCTLGDA.*
  FROM RA_CUSTOMER_TRX_ALL          RCA
      ,RA_CUST_TRX_LINE_GL_DIST_ALL RCTLGDA
 WHERE RCA.CUSTOMER_TRX_ID = RCTLGDA.CUSTOMER_TRX_ID
   AND RCTLGDA.ACCOUNT_CLASS <> 'REC'
   AND RCA.CUSTOMER_TRX_ID = 1337786;

--

SELECT RCTLGDA.*
  FROM RA_CUSTOMER_TRX_ALL          RCA
      ,RA_CUSTOMER_TRX_LINES_ALL    RCL
      ,RA_CUST_TRX_LINE_GL_DIST_ALL RCTLGDA
 WHERE RCA.CUSTOMER_TRX_ID = RCL.CUSTOMER_TRX_ID
   AND RCL.CUSTOMER_TRX_LINE_ID = RCTLGDA.CUSTOMER_TRX_LINE_ID
   AND RCA.CUSTOMER_TRX_ID = 1337786;

--发票收款计划表

SELECT ARP.AMOUNT_DUE_ORIGINAL --发票原始金额(含税)
      ,ARP.TAX_ORIGINAL --发票原始税额 
      ,ARP.TAX_REMAINING --发票税余额
      ,ARP.AMOUNT_APPLIED --发票收款金额
      ,ARP.AMOUNT_LINE_ITEMS_ORIGINAL --发票行原始金额
      ,ARP.AMOUNT_LINE_ITEMS_REMAINING --发票行余额
      ,ARP.AMOUNT_DUE_REMAINING --到期余额
      ,ARP.ACCTD_AMOUNT_DUE_REMAINING --本币到期余额           
      ,ARP.AMOUNT_ADJUSTED --发票调整金额
      ,ARP.AMOUNT_CREDITED --发票做过贷项通知单金额
      ,ARP.FREIGHT_ORIGINAL
      ,ARP.FREIGHT_REMAINING
      ,ARP.DISCOUNT_ORIGINAL
      ,ARP.DISCOUNT_REMAINING
      ,ARP.DISCOUNT_TAKEN_EARNED
      ,ARP.DISCOUNT_TAKEN_UNEARNED
      ,ARP.RECEIVABLES_CHARGES_CHARGED
      ,ARP.RECEIVABLES_CHARGES_REMAINING
      ,ARP.*
  FROM AR_PAYMENT_SCHEDULES_ALL ARP
 WHERE ARP.CUSTOMER_TRX_ID = 1485432 --Num: 80210055

--发票是否做过贷项
SELECT *
  FROM RA_CUSTOMER_TRX_ALL RCA
 WHERE RCA.PREVIOUS_CUSTOMER_TRX_ID = 1337786; --ra_customer_trx_all.customer_trx_id

--发票现金收款金额
SELECT *
  FROM AR_RECEIVABLE_APPLICATIONS_ALL ARA
 WHERE ARA.APPLIED_CUSTOMER_TRX_ID = 1337785
   AND ARA.APPLICATION_TYPE = 'CASH'
   AND ARA.STATUS = 'APP';


--发票被贷项通知单核销金额
SELECT *
  FROM AR_RECEIVABLE_APPLICATIONS_ALL ARA
 WHERE ARA.APPLIED_CUSTOMER_TRX_ID = 1337786
   AND ARA.APPLICATION_TYPE = 'CM'
   AND ARA.STATUS = 'APP';

--发票调整金额
SELECT ADJ.*
  FROM AR_ADJUSTMENTS_ALL  ADJ
      ,RA_CUSTOMER_TRX_ALL RCT
 WHERE RCT.CUSTOMER_TRX_ID = ADJ.CUSTOMER_TRX_ID
   AND ADJ.STATUS = 'A'
   AND RCT.CUSTOMER_TRX_ID = 1337785;


 

--收款录入后产生的信息如下:
--收款主表
SELECT *
  FROM AR_CASH_RECEIPTS_ALL ACRA
 WHERE ACRA.RECEIPT_NUMBER = '20120106001';

--收款历史记录表
SELECT *
  FROM AR_CASH_RECEIPT_HISTORY_ALL ACRH
 WHERE ACRH.CASH_RECEIPT_ID = 304387;

--收款事务处理表
SELECT *
  FROM AR_RECEIVABLE_APPLICATIONS_ALL ARA
 WHERE ARA.CASH_RECEIPT_ID = 304387;

--收款分配表
--收款录入时产生两条记录,SOURCE_ID分别对应 
--SOURCE_TABLE为 'RA' 时SOURCE_ID对应的是AR_RECEIVABLE_APPLICATIONS_ALL.RECEIVABLE_APPLICATION_ID,为CRH时SOURCE_ID对应的是AR_CASH_RECEIPT_HISTORY_ALL.CASH_RECEIPT_HISTORY_ID
--下面SQL获取的是收款录入时产生的未核销科目及收款核销时产生的应收账款和未核销科目
SELECT *
  FROM AR_DISTRIBUTIONS_ALL ADA
 WHERE ADA.SOURCE_ID IN
       (SELECT ARA.RECEIVABLE_APPLICATION_ID
          FROM AR_RECEIVABLE_APPLICATIONS_ALL ARA
         WHERE ARA.CASH_RECEIPT_ID = 304387)
   AND ADA.SOURCE_TABLE = 'RA';
--收款录入时产生两条分录:现金和未核销,下面语句获取的是现金科目
SELECT *
  FROM AR_DISTRIBUTIONS_ALL ADA
 WHERE ADA.SOURCE_ID IN
       (SELECT ACRH.CASH_RECEIPT_HISTORY_ID
          FROM AR_CASH_RECEIPT_HISTORY_ALL ACRH
         WHERE ACRH.CASH_RECEIPT_ID = 304387)
   AND ADA.SOURCE_TABLE = 'CRH';


--应收发票收货方 收单方 到期日等

SELECT CT.CUSTOMER_TRX_ID CUSTOMER_TRX_ID
      ,CT.TRX_NUMBER TRX_NUMBER
      ,CT.OLD_TRX_NUMBER OLD_TRX_NUMBER
      ,CT_REL.TRX_NUMBER CT_RELATED_TRX_NUMBER
      ,CT.RECURRED_FROM_TRX_NUMBER CT_MODEL_TRX_NUMBER
      ,CT.TRX_DATE TRX_DATE
      ,ARPT_SQL_FUNC_UTIL.GET_FIRST_REAL_DUE_DATE(CT.CUSTOMER_TRX_ID
                                                 ,CT.TERM_ID
                                                 ,CT.TRX_DATE) TERM_DUE_DATE --到期日
      ,CT.PREVIOUS_CUSTOMER_TRX_ID PREVIOUS_CUSTOMER_TRX_ID
      ,CT.INITIAL_CUSTOMER_TRX_ID INITIAL_CUSTOMER_TRX_ID
      ,CT.RELATED_BATCH_SOURCE_ID RELATED_BATCH_SOURCE_ID
      ,CT.RELATED_CUSTOMER_TRX_ID RELATED_CUSTOMER_TRX_ID
      ,CT.CUST_TRX_TYPE_ID CUST_TRX_TYPE_ID
      ,CT.BATCH_ID BATCH_ID
      ,CT.BATCH_SOURCE_ID BATCH_SOURCE_ID
      ,CT.REASON_CODE REASON_CODE
      ,CT.TERM_ID TERM_ID
      ,CT.PRIMARY_SALESREP_ID PRIMARY_SALESREP_ID
      ,CT.AGREEMENT_ID AGREEMENT_ID
      ,CT.CREDIT_METHOD_FOR_RULES CREDIT_METHOD_FOR_RULES
      ,CT.CREDIT_METHOD_FOR_INSTALLMENTS CREDIT_METHOD_FOR_INSTALLMENTS
      ,CT.RECEIPT_METHOD_ID RECEIPT_METHOD_ID
      ,CT.INVOICING_RULE_ID INVOICING_RULE_ID
      ,CT.SHIP_VIA SHIP_VIA
      ,CT.FOB_POINT FOB_POINT
      ,CT.FINANCE_CHARGES
      ,CT.COMPLETE_FLAG COMPLETE_FLAG
      ,CT.CUSTOMER_BANK_ACCOUNT_ID CUSTOMER_BANK_ACCOUNT_ID
      ,CT.RECURRED_FROM_TRX_NUMBER RECURRED_FROM_TRX_NUMBER
      ,CT.STATUS_TRX STATUS_TRX
      ,CT.DEFAULT_TAX_EXEMPT_FLAG DEFAULT_TAX_EXEMPT_FLAG
      ,CT.SOLD_TO_CUSTOMER_ID SOLD_TO_CUSTOMER_ID
      ,CT.SOLD_TO_SITE_USE_ID SOLD_TO_SITE_USE_ID
      ,CT.SOLD_TO_CONTACT_ID SOLD_TO_CONTACT_ID
      ,CT.BILL_TO_CUSTOMER_ID BILL_TO_CUSTOMER_ID
      ,CT.BILL_TO_SITE_USE_ID BILL_TO_SITE_USE_ID
      ,RAA_BILL.CUST_ACCT_SITE_ID RAA_BILL_TO_ADDRESS_ID
      ,CT.BILL_TO_CONTACT_ID BILL_TO_CONTACT_ID
      ,RAC_BILL_PARTY.JGZZ_FISCAL_CODE BILL_TO_TAXPAYER_ID
      ,CT.SHIP_TO_CUSTOMER_ID
      ,CT.SHIP_TO_SITE_USE_ID
      ,RAA_SHIP.CUST_ACCT_SITE_ID RAA_SHIP_TO_ADDRESS_ID
      ,CT.SHIP_TO_CONTACT_ID
      ,RAC_SHIP_PARTY.JGZZ_FISCAL_CODE SHIP_TO_TAXPAYER_ID
      ,CT.REMIT_TO_ADDRESS_ID
      ,CT.INVOICE_CURRENCY_CODE
      ,CT.CREATED_FROM
      ,CT.SET_OF_BOOKS_ID
      ,CT.PRINTING_ORIGINAL_DATE
      ,CT.PRINTING_LAST_PRINTED
      ,CT.PRINTING_OPTION
      ,CT.PRINTING_COUNT
      ,CT.PRINTING_PENDING
      ,CT.LAST_PRINTED_SEQUENCE_NUM
      ,CT.PURCHASE_ORDER
      ,CT.PURCHASE_ORDER_REVISION
      ,CT.PURCHASE_ORDER_DATE
      ,CT.CUSTOMER_REFERENCE
      ,CT.CUSTOMER_REFERENCE_DATE
      ,CT.COMMENTS
      ,CT.INTERNAL_NOTES
      ,CT.EXCHANGE_RATE_TYPE
      ,CT.EXCHANGE_DATE
      ,CT.EXCHANGE_RATE
      ,CT.TERRITORY_ID
      ,CT.END_DATE_COMMITMENT
      ,CT.START_DATE_COMMITMENT
      ,CT.ORIG_SYSTEM_BATCH_NAME
      ,CT.SHIP_DATE_ACTUAL
      ,CT.WAYBILL_NUMBER
      ,CT.DOC_SEQUENCE_ID
      ,CT.DOC_SEQUENCE_VALUE
      ,CT.PAYING_CUSTOMER_ID
      ,CT.PAYING_SITE_USE_ID
      ,CT.DEFAULT_USSGL_TRANSACTION_CODE
      ,CT.LAST_UPDATE_DATE
      ,CT.LAST_UPDATED_BY
      ,CT.CREATION_DATE
      ,CT.CREATED_BY
      ,CT.LAST_UPDATE_LOGIN
      ,CT.REQUEST_ID
      ,RAC_BILL_PARTY.PARTY_NAME RAC_BILL_TO_CUSTOMER_NAME --收单方
      ,RAC_BILL.ACCOUNT_NUMBER RAC_BILL_TO_CUSTOMER_NUM
      ,SU_BILL.LOCATION SU_BILL_TO_LOCATION --收单地点
      ,RAA_BILL_LOC.ADDRESS1 RAA_BILL_TO_ADDRESS1 --收单地址
      ,RAA_BILL_LOC.ADDRESS2 RAA_BILL_TO_ADDRESS2
      ,RAA_BILL_LOC.ADDRESS3 RAA_BILL_TO_ADDRESS3_DB
      ,DECODE(RAA_BILL.CUST_ACCT_SITE_ID
             ,NULL
             ,NULL
             ,ARH_ADDR_PKG.FORMAT_LAST_ADDRESS_LINE(RAA_BILL_LOC.ADDRESS_STYLE
                                                   ,RAA_BILL_LOC.ADDRESS3
                                                   ,RAA_BILL_LOC.ADDRESS4
                                                   ,RAA_BILL_LOC.CITY
                                                   ,RAA_BILL_LOC.COUNTY
                                                   ,RAA_BILL_LOC.STATE
                                                   ,RAA_BILL_LOC.PROVINCE
                                                   ,FT_BILL.TERRITORY_SHORT_NAME
                                                   ,RAA_BILL_LOC.POSTAL_CODE)) RAA_BILL_TO_ADDRESS3
      ,RAA_BILL_LOC.CITY RAA_BILL_TO_CITY
      ,RAA_BILL_LOC.COUNTY RAA_BILL_TO_COUNTY
      ,RAA_BILL_LOC.STATE RAA_BILL_TO_STATE
      ,RAA_BILL_LOC.PROVINCE RAA_BILL_TO_PROVINCE
      ,RAA_BILL_LOC.POSTAL_CODE RAA_BILL_TO_POSTAL_CODE
      ,FT_BILL.TERRITORY_SHORT_NAME FT_BILL_TO_COUNTRY
      ,DECODE(RAA_BILL.CUST_ACCT_SITE_ID
             ,NULL
             ,NULL
             ,ARH_ADDR_PKG.ARXTW_FORMAT_ADDRESS(RAA_BILL_LOC.ADDRESS_STYLE
                                               ,RAA_BILL_LOC.ADDRESS1
                                               ,RAA_BILL_LOC.ADDRESS2
                                               ,RAA_BILL_LOC.ADDRESS3
                                               ,RAA_BILL_LOC.ADDRESS4
                                               ,RAA_BILL_LOC.CITY
                                               ,RAA_BILL_LOC.COUNTY
                                               ,RAA_BILL_LOC.STATE
                                               ,RAA_BILL_LOC.PROVINCE
                                               ,RAA_BILL_LOC.POSTAL_CODE
                                               ,FT_BILL.TERRITORY_SHORT_NAME)) RAA_BILL_TO_CONCAT_ADDRESS
       
      ,DECODE(SUBSTRB(RACO_BILL_PARTY.PERSON_LAST_NAME
                     ,1
                     ,50)
             ,NULL
             ,SUBSTRB(RACO_BILL_PARTY.PERSON_FIRST_NAME
                     ,1
                     ,40)
             ,SUBSTRB(RACO_BILL_PARTY.PERSON_LAST_NAME
                     ,1
                     ,50) || ', ' || SUBSTRB(RACO_BILL_PARTY.PERSON_FIRST_NAME
                                            ,1
                                            ,40)) RACO_BILL_TO_CONTACT_NAME
      ,RAC_SHIP_PARTY.PARTY_NAME RAC_SHIP_TO_CUSTOMER_NAME --收货方
      ,RAC_SHIP.ACCOUNT_NUMBER RAC_SHIP_TO_CUSTOMER_NUM
      ,SU_SHIP.LOCATION SU_SHIP_TO_LOCATION --收货地点
      ,RAA_SHIP_LOC.ADDRESS1 RAA_SHIP_TO_ADDRESS1 --收货地址
      ,RAA_SHIP_LOC.ADDRESS2 RAA_SHIP_TO_ADDRESS2
      ,RAA_SHIP_LOC.ADDRESS3 RAA_SHIP_TO_ADDRESS3_DB
      ,DECODE(RAA_SHIP.CUST_ACCT_SITE_ID
             ,NULL
             ,NULL
             ,ARH_ADDR_PKG.FORMAT_LAST_ADDRESS_LINE(RAA_SHIP_LOC.ADDRESS_STYLE
                                                   ,RAA_SHIP_LOC.ADDRESS3
                                                   ,RAA_SHIP_LOC.ADDRESS4
                                                   ,RAA_SHIP_LOC.CITY
                                                   ,RAA_SHIP_LOC.COUNTY
                                                   ,RAA_SHIP_LOC.STATE
                                                   ,RAA_SHIP_LOC.PROVINCE
                                                   ,FT_SHIP.TERRITORY_SHORT_NAME
                                                   ,RAA_SHIP_LOC.POSTAL_CODE)) RAA_SHIP_TO_ADDRESS3
       
      ,RAA_SHIP_LOC.CITY RAA_SHIP_TO_CITY
      ,RAA_SHIP_LOC.COUNTY RAA_SHIP_TO_COUNTY
      ,RAA_SHIP_LOC.STATE RAA_SHIP_TO_STATE
      ,RAA_SHIP_LOC.PROVINCE RAA_SHIP_TO_PROVINCE
      ,RAA_SHIP_LOC.POSTAL_CODE RAA_SHIP_TO_POSTAL_CODE
      ,FT_SHIP.TERRITORY_SHORT_NAME FT_SHIP_TO_COUNTRY
      ,DECODE(RAA_SHIP.CUST_ACCT_SITE_ID
             ,NULL
             ,NULL
             ,ARH_ADDR_PKG.ARXTW_FORMAT_ADDRESS(RAA_SHIP_LOC.ADDRESS_STYLE
                                               ,RAA_SHIP_LOC.ADDRESS1
                                               ,RAA_SHIP_LOC.ADDRESS2
                                               ,RAA_SHIP_LOC.ADDRESS3
                                               ,RAA_SHIP_LOC.ADDRESS4
                                               ,RAA_SHIP_LOC.CITY
                                               ,RAA_SHIP_LOC.COUNTY
                                               ,RAA_SHIP_LOC.STATE
                                               ,RAA_SHIP_LOC.PROVINCE
                                               ,RAA_SHIP_LOC.POSTAL_CODE
                                               ,FT_SHIP.TERRITORY_SHORT_NAME)) RAA_SHIP_TO_CONCAT_ADDRESS
      ,DECODE(SUBSTRB(RACO_SHIP_PARTY.PERSON_LAST_NAME
                     ,1
                     ,50)
             ,NULL
             ,SUBSTRB(RACO_SHIP_PARTY.PERSON_FIRST_NAME
                     ,1
                     ,40)
             ,SUBSTRB(RACO_SHIP_PARTY.PERSON_LAST_NAME
                     ,1
                     ,50) || ', ' || SUBSTRB(RACO_SHIP_PARTY.PERSON_FIRST_NAME
                                            ,1
                                            ,40)) RACO_SHIP_TO_CONTACT_NAME
       
      ,RAC_SOLD_PARTY.PARTY_NAME RAC_SOLD_TO_CUSTOMER_NAME --采购方
      ,RAC_SOLD.ACCOUNT_NUMBER RAC_SOLD_TO_CUSTOMER_NUM
      ,RAC_PAYING_PARTY.PARTY_NAME RAC_PAYING_CUSTOMER_NAME --付款客户
      ,RAC_PAYING.ACCOUNT_NUMBER RAC_PAYING_CUSTOMER_NUM
      ,SU_PAYING.LOCATION SU_PAYING_CUSTOMER_LOCATION
      ,RAA_REMIT_LOC.ADDRESS1 RAA_REMIT_TO_ADDRESS1
      ,RAA_REMIT_LOC.ADDRESS2 RAA_REMIT_TO_ADDRESS2
      ,RAA_REMIT_LOC.ADDRESS3 RAA_REMIT_TO_ADDRESS3_DB
      ,DECODE(RAA_REMIT.CUST_ACCT_SITE_ID
             ,NULL
             ,NULL
             ,ARH_ADDR_PKG.FORMAT_LAST_ADDRESS_LINE(RAA_REMIT_LOC.ADDRESS_STYLE
                                                   ,RAA_REMIT_LOC.ADDRESS3
                                                   ,RAA_REMIT_LOC.ADDRESS4
                                                   ,RAA_REMIT_LOC.CITY
                                                   ,RAA_REMIT_LOC.COUNTY
                                                   ,RAA_REMIT_LOC.STATE
                                                   ,RAA_REMIT_LOC.PROVINCE
                                                   ,FT_REMIT.TERRITORY_SHORT_NAME
                                                   ,RAA_REMIT_LOC.POSTAL_CODE)) RAA_REMIT_TO_ADDRESS3
       
      ,RAA_REMIT_LOC.CITY RAA_REMIT_TO_CITY
      ,RAA_REMIT_LOC.COUNTY RAA_REMIT_TO_COUNTY
      ,RAA_REMIT_LOC.STATE RAA_REMIT_TO_STATE
      ,RAA_REMIT_LOC.PROVINCE RAA_REMIT_TO_PROVINCE
      ,RAA_REMIT_LOC.POSTAL_CODE RAA_REMIT_TO_POSTAL_CODE
      ,FT_REMIT.TERRITORY_SHORT_NAME FT_REMIT_TO_COUNTRY
      ,DECODE(RAA_REMIT.CUST_ACCT_SITE_ID
             ,NULL
             ,NULL
             ,ARH_ADDR_PKG.ARXTW_FORMAT_ADDRESS(RAA_REMIT_LOC.ADDRESS_STYLE
                                               ,RAA_REMIT_LOC.ADDRESS1
                                               ,RAA_REMIT_LOC.ADDRESS2
                                               ,RAA_REMIT_LOC.ADDRESS3
                                               ,RAA_REMIT_LOC.ADDRESS4
                                               ,RAA_REMIT_LOC.CITY
                                               ,RAA_REMIT_LOC.COUNTY
                                               ,RAA_REMIT_LOC.STATE
                                               ,RAA_REMIT_LOC.PROVINCE
                                               ,RAA_REMIT_LOC.POSTAL_CODE
                                               ,FT_REMIT.TERRITORY_SHORT_NAME)) RAA_CONCAT_REMIT_TO_ADDRESS
       
      ,APBA.BANK_ACCOUNT_NAME APBA_BANK_ACCOUNT_NAME
      ,DECODE(NVL(FND_PROFILE.VALUE('AR_MASK_BANK_ACCOUNT_NUMBERS')
                 ,'F')
             ,'N'
             ,APBA.BANK_ACCOUNT_NUM
             ,'F'
             ,RPAD(SUBSTRB(APBA.BANK_ACCOUNT_NUM
                          ,1
                          ,4)
                  ,LENGTH(APBA.BANK_ACCOUNT_NUM)
                  ,'*')
             ,'L'
             ,LPAD(SUBSTRB(APBA.BANK_ACCOUNT_NUM
                          ,-4)
                  ,LENGTH(APBA.BANK_ACCOUNT_NUM)
                  ,'*')) APBA_BANK_ACCOUNT_NUM
      ,APBA.INACTIVE_DATE APBA_INACTIVE_DATE
      ,APB.BANK_NAME APB_CUSTOMER_BANK_NAME
      ,APB.BANK_BRANCH_NAME APB_CUSTOMER_BANK_BRANCH_NAME
      ,ARM.NAME ARM_RECEIPT_METHOD_NAME
      ,ARM.PAYMENT_TYPE_CODE ARM_PAYMENT_TYPE_CODE
      ,ARC.CREATION_METHOD_CODE ARC_CREATION_METHOD_CODE
      ,BS.NAME BS_BATCH_SOURCE_NAME
      ,BS.AUTO_TRX_NUMBERING_FLAG BS_AUTO_TRX_NUMBERING_FLAG
      ,BS.COPY_DOC_NUMBER_FLAG BS_COPY_DOC_NUMBER_FLAG
      ,RAB.NAME RAB_BATCH_NAME
       
      ,CTT.NAME CTT_TYPE_NAME
      ,CTT.TYPE CTT_CLASS
      ,ARPT_SQL_FUNC_UTIL.GET_SALESREP_NAME_NUMBER(CT.PRIMARY_SALESREP_ID
                                                  ,'NAME') RAS_PRIMARY_SALESREP_NAME
      ,ARPT_SQL_FUNC_UTIL.GET_SALESREP_NAME_NUMBER(CT.PRIMARY_SALESREP_ID
                                                  ,'NUMBER') RAS_PRIMARY_SALESREP_NUM
      ,RAT.NAME RAT_TERM_NAME
      ,RAT.IN_USE RAT_TERM_IN_USE_FLAG
      ,SOA.NAME SOA_AGREEMENT_NAME
      ,ORF.DESCRIPTION OF_SHIP_VIA_NAME
      ,ORF.ORGANIZATION_ID OF_ORGANIZATION_ID
      ,AL_FOB.MEANING AL_FOB_MEANING
      ,AL_TAX.MEANING AL_DEFAULT_TAX_EXEMPT_FLAG
      ,CT.CT_REFERENCE CT_REFERENCE
      ,GD.GL_DATE GD_GL_DATE
      ,GDCT.USER_CONVERSION_TYPE GDCT_USER_EXCHANGE_RATE_TYPE
      ,ARPT_SQL_FUNC_UTIL.GET_CB_INVOICE(CT.CUSTOMER_TRX_ID
                                        ,CTT.TYPE) CT_INVOICE_FOR_CB
      ,ARPT_SQL_FUNC_UTIL.GET_DISPUTE_AMOUNT(CT.CUSTOMER_TRX_ID
                                            ,CTT.TYPE
                                            ,CTT.ACCOUNTING_AFFECT_FLAG) PS_DISPUTE_AMOUNT
      ,ARPT_SQL_FUNC_UTIL.GET_DISPUTE_DATE(CT.CUSTOMER_TRX_ID
                                          ,CTT.TYPE
                                          ,CTT.ACCOUNTING_AFFECT_FLAG) PS_DISPUTE_DATE
      ,ARPT_SQL_FUNC_UTIL.GET_MAX_DISPUTE_DATE(CT.CUSTOMER_TRX_ID
                                              ,CTT.TYPE
                                              ,CTT.ACCOUNTING_AFFECT_FLAG) DH_MAX_DISPUTE_DATE
       
      ,ARPT_SQL_FUNC_UTIL.GET_REVENUE_RECOG_RUN_FLAG(CT.CUSTOMER_TRX_ID
                                                    ,CT.INVOICING_RULE_ID) REV_RECOG_RUN_FLAG
      ,ARPT_SQL_FUNC_UTIL.GET_POSTED_FLAG(CT.CUSTOMER_TRX_ID
                                         ,CTT.POST_TO_GL
                                         ,CT.COMPLETE_FLAG) POSTED_FLAG --过账标识?
      ,ARPT_SQL_FUNC_UTIL.GET_SELECTED_FOR_PAYMENT_FLAG(CT.CUSTOMER_TRX_ID
                                                       ,CTT.ACCOUNTING_AFFECT_FLAG
                                                       ,CT.COMPLETE_FLAG) SELECTED_FOR_PAYMENT_FLAG
      ,ARPT_SQL_FUNC_UTIL.GET_ACTIVITY_FLAG(CT.CUSTOMER_TRX_ID
                                           ,CTT.ACCOUNTING_AFFECT_FLAG
                                           ,CT.COMPLETE_FLAG
                                           ,CTT.TYPE
                                           ,CT.INITIAL_CUSTOMER_TRX_ID
                                           ,CT.PREVIOUS_CUSTOMER_TRX_ID) ACTIVITY_FLAG
      ,CTT.POST_TO_GL CTT_POST_TO_GL_FLAG
      ,CTT.ACCOUNTING_AFFECT_FLAG CTT_OPEN_RECEIVABLES_FLAG
      ,CTT.ALLOW_FREIGHT_FLAG CTT_ALLOW_FREIGHT_FLAG
      ,CTT.CREATION_SIGN CTT_CREATION_SIGN
      ,CTT.ALLOW_OVERAPPLICATION_FLAG CTT_ALLOW_OVERAPPLICATION_FLAG
      ,CTT.NATURAL_APPLICATION_ONLY_FLAG CTT_NATURAL_APP_ONLY_FLAG
      ,CTT.TAX_CALCULATION_FLAG CTT_TAX_CALCULATION_FLAG
      ,CTT.DEFAULT_STATUS CTT_DEFAULT_STATUS
      ,CTT.DEFAULT_TERM CTT_DEFAULT_TERM
      ,CTT.DEFAULT_PRINTING_OPTION CTT_DEFAULT_PRINTING_OPTION
      ,DECODE(CT.INVOICING_RULE_ID
             ,NULL
             ,'N'
             ,'Y') RULES_FLAG
       
      ,DECODE(CT.PRINTING_LAST_PRINTED
             ,NULL
             ,'N'
             ,'Y') PRINTED_FLAG
      ,DECODE(CT.PREVIOUS_CUSTOMER_TRX_ID
             ,NULL
             ,'N'
             ,'Y') CM_AGAINST_TRX_FLAG
      ,SU_BILL.STATUS SITE_STATUS
      ,RAC_BILL.STATUS CUSTOMER_STATUS
      ,ARPT_SQL_FUNC_UTIL.GET_OVERRIDE_TERMS(CT.BILL_TO_CUSTOMER_ID
                                            ,CT.BILL_TO_SITE_USE_ID) OVERRIDE_TERMS
      ,DECODE(CT.INITIAL_CUSTOMER_TRX_ID
             ,NULL
             ,DECODE(CTT.TYPE
                    ,'DEP'
                    ,'N'
                    ,'GUAR'
                    ,'N'
                    ,'CB'
                    ,'N'
                    ,'Y')
             ,'Y') COMMITMENTS_EXIST_FLAG
      ,DECODE(CT.AGREEMENT_ID
             ,NULL
             ,DECODE(CTT.TYPE
                    ,'CM'
                    ,'N'
                    ,ARPT_SQL_FUNC_UTIL.GET_AGREEMENTS_EXIST_FLAG(CT.BILL_TO_CUSTOMER_ID
                                                                 ,CT.TRX_DATE))
             ,'Y') AGREEMENTS_EXIST_FLAG
      ,FND_ATTACHMENT_UTIL_PKG.GET_ATCHMT_EXISTS('RA_CUSTOMER_TRX'
                                                ,CT.CUSTOMER_TRX_ID) ATCHMT_FLAG
       
      ,CT.REVERSED_CASH_RECEIPT_ID REVERSED_CASH_RECEIPT_ID
  FROM RA_CUST_TRX_LINE_GL_DIST_ALL GD
      ,RA_CUSTOMER_TRX_ALL          CT
      ,HZ_CUST_ACCOUNTS             RAC_BILL
      ,HZ_PARTIES                   RAC_BILL_PARTY
      ,HZ_CUST_ACCOUNTS             RAC_SHIP
      ,HZ_PARTIES                   RAC_SHIP_PARTY
      ,HZ_CUST_ACCOUNTS             RAC_SOLD
      ,HZ_PARTIES                   RAC_SOLD_PARTY
      ,HZ_CUST_ACCOUNTS             RAC_PAYING
      ,HZ_PARTIES                   RAC_PAYING_PARTY
      ,HZ_CUST_SITE_USES_ALL        SU_BILL
      ,HZ_CUST_SITE_USES_ALL        SU_SHIP
      ,HZ_CUST_SITE_USES_ALL        SU_PAYING
      ,FND_TERRITORIES_VL           FT_BILL
      ,FND_TERRITORIES_VL           FT_SHIP
      ,FND_TERRITORIES_VL           FT_REMIT
      ,HZ_CUST_ACCT_SITES_ALL       RAA_BILL
      ,HZ_PARTY_SITES               RAA_BILL_PS
      ,HZ_LOCATIONS                 RAA_BILL_LOC
      ,HZ_CUST_ACCT_SITES_ALL       RAA_SHIP
      ,HZ_PARTY_SITES               RAA_SHIP_PS
      ,HZ_LOCATIONS                 RAA_SHIP_LOC
      ,HZ_CUST_ACCT_SITES_ALL       RAA_REMIT
      ,HZ_PARTY_SITES               RAA_REMIT_PS
      ,HZ_LOCATIONS                 RAA_REMIT_LOC
      ,HZ_CUST_ACCOUNT_ROLES        RACO_SHIP
      ,HZ_PARTIES                   RACO_SHIP_PARTY
      ,HZ_RELATIONSHIPS             RACO_SHIP_REL
      ,HZ_CUST_ACCOUNT_ROLES        RACO_BILL
      ,HZ_PARTIES                   RACO_BILL_PARTY
      ,HZ_RELATIONSHIPS             RACO_BILL_REL
      ,AP_BANK_ACCOUNTS_ALL         APBA
      ,AP_BANK_BRANCHES             APB
      ,AR_RECEIPT_METHODS           ARM
      ,AR_RECEIPT_CLASSES           ARC
      ,RA_BATCH_SOURCES_ALL         BS
      ,RA_BATCHES_ALL               RAB
      ,RA_CUST_TRX_TYPES_ALL        CTT
      ,RA_TERMS                     RAT
      ,SO_AGREEMENTS                SOA
      ,ORG_FREIGHT                  ORF
      ,GL_DAILY_CONVERSION_TYPES    GDCT
      ,RA_CUSTOMER_TRX_ALL          CT_REL
      ,AR_LOOKUPS                   AL_FOB
      ,AR_LOOKUPS                   AL_TAX
 WHERE CT.CUSTOMER_TRX_ID = GD.CUSTOMER_TRX_ID
   AND 'REC' = GD.ACCOUNT_CLASS
   AND 'Y' = GD.LATEST_REC_FLAG
   AND CT.RELATED_CUSTOMER_TRX_ID = CT_REL.CUSTOMER_TRX_ID(+)
   AND CT.BILL_TO_CUSTOMER_ID = RAC_BILL.CUST_ACCOUNT_ID
   AND RAC_BILL.PARTY_ID = RAC_BILL_PARTY.PARTY_ID
   AND CT.SHIP_TO_CUSTOMER_ID = RAC_SHIP.CUST_ACCOUNT_ID(+)
   AND RAC_SHIP.PARTY_ID = RAC_SHIP_PARTY.PARTY_ID(+)
   AND CT.SOLD_TO_CUSTOMER_ID = RAC_SOLD.CUST_ACCOUNT_ID(+)
   AND RAC_SOLD.PARTY_ID = RAC_SOLD_PARTY.PARTY_ID(+)
   AND CT.PAYING_CUSTOMER_ID = RAC_PAYING.CUST_ACCOUNT_ID(+)
   AND RAC_PAYING.PARTY_ID = RAC_PAYING_PARTY.PARTY_ID(+)
   AND CT.BILL_TO_SITE_USE_ID = SU_BILL.SITE_USE_ID
   AND CT.SHIP_TO_SITE_USE_ID = SU_SHIP.SITE_USE_ID(+)
   AND CT.PAYING_SITE_USE_ID = SU_PAYING.SITE_USE_ID(+)
   AND SU_BILL.CUST_ACCT_SITE_ID = RAA_BILL.CUST_ACCT_SITE_ID
   AND RAA_BILL.PARTY_SITE_ID = RAA_BILL_PS.PARTY_SITE_ID
   AND RAA_BILL_LOC.LOCATION_ID = RAA_BILL_PS.LOCATION_ID
   AND SU_SHIP.CUST_ACCT_SITE_ID = RAA_SHIP.CUST_ACCT_SITE_ID(+)
   AND RAA_SHIP.PARTY_SITE_ID = RAA_SHIP_PS.PARTY_SITE_ID(+)
   AND RAA_SHIP_LOC.LOCATION_ID(+) = RAA_SHIP_PS.LOCATION_ID
   AND CT.BILL_TO_CONTACT_ID = RACO_BILL.CUST_ACCOUNT_ROLE_ID(+)
   AND RACO_BILL.PARTY_ID = RACO_BILL_REL.PARTY_ID(+)
   AND RACO_BILL_REL.SUBJECT_TABLE_NAME(+) = 'HZ_PARTIES'
   AND RACO_BILL_REL.OBJECT_TABLE_NAME(+) = 'HZ_PARTIES'
   AND RACO_BILL_REL.DIRECTIONAL_FLAG(+) = 'F'
   AND RACO_BILL.ROLE_TYPE(+) = 'CONTACT'
   AND RACO_BILL_REL.SUBJECT_ID = RACO_BILL_PARTY.PARTY_ID(+)
   AND CT.SHIP_TO_CONTACT_ID = RACO_SHIP.CUST_ACCOUNT_ROLE_ID(+)
   AND RACO_SHIP.PARTY_ID = RACO_SHIP_REL.PARTY_ID(+)
   AND RACO_SHIP_REL.SUBJECT_TABLE_NAME(+) = 'HZ_PARTIES'
   AND RACO_SHIP_REL.OBJECT_TABLE_NAME(+) = 'HZ_PARTIES'
   AND RACO_SHIP_REL.DIRECTIONAL_FLAG(+) = 'F'
   AND RACO_SHIP.ROLE_TYPE(+) = 'CONTACT'
   AND RACO_SHIP_REL.SUBJECT_ID = RACO_SHIP_PARTY.PARTY_ID(+)
   AND CT.REMIT_TO_ADDRESS_ID = RAA_REMIT.CUST_ACCT_SITE_ID(+)
   AND RAA_REMIT.PARTY_SITE_ID = RAA_REMIT_PS.PARTY_SITE_ID(+)
   AND RAA_REMIT_LOC.LOCATION_ID(+) = RAA_REMIT_PS.LOCATION_ID
   AND RAA_BILL_LOC.COUNTRY = FT_BILL.TERRITORY_CODE(+)
   AND RAA_SHIP_LOC.COUNTRY = FT_SHIP.TERRITORY_CODE(+)
   AND RAA_REMIT_LOC.COUNTRY = FT_REMIT.TERRITORY_CODE(+)
   AND CT.CUSTOMER_BANK_ACCOUNT_ID = APBA.BANK_ACCOUNT_ID(+)
   AND APBA.BANK_BRANCH_ID = APB.BANK_BRANCH_ID(+)
   AND CT.RECEIPT_METHOD_ID = ARM.RECEIPT_METHOD_ID(+)
   AND ARM.RECEIPT_CLASS_ID = ARC.RECEIPT_CLASS_ID(+)
   AND CT.BATCH_SOURCE_ID = BS.BATCH_SOURCE_ID
   AND CT.BATCH_ID = RAB.BATCH_ID(+)
   AND CT.CUST_TRX_TYPE_ID = CTT.CUST_TRX_TYPE_ID
   AND CTT.TYPE <> 'BR'
   AND CT.TERM_ID = RAT.TERM_ID(+)
   AND CT.AGREEMENT_ID = SOA.AGREEMENT_ID(+)
   AND CT.EXCHANGE_RATE_TYPE = GDCT.CONVERSION_TYPE(+)
   AND 'FOB' = AL_FOB.LOOKUP_TYPE(+)
   AND CT.FOB_POINT = AL_FOB.LOOKUP_CODE(+)
   AND CT.SHIP_VIA = ORF.FREIGHT_CODE(+)
   AND CT.ORG_ID = ORF.ORGANIZATION_ID(+)
   AND 'TAX_CONTROL_FLAG' = AL_TAX.LOOKUP_TYPE(+)
   AND CT.DEFAULT_TAX_EXEMPT_FLAG = AL_TAX.LOOKUP_CODE(+)
   AND RACO_SHIP_REL.STATUS(+) = 'A'
   AND RACO_BILL_REL.STATUS(+) = 'A'
   AND CT.CUSTOMER_TRX_ID = 1485432;

--发票收款应用界面脚本

SELECT APP.CASH_RECEIPT_ID CASH_RECEIPT_ID
      ,PS_INV.CUSTOMER_TRX_ID CUSTOMER_TRX_ID
      ,TO_NUMBER('') CM_CUSTOMER_TRX_ID
      ,APP.LAST_UPDATE_DATE LAST_UPDATE_DATE
      ,APP.LAST_UPDATED_BY LAST_UPDATED_BY
      ,APP.CREATION_DATE CREATION_DATE
      ,APP.CREATED_BY CREATED_BY
      ,APP.LAST_UPDATE_LOGIN LAST_UPDATE_LOGIN
      ,APP.PROGRAM_APPLICATION_ID PROGRAM_APPLICATION_ID
      ,APP.PROGRAM_ID PROGRAM_ID
      ,APP.PROGRAM_UPDATE_DATE PROGRAM_UPDATE_DATE
      ,APP.REQUEST_ID REQUEST_ID
      ,CR.RECEIPT_NUMBER RECEIPT_NUMBER
      ,'Y' APPLIED_FLAG
      ,PS_INV.CUSTOMER_ID CUSTOMER_ID
      ,SUBSTRB(PARTY.PARTY_NAME
              ,1
              ,50) CUSTOMER_NAME
      ,CUST.ACCOUNT_NUMBER CUSTOMER_NUMBER
      ,PS_INV.TRX_NUMBER TRX_NUMBER
      ,TO_NUMBER(DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
                       ,-1
                       ,NULL
                       ,PS_INV.TERMS_SEQUENCE_NUMBER)) INSTALLMENT
      ,APP.AMOUNT_APPLIED AMOUNT_APPLIED
      ,NVL(APP.AMOUNT_APPLIED_FROM
          ,APP.AMOUNT_APPLIED) AMOUNT_APPLIED_FROM
      ,APP.TRANS_TO_RECEIPT_RATE TRANS_TO_RECEIPT_RATE
      ,TO_NUMBER(DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
                       ,-1
                       ,NULL
                       ,NVL(APP.EARNED_DISCOUNT_TAKEN
                           ,0) + NVL(APP.UNEARNED_DISCOUNT_TAKEN
                                    ,0))) DISCOUNT
      ,APP.EARNED_DISCOUNT_TAKEN DISCOUNTS_EARNED
      ,APP.UNEARNED_DISCOUNT_TAKEN DISCOUNTS_UNEARNED
      ,PS_INV.DISCOUNT_TAKEN_EARNED DISCOUNT_TAKEN_EARNED
      ,PS_INV.DISCOUNT_TAKEN_UNEARNED DISCOUNT_TAKEN_UNEARNED
      ,TO_NUMBER(DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
                       ,-1
                       ,NULL
                       ,PS_INV.AMOUNT_DUE_REMAINING)) AMOUNT_DUE_REMAINING
      ,DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
             ,-1
             ,TO_DATE(NULL)
             ,PS_INV.DUE_DATE) DUE_DATE
      ,PS_INV.STATUS STATUS
      ,PS_INV.TERM_ID TERM_ID
      ,DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
             ,-1
             ,NULL
             ,L_CLASS.MEANING) TRX_CLASS_NAME
      ,PS_INV.CLASS TRX_CLASS_CODE
      ,CTT.NAME TRX_TYPE_NAME
      ,CTT.CUST_TRX_TYPE_ID CUST_TRX_TYPE_ID
      ,CT.TRX_DATE TRX_DATE
      ,SU.LOCATION LOCATION_NAME
      ,CT.BILL_TO_SITE_USE_ID BILL_TO_SITE_USE_ID
      ,TO_NUMBER(DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
                       ,-1
                       ,NULL
                       ,TRUNC(APP.APPLY_DATE) - TRUNC(PS_INV.DUE_DATE))) DAYS_LATE
      ,CTL.LINE_NUMBER LINE_NUMBER
      ,CTL.CUSTOMER_TRX_LINE_ID CUSTOMER_TRX_LINE_ID
      ,APP.APPLY_DATE APPLY_DATE
      ,APP.GL_DATE GL_DATE
      ,APP.GL_POSTED_DATE GL_POSTED_DATE
      ,APP.REVERSAL_GL_DATE REVERSAL_GL_DATE
      ,PS_INV.EXCHANGE_RATE EXCHANGE_RATE
      ,DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
             ,-1
             ,CR.CURRENCY_CODE
             ,PS_INV.INVOICE_CURRENCY_CODE) INVOICE_CURRENCY_CODE
      ,PS_INV.AMOUNT_DUE_ORIGINAL AMOUNT_DUE_ORIGINAL
      ,PS_INV.AMOUNT_IN_DISPUTE AMOUNT_IN_DISPUTE
      ,PS_INV.AMOUNT_LINE_ITEMS_ORIGINAL AMOUNT_LINE_ITEMS_ORIGINAL
      ,TO_NUMBER(DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
                       ,-1
                       ,NULL
                       ,PS_INV.ACCTD_AMOUNT_DUE_REMAINING)) ACCTD_AMOUNT_DUE_REMAINING
      ,APP.ACCTD_AMOUNT_APPLIED_TO ACCTD_AMOUNT_APPLIED_TO
      ,APP.ACCTD_AMOUNT_APPLIED_FROM ACCTD_AMOUNT_APPLIED_FROM
      ,TO_NUMBER(DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
                       ,-1
                       ,NULL
                       ,APP.ACCTD_AMOUNT_APPLIED_FROM -
                        NVL(APP.ACCTD_AMOUNT_APPLIED_TO
                           ,APP.ACCTD_AMOUNT_APPLIED_FROM))) EXCHANGE_GAIN_LOSS
      ,PS_INV.DISCOUNT_REMAINING DISCOUNT_REMAINING
      ,ARPT_SQL_FUNC_UTIL.GET_TERM_DETAILS(PS_INV.TERM_ID
                                          ,'CALC_DISCOUNT_ON_LINES_FLAG') CALC_DISCOUNT_ON_LINES_FLAG
      ,ARPT_SQL_FUNC_UTIL.GET_TERM_DETAILS(PS_INV.TERM_ID
                                          ,'PARTIAL_DISCOUNT_FLAG') PARTIAL_DISCOUNT_FLAG
      ,CTT.ALLOW_OVERAPPLICATION_FLAG ALLOW_OVERAPPLICATION_FLAG
      ,CTT.NATURAL_APPLICATION_ONLY_FLAG NATURAL_APPLICATION_ONLY_FLAG
      ,CTT.CREATION_SIGN CREATION_SIGN
      ,PS_INV.PAYMENT_SCHEDULE_ID APPLIED_PAYMENT_SCHEDULE_ID
      ,APP.USSGL_TRANSACTION_CODE USSGL_TRANSACTION_CODE
      ,APP.USSGL_TRANSACTION_CODE_CONTEXT USSGL_TRANSACTION_CODE_CONTEXT
      ,CT.PURCHASE_ORDER PURCHASE_ORDER
      ,CT.DOC_SEQUENCE_ID TRX_DOC_SEQUENCE_ID
      ,CT.DOC_SEQUENCE_VALUE TRX_DOC_SEQUENCE_VALUE
      ,BS.NAME TRX_BATCH_SOURCE_NAME
      ,PS_INV.AMOUNT_ADJUSTED AMOUNT_ADJUSTED
      ,PS_INV.AMOUNT_ADJUSTED_PENDING AMOUNT_ADJUSTED_PENDING
      ,PS_INV.AMOUNT_LINE_ITEMS_REMAINING AMOUNT_LINE_ITEMS_REMAINING
      ,PS_INV.FREIGHT_ORIGINAL FREIGHT_ORIGINAL
      ,PS_INV.FREIGHT_REMAINING FREIGHT_REMAINING
      ,PS_INV.RECEIVABLES_CHARGES_REMAINING RECEIVABLES_CHARGES_REMAINING
      ,PS_INV.TAX_ORIGINAL TAX_ORIGINAL
      ,PS_INV.TAX_REMAINING TAX_REMAINING
      ,PS_INV.SELECTED_FOR_RECEIPT_BATCH_ID SELECTED_FOR_RECEIPT_BATCH_ID
      ,APP.RECEIVABLE_APPLICATION_ID RECEIVABLE_APPLICATION_ID
      ,APP.SECONDARY_APPLICATION_REF_ID SECONDARY_APPLICATION_REF_ID
      ,APP.COMMENTS
      ,CTT.ATTRIBUTE10 TRANSACTION_CATEGORY
      ,APP.RECEIVABLES_TRX_ID RECEIVABLES_TRX_ID
      ,DECODE(PS_INV.CLASS
             ,'PMT'
             ,ART.NAME
             ,DECODE(SIGN(APP.APPLIED_PAYMENT_SCHEDULE_ID)
                    ,-1
                    ,ART.NAME
                    ,NULL)) REC_ACTIVITY_NAME
      ,APP.APPLICATION_REF_TYPE
      ,ARPT_SQL_FUNC_UTIL.GET_LOOKUP_MEANING(DECODE(APP.APPLIED_PAYMENT_SCHEDULE_ID
                                                   ,-7
                                                   ,'AR_PREPAYMENT_TYPE'
                                                   ,'APPLICATION_REF_TYPE')
                                            ,APP.APPLICATION_REF_TYPE) APPLICATION_REF_TYPE_MEANING
      ,APP.APPLICATION_REF_ID
      ,APP.APPLICATION_REF_NUM
      ,APP.PAYMENT_SET_ID
      ,APP.APPLICATION_REF_REASON
      ,DECODE(APP.SECONDARY_APPLICATION_REF_ID
             ,NULL
             ,DECODE(PS_INV.CLASS
                    ,'CM'
                    ,ARPT_SQL_FUNC_UTIL.GET_LOOKUP_MEANING('CREDIT_MEMO_REASON'
                                                          ,CT.REASON_CODE)
                    ,ARPT_SQL_FUNC_UTIL.GET_LOOKUP_MEANING('INVOICING_REASON'
                                                          ,CT.REASON_CODE))
             ,ARP_DEDUCTION.GET_TM_ORACLE_REASON(APP.SECONDARY_APPLICATION_REF_ID)) APPLICATION_REF_REASON_MEANING
      ,APP.CUSTOMER_REFERENCE
      ,APP.CUSTOMER_REASON
      ,APP.APPLIED_REC_APP_ID
      ,APP.SECONDARY_APPLICATION_REF_TYPE SECONDARY_APPLICATION_REF_TYPE
      ,APP.SECONDARY_APPLICATION_REF_NUM SECONDARY_APPLICATION_REF_NUM
  FROM AR_RECEIVABLE_APPLICATIONS_ALL APP
      ,AR_CASH_RECEIPTS_ALL           CR
      ,AR_PAYMENT_SCHEDULES_ALL       PS_INV
      ,HZ_CUST_ACCOUNTS               CUST
      ,HZ_PARTIES                     PARTY
      ,RA_CUSTOMER_TRX_ALL            CT
      ,RA_CUST_TRX_TYPES_ALL          CTT
      ,RA_CUSTOMER_TRX_LINES_ALL      CTL
      ,RA_BATCH_SOURCES_ALL           BS
      ,HZ_CUST_SITE_USES_ALL          SU
      ,AR_CONS_INV_ALL                CI
      ,AR_LOOKUPS                     L_CLASS
      ,AR_RECEIVABLES_TRX_ALL         ART
 WHERE APP.DISPLAY = 'Y'
   AND APP.CASH_RECEIPT_ID = CR.CASH_RECEIPT_ID
   AND CT.CUSTOMER_TRX_ID(+) = PS_INV.CUSTOMER_TRX_ID
   AND BS.BATCH_SOURCE_ID(+) = CT.BATCH_SOURCE_ID
   AND CTT.CUST_TRX_TYPE_ID(+) = PS_INV.CUST_TRX_TYPE_ID
   AND CUST.CUST_ACCOUNT_ID(+) = PS_INV.CUSTOMER_ID
   AND CUST.PARTY_ID = PARTY.PARTY_ID(+)
   AND SU.SITE_USE_ID(+) = PS_INV.CUSTOMER_SITE_USE_ID
   AND CTL.CUSTOMER_TRX_LINE_ID(+) = APP.APPLIED_CUSTOMER_TRX_LINE_ID
   AND PS_INV.CLASS = L_CLASS.LOOKUP_CODE
   AND L_CLASS.LOOKUP_TYPE = 'INV/CM'
   AND CI.CONS_INV_ID(+) = PS_INV.CONS_INV_ID
   AND APP.APPLIED_PAYMENT_SCHEDULE_ID = PS_INV.PAYMENT_SCHEDULE_ID
   AND ART.RECEIVABLES_TRX_ID(+) = APP.RECEIVABLES_TRX_ID
   AND CR.CASH_RECEIPT_ID = 294508;


--应收发票及收款产生的会计科目 

--发票产生的会计科目

SELECT GP.PERIOD_NAME
                    ,A.CURRENCY_CODE
                    ,MEW_GET_TRANSACTION_PARTY_F(143
                                                ,A.THIRD_PARTY_NUMBER
                                                ,'C') THIRD_PARTY_NUMBER
                    ,GCC.SEGMENT4 || '.' || GCC.SEGMENT5 CONCATENATED_SEGMENTS
                    ,NVL(A.ENTERED_DR
                        ,0) ENTERED_DR
                    ,NVL(A.ENTERED_CR
                        ,0) ENTERED_CR
                    ,NVL(A.ACCOUNTED_DR
                        ,0) ACCOUNTED_DR
                    ,NVL(A.ACCOUNTED_CR
                        ,0) ACCOUNTED_CR
                FROM XLA_AR_INV_AEL_SL_V  A
                    ,GL_CODE_COMBINATIONS GCC
                    ,GL_PERIOD_STATUSES   GP
               WHERE A.APPLICATION_ID = 222
                 AND A.SET_OF_BOOKS_ID = 143
                 AND A.TRX_HDR_TABLE = 'CT'
                    --   AND A.TRX_HDR_ID = 1484132
                 AND A.ORG_ID BETWEEN 236 AND 242
                 AND GP.PERIOD_NAME = P_PERIOD
                 AND (GCC.SEGMENT4 = P_ACCOUNT OR P_ACCOUNT IS NULL)
                 AND A.CODE_COMBINATION_ID = GCC.CODE_COMBINATION_ID
                 AND A.ACCOUNTING_DATE >= GP.START_DATE
                 AND A.ACCOUNTING_DATE < GP.END_DATE + 1
                 AND GP.APPLICATION_ID = 222
                 AND GP.SET_OF_BOOKS_ID = 143
                 AND A.GL_TRANSFER_STATUS = 'Y'
              UNION ALL

--收款产生的会计科目
              SELECT GP.PERIOD_NAME
                    ,A.CURRENCY_CODE
                    ,MEW_GET_TRANSACTION_PARTY_F(143
                                                ,A.THIRD_PARTY_NUMBER
                                                ,'C') THIRD_PARTY_NUMBER
                    ,GCC.SEGMENT4 || '.' || GCC.SEGMENT5 CONCATENATED_SEGMENTS
                    ,NVL(A.ENTERED_DR
                        ,0) ENTERED_DR
                    ,NVL(A.ENTERED_CR
                        ,0) ENTERED_CR
                    ,NVL(A.ACCOUNTED_DR
                        ,0) ACCOUNTED_DR
                    ,NVL(A.ACCOUNTED_CR
                        ,0) ACCOUNTED_CR
                FROM XLA_AR_REC_AEL_SL_V  A
                    ,GL_CODE_COMBINATIONS GCC
                    ,GL_PERIOD_STATUSES   GP
               WHERE A.APPLICATION_ID = 222
                 AND A.SET_OF_BOOKS_ID = 143
                 AND A.TRX_HDR_TABLE = 'CR'
                    --    AND A.TRX_HDR_ID = 294467
                 AND A.CODE_COMBINATION_ID = GCC.CODE_COMBINATION_ID
                 AND A.ACCOUNTING_DATE >= GP.START_DATE
                 AND A.ACCOUNTING_DATE < GP.END_DATE + 1
                 AND A.ORG_ID BETWEEN 236 AND 242
                 AND GP.PERIOD_NAME = P_PERIOD
                 AND (GCC.SEGMENT4 = P_ACCOUNT OR P_ACCOUNT IS NULL)
                 AND GP.APPLICATION_ID = 222
                 AND GP.SET_OF_BOOKS_ID = 143
                 AND A.GL_TRANSFER_STATUS = 'Y'


--应收模块发票及收款数据与总账的关联即如何由总账追溯到应收

--从总账日记账追溯到应收发票
SELECT GJL.JE_LINE_NUM
      ,GJL.ENTERED_DR
      ,GJL.ENTERED_CR
      ,GJL.ACCOUNTED_DR
      ,GJL.ACCOUNTED_CR
      ,GJL.STAT_AMOUNT
      ,GJL.DESCRIPTION
      ,GJL.TRANSLATION_RATE
      ,GJL.TRANSLATION_AMOUNT
      ,GJL.USSGL_TRANSACTION_CODE
      ,GJL.SET_OF_BOOKS_ID
      ,GJL.CODE_COMBINATION_ID
      ,GJL.ROW_ID
      ,GJL.STATUS
      ,GJL.PERIOD_NAME
      ,GJL.IGNORE_RATE_FLAG
      ,GJL.EFFECTIVE_DATE
      ,GJL.REFERENCE_1
      ,GJL.REFERENCE_2
      ,GJL.REFERENCE_3
      ,GJL.REFERENCE_4
      ,GJL.REFERENCE_5
      ,GJL.REFERENCE_6
      ,GJL.REFERENCE_7
      ,GJL.REFERENCE_8
      ,GJL.REFERENCE_9
      ,GJL.REFERENCE_10
      ,GJL.CONTEXT
      ,GJL.ATTRIBUTE1
      ,GJL.ATTRIBUTE2
      ,GJL.ATTRIBUTE3
      ,GJL.ATTRIBUTE4
      ,GJL.ATTRIBUTE5
      ,GJL.ATTRIBUTE6
      ,GJL.ATTRIBUTE7
      ,GJL.ATTRIBUTE8
      ,GJL.ATTRIBUTE9
      ,GJL.ATTRIBUTE10
      ,GJL.CONTEXT2
      ,GJL.ATTRIBUTE11
      ,GJL.ATTRIBUTE12
      ,GJL.ATTRIBUTE13
      ,GJL.ATTRIBUTE14
      ,GJL.ATTRIBUTE15
      ,GJL.ATTRIBUTE16
      ,GJL.ATTRIBUTE17
      ,GJL.ATTRIBUTE18
      ,GJL.ATTRIBUTE19
      ,GJL.ATTRIBUTE20
      ,GJL.CONTEXT3
      ,GJL.TAX_CODE
      ,GJL.INVOICE_DATE
      ,GJL.INVOICE_IDENTIFIER
      ,GJL.INVOICE_AMOUNT
      ,GJL.NO1
      ,GJL.TAXABLE_LINE_FLAG
      ,GJL.TAX_TYPE_CODE
      ,GJL.TAX_CODE_ID
      ,GJL.TAX_ROUNDING_RULE_CODE
      ,GJL.AMOUNT_INCLUDES_TAX_FLAG
      ,GJL.TAX_DOCUMENT_IDENTIFIER
      ,GJL.TAX_DOCUMENT_DATE
      ,GJL.TAX_CUSTOMER_NAME
      ,GJL.TAX_CUSTOMER_REFERENCE
      ,GJL.TAX_REGISTRATION_NUMBER
      ,GJL.TAX_LINE_FLAG
      ,GJL.TAX_GROUP_ID
      ,GJL.CONTEXT4
      ,GJL.JGZZ_RECON_CONTEXT
      ,GJL.JGZZ_RECON_STATUS
      ,GJL.JGZZ_RECON_DATE
      ,GJL.JGZZ_RECON_ID
      ,GJL.JGZZ_RECON_REF
      ,GJL.JE_HEADER_ID
      ,GJL.GLOBAL_ATTRIBUTE1
      ,GJL.GLOBAL_ATTRIBUTE2
      ,GJL.GLOBAL_ATTRIBUTE3
      ,GJL.GLOBAL_ATTRIBUTE4
      ,GJL.GLOBAL_ATTRIBUTE5
      ,GJL.GLOBAL_ATTRIBUTE6
      ,GJL.GLOBAL_ATTRIBUTE7
      ,GJL.GLOBAL_ATTRIBUTE8
      ,GJL.GLOBAL_ATTRIBUTE9
      ,GJL.GLOBAL_ATTRIBUTE10
      ,GJL.GLOBAL_ATTRIBUTE_CATEGORY
      ,GJL.SUBLEDGER_DOC_SEQUENCE_ID
      ,GJL.SUBLEDGER_DOC_SEQUENCE_VALUE
      ,GJL.CREATION_DATE
      ,GJL.CREATED_BY
      ,GJL.LAST_UPDATE_DATE
      ,GJL.LAST_UPDATED_BY
      ,GJL.LAST_UPDATE_LOGIN
      ,GJL.WAD_ROW_ID
      ,GJL.TRANSACTION_TYPE
      ,GJL.TRANSACTION_DETAIL_TYPE
      ,GJL.EXCEPTION_FLAG
      ,GJL.AMOUNTS_FILLED_FLAG
      ,GJL.TO_CURRENCY_CODE
      ,GJL.TRANSLATED_DR
      ,GJL.TRANSLATED_CR
  FROM GL_JE_LINES_V                GJL
      ,RA_CUSTOMER_TRX_ALL          RCTA
      ,RA_CUST_TRX_LINE_GL_DIST_ALL RCLGDA
 WHERE (JE_HEADER_ID = 3332300)
   AND DESCRIPTION LIKE '%80210595%' --事务处理编号
   AND RCLGDA.CUST_TRX_LINE_GL_DIST_ID = GJL.REFERENCE_3
   AND GJL.REFERENCE_4 = RCTA.TRX_NUMBER
   AND GJL.REFERENCE_2 = RCTA.CUSTOMER_TRX_ID
   AND GJL.SUBLEDGER_DOC_SEQUENCE_ID = RCTA.DOC_SEQUENCE_ID
   AND GJL.SUBLEDGER_DOC_SEQUENCE_VALUE = RCTA.DOC_SEQUENCE_VALUE
 ORDER BY JE_LINE_NUM;


--从总账日记账追溯到应收收款
SELECT GJL.JE_LINE_NUM
      ,GJL.ENTERED_DR
      ,GJL.ENTERED_CR
      ,GJL.ACCOUNTED_DR
      ,GJL.ACCOUNTED_CR
      ,GJL.STAT_AMOUNT
      ,GJL.DESCRIPTION
      ,GJL.TRANSLATION_RATE
      ,GJL.TRANSLATION_AMOUNT
      ,GJL.USSGL_TRANSACTION_CODE
      ,GJL.SET_OF_BOOKS_ID
      ,GJL.CODE_COMBINATION_ID
      ,GJL.ROW_ID
      ,GJL.STATUS
      ,GJL.PERIOD_NAME
      ,GJL.IGNORE_RATE_FLAG
      ,GJL.EFFECTIVE_DATE
      ,GJL.REFERENCE_1
      ,GJL.REFERENCE_2
      ,GJL.REFERENCE_3
      ,GJL.REFERENCE_4
      ,GJL.REFERENCE_5
      ,GJL.REFERENCE_6
      ,GJL.REFERENCE_7
      ,GJL.REFERENCE_8
      ,GJL.REFERENCE_9
      ,GJL.REFERENCE_10
      ,GJL.CONTEXT
      ,GJL.ATTRIBUTE1
      ,GJL.ATTRIBUTE2
      ,GJL.ATTRIBUTE3
      ,GJL.ATTRIBUTE4
      ,GJL.ATTRIBUTE5
      ,GJL.ATTRIBUTE6
      ,GJL.ATTRIBUTE7
      ,GJL.ATTRIBUTE8
      ,GJL.ATTRIBUTE9
      ,GJL.ATTRIBUTE10
      ,GJL.CONTEXT2
      ,GJL.ATTRIBUTE11
      ,GJL.ATTRIBUTE12
      ,GJL.ATTRIBUTE13
      ,GJL.ATTRIBUTE14
      ,GJL.ATTRIBUTE15
      ,GJL.ATTRIBUTE16
      ,GJL.ATTRIBUTE17
      ,GJL.ATTRIBUTE18
      ,GJL.ATTRIBUTE19
      ,GJL.ATTRIBUTE20
      ,GJL.CONTEXT3
      ,GJL.TAX_CODE
      ,GJL.INVOICE_DATE
      ,GJL.INVOICE_IDENTIFIER
      ,GJL.INVOICE_AMOUNT
      ,GJL.NO1
      ,GJL.TAXABLE_LINE_FLAG
      ,GJL.TAX_TYPE_CODE
      ,GJL.TAX_CODE_ID
      ,GJL.TAX_ROUNDING_RULE_CODE
      ,GJL.AMOUNT_INCLUDES_TAX_FLAG
      ,GJL.TAX_DOCUMENT_IDENTIFIER
      ,GJL.TAX_DOCUMENT_DATE
      ,GJL.TAX_CUSTOMER_NAME
      ,GJL.TAX_CUSTOMER_REFERENCE
      ,GJL.TAX_REGISTRATION_NUMBER
      ,GJL.TAX_LINE_FLAG
      ,GJL.TAX_GROUP_ID
      ,GJL.CONTEXT4
      ,GJL.JGZZ_RECON_CONTEXT
      ,GJL.JGZZ_RECON_STATUS
      ,GJL.JGZZ_RECON_DATE
      ,GJL.JGZZ_RECON_ID
      ,GJL.JGZZ_RECON_REF
      ,GJL.JE_HEADER_ID
      ,GJL.GLOBAL_ATTRIBUTE1
      ,GJL.GLOBAL_ATTRIBUTE2
      ,GJL.GLOBAL_ATTRIBUTE3
      ,GJL.GLOBAL_ATTRIBUTE4
      ,GJL.GLOBAL_ATTRIBUTE5
      ,GJL.GLOBAL_ATTRIBUTE6
      ,GJL.GLOBAL_ATTRIBUTE7
      ,GJL.GLOBAL_ATTRIBUTE8
      ,GJL.GLOBAL_ATTRIBUTE9
      ,GJL.GLOBAL_ATTRIBUTE10
      ,GJL.GLOBAL_ATTRIBUTE_CATEGORY
      ,GJL.SUBLEDGER_DOC_SEQUENCE_ID
      ,GJL.SUBLEDGER_DOC_SEQUENCE_VALUE
      ,GJL.CREATION_DATE
      ,GJL.CREATED_BY
      ,GJL.LAST_UPDATE_DATE
      ,GJL.LAST_UPDATED_BY
      ,GJL.LAST_UPDATE_LOGIN
      ,GJL.WAD_ROW_ID
      ,GJL.TRANSACTION_TYPE
      ,GJL.TRANSACTION_DETAIL_TYPE
      ,GJL.EXCEPTION_FLAG
      ,GJL.AMOUNTS_FILLED_FLAG
      ,GJL.TO_CURRENCY_CODE
      ,GJL.TRANSLATED_DR
      ,GJL.TRANSLATED_CR
      ,ADA.LINE_ID
  FROM GL_JE_LINES_V        GJL
      ,AR_CASH_RECEIPTS_ALL ACRA
      ,AR_DISTRIBUTIONS_ALL ADA
 WHERE (GJL.JE_HEADER_ID = 3332299)
   AND GJL.DESCRIPTION LIKE '%20120113001%' --收款编号
   AND GJL.SUBLEDGER_DOC_SEQUENCE_ID = ACRA.DOC_SEQUENCE_ID
   AND GJL.SUBLEDGER_DOC_SEQUENCE_VALUE = ACRA.DOC_SEQUENCE_VALUE
   AND ADA.LINE_ID = GJL.REFERENCE_3 --收款分配ID
 ORDER BY JE_LINE_NUM;


--AR与OM关联关系

interface_line_context : 'ORDER ENTRY'
interface_line_attribute1: order_number
interface_line_attribute2: order_type
interface_line_attribute3: delivery_id
interface_line_attribute4: Waybill
interface_line_attribute5: Count
interface_line_attribute6: order line id
interface_line_attribute10 warehouse id

 

posted @ 2012-05-29 17:58  我不卖豆腐  阅读(1159)  评论(0编辑  收藏  举报