Strange report issue

nvermanverma Member Posts: 396
hey yall,

I created a report for our client where he can select multiple lines and it will create a receipt.

If the user selects a line which has a document type of: credit memo and then he select another line with a document type of invoice; my report works perfectly fine (it calculates the values correctly). However, if its the other way around, and the invoice document type line is before the credit memo document type, then my calculations dont work. I tried debugging the code and in the debugger, it calculates the correct answer but it doesnt display it, so i end up getting the wrong answer.

Any idea what might be happening???

Answers

  • gerrykistlergerrykistler Member Posts: 149
    Would you provide some more detail?

    DataItems in the report
    Sections are you using to display the values
    Variables and maybe code you are using to get the data?
    Gerry Kistler
    KCP Consultores
  • nvermanverma Member Posts: 396
    DateItems and OnAfterGetRecord: http://www2.zshare.ma/153ofl2anrxx

    Sections and Code: http://www2.zshare.ma/dr3vjuqa8tnh
  • gerrykistlergerrykistler Member Posts: 149
    Is the Total footer supposed to be per document or a grouping of documents?

    I do not see where you are adding TotalAmountE anywhere if that matters.
    Gerry Kistler
    KCP Consultores
  • nvermanverma Member Posts: 396
    Its doing it per document and TotalAmountE is calculated here:

    IF ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::"Credit Memo") OR
    ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::Refund) OR
    ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::"Finance Charge Memo") OR
    ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::Reminder) THEN
    BEGIN
    CurrReport.SHOWOUTPUT(FALSE);
    TotalAmountE += "Cust. Ledger Entry".Amount;
    END;

    I have been working on this for few hours now and the strange part is that the debugger calculates the correct answer for Totals variable...but its not outputting the correct answer. No matter what the value the debugger has for totals fields...it always output value of the Inovice's amount..... ](*,)

    When I am going through the debugger and it calculates this line: Totals := TotalAmountI + TotalAmountIC;

    after that it goes through Totals (PreDateItem) trigger that has the following code: "Cust. Ledger Entry".CALCFIELDS(Amount); Do you think this might be resetting the value to the invoice amount????
  • gerrykistlergerrykistler Member Posts: 149
    Well if Totals is meant to be the total for the report, why do you have the Total integer data item? I would do the adding in the Cust. Ledger Entry OnAfterGetRecord and put the Totals in the Cust. Ledger Entry footer with TotalAmountP and AmountOwing.

    You are skipping to show the Total footer section if the document type is Credit Memo anyway so that will not show and would give you a wrong number unless an Invoice was last.

    If I don't have what you are trying to show, maybe a sample of what you want and what you are getting would help.
    Gerry Kistler
    KCP Consultores
  • nvermanverma Member Posts: 396
    I dont want it to show to the line if the document type is credit memo (I dont want to see the description). But i still want it to keep track of the totalAmountIC field so i can use that to calculate the totals field and display the correct answer beside the description of the (document type: invoice)

    Initially I had only the cust. ledger entry as a dataitem...but i had to change it since i couldnt get it to display the correct totals and i believe you are the one who helped me by telling me that i should create a totals dataitem to keep track of totals. .
    viewtopic.php?f=23&t=53343
  • gerrykistlergerrykistler Member Posts: 149
    Fair enough, I am not sure why you started a new thread instead of posting in the original. Now that everything is together in my head the issue is that the Total dataitem is indented under Cust. Ledger Entry. Do not indent it, place it directly below.

    Also as I said in an earlier post and the original, do your adding in the OnAfterGetRecord of Cust. Ledger Entry. The Integer dataitem is just to display the totals after you have accumulated them.
    Gerry Kistler
    KCP Consultores
  • nvermanverma Member Posts: 396
    I did it the way you suggested: I moved Integer DateItem under the Cust. Ledger entry.

    Cust. Ledger Entry - OnAfterGetRecord
    "Cust. Ledger Entry".CALCFIELDS(Amount);
    
    //OMODNV01 - ADD Start
    //Checks to see if the Document Type is Payment. If it is, then Dont show this section.
    //Calculate the Total Amount by adding all the Amount field of "Document Type" 'Payment'
    //Checks to see if the "Document Type" is 'Invoice'. If it is, calculates the Total Amount
    // by addding all the Amount fields.
    IF ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::Payment)  OR
       ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::" ") THEN
      BEGIN
       // CurrReport.SHOWOUTPUT(FALSE);
        TotalAmountP += "Cust. Ledger Entry".Amount;
      END;
    
    
    IF ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::Invoice) THEN
      BEGIN
      //  CurrReport.SHOWOUTPUT(TRUE);
        TotalAmountI += "Cust. Ledger Entry".Amount;
      END;
    //OMODNV01 - ADD Start
    
    //OMODNV04 - ADD Start
    // Checks to see if the Document Type is Credit Memo and if it is, then it keeps tracks of the Amount field 
    // for the selected line
    IF ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::"Credit Memo") THEN
      BEGIN
     //   CurrReport.SHOWOUTPUT(FALSE);
        TotalAmountIC += "Cust. Ledger Entry".Amount;
      END;
    
    //OMODNV02 - ADD Start
    // If the Document Type is "Credit Memo" or "Refund" or "Finance Charge Memmo" or "Reminder" then do not
    // show in this section.
    IF ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::"Credit Memo") OR
       ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::Refund) OR
       ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::"Finance Charge Memo") OR
       ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::Reminder) THEN
      BEGIN
    //    CurrReport.SHOWOUTPUT(FALSE);
        TotalAmountE += "Cust. Ledger Entry".Amount;
      END;
    //OMODNV02 - ADD End
    
    // Totals is calculated by Adding the Document Type: Invoice and Document Type:Credit Memo
    Totals :=TotalAmountIC +  TotalAmountI ;
    //OMODNV04 - ADD End
    
    //OMODNV01 - ADD Start
    //Calculates the AmountOwing by adding the TotalAmountI (Invoice) and TotalAmountP (Payment) and TotalAmountE (EverythingElse)
    AmountOwing := TotalAmountI + TotalAmountP + TotalAmountE;
    //OMODNV01 - ADD End
    

    ( Cust. Ledger entry - PostDateItem ) & (Totals - PostDataItem) has the following code:
    //OMODNV03 - Add Start
    // If the UserDescription Field is empty, it will automatically be set to Cust. Ledger Entries description.
    IF UserDescription = '' THEN
      BEGIN
      //OMODNV04 - ADD Start
        IF ("Cust. Ledger Entry"."Document Type" = "Cust. Ledger Entry"."Document Type"::Invoice) THEN
      //OMODNV04 - ADD End
          UserDescription :=  "Cust. Ledger Entry".Description;
      END;
    //OMODNV03 - Add Start
    

    ScreenShot of what the report looks like now: http://www2.zshare.ma/n7pzojj030sq

    Now it performs the calculations perfectly :thumbsup:. But a whole new issue has been created: If the document type invoice is above the credit memo line, now it wont show the UserDescription. But if its the other way around (credit memo above invoice) it shows the description. ](*,)
  • gerrykistlergerrykistler Member Posts: 149
    Put your UserDescription population in the Cust. Ledger Entry with the totalling.
    Gerry Kistler
    KCP Consultores
  • nvermanverma Member Posts: 396
    :shock:

    It works now!!!

    I have been working with NAV for few months now and I thought I was slowly getting better at troubleshooting and coding but then there are problems like these which I am completely lost.

    Why did moving everything to OnAfterGetRecord (cust. ledger entry) worked??? I sorta see the point of using Totals and putting all the fields in the footer of total but I dont get it at the same time.... Why did it not work initially when we placed the code in the footer of cust. ledger entry???
  • gerrykistlergerrykistler Member Posts: 149
    Because the footer only knows the last record read.
    Gerry Kistler
    KCP Consultores
Sign In or Register to comment.