Code to aplpy transactions to receipt

Hi Chaps,

Im trying to write some code at the moment that will create a cash receipt transaction and aplpy various invoices and credits to it via code.

Where I am struggling seems to be backward engineering the applying section, has anyone one done this before calling the standard navsion functions.?

Many Thanks.

Hmm -

First a few questions - What Version are you using?

Secondly - Why do you need to do this via code? If you change the application method on the customer (or vendor) to ‘Apply to oldest’, Navision will automaticly apply payments.


  1. 4.2

  2. I need to do this as I am writing a contra routine for the customer. Ie where an account could be either a customer or vendor.

I have created a form to which they select the records they want to contra, on both the vendor and cust. ledger entries. My routine creates the cash receipt and purchase payment transactions. Below is the code for the cash receipt side of the transaction.

The code below does work but I was wondering if there was a more efficient way of doing this.

LrecGenJournal.VALIDATE(“Journal Template Name”,VrecSetup.“Contras Cust Template”);
LrecGenJournal.VALIDATE(“Journal Batch Name”,VrecSetup.“Contras Cust Batch”);
LrecGenJournalT.SETRANGE(“Journal Template Name”,VrecSetup.“Contras Cust Template”);
LrecGenJournalT.SETRANGE(“Journal Batch Name”,VrecSetup.“Contras Cust Batch”);
IF LrecGenJournalT.FIND(’+’) THEN LrecGenJournal.“Line No.” := LrecGenJournalT.“Line No.” + 10000
ELSE LrecGenJournal.“Line No.” := 10000;
LrecGenJournal.VALIDATE(“Posting Date”,VrecContra.“Posting Date”);
LrecGenJournal.VALIDATE(“Document No.”,VrecContra.“No.”);
LrecGenJournal.VALIDATE(“Document Type”,LrecGenJournal.“Document Type”::Payment);
LrecGenJournal.VALIDATE(“Account Type”,LrecGenJournal.“Account Type”::Customer);
LrecGenJournal.VALIDATE(“Account No.”,VrecContra.“Customer Code”);
LrecGenJournal.VALIDATE(“Bal. Account Type”,LrecGenJournal.“Bal. Account Type”::“Bank Account”);
LrecGenJournal.VALIDATE(“Bal. Account No.”,VrecContra.“Bank Account Code”);
LrecGenJournal.VALIDATE(“Applies-to ID”,VrecContra.“No.”);
LrecGenJournal.VALIDATE(Amount,GdecCustCont * -1);

LrecApplyingCustLedgEntry.“Entry No.” := 1;
LrecApplyingCustLedgEntry.“Posting Date” := LrecGenJournal.“Posting Date”;
LrecApplyingCustLedgEntry.“Document Type” := LrecGenJournal.“Document Type”;
LrecApplyingCustLedgEntry.“Document No.” := LrecGenJournal.“Document No.”;
LrecApplyingCustLedgEntry.“Customer No.” := LrecGenJournal.“Account No.”;
LrecApplyingCustLedgEntry.Description := LrecGenJournal.Description;
LrecApplyingCustLedgEntry.“Currency Code” := LrecGenJournal.“Currency Code”;
LrecApplyingCustLedgEntry.Amount := LrecGenJournal.Amount;
LrecApplyingCustLedgEntry.“Remaining Amount” := LrecGenJournal.Amount;

LrecCustLedger.SETCURRENTKEY(“Contra No.”);
LrecCustLedger.SETRANGE(“Contra No.”,VrecContra.“No.”);
IF LrecCustLedger.FIND(’-’) THEN
LrecCustLedger.VALIDATE(“Amount to Apply”,LrecCustLedger.“Contra Amount (LCY)”);
UNTIL LrecCustLedger.NEXT = 0;
LrecCustLedger,LrecApplyingCustLedgEntry,LrecCustLedger.“Contra Amount (LCY)”,0,LrecGenJournal.“Applies-to ID”);