This topic is locked
[SOLVED]

 On the Fly Calculation on inline add row?

12/14/2011 3:36:21 AM
PHPRunner General questions
D
d_gan author

I am using Phprunner 5.3, I have created a Invoice project. It almost complete but I wish to do some touch up to make it more user friendly.

Now I have a invoice table with following structure
ID, Invoice#, Product, Serial#, Quantity, Price, Subtotal.
It work perfectly, when I inline add a number of products by key in product,quantity and price. I can get the Total sum of all products after I "save all".

The problem is I need to see the live Total(sum of sub total) figure before I "Save all". I search the forum and it seam there is no solution on this.

As I have almost completed this project and do not wish to start from scratch by changing the invoice table structure to something like this.
ID, Invoice#, Product, Serial#, Quantity, Price, Subtotal,

ID1, Invoice#1, Product1, Serial#1, Quantity1, Price1, Subtotal1,

ID2, Invoice#2, Product2, Serial#2, Quantity2, Price2, Subtotal2,

ID3, Invoice#3, Product3, Serial#3, Quantity3, Price3, Subtotal3,

ID4, Invoice#4,........
If i wish to have 30 item in a invoice then it will be messy.
How to use javascript to sum up all sub total on the fly when I key in price and quantity?

Or is there a work around for this?

C
cgphp 12/14/2011

Check this article: http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm

Enter the code in the "Javascript onload" event of the Add page.

D
d_gan author 12/14/2011



Check this article: http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm

Enter the code in the "Javascript onload" event of the Add page.


Thank Christian, how to use this code on "inline add" which is on a list page not add page?

C
cgphp 12/14/2011

To use fly calculation for inline add on the list page, you have to enter the js code in the "Javascript onload" event of ADD page.

D
d_gan author 12/15/2011



To use fly calculation for inline add on the list page, you have to enter the js code in the "Javascript onload" event of ADD page.


I believe this is the calculation for a sub total for a row, what I need is the sum of this sub total for the whole column.

7542 12/16/2011

Not sure if this helps. My Javascript is very bad. This is some code that I used for a forecast module to total up 12 months usage. I used on the edit page javascript on load. It works in line and on the edit page.
var ctrljan = Runner.getControl(pageid, 'jan');

var ctrlfeb = Runner.getControl(pageid, 'feb');

var ctrlmar = Runner.getControl(pageid, 'mar');

var ctrlapr = Runner.getControl(pageid, 'apr');

var ctrlmay = Runner.getControl(pageid, 'may');

var ctrljun = Runner.getControl(pageid, 'jun');

var ctrljul = Runner.getControl(pageid, 'jul');

var ctrlaug = Runner.getControl(pageid, 'aug');

var ctrlsep = Runner.getControl(pageid, 'sep');

var ctrloct = Runner.getControl(pageid, 'oct');

var ctrlnov = Runner.getControl(pageid, 'nov');

var ctrldec = Runner.getControl(pageid, 'dec');

var ctrltotal = Runner.getControl(pageid, 'total');
function func() {

ctrltotal.setValue(

parseFloat(ctrljan.getValue().replace(",", ".")) +

parseFloat(ctrlfeb.getValue().replace(",", ".")) +

parseFloat(ctrlmar.getValue().replace(",", ".")) +

parseFloat(ctrlapr.getValue().replace(",", ".")) +

parseFloat(ctrlmay.getValue().replace(",", ".")) +

parseFloat(ctrljun.getValue().replace(",", ".")) +

parseFloat(ctrljul.getValue().replace(",", ".")) +

parseFloat(ctrlaug.getValue().replace(",", ".")) +

parseFloat(ctrlsep.getValue().replace(",", ".")) +

parseFloat(ctrloct.getValue().replace(",", ".")) +

parseFloat(ctrlnov.getValue().replace(",", ".")) +

parseFloat(ctrldec.getValue().replace(",", "."))

);

};
ctrljan.on('keyup', func);

ctrlfeb.on('keyup', func);

ctrlmar.on('keyup', func);

ctrlapr.on('keyup', func);

ctrlmay.on('keyup', func);

ctrljun.on('keyup', func);

ctrljul.on('keyup', func);

ctrlaug.on('keyup', func);

ctrlsep.on('keyup', func);

ctrloct.on('keyup', func);

ctrlnov.on('keyup', func);

ctrldec.on('keyup', func);

7542 12/16/2011

Obviously you can use the tips * instead of + where needed