<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Systematica Dynamics Blog &#187; Payroll to Payables</title>
	<atom:link href="http://www.blogsystematicainc.com/tag/payroll-to-payables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blogsystematicainc.com</link>
	<description>Microsoft Dynamics GP and CRM Team Blog</description>
	<lastBuildDate>Sun, 29 Aug 2010 18:55:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>GP Payroll to Payables: How to pass custom data to the check!</title>
		<link>http://www.blogsystematicainc.com/2009/09/gp-payroll-to-payables-how-to-pass-custom-data-to-the-check/</link>
		<comments>http://www.blogsystematicainc.com/2009/09/gp-payroll-to-payables-how-to-pass-custom-data-to-the-check/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 20:31:51 +0000</pubDate>
		<dc:creator>Dwight Brown</dc:creator>
				<category><![CDATA[Dynamics GP]]></category>
		<category><![CDATA[development connection string]]></category>
		<category><![CDATA[dynamics modifier]]></category>
		<category><![CDATA[Garnishment]]></category>
		<category><![CDATA[get computer ID address with vba]]></category>
		<category><![CDATA[Payroll to Payables]]></category>
		<category><![CDATA[SQL server Update Join]]></category>

		<guid isPermaLink="false">http://blog.systematicainc.com/?p=312</guid>
		<description><![CDATA[Garnishment management can be a complex process for companies that manage their Payroll in house. One client of Systematica uses Dynamics GP for both Payroll and Payables and uses the Payroll to Payables integration in order to pay employee garnishments.  The government requires that the garnishment checks include the employee’s last name and the check-date together on [...]]]></description>
			<content:encoded><![CDATA[<p>Garnishment management can be a complex process for companies that manage their Payroll in house. One client of Systematica uses Dynamics GP for both Payroll and Payables and uses the Payroll to Payables integration in order to pay employee garnishments.  The government requires that the garnishment checks include the employee’s last name and the check-date together on the remittance.  This data is not available out-of-the-box, GP simply creates vouchers for each garnishment without passing any data that ties the payables voucher back to the payroll records that created them.  The client was currently opening each garnishment voucher and replacing the document ID (which is a sequentially generated field just used for reference) with the employee name and date.  Our goal was to replace this with a simple command button that would update all of the garnishment document IDs with the employee ID and check date.</p>
<p>Our solution required the following steps:<span id="more-312"></span></p>
<p>1)      Modify ALL employee garnishment deductions to pass the EmployeeID and Deduction code to payables, this can be done by going to the “Payroll Vendor Setup” window (on the HR Home screen this is under Setup à Payables Integration à Vendors). After choosing the Employee, and the Garnishment deduction, select “Emp ID + Ded Code” from the “Voucher Description” dropdown list.</p>
<p>2)      Modify the “Vouchers” search window by adding a command button that will execute a SQL stored procedure.  We keep all SQL stored procedures in a separate database so that we are not changing GP company databases.</p>
<p>3)      Create a stored procedure that accepts the company DB as a parameter and then uses dynamic SQL to update the DocumentID field in the PM10000 table with the data that the client needs to appear on the remittance.  Here are the details of the sproc:</p>
<ol>
<li>Create a temp table that keeps the Dex_Row_ID and the Voucher Number as the primary keys. The temp table also includes the parsed employeeID and garnishment code and other data that the user may want as feedback.  The parsed employeeID and garnishment code are inner joined to the UPR00100 (employee master table) and UPR40900 (deduction setup table) so that any records that don’t match up to employees and garnishments (respectively) just won’t be included in the temp table. This is necessary since the voucher table (PM10000) will have other vouchers that we don’t want to touch and whose transaction description fields may be blank or contain data that won’t match with employee and garnishment codes.</li>
<li>Update the Document ID field in the PM10000 table with the document ID that was concatenated into the temp table.  Use an inner join on the two primary keys in the temp table to update the proper records. For those of you who are curious for how to do a SQL update statement across two table, this is an appropriate example… you just have to use a table alias.</li>
<li>Select from the temp table and present the updated data to the user in a listbox on a user form in GP.  They are also presented with the VendorID to verify that the proper records were updated and the total $ of garnishments so that they can compare the results with their payroll report.  If the totals don’t match it may be due to improper garnishment setup… if the garnishment is not set up to send the EmployeeID and the garnishment code, the records will fail to transfer from payables.</li>
</ol>
<p> </p>
<p>As a side note, I use a function to build the ADODB connection to either the test server or to the production server based on the IP address of the client.  For example all test clients have IP addresses like 10.6.XX.XXX, so I check the client IP address and if it begins with 10.6 I create a connection string that is to the test server, otherwise I build a connection string to live. This is done both to ensure that I am not hitting a live server with test data and to prevent failed connections since the IPs are isolated.  If you would like the code sample for how I do this, please add a comment and I’ll send  you the code! </p>
<p>Option Explicit</p>
<p>Private Sub RenameGarns_Changed()</p>
<p>  </p>
<p>    Dim cn As Connection</p>
<p>    Dim rst As ADODB.Recordset</p>
<p>    Dim cmd As ADODB.Command</p>
<p>    Dim dblTotalAmount As Double</p>
<p>    Dim intNameLength As Integer</p>
<p>    dblTotalAmount = 0</p>
<p> </p>
<p>    Set cn = New ADODB.Connection</p>
<p>    cn.ConnectionString = GDLINTF_GPConnStr()</p>
<p>    On Error GoTo CantConnect</p>
<p>    cn.Open</p>
<p>    On Error GoTo MiscError</p>
<p>  </p>
<p>  </p>
<p>    Set cmd = New ADODB.Command</p>
<p>    Set rst = New ADODB.Recordset</p>
<p>    rst.CursorType = adOpenKeyset</p>
<p>    rst.LockType = adLockOptimistic</p>
<p>   </p>
<p>    cmd.CommandType = adCmdStoredProc &#8216;Define the ADODB command</p>
<p>    cmd.ActiveConnection = cn &#8216;Set the command connection string</p>
<p>    cmd.CommandText = &#8220;gp_spUpdateGarnishmentsPayablesDocID_upd&#8221;</p>
<p>   </p>
<p>    With cmd</p>
<p>        .Parameters.Append cmd.CreateParameter(&#8220;@GPDB&#8221;, adVarChar, adParamInput, 10, UserInfoGet.IntercompanyID)</p>
<p>    End With</p>
<p>    </p>
<p>    </p>
<p>    &#8216;Execute stored procedure and return to a recordset</p>
<p>    Set rst = cmd.Execute</p>
<p>    frmGarnUpdateMessage.lstGarnRows.AddItem (&#8220;Old Doc #&#8221; &amp; vbTab &amp; vbTab &amp; &#8220;EmployeeID&#8221; &amp; vbTab &amp; &#8220;CheckDate&#8221; &amp; vbTab &amp; &#8220;New Doc #&#8221; &amp; vbTab &amp; vbTab &amp; &#8220;Amount&#8221; &amp; vbTab &amp; &#8220;Vendor ID&#8221;)</p>
<p>    Do Until rst.EOF</p>
<p>        intNameLength = Len(rst!EmpName)</p>
<p>        </p>
<p>        frmGarnUpdateMessage.lstGarnRows.AddItem (rst!OldDocNumber &amp; String(20 &#8211; intNameLength, &#8221; &#8220;) &amp; vbTab &amp; rst!EmployeeID &amp; vbTab &amp; vbTab &amp; rst!CheckDate &amp; vbTab &amp; vbTab &amp; rst!NewDocNumber &amp; String(20 &#8211; intNameLength, &#8221; &#8220;) &amp; vbTab &amp; &#8220;$&#8221; &amp; rst!Amount &amp; vbTab &amp; rst!VendorID)</p>
<p>       </p>
<p>        dblTotalAmount = dblTotalAmount + rst!Amount</p>
<p>        rst.MoveNext</p>
<p>    Loop</p>
<p>       </p>
<p>   </p>
<p>    If CBool(cn.State And adStateOpen) = True Then cn.Close</p>
<p>    Set cn = Nothing</p>
<p>       </p>
<p>    frmGarnUpdateMessage.lstGarnRows.AddItem (&#8220;&#8221;)</p>
<p>    frmGarnUpdateMessage.lstGarnRows.AddItem (&#8220;Total garnishments: $&#8221; &amp; dblTotalAmount)</p>
<p>    frmGarnUpdateMessage.Show</p>
<p>    Exit Sub</p>
<p>   </p>
<p>MiscError:</p>
<p>    If CBool(rst.State And adStateOpen) = True Then rst.Close</p>
<p>    Set rst = Nothing</p>
<p>    </p>
<p>    If CBool(cn.State And adStateOpen) = True Then cn.Close</p>
<p>    Set cn = Nothing</p>
<p>    MsgBox &#8220;There was a problem running the update.&#8221;</p>
<p>    Exit Sub</p>
<p>CantConnect:</p>
<p>    MsgBox &#8220;There was a problem connecting to the data.&#8221;</p>
<p> </p>
<p> </p>
<p>End Sub</p>
<p> </p>
<p> </p>
<p>CREATE PROCEDURE [dbo].[gp_spUpdateGarnishmentsPayablesDocID_upd] (@GPDB As VarChar(10))</p>
<p>     </p>
<p>AS</p>
<p>BEGIN</p>
<p>      &#8212; SET NOCOUNT ON added to prevent extra result sets from</p>
<p>      &#8212; interfering with SELECT statements.</p>
<p>      SET NOCOUNT ON;</p>
<p>     </p>
<p>            DECLARE @SQLScript As VarChar(Max)</p>
<p>           </p>
<p> </p>
<p>            Declare @Space As VarChar(10)</p>
<p> </p>
<p>            Set @Space = &#8221;&#8221; + &#8216; &#8216;+ &#8221;&#8221;</p>
<p> </p>
<p>            /*</p>
<p>            The first Select statement will parse the Transaction Description passed by payroll into both the employeeID</p>
<p>            and the Garn type. An inner join, joins the parsed garnishments with all garn types in the deduction table</p>
<p>            so that (by INNER joining) only vouchers with a parsed garnishment (DEDTYPE = 2) will be inserted into the temp table</p>
<p>            this temp table includes the voucher number, the dex row ID, the old document number, the employee name and the</p>
<p>            new document number so that all data needed for the update statement and the feedback</p>
<p>            for the vba code will be available in the temp table</p>
<p>            */</p>
<p>            Set @SQLScript =</p>
<p>            &#8216;Select PM.VCHNUMWK,PM.DEX_ROW_ID,SUBSTRING(PM.TRXDSCRN,0,CHARINDEX(&#8216; + @Space + &#8216;,PM.TRXDSCRN)) As EmployeeID,</p>
<p>            Left(convert(varchar(10),PM.PSTGDATE, 101),5) As CheckDate,</p>
<p>            PM.DOCNUMBR As OldDocNumber,</p>
<p>            RTRIM(Emp.LASTNAME)  As EmpName,</p>
<p>            LEFT(RTRIM(Emp.LASTNAME) ,14) + &#8216; + @Space + &#8216;+ Left(convert(varchar(10),PM.PSTGDATE, 101),5) As NewDocNumber,</p>
<p>            DocAmnt As Amount,</p>
<p>            VendorID</p>
<p>            INTO #VOUCH</p>
<p>            From &#8216; + @GPDB + &#8216;.dbo.PM10000 PM (NOLOCK)</p>
<p>            INNER JOIN &#8216; + @GPDB + &#8216;.dbo.UPR40900 Deds (NOLOCK) On SUBSTRING(PM.TRXDSCRN,CHARINDEX(&#8216; + @Space + &#8216;,PM.TRXDSCRN)+1,10) = Deds.DEDUCTON AND Deds.DEDTYPE = 2</p>
<p>            INNER JOIN &#8216; + @GPDB + &#8216;.dbo.UPR00100 Emp (NOLOCK) ON Emp.EmployID = SUBSTRING(PM.TRXDSCRN,0,CHARINDEX(&#8216; + @Space + &#8216;,PM.TRXDSCRN))</p>
<p>            &#8216;</p>
<p>           </p>
<p>            /* Update the voucher work table with the values in the temp table */</p>
<p>            Set @SQLScript = @SQLScript + </p>
<p>            &#8216;UPDATE PM Set PM.DOCNUMBR= Vouch.NewDocNumber</p>
<p>            From &#8216; + @GPDB + &#8216;.dbo.PM10000 PM (NOLOCK)</p>
<p>            INNER Join #VOUCH Vouch ON PM.VCHNUMWK = Vouch.VCHNUMWK AND PM.DEX_ROW_ID = Vouch.Dex_Row_ID</p>
<p>            &#8216;</p>
<p>           </p>
<p>            /* Select all the data in the temp table so that it can be returned to VBA and displayed on screen*/</p>
<p>            Set @SQLScript = @SQLScript + &#8216;SELECT * FROM #VOUCH</p>
<p>            &#8216;    </p>
<p> </p>
<p>            Set @SQLScript = @SQLScript + &#8216;DROP TABLE #VOUCH&#8217;</p>
<p>           </p>
<p>            &#8211;Print (@SQLScript)</p>
<p>            Execute(@SQLScript)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blogsystematicainc.com/2009/09/gp-payroll-to-payables-how-to-pass-custom-data-to-the-check/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
