Microsoft Great Plains is one of three Microsoft Business Solutions mid-market ERP products: Great Plains, Solomon, Navision. Considering that Great Plains is now very good candidate for integration with POS application, such as Microsoft Retail Management System or RMS and Client Relation Systems, such as Microsoft CRM ? there is common need in Great Plains customizations and integrations, especially on the level of MS SQL Server transact SQL queries and stored procedures.
In this small article we'll show you how to create auto-apply utility, when you integrate huge number of sales transactions and payments. We will be working with RM20101 ? Receivables Open File and RM20201 ? Receivables Apply Open File.
Let's see SQL code:
declare @curpmtamt numeric(19,5)
declare @curinvamt numeric(19,5)
declare @curpmtnum varchar(20)
declare @curinvnum varchar(20)
declare @curinvtype int
declare @curpmttype int
declare @maxid int
declare @counter int
-- Create a temporary table
create table #temp
(
[ID] int identity(1,1) primary key,
CUSTNMBR varchar(15),
INVNUM varchar(20),
INVTYPE int,
PMTNUM varchar(20),
PMTTYPE int,
INVAMT numeric(19,5),
PMTAMT numeric(19,5),
AMTAPPLIED numeric(19,5)
)
create index IDX_INVNUM on #temp (INVNUM)
create index IDX_PMTNUM on #temp (PMTNUM)
-- Insert unapplied invoices and payments
insert into #temp
(
CUSTNMBR,
INVNUM,
INVTYPE,
PMTNUM,
PMTTYPE,
INVAMT ,
PMTAMT,
AMTAPPLIED
)
select
CUSTNMBR = a.CUSTNMBR,
INVNUM = b.DOCNUMBR,
INVTYPE = b.RMDTYPAL,
PMTNUM = a.DOCNUMBR,
PMTTYPE = a.RMDTYPAL,
INVAMT = b.CURTRXAM,
PMTAMT = a.CURTRXAM,
AMTAPPLIED = 0
from RM20101 a
join RM20101 b on (a.CUSTNMBR = b.CUSTNMBR)
join RM00101 c on (a.CUSTNMBR = c.CUSTNMBR)
where
a.RMDTYPAL in (7, 8, 9) and
b.RMDTYPAL in (1, 3) and
a.CURTRXAM 0 and
b.CURTRXAM 0
order by
a.custnmbr,
b.DOCDATE,
a.DOCDATE,
a.DOCNUMBR,
b.DOCNUMBR
-- Iterate through each record
select @maxid = max([ID])
from #temp
select @counter = 1
while @counter = @curpmtamt) and (@curpmtamt>0) and (@curinvamt>0)-- if the invoice amount is greater or the same as the payment amount
begin
select @curinvamt = @curinvamt - @curpmtamt -- invoice amount remaining
-- update with the amount that is applied to the current invoice from
-- the current payment
update #temp
set
AMTAPPLIED = @curpmtamt
where
[ID] = @counter
-- update with amount of invoice remaining
update #temp
set
INVAMT = @curinvamt
where
INVNUM = @curinvnum and
INVTYPE = @curinvtype
-- update with amount of payment remaining
update #temp
set
PMTAMT = 0
where
PMTNUM = @curpmtnum and
PMTTYPE = @curpmttype
end
else if (@curinvamt 0) and (@curinvamt>0)-- if the invoice amount is lesser to the payment amount
begin
select @curpmtamt = @curpmtamt - @curinvamt -- payment amount remaining
-- update with the amount that is applied to the current invoice from
-- the current payment
update #temp
set
AMTAPPLIED = @curinvamt
where
[ID] = @counter
-- update with amount of invoice remaining
update #temp
set
INVAMT = 0
where
INVNUM = @curinvnum and
INVTYPE = @curinvtype
-- update with amount of payment remaining
update #temp
set
PMTAMT = @curpmtamt
where
PMTNUM = @curpmtnum and
PMTTYPE = @curpmttype
end
-- go to the next record
select @counter = @counter + 1
end
-- update the RM Open table with the correct amounts
update
RM20101
set
CURTRXAM = b.INVAMT
from
RM20101 a
join #temp b on (a.DOCNUMBR = b.INVNUM and a.RMDTYPAL = b.INVTYPE)
update
RM20101
set
CURTRXAM = b.PMTAMT
from
RM20101 a
join #temp b on (a.DOCNUMBR = b.PMTNUM and a.RMDTYPAL = b.PMTTYPE)
-- create the RM Apply record or update if records already exist
update
RM20201
set
DATE1 = convert(varchar(10), getdate(), 101),
GLPOSTDT = convert(varchar(10), getdate(), 101),
APPTOAMT = APPTOAMT + a.AMTAPPLIED,
ORAPTOAM = ORAPTOAM + a.AMTAPPLIED,
APFRMAPLYAMT = APFRMAPLYAMT + a.AMTAPPLIED,
ActualApplyToAmount = APFRMAPLYAMT + a.AMTAPPLIED
from
#temp a
join RM20101 b on (b.DOCNUMBR = a.INVNUM and b.RMDTYPAL = a.INVTYPE)
join RM20101 c on (c.DOCNUMBR = a.PMTNUM and c.RMDTYPAL = a.PMTTYPE)
join RM20201 d on (d.APFRDCTY = a.PMTTYPE and
d.APFRDCNM = a.PMTNUM and
d.APTODCTY = a.INVTYPE and
d.APTODCNM = a.INVNUM)
where
a.AMTAPPLIED 0
insert into RM20201
(CUSTNMBR,
DATE1,
GLPOSTDT,
POSTED,
APTODCNM,
APTODCTY,< /p>
APTODCDT,
ApplyToGLPostDate,
CURNCYID,
CURRNIDX,
APPTOAMT,
ORAPT OAM,
APFRDCNM,
APFRDCTY,
APFRDCDT,
ApplyFromGLPostDate,
FROMCURR,
< p>APFRMAPLYAMT,ActualApplyToAmount)
select
CUSTNMBR = a.CUSTNMBR,
DATE1 = convert(varchar(10), getdate(), 101),
GLPOSTDT = convert(varchar(10), getdate(), 101),
POSTED = 1,
APTODCNM = a.INVNUM,
APTODCTY = a.INVTYPE,
APTODCDT = b.DOCDATE,
ApplyToGLPostDate = b.GLPOSTDT,
CURNCYID = b.CURNCYID,
CURRNIDX = '',
APPTOAMT = a.AMTAPPLIED,
ORAPTOAM = a.AMTAPPLIED,
APFRDCNM = a.PMTNUM,
APFRDCTY = a.PMTTYPE,
APFRDCDT = c.DOCDATE,
ApplyFromGLPostDate = c.GLPOSTDT,
FROMCURR = c.CURNCYID,
APFRMAPLYAMT = a.AMTAPPLIED,
ActualApplyToAmount = a.AMTAPPLIED
from
#temp a
join RM20101 b on (b.DOCNUMBR = a.INVNUM and b.RMDTYPAL = a.INVTYPE)
join RM20101 c on (c.DOCNUMBR = a.PMTNUM and c.RMDTYPAL = a.PMTTYPE)
where
a.AMTAPPLIED 0 and
not exists (select 1
from RM20201 d
where d.APFRDCTY = a.PMTTYPE and
d.APFRDCNM = a.PMTNUM and
d.APTODCTY = a.INVTYPE and
d.APTODCNM = a.INVNUM)
drop table #temp
About The Author
Andrew Karasev is Chief Technology Officer in Alba Spectrum Technologies ? USA nationwide Great Plains, Microsoft CRM customization company, with offices in Chicago, San Francisco, Los Angeles, San Diego, Phoenix, Houston, Miami, Atlanta, New York, Madrid, Brazil, Moscow ( http://www.albaspectrum.com), you can reach Andrew 1-866-528-0577, he is Dexterity, SQL, C#.Net, Crystal Reports and Microsoft CRM SDK developer; http://www.albaspectrum.com
shuttle from O'Hare Bingham .. Lockport Chicago limo O’HareMicrosoft Business Solutions CRM proved to be reliable solution in... Read More
C/SIDE (Client/Server Integrated Development Environment) - The core of... Read More
Microsoft Business Solutions Great Plains is marketed for mid-size companies... Read More
IBM Lotus Domino or Microsoft Exchange?The severe competition continues for... Read More
Microsoft Business Solutions Great Plains is very popular ERP/MRP applications... Read More
Cyberspace has opened up a new frontier with exciting possibilities... Read More
Microsoft Great Plains, designed back in 1990th as database transferable... Read More
First we had the original Google search that evolved into... Read More
With the advent of 'Service Pack 2' for Windows XP... Read More
To all web designers out there, this article is for... Read More
Since Version 8.0 Microsoft Business Solutions Great Plains & Great... Read More
As of now - Great Plains Dynamics/eEnterprise is transformed/renamed into... Read More
The Windows registry is a huge database that ensures normal... Read More
Microsoft CRM ? Client Relationship Management package from Microsoft Business... Read More
Upgrading. Downtime. Maintenance. Hardware obsolescence. Implementation issues. The litany of... Read More
Stealing company information used to be the specialty of spies... Read More
It is now common thing when large corporation selects mid-market... Read More
Microsoft Great Plains serves majority of US based horizontal and... Read More
The Internet is reshaping every form of communications medium, and... Read More
So, why should you use any O/R mapping tool? I... Read More
With any good luck and a good amount of hard... Read More
Anyone who has ever used Microsoft Word knows that it... Read More
The Software 2005 conference is now a wrap. This conference,... Read More
Programming Help for BeginnersWe write programs to instruct computers. When... Read More
Although statistics often is blamed for various deadly sins --... Read More
Mishawaka limo O'Hare ..How many steps does it take you to locate and... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software eEnterprise,... Read More
In 2004 Oracle, Inc. made its new step toward J2EE... Read More
With any good luck and a good amount of hard... Read More
It's not very often I get excited about a software... Read More
Some companies that are in need of fleet management may... Read More
You might think you don't need a firewall... Read More
IntroductionDuring the early years of our modern computer era, very... Read More
Customer Relationship Management, abbreviated "CRM," is the term for a... Read More
And kill the best layout software in the process of... Read More
XML parser is a software module to read documents and... Read More
ERP (Enterprise Resource Planning) Overview covers What is ERP, Brief... Read More
What is IRC?IRC is Internet Relay Chat. It is a... Read More
Pirated software is on the increase and now accounts for... Read More
While several preventive maintenance software manufacturers offer free trials for... Read More
The stakes are high when considering security, privacy, and savings,... Read More
If you are software developer or database administrator - we... Read More
Whether you have used Microsoft Word for years, have just... Read More
The purpose of one of our projects was MS Exchange... Read More
Microsoft Business Solutions CRM is present several years on the... Read More
After almost two decades of existence, Quark has become the... Read More
Microsoft Business Solutions Great Plains has Project Accounting module where... Read More
According to a survey conducted by InfoTrends/CAP Ventures entitled "Content-Centric... Read More
... Read More
Microsoft Business Solutions CRM and IBM Lotus Notes Domino, being... Read More
Software |