Bizarre Results from Calc Element

nclaypool

Member
I have a form with a calc element that takes the extended price of a repeating group, adds it up, tacks on the additional fees element then saves that as the grand total.

I've been fiddling with this element for a few days now as it caused all sorts of problems syntax wise when I moved up our PHP version, I've straightened out all the syntax errors but now the calculations are coming back with some unusual results.

PHP:
$po_id = '{purchase_orders___id}';

$mydb = JFactory::getDbo();

$myquery = $mydb->getQuery(true);

$myquery
  ->select('ext_price')
  ->from('purchase_orders_30_repeat')
  ->where('parent_id = ' . $po_id);
$all_ext_price = $mydb->loadColumn();

$subtotal = array_sum($all_ext_price);
$grand_total = $subtotal + '{purchase_orders___additional_fees}';

return $grand_total;

This is the code as it exists today. As an example I created a test record where the grand total should have come back as $1 but instead came back as $74. I have no idea where its getting the values from that allows it to calculate up to an amount that high.

Any guidance would be greatly appreciated.
 
I think I might have figured out where I went wrong here...I was missing the "$mydb->setQuery($myquery);" line.
However, with that line added back in I now get a SQL syntax error: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

PHP:
$po_id = '{purchase_orders___id}';

$mydb = JFactory::getDbo();

$myquery = $mydb->getQuery(true);

$myquery
  ->select('ext_price')
  ->from('purchase_orders_30_repeat')
  ->where('parent_id = ' . $po_id);
 
 
$mydb->setQuery($myquery);
$all_ext_price = $mydb->loadColumn();

$subtotal = array_sum($all_ext_price);
$grand_total = $subtotal + '{purchase_orders___additional_fees}';

return $grand_total;
 
In new records '{purchase_orders___id}' will be empty.
Also you won't have the repeat group values in the DB before the record is saved. What should the calc element display in the form?
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top