This topic is locked

Implementing Running Total In Phprunner

6/7/2013 4:58:17 PM
PHPRunner Tips and Tricks
admin

As Wikipedia says "running total is the summation of a sequence of numbers which is updated each time a new number is added to the sequence, simply by adding the value of the new number to the running total". It is also known as running sum or running balance.
Adding running total to one of list pages is really simple. Lets consider table Balance with fields ID and Amount.
1.Modify SQL query adding a calculated Total field:

SELECT

ID,

Amount,

0 as Total

from Balance


2. Events Editor, Balance table: BeforeProcessList event:

$_SESSION["Total"]=0;


We are going to accumulate the current total amount in session variable $_SESSION["Total"]. This variable needs to be reset when page is loaded.
3. 'Total' field in Visual Editor. Set 'View as' type to 'Custom' and use the following code:

$_SESSION["Total"] += $data["Amount"];

$value = $_SESSION["Total"];


This is it. Here is how it looks in live application.

90288 8/4/2017



As Wikipedia says "running total is the summation of a sequence of numbers which is updated each time a new number is added to the sequence, simply by adding the value of the new number to the running total". It is also known as running sum or running balance.
Adding running total to one of list pages is really simple. Lets consider table Balance with fields ID and Amount.
1.Modify SQL query adding a calculated Total field:

SELECT

ID,

Amount,

0 as Total

from Balance


2. Events Editor, Balance table: BeforeProcessList event:

$_SESSION["Total"]=0;


We are going to accumulate the current total amount in session variable $_SESSION["Total"]. This variable needs to be reset when page is loaded.
3. 'Total' field in Visual Editor. Set 'View as' type to 'Custom' and use the following code:

$_SESSION["Total"] += $data["Amount"];

$value = $_SESSION["Total"];


This is it. Here is how it looks in live application.




Great this is wonderfull, How about if it is grouped by column like Customer for example?

jadachDevClub member 1/8/2018

This just came in very handy for a project I am doing. Does anyone know how I can format the total field to currency? I am using C#.

I tried this on View As Custom, but it doesn't make any change.

XSession.Session["Total"] += data["Budgeted"].ToString();

value = String.Format("{0:C}", XSession.Session["Total"]);



Thanks!!

admin 1/16/2018

Jerry,
I just double checked in ASPRunner.NET, your code works with both integer and floating point values. What results are you getting?

jadachDevClub member 1/16/2018



Jerry,
I just double checked in ASPRunner.NET, your code works with both integer and floating point values. What results are you getting?


I am using floats in my sql server database. I would love to be able to display the running total as currency. But no matter what I try, I end up with this:


Thanks

admin 1/17/2018

Jerry,
got it, I thought there were an issue with calculation. You need to convert it to float first.

XSession.Session["Total"] += data["Budgeted"].ToString();

value = String.Format("{0:C}", float.Parse(XSession.Session["Total"]));
jadachDevClub member 1/17/2018



Jerry,
got it, I thought there were an issue with calculation. You need to convert it to float first.

XSession.Session["Total"] += data["Budgeted"].ToString();

value = String.Format("{0:C}", float.Parse(XSession.Session["Total"]));



It's a thing of beauty. The app looks great now. Thank you so much.