+ // 1. calculate sums of material/labour/overhead costs
+
+ // sum collected BOM material & labour costs (no way for separate overhead here for now - needs flag in bom or stock_master)
+ $bom = get_wo_requirements($woid);
+ $m_cost = $l_cost = 0;
+ while ($component = db_fetch($bom))
+ {
+ if (!is_service($component["mb_flag"]))
+ $m_cost += $component['unit_cost']*$component['units_issued'];
+ else
+ $l_cost += $component['unit_cost']*$component['units_issued'];
+ }
+
+ // add additional material issues
+ $issues = get_additional_issues($woid);
+ while ($issue = db_fetch($issues))
+ {
+ if (!is_service($issue["mb_flag"]))
+ $m_cost += $issue['unit_cost']*$issue['qty_issued'];
+ else
+ $l_cost += $issue['unit_cost']*$issue['qty_issued'];
+ }
+
+ // and additional costs
+ $o_cost = get_gl_wo_cost($woid, WO_OVERHEAD);
+ $l_cost += get_gl_wo_cost($woid, WO_LABOUR);
+
+ $total_cost = $o_cost + $m_cost + $l_cost;
+
+ add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $product['wip_account'],
+ 0, 0, $memo, -$total_cost);
+
+ add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $product['inventory_account'],
+ 0, 0, $memo, $total_cost);