After many attempts trying to use GP's next voucher number, and much frustration, I would strongly, strongly recommend maintaining your own next doc number table.
I made 3 attempts at using the PM40100 table to get the next voucher number. Each time it appeared to work, but what I found is that in an environment with multiple AP clerks entering vouchers, the voucher number that my integration retrieved from the table, despite locks and tons of code to prevent dups, would eventually be a number that had been retrieved previously by a GP user.
On my 3rd attempt I reverse engineered the GP stored procedure that is used to get the next voucher number (it is very scary code) and used that design and code in my integration to try and avoid the duplicate voucher numbers, but even that didn't work 100%. I honestly don't know how GP is doing it reliably, unless they have additional logic in the application to further try and prevent dups.
The good news is that as soon as I switched over to my own voucher number table, things worked perfectly and I never had a problem or error again related to that issue. I created a table with a Prefix field and a Number field, so that I could easily increment the number and just append it to the prefix. So, perhaps Web site imports are "WEB" + "100001", vendor electronic billing files are "VEN" + "100001", etc. If you add a few additional fields (ImportType = PMVCH, RMINV, etc.) you can use the same table for all document numbers (except perhaps GL JEs, if you want those in sequence).
Good luck!