Calculating total amount of detail sub-form.
Posted: 2015-04-24 12:39
Hi,
I create an orders(parent table) and order_details(sub-form table), I would like to sum the Amount of sub-form table and update to the field called SubTotal of the parent table:
// OrderID_D - sub-form field that contain order id, Amount - total of each item
// SubTotal - parent field to keep total item amount of sub-form table
$id = makeSafe($data['OrderID_D']);
$tot = sqlValue("SELECT SUM(Amount) FROM order_details WHERE OrderID_D='$id' ");
sql("UPDATE orders SET SubTotal = '$tot' WHERE OrderID='$id'", $eo);
I get zero SubTotal after keeping the above code in the sub-form function order_details_after_update($data, $memberInfo, &$args), am I coded wrongly or keeping at the wrong function?
Any help will be appreciated.
Regards
Thomas Pang
I create an orders(parent table) and order_details(sub-form table), I would like to sum the Amount of sub-form table and update to the field called SubTotal of the parent table:
// OrderID_D - sub-form field that contain order id, Amount - total of each item
// SubTotal - parent field to keep total item amount of sub-form table
$id = makeSafe($data['OrderID_D']);
$tot = sqlValue("SELECT SUM(Amount) FROM order_details WHERE OrderID_D='$id' ");
sql("UPDATE orders SET SubTotal = '$tot' WHERE OrderID='$id'", $eo);
I get zero SubTotal after keeping the above code in the sub-form function order_details_after_update($data, $memberInfo, &$args), am I coded wrongly or keeping at the wrong function?
Any help will be appreciated.
Regards
Thomas Pang