SQL Script To Return Functional Currencies For All Companies Without a Cursor

Microsoft Dynamics GPI posted a script a while ago which used a cursor to return the functional currencies for all companies connected to a system database. However, I have recently revisited this script and created a version which does not use a cursor.

This script has been written to only return the companies which do not have a functional currency set; if you want to see all companies, regardless of the functional currency, remove the highlighted section.

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (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).
*/
CREATE TABLE #FunctionalCurrencies(
	INTERID VARCHAR(5)
	,FUNLCURR VARCHAR(20)
)
GO

DECLARE @SQL NVARCHAR(MAX)
SELECT @SQL = STUFF((
					SELECT 
						CHAR(13) 
							+ 'SELECT 
								''' + INTERID + '''
								,FUNLCURR
							FROM
								' + INTERID + '.dbo.MC40000
							WHERE
								LEN(FUNLCURR) = 0'
					FROM
						DYNAMICS.dbo.SY01500
					FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '')

INSERT INTO #FunctionalCurrencies
	EXEC sys.sp_executesql @SQL
GO

SELECT * FROM #FunctionalCurrencies
GO

DROP TABLE #FunctionalCurrencies
GO

Purchase Order Approval Workflow Automatically Rejected

Microsoft Dynamics GPA client reported a problem with their PO Approval Workflow process failing whenever a PO was submitted for approval. As soon as the Submit button was pressed, the document was rejected, but did not show a user:

Purchase Order Entry

Continue reading “Purchase Order Approval Workflow Automatically Rejected”

Copy Fiscal Calendar To All Companies

Microsoft Dynamics GPIn the last post I mentioned that I create scripts when implementing Microsoft Dynamics GP and then make them available to clients when they would be of benefit. The last script I posted, allowed calendars to ve copied from one database to another. Afetr writing that scirpt I then adapted it by wrapping a cursor around it which allowed a source database to be defined and the calendar copied to all other databases.

The original script is still useful as it allows a targeted copying of calendars from a source to a destination database, but the new allows calendars to be quickly replicated across all companies if they share the same financial year.

The script has two parameters (highlighted) at the top which need to be set:

  • Year
  • SourceDatabase
  • Continue reading “Copy Fiscal Calendar To All Companies”

    Copy Fiscal Calendar To A New Company

    Microsoft Dynamics GPI have a bit of catching up to do on writing posts, but to start the year off I am back to some SQL scripts. As I have mentioned before I have a number of clients with multiple, and in some cases well over 100, companies in Microsoft Dynamics GP.

    I do try to make life easier for them when possible so have been sharing a number of scripts I have for implementing systems. One such script is one which will copy financial (fiscal) calendars from one database to another.

    There are three parameters at the top which need to be set before running the script:

    1. Year
    2. Source Company
    3. Destination Company

    These parameters are highlighted below:

    /*
    Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (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).
    */
    DECLARE @Year VARCHAR(4) = '2014'
    DECLARE @SourceDatabase VARCHAR(5) = 'TWO'
    DECLARE @DestinationDatabase VARCHAR(5) = 'THREE'
    DECLARE @SQLStatement VARCHAR(1000)
    
    SET @SQLStatement =
    	'INSERT INTO ' + @DestinationDatabase + '..SY40101
    		(YEAR1,FSTFSCDY,LSTFSCDY,NUMOFPER,HISTORYR)
    	--VALUES
    		(SELECT
    			YEAR1,FSTFSCDY,LSTFSCDY,NUMOFPER,HISTORYR
    		FROM
    			' + @SourceDatabase + '..SY40101
    		WHERE
    			(SELECT
    				COUNT(YEAR1)
    			FROM
    				' + @DestinationDatabase + '..SY40101
    			WHERE
    				YEAR1 = ' + @Year + ') = 0
    		AND
    			YEAR1 = ' + @Year + ')'
    EXEC (@SQLStatement)
    
    SET @SQLStatement =
    	'INSERT INTO ' + @DestinationDatabase + '..SY40100
    		(CLOSED,SERIES,ODESCTN,FORIGIN,PERIODID,PERIODDT,PERNAME
    		,PSERIES_1,PSERIES_2,PSERIES_3,PSERIES_4,PSERIES_5,PSERIES_6,
    		YEAR1,PERDENDT)
    	--VALUES
    		(SELECT
    			CLOSED,SERIES,ODESCTN,FORIGIN,PERIODID,PERIODDT,PERNAME
    			,PSERIES_1,PSERIES_2,PSERIES_3,PSERIES_4,PSERIES_5,PSERIES_6,
    			YEAR1,PERDENDT
    		FROM
    			' + @SourceDatabase + '..SY40100
    		WHERE
    			(SELECT
    				COUNT(YEAR1)
    			FROM
    				' + @DestinationDatabase + '..SY40100
    			WHERE
    				YEAR1 = ' + @Year + ') = 0
    			AND
    				YEAR1 = ' + @Year + ')'
    EXEC (@SQLStatement)
    GO

    The calendar will only be copied if the destination database does not contain a calendar with the same name.

    SQL Script To Copy Tax Setup To A New Company

    Microsoft Dynamics GPWhile helping a client configure some new companies recently, we needed to create the tax schedules in each of the companies; unfortunately, there were about 30 tax schedules and 4 companies which needed them. To do manually, or even with a macro, was going to take a while, so I took a few minutes out to see if it was going to be possible to run the update using a SQL script.

    The below is what I came up with and appeared to work fine for the companies we tested it in. One item to note, is that the Account Index is set to 0 so all companies do need the tax nominal account entering once they have been copied.

    There are two variables at the top which will need to be configured before running the script: @SourceCompany and @DestinationCompany.

    /*
    Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (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).
    */
    DECLARE @Statement AS VARCHAR(2000)
    DECLARE @SourceCompany AS VARCHAR(5)
    DECLARE @DestinationCompany AS VARCHAR(2000)
    
    SET @SourceCompany = 'TWO'
    SET @DestinationCompany = 'PI'
    
    -- Sales/Purchases Tax Schedule Header Master
    SET @Statement = 'INSERT INTO ' + @DestinationCompany + '..TX00101
    	(TAXSCHID,TXSCHDSC)
    --VALUES
    	(SELECT 
    		TAXSCHID,TXSCHDSC
    	FROM
    		' + @SourceCompany + '..TX00101 AS TX
    	WHERE
    		(SELECT COUNT(TAXSCHID) FROM ' + @DestinationCompany + '..TX00101 WHERE TAXSCHID = TX.TAXSCHID) = 0)'
    EXEC (@Statement)
    
    -- Sales/Purchases Tax Schedule Master
    SET @Statement = 'INSERT INTO ' + @DestinationCompany + '..TX00102
    	(TAXSCHID,TAXDTLID,TXDTLBSE,TDTAXTAX,Auto_Calculate)
    --VALUES
    	(SELECT
    		TAXSCHID,TAXDTLID,TXDTLBSE,TDTAXTAX,Auto_Calculate
    	FROM
    		' + @SourceCompany + '..TX00102 AS TX
    	WHERE
    		(SELECT COUNT(TAXSCHID) FROM ' + @DestinationCompany + '..TX00102 WHERE TAXSCHID = TX.TAXSCHID AND TAXDTLID = TX.TAXDTLID) = 0)'
    EXEC (@Statement)
    
    -- Sales/Purchases Tax Master
    SET @Statement = 'INSERT INTO ' + @DestinationCompany + '..TX00201
    	(TAXDTLID,TXDTLDSC,TXDTLTYP,ACTINDX,TXIDNMBR,TXDTLBSE,TXDTLPCT,TXDTLAMT,TDTLRNDG,TXDBODTL,TDTABMIN,
    	TDTABMAX,TDTAXMIN,TDTAXMAX,TDRNGTYP,TXDTQUAL,TDTAXTAX,TXDTLPDC,TXDTLPCH,TXDXDISC,CMNYTXID,NOTEINDX,
    	NAME,CNTCPRSN,ADDRESS1,ADDRESS2,ADDRESS3,CITY,STATE,ZIPCODE,COUNTRY,PHONE1,PHONE2,PHONE3,FAX,TXUSRDF1,
    	TXUSRDF2,VATREGTX,TaxInvReqd,TaxPostToAcct,TaxBoxes,IGNRGRSSAMNT,TDTABPCT)
    --VALUES
    	(SELECT
    		TAXDTLID,TXDTLDSC,TXDTLTYP,0,TXIDNMBR,TXDTLBSE,TXDTLPCT,TXDTLAMT,TDTLRNDG,TXDBODTL,TDTABMIN,
    		TDTABMAX,TDTAXMIN,TDTAXMAX,TDRNGTYP,TXDTQUAL,TDTAXTAX,TXDTLPDC,TXDTLPCH,TXDXDISC,CMNYTXID,0,
    		NAME,CNTCPRSN,ADDRESS1,ADDRESS2,ADDRESS3,CITY,STATE,ZIPCODE,COUNTRY,PHONE1,PHONE2,PHONE3,FAX,TXUSRDF1,
    		TXUSRDF2,VATREGTX,TaxInvReqd,TaxPostToAcct,TaxBoxes,IGNRGRSSAMNT,TDTABPCT
    	FROM
    		' + @SourceCompany + '..TX00201 AS TX 
    	WHERE
    		(SELECT COUNT(TAXDTLID) FROM ' + @DestinationCompany + '..TX00201 WHERE TAXDTLID = TX.TAXDTLID) = 0)'
    EXEC (@Statement)
    
    -- Sales/Purchases Tax Summary Master
    SET @Statement = 'INSERT INTO ' + @DestinationCompany + '..TX00202
    	(TAXDTLID,TDTSYTD,TDSLLYTD,TXDTSYTD,TDTSLYTD,TXDSTYTD,TDSTLYTD,KPCALHST,KPERHIST)
    --VALUES
    	(SELECT
    		TAXDTLID,TDTSYTD,TDSLLYTD,TXDTSYTD,TDTSLYTD,TXDSTYTD,TDSTLYTD,KPCALHST,KPERHIST
    	FROM
    		' + @SourceCompany + '..TX00202 AS TX
    	WHERE
    		(SELECT COUNT(TAXDTLID) FROM ' + @DestinationCompany + '..TX00202 WHERE TAXDTLID = TX.TAXDTLID) = 0)'
    EXEC (@Statement)

    If you do use this script, then please make sure you have a good backup before running it and also test afterwards.

    VAT 100 Is Missing

    Microsoft Dynamics GPI ran into an issue recently when installing Microsoft Dynamics GP 2010 R2 where the VAT Return was not available. I was configuring the system in preparation for training a new client and was running through the Company options (Microsoft Dynamics GP menu ¯ Tools ¯ Routines ¯ Company ¯ Company ¯ Options button) where I was sure the Enable VAT 100 option was but in this case wasn’t;

    Company Options - No Enable VAT 100 Option

    Continue reading “VAT 100 Is Missing”

    Feature Explained: Date Effective Tax Rates

    Microsoft Dynamics GPOver the last two or three years the VAT rate in the UK has changed three times; temporarily down to 15% from 17.5% and then back up a year later before a permanent rise in January 2011. On each occasion we issued advice to customers on how to handle these changes within Microsoft Dynamics GP; there were two ways for them to make the change; either create a new Tax Detail or amend the existing one. Personally I recommended the former as it is somewhat cleaner; you can tell at a glance what the VAT rate will be without the need to check the date the invocie was registered. If the latter option was taken users needed to remember which rate is effective on what date during the cross over period which means lots of scope for errors. Continue reading “Feature Explained: Date Effective Tax Rates”