Apply Customer Ledger Entries in Code unit 12

Mauddib
Mauddib Member Posts: 269
Whatexactly are the conditions for Completed to become true in Code unit 12 function ApplyCustLedgEntry(). This function being called in the line....

ApplyCustLedgEntry(
CVLedgEntryBuf,DtldCVLedgEntryBuf,GenJnlLine,NextTransactionNo,
GLSetup."Appln. Rounding Precision");

My head is burning up trying to find out what is required for the loop to end when it reaches the line:

UNTIL Completed;

The reason for asking is that for one customer, and it has never happed to any other customer, the code is looping here to infinity and nothing happens when trying to post an invoice.

Thinking there may be something wrong with the invoice posting i tried to post an INVOICE journal to take all PAYMENTS off the customers account. I then intended to post a PAYMENT journal of one line to put the balance back on the customers account. Thinking this would help.

However the same infinity loop happens then too so I cant remove the customer ledger entries and hence bypass whichever one has become corrupt, so instead I need to know why its happening so I can fix the corrupt data.

Comments

  • markborges
    markborges Member Posts: 170
    Hi there Mauddib.

    Lately I've changed my codeunit 12 so that I could insert a new condition to this Completed variable you're stuck at.

    Look at this code (it's exactly where the Completed variable is set):
      IF GenJnlLine."Applies-to Doc. No." <> '' THEN
        Completed := TRUE
      ELSE
        IF OldCustLedgEntry.GETFILTER(OldCustLedgEntry.Positive) <> '' THEN BEGIN
          IF OldCustLedgEntry.NEXT = 1 THEN
            Completed := FALSE
          ELSE BEGIN
            OldCustLedgEntry.SETRANGE(Positive);
            OldCustLedgEntry.FIND('-');
            OldCustLedgEntry.CALCFIELDS("Remaining Amount");
            Completed := OldCustLedgEntry."Remaining Amount" * NewCVLedgEntryBuf."Remaining Amount" >= 0;
          END
        END ELSE BEGIN
          IF NewCVLedgEntryBuf.Open THEN
            Completed := OldCustLedgEntry.NEXT = 0
          ELSE
            Completed := TRUE;
        END;
    

    You should check back on the code, and rather debug it to see all the variables so that you can check why Completed is never TRUE.

    Note: This code is right above the "UNTIL Completed" line.

    Best regards,

    :wink:
    Marcelo Borges
    D365 Business Central Solutions Architect
    BC AL/NAV C/AL Developer
    BC Repositories.com