how to calculate total per Page, could u give me a hand?

OnewayOneway Member Posts: 53
hi,everyone
i am a jackaroo of navision. could u plz give me a hand on below question?

i am trying designing a report for sales invoice. the requirements are every page could hold 4 records if less than 4 there are should be insert blank line. for the second requirement, every page should a total for current page amount be there. i have done the first requiement, but for the second it really beyond me.


thanks lots!!!!

Comments

  • OnewayOneway Member Posts: 53
    thanks, but may be u get me wrong
  • themavethemave Member Posts: 1,058
    He is trying to figure out how to print a page total, not a page number.

    unfortunately, I am trying to find the same thing so I can't help him, but telling to search for page number printing is not the answer he is looking for.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    OK, now I understand.

    You can try to use a TransHeader or TransFooter to print the total so far, as used in some G/L reports (eg. report 4 uses a Transfooter with the text "Continued" ...).

    If you want page totals (a total of only the amounts shown on a page), you can store the totals in some variables. Set these variables to 0 when printing the header on every page (in the OnPreSection-trigger). Give them a value in the OnAfterGetRecord of the Sales Invoice Line dataitem. You can then print those variables in a Footer-section (use PrintOnEveryPage = Yes).

    This way, your page-totals are always initialized, when a new page is started.

    Hope this helps.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • OnewayOneway Member Posts: 53
    hehe!thanx everyone.

    i know the theory, and also tried using a variable and force it be "0" when start a new page. but i am failed

    ###########OnAfterGetRecord

    Lcount+=1;



    IF Lcount>4 THEN
    BEGIN
    //before judge it have added "1", so lcount2:=lcount-1
    LCount2:=Lcount-1;
    //before judge it have added "1", so lcount:=1 not "0"
    Lcount:=0;
    CurrReport.NEWPAGE;
    END;

    PageTotal:=PageTotal+"Sales Invoice Line"."Line Amount";
    IF Lcount=4 THEN
    BEGIN
    PageTotal:=0;
    END;
  • DenSterDenSter Member Posts: 8,307
    No you misunderstand...

    If you set the field to keep totals, you don't have to program anything. Navision will take care of the running totals at the end of the page and the beginning of the page.

    What you need to do is add a TransHeader section and a TransFooter section to your report. Then you make sure that Navision keeps totals of your field, either in the TotalFields property of the dataitem or as a line of code in the OnPreDataitem trigger:
    CurrReport.CREATETOTALS(MyRec.MyField,MyVariable);
    
    Then, all you need to do is put a textbox in the transheader and footer, set the SourceExpr of that textbox to your field or variable, and Navision will put the calculated running total in it. No extra lines of calculation code necessary.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    I don't think he meant a "running total", but a total for the lines shown on the page.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • DenSterDenSter Member Posts: 8,307
    Oh I see, I am the one who misunderstands here :) it's the total of the one page itself he is looking for. Ok, I'll try to elaborate (not looking at Navision right now).

    You make sure you have a header section that prints on every page, as well as a footer section that prints on every page. The you need two variables to keep your total (one to calculate and one to display). The reason that you need two is that if you reset the value of your total in the header section, it will not have the right value by the time you get to the footer section.

    So you have two decimal variables, one called TotalToCalculate, and one called TotalToDisplay. In your footer section, you put a textbox with SourceExpr TotalToDisplay. Then select your header section and open the C/AL editor, and type in the following:
    TotalToCalculate := 0;
    
    This should initialize your page total. I'm not a fan of programming values in a section trigger, but this is one of those cases that you really don't have a choice.

    Then in your OnAfterGetRecord trigger, you do this:
    TotalToCalculate += "Sales Invoice Line"."Line Amount";
    TotalToDisplay := TotalToCalculate;
    
    I believe this should do the trick.
  • SaroSaro Member Posts: 58
    you can also use
    currreport.createtotals(yourvariable)
    Saro
Sign In or Register to comment.