Page 1 of 1

Calculating total amount of detail sub-form.

Posted: 2015-04-24 12:39
by Thomas Pang
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

Re: Calculating total amount of detail sub-form.

Posted: 2015-05-21 06:27
by Satya Kavala
Hello Thomas,
Please Check Your PM.

Re: Calculating total amount of detail sub-form.

Posted: 2016-02-26 08:10
by vdubuk
Hi Thomas, did you manage to work out how to do it?