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; akarasev@albaspectrum.com
![]() |
|
![]() |
|
![]() |
|
![]() |
There are certain pluses and minuses in both cases and... Read More
Looks like Microsoft Great Plains becomes more and more popular,... Read More
If you company is small or mid-size special products or... Read More
Lotus Notes Domino is very efficient in electronic document workflow... Read More
Linux essentials:It's free for download but you have to pay... Read More
1. With mapping software you can create a report that... Read More
Whether you are a small consultancy firm, a medium sized... Read More
Once upon a time not so long ago, there was... Read More
XML Server can be a Web Server that stores the... Read More
With any good luck and a good amount of hard... Read More
Microsoft Great Plains is becoming more and more popular and... Read More
Microsoft Business Solutions Great Plains is marketed for mid-size companies... Read More
If you feel intimidated when someone tries to teach you... Read More
Microsoft CRM customization techniques are very diversified and based on... Read More
Microsoft CRM ? Client Relationship Management package from Microsoft Business... Read More
OEComplete is a utility for managing the personal information of... Read More
Looks like Microsoft Great Plains becomes more and more popular,... Read More
Your computer cost you from hundreds to thousands of dollars,... Read More
I provide, here clear explanations and a count of function... Read More
Introduction: The creating of a computer program involves a number... Read More
Now there are Three Steps To Heaven Just listen and... Read More
Manufacturing in the USA is far away down from mid... Read More
The objective for Zandi Digital is to make available clever... Read More
If there still are few unprotected computers left, I haven't... Read More
The software giants don't do everything and don't always produce... Read More
Following tips help you to learn a software in lesser... Read More
This is the tutorial where we really get into programming.... Read More
In the previous ISDN article, we looked at how and... Read More
At the end of XX century, in the late 1990th... Read More
When making a decision to buy any piece of software... Read More
Great Plains Accounting, accounting package for mid-size and small companies... Read More
2005 ? Back to the Future.What does the future hold?... Read More
Microsoft Great Plains may be recommended for international freight forwarding... Read More
Although statistics often is blamed for various deadly sins --... Read More
Well, even if the combination might look very unusual, we... Read More
Scrapbooks are very popular these days. I think that almost... Read More
First we had the original Google search that evolved into... Read More
Whether you are an experienced web programmer or a complete... Read More
Microsoft Business Solutions CRM and IBM Lotus Notes Domino, being... Read More
Microsoft Business Solutions offers several ERP applications: Great Plains, Navision,... Read More
Microsoft Great Plains is main Microsoft Business Solutions accounting package... Read More
Microsoft CRM is CRM answer from Microsoft Business Solutions. If... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics... Read More
If you have Microsoft Great Plains and support it... Read More
Microsoft Business Solutions main middle market ERP application - Microsoft... Read More
C++ Function templates are those functions which can handle different... Read More
Our opinion is based on our Microsoft Business Solutions Great... Read More
If you have Great Plains Dynamics/eEnterprise (version 6.0 or earlier)... Read More
Microsoft Retail Management System serves retail single store as well... Read More
Microsoft Great Plains ? ERM from Microsoft Business Solutions and... Read More
Considering whether or not your software company should hire a... Read More
You probably didn't casually invite, or extend a formal attendance... Read More
Once a business idea is selected, it is highly recommended... Read More
Just imagine: you are walking, say, towards your car, and... Read More
As Mozilla Firefox nears 10% market share, with well over... Read More
Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics/eEnterprise... Read More
There are so many different programs that clutter up your... Read More
Microsoft Business Solutions CRM is present several years on the... Read More
Java has come along a long way. Many would agree... Read More
Remember old good days when your company probably had Great... Read More
Ok... Where to start?Well, I guess I will start at... Read More
Lotus Domino/Notes ? Microsoft Great Plains tandem as ERP with... Read More
Microsoft Business Solutions Great Plains might be considered as ERP... Read More
While paper labeling CDs and DVDs may appear to be... Read More
When you visit department stores and see that majority of... Read More
Introduction: The creating of a computer program involves a number... Read More
Software |