automating Payment Allocation to invoice

kamranshehzadkamranshehzad Posts: 165Member
Hi
I want to automate payment allocation to invoices. Eg, if i have 1 payment that needs to be applied to 1 invoice and it needs to be allocated. I want this process automated rather than going into customer ledger and set applies to id and then post.

I wrote a code unit that takes the parameters and set applies to id, amount and applying entry for payment and invoice but posting fails.

I can't see any other entry that needs to be done before posting during Nav set aplies to id process.
I can't see any entry in gen journal line either.

Am I missing something that needs to be done before i execute CU 226 with the payment record ?

regards,
KS

Answers

  • SavatageSavatage Posts: 7,140Member
    If you set the Application Method to "Apply To Oldest" in the customer card all payments will automatically be applied.

    Is this what you're looking for?
  • kamranshehzadkamranshehzad Posts: 165Member
    No. we need manual payment allocations. ](*,)
    KS
  • kamranshehzadkamranshehzad Posts: 165Member
    shouldn't I just pass the desired record to CU101 and that will do the job????
    KS
  • SavatageSavatage Posts: 7,140Member
    I want to automate payment allocation
    we need manual payment allocations.

    :-k
  • kamranshehzadkamranshehzad Posts: 165Member
    Savatage wrote:
    I want to automate payment allocation
    We want to automate it as we want to allocate the payments that we have been paid for using a routine.

    we need manual payment allocations.
    This is something we set in customer profile so system wont automatically allocate the payment based on the oldest entry.
    Its a setting in customer card i believe.
    :-k

    ](*,)
    KS
  • kamranshehzadkamranshehzad Posts: 165Member
    Can any one guide me on this?
    regards,
    KS
  • garakgarak Posts: 3,263Member
    What for an "Application Methode" do you use? It's behind the Register Payments.There are two options:

    Manual and "Apply to Oldest".

    Manual means that the program will apply payments only if you specify a document.

    Apply to Oldest means that if you do not specify a document for the payment to be applied to, the program will apply the payment to the oldest of the customer's open entries.

    Regards
    Do you make it right, it works too!
  • kamranshehzadkamranshehzad Posts: 165Member
    garak wrote:
    What for an "Application Methode" do you use? It's behind the Register Payments.There are two options:

    Manual and "Apply to Oldest".

    Manual means that the program will apply payments only if you specify a document.

    Apply to Oldest means that if you do not specify a document for the payment to be applied to, the program will apply the payment to the oldest of the customer's open entries.

    Regards

    No Man.. you are not getting the point. I am getting orders and then payments from other system through our written interfaces in nav. in order to allocate those payments , i am getting the allocations ( they can't come at same time as mostly payments get allocated later on) through interfaces.
    Now I need to write a routine that picks up the sales payment and related invoices (I can filter them ) and allocate them.
    I am trying to replicate the allocation process but facing issues.

    so all i want to know if there is any example that some one give me or advise me the best way to do so.

    We dont want to use the above given process as some times allocated amount is not equal to payment or some times payment is allocated to multiple invoices etc.

    hope its clear now.

    please advise.
    regards,
    KS
  • ayhan06ayhan06 Posts: 210Member
    garak wrote:
    What for an "Application Methode" do you use? It's behind the Register Payments.There are two options:

    Manual and "Apply to Oldest".

    Manual means that the program will apply payments only if you specify a document.

    Apply to Oldest means that if you do not specify a document for the payment to be applied to, the program will apply the payment to the oldest of the customer's open entries.

    Regards

    No Man.. you are not getting the point. I am getting orders and then payments from other system through our written interfaces in nav. in order to allocate those payments , i am getting the allocations ( they can't come at same time as mostly payments get allocated later on) through interfaces.
    Now I need to write a routine that picks up the sales payment and related invoices (I can filter them ) and allocate them.
    I am trying to replicate the allocation process but facing issues.

    so all i want to know if there is any example that some one give me or advise me the best way to do so.

    We dont want to use the above given process as some times allocated amount is not equal to payment or some times payment is allocated to multiple invoices etc.

    hope its clear now.

    please advise.
    regards,
    1. amount to apply must be set as remaining amount. (note that remaining amount is flow field)
    2. generate a random applies-to Id and set "Applies-to ID" field on both gen. journal and cust. ledger entry.
    3. call cu 103 to update cust. ledger entry..

    you can look into report 393 to see how NAV can handle this..no need to use "Applying Entry" etc.. just "amount to apply" and "Applies-To ID" can solve your problem.

    If you are geting error, please explain your problem in detail.
  • kamranshehzadkamranshehzad Posts: 165Member
    1. amount to apply must be set as remaining amount. (note that remaining amount is flow field)
    2. generate a random applies-to Id and set "Applies-to ID" field on both gen. journal and cust. ledger entry.
    3. call cu 103 to update cust. ledger entry..

    you can look into report 393 to see how NAV can handle this..no need to use "Applying Entry" etc.. just "amount to apply" and "Applies-To ID" can solve your problem.

    If you are geting error, please explain your problem in detail.

    thanks this something i was looking for.

    I did trying to set it cust ledger entry to amount to apply (validating it was setting the remaining amount i believe)
    and was setting applied to id in cust ledger entry but not in gen. journal. and was calling cu 103 to update the entry and then was trying to post.
    upon posting it finds that applying entry and applied to entry are same. i thinks this is due to missing applicatoin to g j entry.
    I did look into GJ line table but i can't find any entry there.

    Can you please advise me on this? am i looking at wrong table?

    regards,
    KS
  • kamranshehzadkamranshehzad Posts: 165Member
    I did the following to make it work

    1- set the values of applying payment ledger entry (with out using code unit 103)
    2- set the values of invoice ledger entry
    3- passing the invoice entry to CustEntry-Apply Posted Entries

    it does the job but I am not sure whether this will not cause any other issue. can some one please advise me on this.

    here is the test code i wrote for this. Please feel free to comment on any thing in code. ill welcome it.
    Documentation()
    - THIS CODE UNIT IS DESIGNED TO
      - SELECT THE RELATED PAYMENT
      - APPLIES TO ID
      - POST THE ENTRY AS ALLOCATED ENTRY
    
    OnRun()
    
    ToDocNo := '471';
    ToExtDocNo := '883';
    ToERPDocType := 'Invoice';
    AmountToApply := 10;
    ByDocNo := '552624';
    ByExtDocNo := '1856';
    ByERPDocType := 'Payment';
    
    IF ByERPDocType = 'Payment' THEN BEGIN
    
      ApplyingCustLedgEntry.SETCURRENTKEY("Document Type" ,"Document No." , "External Document No.");
      ApplyingCustLedgEntry.SETRANGE("Document Type", ApplyingCustLedgEntry."Document Type"::Payment);
      ApplyingCustLedgEntry.SETRANGE("Document No.", ByDocNo);
      ApplyingCustLedgEntry.SETRANGE("External Document No.", ByExtDocNo);
    
      IF ApplyingCustLedgEntry.FIND('-') THEN
        IF ApplyingCustLedgEntry.Open THEN
          IF ToERPDocType = 'Invoice' THEN BEGIN
            CustLedgerEntry.SETCURRENTKEY("Document Type" ,"Document No." , "External Document No.");
            CustLedgerEntry.SETRANGE("Document Type", ApplyingCustLedgEntry."Document Type"::Invoice);
            CustLedgerEntry.SETRANGE("Document No.", ToDocNo);
            CustLedgerEntry.SETRANGE("External Document No.", ToExtDocNo);
    
            IF CustLedgerEntry.FIND('-') THEN BEGIN
              ApplyingCustLedgEntry.VALIDATE("Applies-to ID",USERID);
              ApplyingCustLedgEntry.VALIDATE("Amount to Apply", -AmountToApply);
              ApplyingCustLedgEntry.CALCFIELDS("Remaining Amount");
                ApplyingCustLedgEntry.MODIFY;
    
                CustLedgerEntry.RESET;
                CustLedgerEntry.SETCURRENTKEY("Document Type" ,"Document No." , "External Document No.");
                CustLedgerEntry.SETRANGE("Document Type", ApplyingCustLedgEntry."Document Type"::Invoice);
                CustLedgerEntry.SETRANGE("Document No.", ToDocNo);
                CustLedgerEntry.SETRANGE("External Document No.", ToExtDocNo);
                
                CustLedgerEntry.VALIDATE("Applies-to ID",USERID);
                CustLedgerEntry.VALIDATE("Amount to Apply",AmountToApply);
                CustLedgerEntry.CALCFIELDS("Remaining Amount");
                CustLedgerEntry.MODIFY;
    
                CustLedgerEntry.RESET;
                CustLedgerEntry.SETCURRENTKEY("Document Type" ,"Document No." , "External Document No.");
                CustLedgerEntry.SETRANGE("Document Type", ApplyingCustLedgEntry."Document Type"::Invoice);
                CustLedgerEntry.SETRANGE("Document No.", ToDocNo);
                CustLedgerEntry.SETRANGE("External Document No.", ToExtDocNo);
    
                 IF CustLedgerEntry.FIND('-') THEN BEGIN
                       CustEntryApplyPostedEntry.RUN(CustLedgerEntry);
                 END;
           END;
          END;
    END;
    
    PostEntry(VAR CustEntryApplyPostedEntries : Record "Cust. Ledger Entry")
    
         CustEntryApplyPostedEntry.RUN(CustEntryApplyPostedEntries);
    
    KS
  • MubasherMubasher Posts: 25Member
    Hi Kamran,
    Did you find the solution? I facing the same scenario can you shave code or any helping materiel to solve this problem.
Sign In or Register to comment.