Hello, i was doing some customization then i realized i had to post an application of a payment against an invoice in code. I felt the urge to share with someone there that may be facing a hurdle doing so. Just follow these easy steps.
- Search and found the invoice record in the customer Ledger Entry table
- Once you have find the invoice entry from the customer ledger entry table, Search for the payment entry as well from the customer ledger entry table
- Edit and update the Invoice ledger Entry you found above
- Set Applies to ID
- Post Application
Here is a sample code to achieve that;
CustomerLdgEntryInv.RESET;//CustomerLdgEntryInv is a record variable of table 21
CustomerLdgEntryInv.SETRANGE(CustomerLdgEntryInv."Document Type", CustomerLdgEntryInv."Document Type"::Invoice);//Find only Invoices
CustomerLdgEntryInv.SETRANGE(CustomerLdgEntryInv.Open, TRUE);// Find only Open entries to apply
IF CustomerLdgEntryInv.FINDFIRST THEN BEGIN
// Search for Payment entries in customer ledger entries
CustomerLdgEntry.RESET;//CustomerLdgEntryInv is a record variable of table 21
CustomerLdgEntry.SETRANGE(CustomerLdgEntry."Document Type", CustomerLdgEntry."Document Type"::Payment);// Find the payment
CustomerLdgEntry.SETRANGE(CustomerLdgEntry.Open, TRUE);// Find the payment Ledger Entry
IF CustomerLdgEntry.FINDFIRST THEN REPEAT//Repeat for all the payment entries
//set applies to ID
CustomerLdgEntry.CALCFIELDS(Amount);
//Update all the invoice entries
CustomerLdgEntryInv.CALCFIELDS(Amount);
CustomerLdgEntryInv."Applying Entry" := TRUE;
CustomerLdgEntryInv."Applies-to ID" := USERID;
CustomerLdgEntryInv.CALCFIELDS("Remaining Amount");
CustomerLdgEntryInv.VALIDATE("Amount to Apply", CustomerLdgEntryInv."Remaining Amount");
CODEUNIT.RUN(CODEUNIT::"Cust. Entry-Edit", CustomerLdgEntryInv);
COMMIT;// Commit the change
SetAppliesToID.SetApplId(CustomerLdgEntry,CustomerLdgEntryInv,USERID);// SatAppliesToID is a codeUnit variable of Code Unit 101
// Post the application
PostAppn.Apply(CustomerLdgEntryInv,SalesInvoiceHeader."No.",SalesInvoiceHeader."Posting Date"); // PostAppn is a codeUnit variable of CodeUnit 226
UNTIL CustomerLdgEntry.NEXT = 0;
END;
I would like to hear your opinion of this blog and article. Please leave a comment
Best regards
Author
I would like to hear your opinion of this blog and article. Please leave a comment
Best regards
Author
Thank you very much!!
ReplyDeleteMicrosoft Dynamics Nav/Business Central: Dynamics Nav 2016 Applying And Posting Entries In Code >>>>> Download Now
ReplyDelete>>>>> Download Full
Microsoft Dynamics Nav/Business Central: Dynamics Nav 2016 Applying And Posting Entries In Code >>>>> Download LINK
>>>>> Download Now
Microsoft Dynamics Nav/Business Central: Dynamics Nav 2016 Applying And Posting Entries In Code >>>>> Download Full
>>>>> Download LINK 5N
i used this:
ReplyDeleteIF gCLE.FINDSET THEN REPEAT
gCLE.VALIDATE("Applies-to ID",lGenJournalLine."Document No.");
gCLE.CALCFIELDS("Remaining Amt. (LCY)");
gCLE.VALIDATE("Amount to Apply",gCLE."Remaining Amt. (LCY)");
gCLE.MODIFY;
UNTIL gCLE.NEXT=0;
lGenJournalLine.VALIDATE("Applies-to ID",lGenJournalLine."Document No.");
lGenJournalLine.VALIDATE(Amount,-pPaymentAmount);
lGenJournalLine.VALIDATE("Bal. Account Type",lGenJournalBatch."Bal. Account Type");
lGenJournalLine.VALIDATE("Bal. Account No.",lGenJournalBatch."Bal. Account No.");
lGenJournalLine.INSERT;
CODEUNIT.RUN(CODEUNIT::"Gen. Jnl.-Post",lGenJournalLine);
MESSAGE('Payment successful');
END;