Home » Listing Details
Top Websites
  1. Dynamics GP Help
    Over 6400 resources listed.
  2. Mark Polino's DynamicAccounting.net
    Over 5100 resources listed.
  3. Rose Business Solutions Blog New
    Over 2200 resources listed.
  4. Developing for Dynamics GP - By David Musgrave and the MS GP Dev Support Team
    Over 1100 resources listed.
  5. Mariano Gomez at The Dynamics GP Blogster
    Over 1000 resources listed.
  6. Microsoft Dynamics Partner Community Blog
    Over 900 resources listed.
  7. Christina Phillips, Steve Endow & Lorren Zemke at Dynamics GP Land
    Over 700 resources listed.
  8. Mohammad Daoud's Dynamics GP Blog
    Over 600 resources listed.
  9. Vaidy Mohan at Dynamics GP - Learn & Discuss
    Over 500 resources listed.
  10. Inside Microsoft Dynamics GP Official Blog
    Over 500 resources listed.
  11. eOne Business Solutions Blog
    Over 400 resources listed.
  12. About Dynamics, Development and Life
    Over 300 resources listed.
  13. Frank Hamelly at GP2theMax
    Over 300 resources listed.
  14. Dynamics CPM
    Over 300 resources listed.
  15. BKD Dynamics GP Insights Blog
    Over 200 resources listed.
  16. Leslie Vail at Dynamics Confessor Blogspot
    Over 200 resources listed.
  17. Victoria Yudin's Dynamics GP Website
    Over 200 resources listed.
    Victoria Yudin
  18. Janakiram M.P. at DynamicsBlogger
    Over 100 resources listed.
  19. VS Tools Forum
    Over 100 resources listed.
    Your Resource for Visual Studio Tools for Dynamics GP
  20. Inside Microsoft Dynamics GP Official Blog
    Over 100 resources listed.
  21. US Dynamics GP Field Team Blog
    Over 100 resources listed.
  22. Catherine Eibner MBS Developer Evangelist
    Over 100 resources listed.
  23. Sivakumar Venkataraman at Interesting Findings & Knowledge Sharing
    Over 100 resources listed.
  24. Dynamics Small Business
    Over 100 resources listed.
  25. Belinda, The GP CSI
    Over 100 resources listed.

ID:12670
Title:SQL View for Payables Transactions with AA Codes
URL:http://cvakumar.com/msdynamics/2010/03/01/sql-view-for-payables-transactions-with-aa-codes/
Description:

Guys

There is a smartlist object for AP transactions, but this smartlist does not show the analytical accounting information in it.

So in this post, I have decided to post a SQL view to generate a view to show AP transaction information along with the analytical accounting information.


IF EXISTS ( SELECT  *
            FROM    sys.views
            WHERE   object_id = OBJECT_ID(N'[dbo].[vw_AAG20000]') )
    DROP VIEW  [dbo].[vw_AAG20000]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vw_AAG20000]
AS  SELECT  [aaSubLedgerHdrID],
            [SERIES],
            [DOCTYPE] = CASE WHEN [DOCTYPE] = 0 THEN 1
                             WHEN [DOCTYPE] = 1 THEN 6
                             ELSE 5
                        END,
            [DOCNUMBR],
            [Master_ID],
            [aaHdrErrors],
            [DEX_ROW_ID]
    FROM    [dbo].[AAG20000]

GO

IF EXISTS ( SELECT  *
            FROM    sys.views
            WHERE   object_id = OBJECT_ID(N'[dbo].[vw_APTransactions]') )
    DROP VIEW  [dbo].[vw_APTransactions]

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vw_APTransactions]
AS  SELECT  *,
            'Open' AS STATUS
    FROM    dbo.PM20000
    UNION ALL
    SELECT  *,
            'History' AS STATUS
    FROM    dbo.PM30200

GO

IF EXISTS ( SELECT  *
            FROM    sys.views
            WHERE   object_id = OBJECT_ID(N'[dbo].[vw_APAAInformation]') )
    DROP VIEW  [dbo].[vw_APAAInformation]

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[vw_APAAInformation]
AS  SELECT  A.VENDORID,
            I.VENDNAME,
            I.VNDCLSID AS VENDORCLASS,
            J.VNDCLDSC AS VENDORCLASSDESC,
            A.VCHRNMBR AS VOUCHERNO,
            A.DOCNUMBR AS INVOICENO,
            A.DOCDATE AS DOCUMENTDATE,
            A.PSTGDATE AS POSTINGDATE,
            G.ACTNUMST AS GLACCOUNTNO,
            H.ACTDESCR AS GPACCOUNTDESC,
            F.aaTrxDimCode AS DIMCODE,
            F.aaTrxDimCodeDescr AS DIMCODEDESC,
            ( C.DEBITAMT - C.CRDTAMNT ) AS AMOUNT,
            YEAR(A.PSTGDATE) AS TRXYEAR,
            'Week ' + REPLICATE('0', 2 - LEN({fn WEEK(A.PSTGDATE)}))
            + LTRIM(RTRIM(STR({fn WEEK(A.PSTGDATE)}))) AS WEEKNO,
            REPLICATE('0', 2 - LEN(MONTH(A.PSTGDATE)))
            + ( LTRIM(RTRIM(STR(MONTH(A.PSTGDATE)))) + ':'
                + ( LEFT({fn  MONTHNAME(A.PSTGDATE)}, 3) ) + ''''
                + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))), 3, 2) ) AS PERIOD,
            QUARTERNO = CASE {fn QUARTER(A.PSTGDATE)}
                          WHEN 1
                          THEN 'Q1:Jan' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2) + '-Mar' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2)
                          WHEN 2
                          THEN 'Q2:Apr' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2) + '-Jun' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2)
                          WHEN 3
                          THEN 'Q3:Jul' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2) + '-Sep' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2)
                          ELSE 'Q4:Oct' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2) + '-Dec' + ''''
                               + SUBSTRING(LTRIM(RTRIM(STR(YEAR(A.PSTGDATE)))),
                                           3, 2)
                        END,
            A.[STATUS] AS STATUS,
            DOCUMENTTYPE = CASE WHEN A.DOCTYPE = 1 THEN 'Invoices'
                                WHEN A.DOCTYPE = 5 THEN 'Credit Notes'
                                WHEN A.DOCTYPE = 6
                                     AND A.CHEKBKID = 'XXXXX' THEN 'Checks'
                                WHEN A.DOCTYPE = 6
                                     AND A.CHEKBKID = 'YYYYY' THEN 'ACH'
                                WHEN A.DOCTYPE = 6
                                     AND A.CHEKBKID = 'ZZZZZ' THEN 'Wires'
                                ELSE 'Miscellaneous'
                           END,
            A.CHEKBKID AS CHECKBOOK
    FROM    dbo.vw_APTransactions A
            INNER JOIN dbo.vw_AAG20000 B
                ON B.DOCNUMBR = A.VCHRNMBR
                   AND B.DOCTYPE = A.DOCTYPE
            INNER JOIN dbo.AAG20001 C
                ON B.aaSubLedgerHdrID = C.aaSubLedgerHdrID
            INNER JOIN dbo.AAG20002 D
                ON C.aaSubLedgerHdrID = D.aaSubLedgerHdrID
                   AND C.aaSubLedgerDistID = D.aaSubLedgerDistID
            INNER JOIN dbo.AAG20003 E
                ON D.aaSubLedgerHdrID = E.aaSubLedgerHdrID
                   AND D.aaSubLedgerDistID = E.aaSubLedgerDistID
                   AND D.aaSubLedgerAssignID = E.aaSubLedgerAssignID
            INNER JOIN dbo.AAG00401 F
                ON E.aaTrxDimID = F.aaTrxDimID
                   AND E.aaTrxCodeID = F.aaTrxDimCodeID
            INNER JOIN dbo.GL00105 G
                ON C.ACTINDX = G.ACTINDX
            INNER JOIN dbo.GL00100 H
                ON H.ACTINDX = G.ACTINDX
            INNER JOIN dbo.PM00200 I
                ON I.VENDORID = A.VENDORID
            LEFT OUTER JOIN dbo.PM00100 J
                ON I.VNDCLSID = J.VNDCLSID
    WHERE   A.VOIDED <> 1
            AND A.DOCTYPE <> 6

GO

GRANT SELECT, INSERT, UPDATE, DELETE ON vw_AAG20000 TO DYNGRP
GRANT SELECT, INSERT, UPDATE, DELETE ON vw_APTransactions TO DYNGRP
GRANT SELECT, INSERT, UPDATE, DELETE ON vw_APAAInformation TO DYNGRP

Hope this post was helpful to you.

Until next post…

Category:SQL SCRIPTS: Analytical Accounting (SQL)
Link Owner:
Date Added:June 21, 2010 04:09:35 PM
Number Hits:164
RatingsAverage rating: (0 votes)
Reviews

No Reviews Yet.