This script is part of the SQL Scripts for Microsoft Dynamics GP where I will be posting the scripts I wrote against Microsoft Dynamics GP over the 19 years before I stopped working with Dynamics GP.
This script returns a list of Payables distributions for transactions with a current transaction amount not equal to 0.
/*
Created by Ian Grieve of azurecurve | Ramblings of an IT Professional (http://www.azurecurve.co.uk)
This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int).
*/
SELECT
PM.VCHRNMBR AS 'Voucher Number'
,PM.DSTSQNUM / 16384 AS 'Dist Seq No'
,PM.CNTRLTYP
,PM.CRDTAMNT AS 'Credit Amnt'
,PM.DEBITAMT AS 'Debit Amnt'
,GL.ACTNUMST AS 'Account Number'
,CASE WHEN PM.DISTTYPE = 1 THEN 'Cash'
WHEN PM.DISTTYPE = 2 THEN 'Payable'
WHEN PM.DISTTYPE = 3 THEN 'Discount Available'
WHEN PM.DISTTYPE = 4 THEN 'Discount Taken'
WHEN PM.DISTTYPE = 5 THEN 'Finance Charge'
WHEN PM.DISTTYPE = 6 THEN 'Purchase'
WHEN PM.DISTTYPE = 7 THEN 'Trade Discount'
WHEN PM.DISTTYPE = 8 THEN 'Misc Charge'
WHEN PM.DISTTYPE = 9 THEN 'Freight'
WHEN PM.DISTTYPE = 10 THEN 'Taxes'
WHEN PM.DISTTYPE = 11 THEN 'Writeoffs'
WHEN PM.DISTTYPE = 12 THEN 'Other'
WHEN PM.DISTTYPE = 13 THEN 'GST Disc'
WHEN PM.DISTTYPE = 14 THEN 'PPS Amount'
WHEN PM.DISTTYPE = 15 THEN ''
WHEN PM.DISTTYPE = 16 THEN 'Round'
WHEN PM.DISTTYPE = 17 THEN 'Realised Gain'
WHEN PM.DISTTYPE = 18 THEN 'Realised Loss'
WHEN PM.DISTTYPE = 19 THEN 'Due To'
ELSE
'Due From'
END AS 'Distribution Type'
,PM.CHANGED AS 'Changed'
,PM.USERID AS 'User ID'
,CASE WHEN PM.PSTGSTUS = 0 THEN
'Unposted'
WHEN PM.PSTGSTUS = 1 THEN
'Posted'
WHEN PM.PSTGSTUS = 2 THEN
''
ELSE
'Unposted Cheque'
END AS 'Posting Status'
,PM.VENDORID AS 'Vendor ID'
,PM.TRXSORCE AS 'Trx Source'
,PM.PSTGDATE AS 'Posting Date'
,PM.INTERID AS 'Intercompany ID'
,PM.CURNCYID AS 'Currency ID'
,PM.CURRNIDX AS 'Currency Index'
,PM.APTVCHNM AS 'Apply To Voucher'
,PM.DistRef AS 'Distribution Ref'
FROM
PM10100 PM --PM Distribution WORK OPEN (PM10100)
INNER JOIN
GL00105 GL --Account Index Master (GL00105)
ON
PM.DSTINDX = GL.ACTINDX
WHERE
VCHRNMBR IN
(
SELECT
VCHRNMBR
FROM
PM20000 --PM Transaction OPEN File (PM20000)
WHERE CURTRXAM <> 0
)