AR Balancing - Accounts Receivable Balance to General Ledger
The AR Balance Super Query
SELECT 'POSTED AR ',sum(D.CREDIT_AMOUNT) AMOUNT FROM ARTCSHDT D UNION select 'AR BEG BAL ',sum(debit_amount) from artinv I where invoice_type='B' UNION select 'INVOICED AR ',sum(debit_amount) from artinv I where invoice_type<>'B' UNION select 'INVOICED GL ' ,SUM(TRX_AMOUNT) AMOUNT from glttrx where source_app='R' and source_trans_type IN ('IR','SR') UNION select 'POSTED GL ' ,SUM(TRX_AMOUNT) AMOUNT from glttrx where source_app='R' and source_trans_type IN ('CR','PR') UNION select 'INV DB TOT ' ,SUM(DEBIT_AMOUNT) AMOUNT from ARTINV UNION select 'INV CR TOT ' ,SUM(CREDIT_AMOUNT) AMOUNT from ARTINV UNION select 'AR BALANCE ', sum(debit_amount-credit_amount) ar_balance from artinv UNION select 'AR BAL G/L ', sum(trx_amount) from glttrx where gl_account=:ar_account UNION select 'ARGL<> APP R' ,SUM(TRX_AMOUNT) AMOUNT from glttrx where source_APP<>'R' AND GL_ACCOUNT=:ar_account UNION select CAST('ARGL R ST:'||SOURCE_TRANS_TYPE AS CHAR(12)) ,SUM(TRX_AMOUNT) AMOUNT from glttrx where source_app='R' and source_trans_type not IN ('IR','SR','CR','PR') and GL_ACCOUNT=:ar_account GROUP BY SOURCE_TRANS_TYPE