Oracle AR - 收款界面上的非数据库项金额查询SQL

SELECT SUM(decode(ra.status
                 ,'APP'
                 ,decode(ra.confirmed_flag
                        ,'N'
                        ,0
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0))
                 ,'ACTIVITY'
                 ,decode(ra.applied_payment_schedule_id
                        ,-2
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,-3
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,-5
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,-6
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,-8
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,-9
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,decode(ra.receivables_trx_id
                               ,-16
                               ,nvl(nvl(ra.amount_applied_from
                                       ,ra.amount_applied)
                                   ,0)))
                 ,0)) applied_amount --已核销金额
      ,SUM(decode(ra.status
                 ,'ACTIVITY'
                 ,decode(applied_payment_schedule_id
                        ,-3
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,0)
                 ,0)) write_off_amount
      ,SUM(decode(ra.status
                 ,'ACTIVITY'
                 ,decode(applied_payment_schedule_id
                        ,-5
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,0)
                 ,0)) chargeback_amount
      ,SUM(decode(ra.status, 'UNAPP', nvl(ra.amount_applied, 0), 0)) unapplied_amount --未核销金额
      ,SUM(decode(ra.status, 'ACC', nvl(ra.amount_applied, 0), 0)) on_account_amount --记账金额
      ,SUM(decode(ra.status
                 ,'OTHER ACC'
                 ,decode(applied_payment_schedule_id
                        ,-4
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,0)
                 ,0)) claim_amount --现金索赔金额
      ,SUM(decode(ra.status
                 ,'OTHER ACC'
                 ,decode(applied_payment_schedule_id
                        ,-7
                        ,nvl(nvl(ra.amount_applied_from, ra.amount_applied)
                            ,0)
                        ,0)
                 ,0)) prepayment_amount --预付款金额
      ,SUM(decode(ra.status, 'UNID', nvl(ra.amount_applied, 0), 0)) unidentified_amount --未标识金额
      ,SUM(decode(ra.status, 'APP', nvl(ra.earned_discount_taken, 0), 0)) discounts_earned --应得折扣金额
      ,SUM(decode(ra.status, 'APP', nvl(ra.unearned_discount_taken, 0), 0)) discounts_unearned --未得折扣金额
      ,SUM(decode(ra.status
                 ,'APP'
                 ,nvl(ra.acctd_amount_applied_from -
                      ra.acctd_amount_applied_to
                     ,0)
                 ,'ACTIVITY'
                 ,nvl(ra.acctd_amount_applied_from -
                      ra.acctd_amount_applied_to
                     ,0)
                 ,0)) tot_exchange_gain_loss --汇率损益
  FROM ar_receivable_applications_all ra
 WHERE ra.cash_receipt_id = &p_cr_id;

注:SQL来源ARP_PROCESS_RCTS.POST_QUERY_LOGIC。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值