Great Plains Customization ? Programming Auto-apply in Accounts Receivable

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

In The News:


pen paper and inkwell


cat break through


Software Tools To Help Your Business Sell More

Sales are all about leverage, because there is only so... Read More

Separate Anti-Keylogging Protection: Who Needs it Most?

If there still are few unprotected computers left, I haven't... Read More

Most Common Ways to Accumulate Spyware (where It is Downloaded to Your PC)

It is possible that if one avoided all sources of... Read More

Builders Beware

Which Type of Shop Can Rely On A Home Built... Read More

CRM 101: Customer Relationship Management for Beginners

Customer Relationship Management, abbreviated "CRM," is the term for a... Read More

Is Your Computer Sick?

Viruses and spyware usually show up on your computer one... Read More

Causes of ERP Failures

ERP is the acronym of Enterprise Resource Planning. Multi-module ERP... Read More

My Experience - Making a Vision into Reality

Disclaimer: All the thoughts expressed are my views only! Your... Read More

About Microsoft Sysprep (System Preparation) Utility (Windows 2000)

The Microsoft system preparation utility for Windows 2000 is a... Read More

Manufacturing Outsourcing: Microsoft Great Plains Implementation, Customization & Reporting

Manufacturing in the USA is far away down from mid... Read More

PHP On-The-Fly!

IntroductionPHP can be used for a lot of different things,... Read More

Microsoft Small Business Manager Customization Options - Overview

Microsoft Business Solutions Small Business Manager is Great Plains Dexterity... Read More

How to Backup Windows XP Home Edition

Your computer cost you from hundreds to thousands of dollars,... Read More

Cisco Certification: Introduction To ISDN, Part V

The major reason I recommend getting your hands on real... Read More

Microsoft Great Plains Chemicals & Paint Industry Implementation & Customization Notes

Microsoft Great Plains fits to majority of industries, in the... Read More

Microsoft Great Plains: Dexterity vs. eConnect ? FAQ

Microsoft Business Solutions Great Plains, former Great Plains Software Dynamics/eEnterprise... Read More

Groupware and Version History: Collaboration Series #1

This article is the first of a series of articles... Read More

A Simple Guide To Wikis

A wiki is an editable text-based website. But you don't... Read More

Unofficial Windows 98 SE Service Pack 2.0 RC2

Microsoft has never released a service pack for Windows98 SE,... Read More

The XP Firewall Isnt Enough

You might think you don't need a firewall... Read More

Microsoft RMS ? Great Plains Integration ? Overview For IT Specialist

Microsoft Great Plains and Microsoft Retail Management System (Microsoft RMS)... Read More

Microsoft Great Plains: Interest Calculation Example ? Stored Procedure for Crystal Report

This is intermediate level SQL scripting article for DB Administrator,... Read More

Is Your Family Protected?

When you think... Read More

.Net Charts and Graphs Interact with Businesses and Customers

Bar charts, bar graphs, and any other chart or graph... Read More

Linux Dual Boot-How To Format

Just the thought of a duel-boot scares many people away,... Read More

Microsoft Great Plains Implementation ? Overview for IT Director/Controller

What is installation in the language of technology? Installation... Read More

The Opera Alternative

Security flaws have long plagued Internet Explorer (IE), the market-dominating... Read More

The Dreaded Paper Label - Should it be Used?

While paper labeling CDs and DVDs may appear to be... Read More

Microsoft CRM: Data Conversion ? Import from Act!

Best Software Act! is very popular CRM for small and... Read More

Microsoft eCommerce Web-development: Great Plains eConnect .Net ? Highlights for Programmer

In our small article we'll consider Microsoft Business Solutions Great... Read More

How to Tell You Have Spyware, Ad-ware or Viruses

Usually, the easiest way to tell you have spyware is... Read More

Dig Out That Worm

Internet worms. Is your PC infected?If your computer has become... Read More

Software: What Suits Me?

Almost all new and major brand of PCs come with... Read More