(DEV) Where to clear total variables on a report

redhotmustangredhotmustang Member Posts: 91
Hi there,

I'm correcting a report that lists student's expenses.

The report first shows the list of expenses student by student.
Like:
Student - Description - Quantity - Amount
Student 1 - Lunch - 2 - $25
Student 1 - Gym - 1 - $50
TotalStudent = $100

Student - Description - Quantity - Amount
Student 2 - Lunch - 3 - $25
Student 1 - Gym - 2 - $50
TotalStudent = $175

Grand Total (All students) - $275
I use a variable to multiply the amount by the quantity, and then a new var that adds the student's total.

This code is on the body section
QtdAmount := Quantity * Amount;
TotalStudent := TotalStudent + QtdAmount;

The TotalStudent is on the group footer section.

The issue is that when I proccess the following sudent the TotalStudent brings the info (the total) of the previous student.

I'm trying to clear this variable. But I don't know where to do it.
In which section?

Thank you in advance.
Regards.
Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)

Answers

  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Add one more group footer down the one you are talking about.
    there in OnPreSection() OR OnPostSection() clear the variable
    (TotalStudent = 0;)


    And how about adding (TotalStudent = 0;) in the OnPostSection() of the Group Footer you are talking about......??
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • BBlueBBlue Member Posts: 90
    Hello,

    I understand you group by student code probably. You can have a structure with
    Currreport.CREATETOTALS(QtdAmount);
    
    in OnPreDataItem of your DataItem. then show QtdAmount variable in Group Footer section.

    In the end you can add a Footer section for the dataitem and show again QtdAmount variable for grand totals.
    //Bogdan
  • redhotmustangredhotmustang Member Posts: 91
    And how about adding (TotalStudent = 0;) in the OnPostSection() of the Group Footer you are talking about......??

    That makes the TotalStudent appears as 0. That is, it calculates the total and then clears it. And in the report the total appears as 0.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    And what about the 1st one..
    Add one more group footer down the one you are talking about.
    there in OnPreSection() OR OnPostSection() clear the variable
    (TotalStudent = 0;)
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • redhotmustangredhotmustang Member Posts: 91
    Problem solved.

    I cleared the variable in Student Group Header. That is, every time a student is processed the variable is cleared.

    We have to clear before every student is processed.

    Thanks!
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • redhotmustangredhotmustang Member Posts: 91
    Second part of the report:
    Now I need to add the expenses from all the students per service (like lunches, classes, books).

    Like this:
    Service TotalQuantity TotalAmount
    Lunch 5 $100
    Books 3 $300
    Classes 1 $50
    GrantTotal $450

    The TotalAmount is the Quantity * Amount (that is, the TotalAmount has already this value calculated).

    There is a field Description with the name of the service adquired, and the TotalAmount for that service that totals all the Students expenses for that service.

    The GrandTotal is the total of all services.

    I'm trying to code it, like this:
    TotalAmount := Quantity * Amount
    

    But this will only calculate the last quantity found * last amount found.
    I mean if student A has bougth 2 lunches, and student B 3 lunches, it will multiply the quantity of last student times the amount of the last student.
    I need to multiply the quantity per amount, student by student, because some students have discounts. And not the total of quantities times the total of amounts.

    I tried lots of things, but I can't find the answer.
    Hope you can help me, thanks.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • redhotmustangredhotmustang Member Posts: 91
    Problem solved.

    I had to code it on the dataitem OnAfterGetRecord() trigger.
    I cleared the variable, and add the amount * quantity for every service.

    I was trying to code it on the group footer section.

    Regards.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
  • DenSterDenSter Member Posts: 8,305
    As I was reading your post I was preparing to tell you never to write any data manipulation code in any of the section triggers. Everything data related should be in dataitem triggers. Section triggers should really only be for layout, formatting, and whether the section is printed or not.

    That is by far THE most important lesson to be learned in NAV report writing, and you seemed to have picked up on that yourself. Well done :mrgreen:
  • redhotmustangredhotmustang Member Posts: 91
    Thank you very much. Lesson learned.
    Experimenting is the most important part of the learning process! But I only wish I add more time to study in order to get things done easier and faster when my teammates ask me.

    Regards.
    Redcodestudio: Web Development, FLASH & Webdesign (and a little NAV, in the future)
Sign In or Register to comment.