Friday, March 10, 2017

Useful query for Accounts Ledger Report in Oracle


select a.account_id,a.account_name,a.voucher_date, a.DOC_TYPE_ID
  ,a.VOUCHER_NO,b.debit,b.credit,b.narration from
(
select a.account_id ,sum(b.debit)-sum(b.credit) open from
(
select a.account_id,b.debit,b.credit
from voucher_dtl b,voucher_mst a
where a.account_id=:account_id
AND DOC_TYPE_ID='JV'
union all
select a.account_id ,b,debit,b.credit from voucher_mst a,voucher_dtl b
where DOC_TYPE_ID='JV'
)
group by account_id
)a
,
(SELECT a.voucher_date, a.VOUCHER_NO,
a.DOC_TYPE_ID , ACCOUNT_ID, A.ACCOUNT_NAME,
(B.DEBIT) DEBIT, B.NARRATION, (B.CREDIT) CREDITt
FROM voucher_mst a,voucher_dtl b
where ACCOUNT_ID=:ACCOUNT_ID
AND DOC_TYPE_ID='JV'
and
(DEBIT>0
or
CREDIT>0
)

)b,
(
select account_code ,sum(dr_amount)-sum(cr_Amount) due from
(
select account_code,dr_Amount,cr_amount
from MATRIX.journal
where account_code=:accounts
and cDate<=:date_2
AND decode(:STATUS,'ORIGINAL',o_r,'IT',I_T,'GST',G_T)='YES'
AND decode(:ORG,'ALL','ALL',COMPANY)=:ORG
and voucher_type<>'Open'
union all
select account_code ,dr_Amount,cr_amount from MATRIX.journal
where voucher_type='Open'
AND decode(:STATUS,'ORIGINAL',o_r,'IT',I_T,'GST',G_T)='YES'
AND decode(:ORG,'ALL','ALL',COMPANY)=:ORG
and account_code=:accounts
)
group by account_code
)c,MATRIX.ledger
where a.account_code=b.account_code(+)
and a.account_code=c.account_code(+)
and a.account_Code=ledger.accountid

order by cdate

No comments:

Post a Comment