Quantcast
Channel: NAV Three Tier — mibuso.com
Viewing all articles
Browse latest Browse all 10068

Applying vendor ledger entries through code

$
0
0
Hi,

I need to write a batch job in NAV 2015 that creates vendor payment entries in the G/L Journal and applies them to the relevant vendor invoices. I must use ONE payment entry per vendor. This payment has to be applied to several vendor invoices (always more than 1 invoice per vendor). Normally the user would open page 233 (Apply Vendor Entries), mark all the invoices, Close the page with OK and post the Journal. Since I cannot use a page that opens in my batch job I have filled out the field "Applies-to ID" on the General Journal (vendor payment) as well as on all the vendor ledger entries (invoices) against which the payment shall be applied. I also made sure the field "Amount to Apply" on the vendor ledger entries (invoices) is filled out with the remaining amount of the relevant ledger entry. When I post the journal the payment is registered, the balance of the vendor is zero. So far so good. But - the payment and the invoices are all still open. The entries were not applied.

I have been searching/testing for hours and I can't find what I am still missing. When I mark the entries through page 233 (Apply Vendor Entries) and post, then everything is fine.

Here is the code that I used for testing:


GLJournal.RESET;
GLJournal.SETRANGE(GLJournal."Journal Batch Name",'STANDARDA');
IF GLJournal.FINDFIRST THEN BEGIN
CLEAR(VendEntry);
VendEntry.SETCURRENTKEY("Vendor No.",Open);
VendEntry.SETRANGE("Vendor No.",'K8118');
VendEntry.SETRANGE(Open,TRUE);
IF VendEntry.FINDSET THEN REPEAT
VendEntry.VALIDATE("Applies-to ID",GLJournal."Document No.");
VendEntry.CALCFIELDS("Remaining Amount");
VendEntry.VALIDATE("Amount to Apply",VendEntry."Remaining Amount");
VendEntry.MODIFY;
UNTIL VendEntry.NEXT = 0;

GLJournal.VALIDATE("Applies-to ID",GLJournal."Document No.");

CODEUNIT.RUN(CODEUNIT::"Gen. Jnl.-Post",GLJournal);
END;

I would really appreciate if somebody could help me to solve this problem.

Many thanks in advance.
MACL2

Viewing all articles
Browse latest Browse all 10068


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>