Friday, October 14, 2016

Ledger Postings

I`m not an accountant, so I have problems navigating the Ledger Data Model.  I recently had a request, so I took the opportunity to see how things link together.  The query looked useful, so I thought I would keep a copy of it.


                DECLARE @recId BIGINT

                SELECT @recId = RECID
                FROM MAINACCOUNT
                WHERE MAINACCOUNTID = 'your account id'

                SELECT GJE.ACCOUNTINGDATE Date,LJTA.JOURNALNUM Journal,
                GJE.SUBLEDGERVOUCHER Voucher, V.ACCOUNTNUM Vendor, D.NAME Name,
                LJTR.INVOICE Invoice, GJAE.TEXT Description, GJAE.TRANSACTIONCURRENCYCODE Currency, 
                GJAE.TRANSACTIONCURRENCYAMOUNT TransactionAmount,
                GJAE.ACCOUNTINGCURRENCYAMOUNT AccountingAmount
                FROM LedgerJournalTable LJTA
                INNER JOIN LedgerJournalTrans LJTR ON LJTA.JOURNALNUM = LJTR.JOURNALNUM
                                AND LJTA.DATAAREAID = LJTR.DATAAREAID
                                AND LJTA.PARTITION = LJTR.PARTITION
                INNER JOIN GeneralJournalEntry GJE ON GJE.SUBLEDGERVOUCHER = LJTR.VOUCHER
                                AND GJE.PARTITION = LJTR.PARTITION
                INNER JOIN GeneralJournalAccountEntry GJAE ON GJE.RECID = GJAE.GENERALJOURNALENTRY
                                AND GJE.PARTITION = GJAE.PARTITION
                INNER JOIN DimensionAttributeValueCombination DAVCV ON DAVCV.RECID = LJTR.LEDGERDIMENSION
                                AND DAVCV.PARTITION = LJTR.PARTITION
                INNER JOIN VENDTABLE V ON V.ACCOUNTNUM = DAVCV.DISPLAYVALUE
                                AND V.PARTITION = DAVCV.PARTITION
                INNER JOIN DIRPARTYTABLE D ON V.PARTY = D.RECID
                                AND V.PARTITION = D.PARTITION
                WHERE EXISTS (SELECT 1 FROM DimensionAttributeValueCombination DAVC
                                WHERE DAVC.RecId = GJAE.LEDGERDIMENSION
                                AND DAVC.PARTITION = GJAE.PARTITION
                                AND DAVC.MAINACCOUNT = @recId);

No comments:

Post a Comment