I know this has a simple answer but I can't seem to get my head around this search. I have scoured the forums for several hours and can't seem to find an answer. I have a Work_Orders table that has two fields total_labor and total travel. I have a related table Time_Entry that shows up as a grid on the Work_Orders data entry screen that has labor_time and travel_time fields that are date stamped and have a foreign key workorder_id that relates them to the Work_Order record. What I need is a field that uses the beforeSave function in the Delegate Class to update the total fields. I only want to total the entries with the related workorder_id for the record I am in.
Here is what I have so far:
class tables_Work_Orders {
function beforeSave(&$record){
$lab = mysql_query("Select sum(labor_time) from Time_Entry t inner join Work_Orders w where t.workorder_id=w.workorder_id ");
$trv = mysql_query("Select sum(travel_time) from Time_Entry t inner join Work_Orders w where t.workorder_id=w.workorder_id");
$record->setValue('total_labor', $lab);
$record->setvalue('total_travel', $trv);
}
}
All that shows up in the total_labor and total_travel fields is 99.99
TIA
Jason