This topic is locked

Need Help

5/29/2016 2:05:57 AM
PHPRunner General questions
S
spluskhan author

*I have some serious prob with my app.
i want to calculate the following fields into Total Amount:
Total + GST (fields) to get Overall total amount...
But the prob is:

Total field is define as CUSTOM code >> $value = ($data["price"]
$data["quantity"]) ;

and

GST field is define as CUSTOM code >> 10%
When i code CUSTOM in Total Amount Field to get total:

$value = ($data["total"] + $data["gst"]) ;

it show blank.
How do i calculate custom fields??

**

HJB 5/29/2016

Why to run CUSTOM CODE? On simple issues like that?
Citing example code ex http://www.xlinesoft.com/articles/how_to_use_calculated_fields.htm
quote
PHPRunner Example
$values["Tax"] = 0.01$values["Price"] + 2$values["Horsepower"];
unquote

S
spluskhan author 5/30/2016

Not working, any solution ?

lefty 5/30/2016



Not working, any solution ?


Walkfly has the correct answer above . delete your total field
and add in your query.
((price * quantity) + gst) AS totalcalculation,
Then check off totalcalculation in query designer and set up as readonly. That's it.

If you want to do it on the fly in add/edit pages see link from walkfly above for JavaScript onload.

HJB 5/31/2016

Try this, to be placed in the EVENTS section of PHPR, here in the EDIT subsection, under BEFORE RECORD UPDATED:
$values["total_amount"] = ($values["price"] $values["quantity"]) + ($values["total"] $values["gst"]);
In other words, EVENT oriented programming has really nothing to do with FIELD oriented (custom) programming at all as the values are called from named fields BEFORE the update.
I tried this on a more simpler "price * quantity = total" sample programming at my end and it worked fine.
HTH

S
spluskhan author 5/31/2016

So what do you suggest i have to remove CUSTOM coding in total field??

HJB 5/31/2016

Yes ..., further sent a PM to you few seconds ago where to download the demo project file of mine (under PHPRunner 9.0 beta) which includes the SQL file to get imported via PHPMyAdmin.