應收計算SQL

2021-08-30 16:55:17 字數 4547 閱讀 4480

應收開票金額:

select sum(rcl.extended_amount * nvl(rct.exchange_rate, 1))

from ra_customer_trx_all rct,

ra_customer_trx_lines_all rcl,

ra_cust_trx_line_gl_dist_all gd,

ra_cust_trx_types_all ctt

where 1 = 1

and rct.customer_trx_id = gd.customer_trx_id

and 'rec' = gd.account_class

and 'y' = gd.latest_rec_flag

and rct.customer_trx_id = rcl.customer_trx_id

and rct.cust_trx_type_id = ctt.cust_trx_type_id

and ctt.type in ('inv', 'cm') --標準發票,貸項通知單

and ctt.org_id = rct.org_id

and gd.gl_date < = to_date('&deadline_date','yyyy-mm-dd')

and rct.trx_number = '&in_trx_number';

收款原始金額:

分為兩部分:

1。不存在沖銷記錄的收款金額:

select cr.amount * nvl(cr.exchange_rate, 1) amount

from ar_cash_receipts_all cr,

ar_cash_receipt_history_all crh_first_posted

where 1 = 1

and crh_first_posted.cash_receipt_id = cr.cash_receipt_id

and crh_first_posted.org_id = cr.org_id

and crh_first_posted.first_posted_record_flag = 'y'

and cr.cash_receipt_id = &in_cash_receipt_id

and trunc(crh_first_posted.gl_date) <=

trunc(to_date(&iv_deadline, 'yyyy-mm-dd hh24:mi:ss'))

and not exists

(select 1

from ar_cash_receipt_history_all crh_current --沖銷日期;

where crh_current.cash_receipt_id = cr.cash_receipt_id

and crh_current.org_id = cr.org_id

and crh_current.current_record_flag = nvl('y', cr.receipt_number)

and crh_current.status = 'reversed')

2。存在收款記錄的收款金額:

select cr.amount * nvl(cr.exchange_rate, 1) amount,

from ar_cash_receipts_all cr,

ar_cash_receipt_history_all crh_first_posted,

ar_cash_receipt_history_all crh_current --沖銷日期

where 1 = 1

and crh_first_posted.cash_receipt_id = cr.cash_receipt_id

and crh_first_posted.org_id = cr.org_id

and crh_first_posted.first_posted_record_flag = 'y'

and cr.cash_receipt_id = &in_cash_receipt_id

and trunc(crh_first_posted.gl_date) <=

trunc(to_date(&iv_deadline, 'yyyy-mm-dd hh24:mi:ss'))

and crh_current.cash_receipt_id = cr.cash_receipt_id

and crh_current.org_id = cr.org_id

and crh_current.current_record_flag = nvl('y', cr.receipt_number)

and crh_current.status = 'reversed'

--沖銷gl日期早於或者等於引數"截止日期不選

and crh_current.gl_date >

trunc(to_date(&iv_deadline, 'yyyy-mm-dd hh24:mi:ss'))

3。開票已核銷

select sum(decode(rcta.invoice_currency_code,

'cny',

decode(upper(upper(rctta.type)) ||

'cmcm',

decode(upper(upper(rctta.type)) ||

'cmcm',

from ar.ra_customer_trx_all rcta,

ar.ra_cust_trx_types_all rctta,

ar.ra_cust_trx_line_gl_dist_all rctlgda,

where rcta.cust_trx_type_id = rctta.cust_trx_type_id

and upper(rctta.type) in ('inv', 'cm', 'dm')

and upper(rctta.post_to_gl) = 'y'

and upper(rctta.accounting_affect_flag) = 'y'

and upper(rctlgda.account_class) = 'rec'

and upper(rctlgda.latest_rec_flag) = 'y'

and rctlgda.customer_trx_id = rcta.customer_trx_id

and upper(rcta.complete_flag) =

decode(upper('n'), 'y', upper(rcta.complete_flag), 'n', 'y')

araa.customer_trx_id = rcta.customer_trx_id)

and araa.display = 'y'

and rcta.trx_number = &in_trx_number

4。收款已核銷

select acra.cash_receipt_id,

acra.receipt_number,

decode(acra.currency_code,

'cny',

0),nvl(araa.trans_to_receipt_rate, 1))

from ar_cash_receipts_all acra,

ar_cash_receipt_history_all acrha,

where acrha.gl_date <= to_date('&deadline_date', 'yyyy-mm-dd')

and (((acra.receipt_method_id = 1042 and

acrha.status not in ('remitted', 'cleared' , 'risk_eliminated') and

nvl(acrha.current_record_flag, 'y') = 'y')) or

(acra.receipt_method_id <> 1042 and

nvl(acrha.current_record_flag, 'n') = 'y'))

and exists (select 'a'

from ar_cash_receipt_history_all t

where t.cash_receipt_id = acrha.cash_receipt_id

and t.current_record_flag = 'y'

and t.status != 'reversed')

and acra.cash_receipt_id = acrha.cash_receipt_id

and upper(acrha.status) != 'reversed'

and araa.cash_receipt_id = acra.cash_receipt_id

and araa.display = 'y'

and araa.gl_date <= to_date('&deadline_date', 'yyyy-mm-dd')

and acra.receipt_number = '&in_receipt_number';

以上sql在r12中已經驗證過,並非100%原創。希望對大家有幫助。

我也是站在了巨人的肩上。哈哈

應收計算SQL

應收開票金額 select sum rcl.extended amount nvl rct.exchange rate,1 from ra customer trx all rct,ra customer trx lines all rcl,ra cust trx line gl dist all ...

ERP實務 何謂應收 逾期應收 提列呆帳

應收帳款 所謂的應收帳款指的是,當貨品或服務銷售給客戶之後,應該向客戶端收取的金額款項,這部份稱之為應收帳款的加項。而一般是由預收 暫收 銷退 折讓而產生的待抵帳款,這部份就被歸列在應收帳款的減項。逾期應收 一般來說,在與客戶敲定訂單時,會一併把收款條件談好,所以立應收時,就會有乙個應收款日。而逾期...

金蝶應收應付模組流程 金蝶應收應付手冊

1 公司資訊 公司資訊內容包括 公司名稱 位址 稅務登記號 開戶銀行和賬號。系統可以根據此處錄入的開戶銀行和賬號,在新增收款單 退款單 預收單時自 動填充。公司名稱 公司位址和公司 預設取賬套設定中對應的內容,允許修改,但是修改後不回填賬套設定中對應的內容。開戶銀行 賬號 稅務登記號預設取系統設定 ...