How to set Amount to Apply in Payment Allocation to invoice from code

samantha73
Member Posts: 118
Hi Guys
I thought it's simple to allocate payments to invoices from code but after couple of days of trying I need help..:)
Basically it works setting the Applied-To-Id and remaining amount , but always takes the remaining amount instead of the amount to apply
This is my simple codeunit
so far the only way to get amount to apply populated was changing the setappl.ID codeunit (creating my own) as below
I still cannot use above since I need discounts, tolerance etc to be working and want to get see the best possible option. Looks like writing to ledger entries is quite complicated
I thought it's simple to allocate payments to invoices from code but after couple of days of trying I need help..:)
Basically it works setting the Applied-To-Id and remaining amount , but always takes the remaining amount instead of the amount to apply
This is my simple codeunit
var CustLedgEntry: Record "Cust. Ledger Entry"; ApplyingCustLedgEntry: Record "Cust. Ledger Entry"; CustEntrySetApplID: Codeunit "Cust. Entry-SetAppl.ID"; CustEntryApplyPostedEntries: Codeunit "CustEntry-Apply Posted Entries"; begin CustLedgEntry.SetRange("Entry No.", 144); ApplyingCustLedgEntry.SetRange("Entry No.", 157); CustLedgEntry.Validate("Amount to Apply", -25); ApplyingCustLedgEntry.Validate("Applies-to ID", 'TEST1234'); ApplyingCustLedgEntry.VALIDATE("Amount to Apply", 25); CustEntrySetApplID.SetApplId(CustLedgEntry, ApplyingCustLedgEntry, 'test1234'); ApplyingCustLedgEntry.VALIDATE("Amount to Apply", 25); ApplyingCustLedgEntry.MODIFY(true); CustEntryApplyPostedEntries.Apply(ApplyingCustLedgEntry, ApplyingCustLedgEntry."Document No.", CustLedgEntry."Posting Date"); end;
so far the only way to get amount to apply populated was changing the setappl.ID codeunit (creating my own) as below
if ((CustLedgerEntry."Amount to Apply" <> 0) and (CustEntryApplID = '')) or (CustEntryApplID = '') then CustLedgerEntry."Amount to Apply" := [b]ApplyingCustLedgerEntry."Amount to Apply" * -1[/b]//-1//original 0 else if CustLedgerEntry."Amount to Apply" = 0 then begin CustLedgerEntry.CalcFields("Remaining Amount"); CustLedgerEntry."Amount to Apply" := [b]ApplyingCustLedgerEntry."Amount to Apply" * -1[/b];//original CustLedgerEntry."Remaining Amount" end;
I still cannot use above since I need discounts, tolerance etc to be working and want to get see the best possible option. Looks like writing to ledger entries is quite complicated
0
Answers
-
Hi,
So you want to override "amount to apply" field.
Why dont you create an event subscriber to onaftervalidate for that field?
not sure if I understand what do you want to do.
0 -
Ok thanks..let me try to explain - it's simple . From the front end you can part pay (invoice remaining 100 payment 50) an invoice though either cash receipt journal or payment journal. How to do this from code?0
-
you can use also "applies to do type" and "applies to doc no" fields instead "applies to id". that should solve the issue.
if you would need to split a payment between several documents proportionally, then you would need to set applies to ID and amount to apply in customer ledger entry/vendor ledger entry.
I think it's codeunits 226/227 that will allow you to edit both tables.
just follow the code in nav standard, I've done this a lot years ago but I dont recall precisely.
hoe this helps.
1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions