wmickey
28th April 2008, 21:27
I am trying to automate the matching and approving of receipts using AFS. After printing the Purchase Invoice, I am using AFS to create the data in session tfacp1110s000, which works fine. Then I want to continue and match/approve the receipt lines. When I say ‘Yes’ to Link Receipts in tfacp1230s000, and the amount to be matched = receipt amount – all works fine. However, when I say ‘No’ to Link and go to tfacp1131s000 to find specific lines and change status to ‘completely’, it can not fine my specific record. Then once I get the records matched, I need to approve them. Attached is my code. Has anyone done something similar and can help me with this?

if curr.company = 100 then
stpapi.put.field("tfgld1101m000", "tfgld101.year", str$(fiscal.yr))
stpapi.put.field("tfgld1101m000", "tfgld101.btno", str$(batch))
stpapi.put.field("tfgld1101m000", "tfgld101.ttyp", trans.type)
retval1 = stpapi.find("tfgld1101m000", error.msg)
if not retval1 then
message("Error %s", error.msg)
retval2 = stpapi.recover("tfgld1101m000", recover.msg)
else
stpapi.handle.subproc("tfgld1101m000", "tfacp1110s000", "add")
stpapi.zoom.option("tfgld1101m000", 1, "tfacp1110s000", error.msg)
if error.msg > "" then
message("Error %s", error.msg)
endif
stpapi.put.field("tfacp1110s000", "tfacp200.ninv", "0")
stpapi.put.field("tfacp1110s000", "tfacp200.suno", supplr)
stpapi.put.field("tfacp1110s000", "screen.amnt", str$(amnt))
stpapi.put.field("tfacp1110s000", "tfacp200.isup", supinv)
stpapi.put.field("tfacp1110s000", "tfacp200.refr", poref)
stpapi.put.field("tfacp1110s000", "tfacp200.orno", str$(purchord))
stpapi.put.field("tfacp1110s000", "tfacp200.loco",str$(orig.company))
stpapi.put.field("tfacp1110s000", "tfacp200.paym", "D06")
stpapi.put.field("tfacp1110s000", "tfacp200.bank", "ACH")
stpapi.put.field("tfacp1110s000", "tfacp200.reas", "MIS")
retval1 = stpapi.insert("tfacp1110s000", true, error.msg)
if not retval1 then
message("Error %s", error.msg)
retval2 = stpapi.recover("tfacp1110s000", recover.msg)
else
|* get.receipt.amount()
|* Open Receipts match the Purch Invoice amount - match all receipts
|* Processing both as Yes- works fine. matches and approves.
if open.amount = amnt then
stpapi.put.field("tfacp1230s000", "link", str$(etol(tcyesno.yes)))
stpapi.put.field("tfacp1230s000", "approve", str$(etol(tcyesno.yes)))
stpapi.continue.process("tfacp1230s000", error.msg)
if error.msg > "" then
message("Error %s", error.msg)
endif
stpapi.end.session("tfacp1230s000")
endif

|* This is where everything falls apart - I can not select specific records
|* and change them to completed status, then continue to approve them.

|* Open Receipts are <> the Purch Invoice amount - match individual receipts
|* Then need to aprove the records after matching
if open.amount <> amnt then
stpapi.put.field("tfacp1230s000", "link", str$(etol(tcyesno.no)))
stpapi.put.field("tfacp1230s000", "approve", str$(etol(tcyesno.no)))
stpapi.handle.subproc("tfacp1230s000", "tfacp1131s000", "add")
stpapi.zoom.option("tfacp1230s000", 1, "tfacp1131s000", error.msg)
if error.msg > "" then
message("Error %s", error.msg)
endif

|* This is where everything falls apart - I can not select specific records
|* and change them to completed status, then continue to approve them.

|* Find the specific Line to mark and update to completed
stpapi.put.field("tfacp1131s000", "tdpur045.suno", str$(supplr))
stpapi.put.field("tfacp1131s000", "tdpur045.orno", str$(purchord))
stpapi.put.field("tfacp1131s000", "tdpur045.pono", str$(10))
stpapi.put.field("tfacp1131s000", "tdpur045.srnb", "1")
retval1 = stpapi.change.view("tfacp1131s000", error.msg)
if not retval1 then
message("Record not found")
retval2 = stpapi.recover("tfacp1131", recover.msg)
else
retval1 = stpapi.mark("tfacp1131s000",error.msg)
if not retval1 then
message("Record not found")
endif
endif
stpapi.put.field("tfacp1131s000", "tdpur045.matc", str$(2))
retval1 = stpapi.update("tfacp1131s000", true, error.msg)
if not retval1 then
message("Error %s", error.msg)
retval2 = stpapi.recover("tfacp1131s000", recover.msg)
endif
stpapi.end.session("tfacp1131s000")

|* Now finished matching receipts
|* Match/Apprive Purchase Invoice with Orders (Approve Button)
if amnt = tfacp200.link then
stpapi.continue.process("tfacp1230s000", error.msg)
if error.msg > "" then
message("Error %s", error.msg)
endif
else
message("Net= %d", net.amount)
endif
stpapi.end.session("tfacp1230s000")

endif |* End individual match

endif |* Can't write transaction record
stpapi.end.session("tfacp1110s000")
endif |* Can't find batch
stpapi.end.session("tfgld1101m000")
endif |* Company = 100
}

function get.receipt.amount()
{
switch.to.company(orig.company)
open.amount = 0
select *
from tdpur045
where tdpur045._index8 = {:supplr}
and tdpur045.orno = :purchord
and tdpur045.srnb > 0
and tdpur045.matc <> 2 |*Completely
selectdo
open.amount = open.amount + (tdpur045.amnt - tdpur045.iamt)
endselect
switch.to.company(100)
}

mark_h
29th April 2008, 16:40
Your sequence of sessions is different than anything I do - the section of code I do not understand has the following in it:

if open.amount <> amnt then
stpapi.put.field("tfacp1230s000", "link", str$(etol(tcyesno.no)))
stpapi.put.field("tfacp1230s000", "approve", str$(etol(tcyesno.no)))
stpapi.handle.subproc("tfacp1230s000", "tfacp1131s000", "add")
stpapi.zoom.option("tfacp1230s000", 1, "tfacp1131s000", error.msg)
if error.msg > "" then
message("Error %s", error.msg)
endif

Do you need a save or update before calling tfacp1131s000? Or better yet can you save it here and then launch another session(a main session) to do what you are looking for? I pretty much only do automatching. I can not find anything that does exactly what you are doing.

lwentz
29th April 2008, 19:28
I work with wmickey and would like to know how you handle everything using automatch. How do you get Baan to only match the receipts that apply to the payment amount (in our case the Purchase Invoice amount). If you say 'Yes' to Link and have other outstanding receipts from another shipment, they all get marked as status 'completely', then there is a variance between the matched amount and the payment amount. Is there another way to match/approve receipts?

mark_h
29th April 2008, 19:52
One thing I was asking was can you use tfacp1230m000 to do what you are trying to do through tfacp1230s000? I do not know the difference in all the sessions, but almost everything I have runs through tfacp1133s000. I know at one point we used tfacp1230m000 instead of going through tfacp1230s000. I will look around some more to see if we do use tfacp1131s000 in any sessions.

mark_h
29th April 2008, 22:23
Well I looked around and the only piece of code I see that uses tfacp1131s000 kills it if the session even starts. Back to the original post of mine - have you tried an update or save before doing the stpapi.zoom.option? How do you do this work manually? Do you set the two options and then zoom? Or does it automatically happen?

stpapi.put.field("tfacp1230s000", "link", str$(etol(tcyesno.no)))
stpapi.put.field("tfacp1230s000", "approve", str$(etol(tcyesno.no)))

||| Maybe an update or save before launching the sub-session might work

stpapi.handle.subproc("tfacp1230s000", "tfacp1131s000", "add")
stpapi.zoom.option("tfacp1230s000", 1, "tfacp1131s000", error.msg)
if error.msg > "" then
message("Error %s", error.msg)
endif

ravi99
26th January 2009, 02:24
Hi Wmickey/anybody,

I am trying to do purchase invoice matching and approval process by using AFS. When I run my session, it hangs at:

retval1 = stpapi.insert("tfacp1110s000", true, error.msg)

Can you you help me with this. I am not sure what might be wrong? Basically I have main table and maintain session and user have the oprion to flag 'matched' field to 'yes' then AFS should start and complete the 'Match & approval ' process and update maintain with another flag to 'Yes'. In this case let assume purchase invoice amount always matches with receipt amount.

Thanks in advane
Ravi

mark_h
26th January 2009, 14:59
Check what is going on in the background. I had to do some funny stuff to get it to work for me. I have not used this in years - thankfully. I doubt your system is like ours, but this should give you an idea of what I had to do to get it to work. We have not used this since 2005.


stpapi.insert( "tfacp1110s000", 1,msg)
if(strip$(msg)="Supplier not found") then
write_error_files()
stpapi.end.session( "tfacp1110s000" ) |Stop automatching of invoices.
continue | Get next record
endif
| Try this kill all sessions excep tfacp1110s000
stpapi.end.session( "tfacp1230s000" ) |Stop automatching of invoices.
stpapi.end.session( "tfacp1131s000" ) |Stop Match Receipts
stpapi.end.session( "tfacp1130s000" )

rc = stpapi.browse.set( "tfacp1110s000", "last.set" )
stpapi.zoom.option( "tfacp1110s000", 1, "tfacp1230s000", msg )
stpapi.update( "tfacp1230s000", 1, msg )
stpapi.handle.subproc( "tfacp1230s000", "tfacp1133s000","add" )
stpapi.handle.subproc( "tfacp1230s000", "tfacp1140s000","add" )

|************************************************************************************************
| New Step 7. Use session tfacp1230s000 to start tfacp1133s000.
|************************************************************************************************
stpapi.application.option( "tfacp1230s000", 1, 0, msg)
if(strip$(msg)<>"")then
message("f1230s000.Book_Variances:%s",msg)
endif
prefix.po = shiftl$(shiftr$(read.po))
prefix.po = prefix.po(1;1)
on case prefix.po
endcase
stpapi.put.field( "tfacp1133s000", "tfacp101.comp", str$(fin.compnr))
stpapi.put.field( "tfacp1133s000", "tfacp101.leac", acct)
stpapi.put.field( "tfacp1133s000", "tfacp101.amnt", str$(adj.amnt))
stpapi.put.field( "tfacp1133s000", "tfacp101.dbcr", str$(tfgld.dbcr.credit))
stpapi.put.field( "tfacp1133s000", "tfacp101.refr", adj.vchr)
stpapi.put.field( "tfacp1133s000", "tfacp101.fyer", str$(2000))
stpapi.put.field( "tfacp1133s000", "tfacp101.fprd", str$(12))
stpapi.put.field( "tfacp1133s000", "tfacp101.ryer", str$(2000))
stpapi.put.field( "tfacp1133s000", "tfacp101.rprd", str$(12))
stpapi.put.field( "tfacp1133s000", "tfacp101.qty1", str$(0.0))
stpapi.put.field( "tfacp1133s000", "tfacp101.qty2", str$(0.0))
stpapi.insert( "tfacp1133s000", 1, msg )
if(strip$(msg)<>"")then
message("f1133s000.save:%s",msg)
endif
stpapi.end.session( "tfacp1133s000" )


stpapi.update( "tfacp1230s000", 1, msg)

|************************************************************************************************
| New Step 8. Check session tfacp1230s000 to make sure everything is okay.
|************************************************************************************************
stpapi.get.field( "tfacp1230s000", "net.amnt", dummy )
net.amnt = val(dummy)
stpapi.get.field( "tfacp1230s000", "receipts", dummy )
amount = val(dummy)

| These fields were blank
stpapi.get.field( "tfacp1230s000", "link", dummy)
link.rec = ltoe(lval(dummy))
stpapi.get.field( "tfacp1230s000", "approve", dummy )
approve = ltoe(lval(dummy))
if(net.amnt <> amount
or link.rec <> tcyesno.yes or
approve <> tcyesno.yes) then
msg = "tfacp1230s000: Not approved mis-match."
stpapi.end.session( "tfacp1230s000" ) |Stop automatching of invoices.
stpapi.end.session( "tfacp1131s000" ) |Stop Match Receipts
stpapi.end.session( "tfacp1130s000" ) |Stop Match/Approve Purchase inv.
stpapi.end.session( "tfacp1110s000" ) |Stop the tfacp1130s00 session
rprt_send()
continue
endif
|************************************************************************************************
| New Step 9. Everything checked out. Do a continue is tfacp1230s000
|************************************************************************************************
stpapi.continue.process( "tfacp1230s000", msg )
| No matter what happens an error is returned. Just end
| all sessions.
msg = "tfacp1110s000 Insert: "&strip$(msg)
stpapi.end.session( "tfacp1131s000" ) |Stop Match Receipts
stpapi.end.session( "tfacp1130s000" ) |Stop Match/Approve Purchase inv.
| then kill session tfacp1140s000 which says it was approved.
stpapi.end.session( "tfacp1140s000" )
stpapi.end.session( "tfacp1230s000" ) |Stop automatching of invoices.
stpapi.end.session( "tfacp1110s000" )
| Part processed completely or with a Check mauc error.
rprt_send()
endwhile
| End tfacp1110s000 - End this one first.
stpapi.end.session( "tfacp1110s000" )
| End tfgld1101m000
stpapi.end.session( "tfgld1101m000" )

lwentz
26th January 2009, 15:05
Ravi,
Verify that session tfacp1110s000 is really open at the time of insert. We use UNIX - So I put the session in Debug mode and once on the insert line - Open Option Dialog- start shell. Do a ps command to see the list of sessions running. Verify that the session is in the list.

I had that issue and found that session tfgld1101m000 was not correctly finding and marking the Transaction Type record.

Lisa

ravi99
26th January 2009, 15:06
Thanks Mark. I will change my code and let you know. Do I need to change : tfacp1110 & tfacp1230 code also? Please let me know. Did you change these codes (tfacp1110 & tfacp1230)?

ravi99
26th January 2009, 15:09
Hi Mark,

There is a zoom.to$ to session: tfacp1230s000 within tfacp1110. I believe I need to change the code: tfacp1110 so that session: tfacp1230s000 is not activated when I run tfacp1110s000 in AFS mode, please let me know.

I really appreciate your prompt reply.

Ravi

mark_h
26th January 2009, 16:26
Hi Mark,

There is a zoom.to$ to session: tfacp1230s000 within tfacp1110. I believe I need to change the code: tfacp1110 so that session: tfacp1230s000 is not activated when I run tfacp1110s000 in AFS mode, please let me know.

I really appreciate your prompt reply.

Ravi
Sorry, but I can not answer that question. I really am not that familiar with the sessions and I do not know what happens on your system. I know the session automatically launches on ours and that is how the users had me process the records. If you have the source code then yes you can skip that piece of processing - I just do not know if it is the right thing to do.

ravi99
28th January 2009, 14:10
Thanks Mark for your help. Your program script helped me. I really appreciate your help.