Software informational articles

Great plains customization ? encoding auto-apply in balance sheet receivable - software

 

Microsoft Great Plains is one of three Microsoft Commerce Solutions mid-market ERP products: Great Plains, Solomon, Navision. Bearing in mind that Great Plains is now very good aspirant for integration with POS application, such as Microsoft Retail Management Approach or RMS and Client Family member Systems, such as Microsoft CRM - there is conventional need in Great Plains customizations and integrations, above all on the level of MS SQL Ma?tre d' deal with SQL queries and stored procedures.

In this small condition we'll show you how to construct auto-apply utility, when you integrate huge digit of sales transactions and payments. We will be operational 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

-- Conceive a acting table

create table #temp

(

[ID] int identity(1,1) core 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)

-- Add 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 all through each record

select @maxid = max([ID])

from #temp

select @counter = 1

while @counter = @curpmtamt) and (@curpmtamt>0) and (@curinvamt>0)-- if the bill quantity is better or the same as the payment amount

begin

select @curinvamt = @curinvamt - @curpmtamt -- account sum remaining

-- bring up to date with the total that is useful to the flow bill from

-- the flow payment

update #temp

set

AMTAPPLIED = @curpmtamt

where

[ID] = @counter

-- inform with quantity of account remaining

update #temp

set

INVAMT = @curinvamt

where

INVNUM = @curinvnum and

INVTYPE = @curinvtype

-- bring up to date with total of payment remaining

update #temp

set

PMTAMT = 0

where

PMTNUM = @curpmtnum and

PMTTYPE = @curpmttype

end

else if (@curinvamt 0) and (@curinvamt>0)-- if the bill quantity is minor to the payment amount

begin

select @curpmtamt = @curpmtamt - @curinvamt -- payment total remaining

-- inform with the quantity that is practical to the flow account from

-- the contemporary payment

update #temp

set

AMTAPPLIED = @curinvamt

where

[ID] = @counter

-- bring up to date with quantity of bill remaining

update #temp

set

INVAMT = 0

where

INVNUM = @curinvnum and

INVTYPE = @curinvtype

-- inform with sum 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

-- bring up to date the RM Open table with the acceptable 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)

-- build the RM Apply background or bring up to date if minutes previously 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,

APTODCDT,

ApplyToGLPostDate,

CURNCYID,

CURRNIDX,

APPTOAMT,

ORAPTOAM,

APFRDCNM,

APFRDCTY,

APFRDCDT,

ApplyFromGLPostDate,

FROMCURR,

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 Equipment Bureaucrat in Alba Spectrum Technologies - USA generally 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, Rock Gossip and Microsoft CRM SDK developer; akarasev@albaspectrum. com


MORE RESOURCES:
Developed by:
home | site map
goldenarticles.net © 2018